我有以下插入语句的代码。
cursor = self.conn.cursor()
print("New config with values: {0}, {1}".format(self.scale_factor, self.min_neighbours))
cursor.execute("INSERT INTO config(scale_factor, min_neighbours) VALUES(?,?)", float(self.scale_factor), int(self.min_neighbours))
self.conn.commit()
record_id = cursor.execute('SELECT @@IDENTITY AS id;').fetchone()[0]
if record_id:
self.id = record_id
print("Insertion succesfull. Generated id: {0}".format(record_id))
else:
print("Insertion failed.")
插入成功,但除身份列外未插入任何数据。
程序输出:
New config with values: 0, 0.08
Config insertion succesfull. Inserted id: 176
从表中选择:
id | scale_factor | min_neighbours
176 | 0.0000 | 0
从SQL事件探查器插入:
INSERT INTO config(scale_factor, min_neighbours) VALUES(0.0,0)
有人知道为什么这些值为零吗?我是python的新手。