Python 如何在向每列插入null时,仅将一个值作为变量插入sqlite3表
我想修改下面的代码,以便只向表中插入Python 如何在向每列插入null时,仅将一个值作为变量插入sqlite3表,python,sqlite,tkinter,insert,Python,Sqlite,Tkinter,Insert,我想修改下面的代码,以便只向表中插入input变量。所有其他列应存储NULL值。我认为最明显的解决方案是声明column2=NULL和column3=NULL,但我在想还有其他方法吗 import sqlite3 column1 = input() sqliteConnection = sqlite3.connect('database.db') cursor = sqliteConnection.cursor() sqlite_insert_with_param = "INSE
input
变量。所有其他列应存储NULL
值。我认为最明显的解决方案是声明column2=NULL
和column3=NULL
,但我在想还有其他方法吗
import sqlite3
column1 = input()
sqliteConnection = sqlite3.connect('database.db')
cursor = sqliteConnection.cursor()
sqlite_insert_with_param = "INSERT INTO ideas (column1, column2, column3) VALUES (?, ?, ?);" #column1 is primary key
data_tuple = (column1, column2, column3)
cursor.execute(sqlite_insert_with_param, data_tuple)
sqliteConnection.commit()
cursor.close()
最后,我希望它能在Tkinter应用程序中工作,该应用程序使用
条目
-小部件提示用户输入第1列,并且它将创建数据库条目,而不包含主键以外的任何其他信息。如果您从列表中删除其他列,例如:
sqlite_insert_with_param = "INSERT INTO ideas (column1) VALUES (?);"
data_tuple = (column1,)
cursor.execute(sqlite_insert_with_param, data_tuple)
sqliteConnection.commit()
然后,新插入行中的column2
和column3
将为null
,除非您在表的定义中为它们定义了默认值