I'm writing my own python wrapper on top of official mysqldb connector. I'm trying to design method that would dynamically extract row data knowing KEY ID.
SELECT * FROM cameras;
+----------+----------------------+-----------+------------+
| cameraID | cameraName | fullframe | sensorSize |
+----------+----------------------+-----------+------------+
| 2 | Canon EOS 5D Mark II | 1 | 36x24 |
| 3 | Nikon | 1 | 10x10 |
+----------+----------------------+-----------+------------+
knowing table name ("cameras" in example above), and primaryID key integer value (but not primaryID column name), how can i get a row ?
if I had primary key column name, than i could construct:
mysql> SELECT * FROM cameras WHERE cameraID=2;
But How can I ask for it without column name ? Is there something like "WHERE ID=#" or "WHERE 'COLUMN KEY'=#"?
Edit:
I was trying to create multistatement:
mysql> SELECT @columnID:=`COLUMN_NAME` AS columnID FROM `information_schema`.`COLUMNS` WHERE (`TABLE_NAME` = 'cameras') AND (`COLUMN_KEY` = 'PRI');
+----------+
| columnID |
+----------+
| cameraID |
+----------+
but mysql did not allow me to use variable as column name directly:
mysql> SELECT * FROM cameras WHERE ', @columnID, '= '2';
Empty set (0.00 sec)
Best Answer
So I found one 'solution' for mysql:
As I am using python connector to execute those commands, I had to modify it to different approach. Multiquery was not working for me in this case
(2, 'Canon EOS 5D Mark II', 1, '36x24')