[Python] Problemi in scrittura DB con executemany()

Maria Grazia Toffetti grazia.toffetti a gracelab.it
Mar 7 Ott 2008 23:37:51 CEST


guarda se è il tuo caso

http://mysql-python.sourceforge.net/FAQ.html#other-errors

Starting with 1.2.0, MySQLdb disables autocommit by default, as required by
the DB-API standard (PEP-249). If you are using InnoDB tables or some other
type of transactional table type, you'll need to do connection.commit()
before closing the connection, or else none of your changes will be written
to the database.

Grazia

On Mon, Oct 6, 2008 at 9:25 PM, Francesco Martino <
francesco.martino a unipd.it> wrote:

> Chiedo scusa ma ho riportato il codice in modo errato.
> Di seguito si trova quello corretto:
>
>
>
> ****************************************************************************************************************
> import MySQLdb
>
> db = MySQLdb.connect(host = 'localhost', db = 'nome_db', user = 'user',
> passwd = 'password')
> cur = db.cursor()
>
> def createTable(curs):
>     curs.execute('SELECT tab1.valA, tab1.valB, tab2.valC, tab2.valD\
>    FROM tab1 JOIN tab2 \
>    ON tab1.valE = tab2.valE\
>    WHERE tab1.valA>0')
>    for data in cur.fetchall():
>        dataList.append(data)
>     curs.execute('CREATE TABLE tab3 (\
>       valA char(50),\
>      valB char(50),\
>      valC char(50),\
>      valD char(50))')
>    print 'tabella costruita...'
>    curs.executemany("INSERT INTO tab3 (valA, valB, valC, valD) \
>      VALUES (%s,%s,%s,%s)", dataList)
>    print 'valori inseriti'
>
> if __name__= '__main__':
>    createTable(cur)
>
> ****************************************************************************************************************
>
> Francesco
> _______________________________________________
> Python mailing list
> Python a lists.python.it
> http://lists.python.it/mailman/listinfo/python
>
-------------- parte successiva --------------
Un allegato HTML è stato rimosso...
URL: http://lists.python.it/pipermail/python/attachments/20081007/800917cf/attachment-0001.htm 


Maggiori informazioni sulla lista Python