[Tutor] what is wrong with this code?

Norman Khine norman at khine.net
Mon Apr 26 19:45:13 CEST 2010


thanks for the reply.

On Mon, Apr 26, 2010 at 7:18 PM, Serdar Tumgoren <zstumgoren at gmail.com> wrote:
>
>> user_tables = ['notification', 'userNotification', 'product_comments',
>> 'product_donation_paypalTransaction', 'product_donation',
>> 'productList_recommended', 'productList_user_assoc',
>> 'profile_values']
>>
>> drop_user_tables = """DROP TABLE IF EXISTS db2.%s"""
>>
>> try:
>>    cursor.execute(drop_user_tables, (x for x in user_tables))
>
> Norman,
> It looks like what you're after is the cursor's "executemany" method, which
> is supported by many common database adapters that comply with DB-API2.0.
>
> If you're using sqlite3, there are more details here:
>
>     http://docs.python.org/library/sqlite3.html#sqlite3.Cursor.executemany
>
> In your code, you seem to be trying to loop over the values in the
> user_tables list. I haven't tested this, but instead try simply passing the
> list of user_tables to executemany:
>
>     cursor.executemany(drop_user_tables, user_tables)

i am using MySQLdb, to make changes to a database.
>
> If the above doesn't work or is not available with your database adapter,
> how about just using a simple loop?
>
> for table in user_tables:
>     cursor.execute(drop_user_tables, (table,))

both ways, i got this error:

$ py upgrade.py
Error (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 ''notification'' at line 1")
aqoon:ookoodoo khinester$ py upgrade.py
Error (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 ''notification'' at line 1")

but my query, is fine:

drop_user_tables = """DROP TABLE IF EXISTS db2.%s"""


>
>
>


More information about the Tutor mailing list