Tim Chase a écrit :
sql = ''' INSERT INTO table (column1,column2, ...) VALUES ( %s,
%s, ....); '''
for row in rows:
connection.cursor.execute(sql % (row[0],row[1],....))
connection.corsur.commit()
(snip)
The first step is to use the database's quoting to prevent problems
where miscreant characters (such as a single-quote) appear in the data:
connection.cursor.exeute(sql, (row[0], row[1]))
instead of
connection.cursor.exeute(sql % (row[0], row[1]))
(if your columns in your CSV happen to match the order of your INSERT
statement, you can just use
execute(sql, tuple(row))
Or more simply:
cursor.execute(sql, row)
--
http://mail.python.org/mailman/listinfo/python-list