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?)',('2017-05-28','12:23:32' 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:?,?,?)',('2017-05-28','12:23:233 , 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,',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)