info = "'INSERT INTO brush_card_record(brush_card_date, brush_card_time, card_num_6061, card_num_6654) VALUES(?,?,?,?)',('2017-05-28','12:23:32', 123, 0)"
cur.execute(info)
这样会报错:sqlite3.OperationalError
cur.execute('INSERT INTO brush_card_record(brush_card_date, brush_card_time, card_num_6061, card_num_6654) VALUES(?,?,?,?)',('2017-05-28','12:23:32', 123, 0))
这样就可以运行。
世界只因有你2017-06-12 09:29:56
info =“插入brush_card_record(brush_card_date,brush_card_time,card_num_6061,card_num_6654)值(%s,%s,%s,%s)”%('2017-05-28','12:23:32',123 , 0)
或者str.format
曾经蜡笔没有小新2017-06-12 09:29:56
问题已找到,谢谢回答的朋友!
数据库表插入新数据为动态时,更好的处理方式是先生成str,然后作为参数传进cur.execute()中。
代码示例:
insert_info = '''\
INSERT INTO %s(brush_card_date, brush_card_time, card_num_6061, card_num_6654) \
VALUES("%s", "%s", %s, %s)''' % (f_table_name, date, now_time, gold_6061, gold_6654)
cur.execute(insert_info)