a simple problem but I do not know why...:(, could anyone help me?
MySQLdb nominally uses just the %s placeholder style, in my script, i
got error if you want to use placeholder(%s) for table name:
+++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ +
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.4/site-packages/MySQLdb/cursors.py", line
166, in execute
self.errorhandl er(self, exc, value)
File "/usr/lib/python2.4/site-packages/MySQLdb/connections.py" , line
35, in defaulterrorhan dler
raise errorclass, errorvalue
_mysql_exceptio ns.ProgrammingE rror: (1064, "You have an error in your
SQL syntax; check the manual that corresponds to your MySQL server
version for the right syntax to use near ''tmp') where tID=1' at line
1")
+++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ ++++
But sql worked but the I got no query result:
+++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ ++++
0L <------------------ check here
()
+++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ ++++
And then, it worked if I do:
+++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ ++++
'select tID,tNote from tmp where tID = 1'
1L
({'tID': 1L, 'tNote': 'kao'},)
+++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ ++++
+++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ ++++
mysqldesc tmp
-;
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| tID | int(11) | NO | PRI | NULL | auto_increment |
| tDate | date | YES | | NULL | |
| tSID | int(11) | NO | | NULL | |
| tCom | varchar(15) | YES | | NULL | |
| tNote | text | YES | | NULL | |
+-------+-------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)
+++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++
mysql>
mysql>
Thanks,
MySQLdb nominally uses just the %s placeholder style, in my script, i
got error if you want to use placeholder(%s) for table name:
+++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ +
>>str="select tID,tNote from %s where tID=1" <-------- check here
>>>
>>e=["tmp"]
>>>
>>e=["tmp"]
>>s.dbptr.execu te(str,e)
File "<stdin>", line 1, in ?
File "/usr/lib/python2.4/site-packages/MySQLdb/cursors.py", line
166, in execute
self.errorhandl er(self, exc, value)
File "/usr/lib/python2.4/site-packages/MySQLdb/connections.py" , line
35, in defaulterrorhan dler
raise errorclass, errorvalue
_mysql_exceptio ns.ProgrammingE rror: (1064, "You have an error in your
SQL syntax; check the manual that corresponds to your MySQL server
version for the right syntax to use near ''tmp') where tID=1' at line
1")
>>>
But sql worked but the I got no query result:
+++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ ++++
>>str="select tID,tNote from tmp where %s = %s" <----------check here
>>e=["tID",int(1 )]
>>s.dbptr.execu te(str,e)
>>e=["tID",int(1 )]
>>s.dbptr.execu te(str,e)
>>>
>>s.dbptr.fetch all()
>>s.dbptr.fetch all()
>>>
And then, it worked if I do:
+++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ ++++
>>str="select tID,tNote from %s where %s = %s" % ("tmp","tID" ,1)
>>>
>>str
>>>
>>str
>>s.dbptr.execu te(str)
>>>
>>s.dbptr.fetch all()
>>s.dbptr.fetch all()
+++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ ++++
+++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ ++++
mysqldesc tmp
-;
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| tID | int(11) | NO | PRI | NULL | auto_increment |
| tDate | date | YES | | NULL | |
| tSID | int(11) | NO | | NULL | |
| tCom | varchar(15) | YES | | NULL | |
| tNote | text | YES | | NULL | |
+-------+-------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)
+++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++
mysql>
mysql>
Thanks,
Comment