简体   繁体   中英

How do I run the sqlite3 insert statement once in Python?

import sqlite3

conn = sqlite3.connect('test3.db')
cursor = conn.cursor()

cursor.execute("""create table if not exists test(
num integer primary key autoincrement,
name char(5))""")

cursor.execute("insert into test(num, name) values(null, 'andy')")
conn.commit()    

for i in cursor.execute("select *from test"):
if int(i[0]) <= 1:  
    conn.commit()
else:       
    conn.close()

I put the sqlite3 value in wx.combobox , choices and have the changed value applied to sqlite3 when the wx.combobox value is changed. I have a problem during operation and want to fix it.

When you run the program cursor.execute ("insert into test (num, name) values ​​(null, 'andy')") This statement continues execution. How do I get my program to run once when I run it?

据我了解,您无需在查询中传递数字,因为它已设置为自动增量。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM