다크매터 다크매터 - 3 years ago 214
Python Question

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"):
print(i)


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?

Answer Source

From what I understand you do not need to pass the number in query as it is set to autoincrement.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download