Форум сайта python.su
Имею такой код:
import MySQLdb conn = MySQLdb.connect (host = "localhost", user = "root", passwd = "password", db = "devdb") cursor = conn.cursor () ## skipped for key in y: ## skipped text = str(sortedlist)[1:-1] print "TEXT for id = %d" %key, text #cursor.execute('INSERT INTO similar_tags (tag_id,ids_text) VALUES (%d,"%s"); '\ # %(key,text)) s ="INSERT INTO similar_tags (tag_id,ids_text)\ VALUES (%d,'%s'); "\ %(key,text) print "s= ",s #cursor.execute(s) cursor.execute(""" INSERT INTO similar_tags (tag_id,ids_text)\ VALUES (%s,%s); """,(key,text) ) print "Number of rows inserted: %d" % cursor.rowcount
TEXT for id = 7 8L, 6L, 5L, 4L, 3L, 2L, 1L
s= INSERT INTO similar_tags (tag_id,ids_text) VALUES (7,'8L, 6L, 5L, 4L, 3L, 2L, 1L');
Number of rows inserted: 1
TEXT for id = 8 7L, 6L, 5L, 4L, 3L, 2L, 1L
s= INSERT INTO similar_tags (tag_id,ids_text) VALUES (8,'7L, 6L, 5L, 4L, 3L, 2L, 1L');
Number of rows inserted: 1
Офлайн
conn.commit() ?
When you are finished with a transaction, you should execute either db.commit() or db.rollback(). If your server and tables don't support transactions, commit() will still work, but rollback() will raise an exception. Note carefully that these are methods of the connection and not methods of the cursor, even though c.execute(…) is what started the transaction.
Отредактировано (Март 3, 2008 00:26:02)
Офлайн
Если тип таблицы InnoDB - надо коммит делать полюбому.
Офлайн
Спасибо большое.
Офлайн