Drop Table w/ MySQLdb?
James Mills
prologic at shortcircuit.net.au
Sun Jun 6 11:29:45 EDT 2010
On Mon, Jun 7, 2010 at 1:07 AM, Victor Subervi <victorsubervi at gmail.com> wrote:
> Hi;
> I tried this:
>
> cursor.execute('drop table tmp%s', tmpTable)
>
> and got this error:
>
> Traceback (most recent call last):
> File "/var/www/html/angrynates.com/cart/cart.py", line 196, in ?
> cart()
> File "/var/www/html/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?
If I remember correctly, you should use '?', eg:
cursor.execute("DROP TABLE ?", my_table)
cheers
James
More information about the Python-list
mailing list