Drop Table w/ MySQLdb?
Thomas Jollans
thomas at jollans.com
Sun Jun 6 15:38:33 EDT 2010
On 06/06/2010 05:07 PM, Victor Subervi wrote:
> Hi;
> I tried this:
>
> cursor.execute('drop table tmp%s', tmpTable)
It looks like you're trying to %s-insert *part* of the table name. I
doubt any DB interface allows that. cursor.execute('drop table %s',
table_name) might work, otherwise, you'll have to write the query
yourself, in full.
>
> and got this error:
>
> Traceback (most recent call last):
> File "/var/www/html/angrynates.com/cart/cart.py
> <http://angrynates.com/cart/cart.py>", line 196, in ?
> cart()
> File "/var/www/html/angrynates.com/cart/cart.py
> <http://angrynates.com/cart/cart.py>", line 189, in cart
> cursor.execute('drop table tmp%s', tmpTable)
> File "/usr/lib64/python2.4/site-packages/MySQLdb/cursors.py", line
> 163, in execute
> self.errorhandler(self, exc, value)
> File "/usr/lib64/python2.4/site-packages/MySQLdb/connections.py",
> line 35, in defaulterrorhandler
> raise errorclass, errorvalue
> 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 ''127541158007'' at line 1")
>
> But when I print that statement out (exchanging the comma for a %) and
> manually enter it:
>
> mysql> drop table tmp127541158007;
> Query OK, 0 rows affected (0.00 sec)
>
> I am able to successfully drop the table. Why?
> TIA,
> beno
More information about the Python-list
mailing list