replace the name of table before calling *.execute. s.dbptr.execute(str % (e[0]))
good luck. Edwin -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Evan Sent: Thursday, August 14, 2008 11:27 AM To: python-list@python.org Subject: a question about mysqldb 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: +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ >>> str="select tID,tNote from %s where tID=1" <-------- check here >>> >>> e=["tmp"] >>> s.dbptr.execute(str,e) 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.errorhandler(self, exc, value) File "/usr/lib/python2.4/site-packages/MySQLdb/connections.py", line 35, in defaulterrorhandler raise errorclass, errorvalue _mysql_exceptions.ProgrammingError: (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.execute(str,e) 0L <------------------ check here >>> >>> s.dbptr.fetchall() () >>> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ And then, it worked if I do: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ >>> str="select tID,tNote from %s where %s = %s" % ("tmp","tID",1) >>> >>> str 'select tID,tNote from tmp where tID = 1' >>> s.dbptr.execute(str) 1L >>> >>> s.dbptr.fetchall() ({'tID': 1L, 'tNote': 'kao'},) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ mysql> desc 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, -- http://mail.python.org/mailman/listinfo/python-list The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list