python - SQL Server:pypodbc 插入空值
问题描述
我有以下插入语句的代码。
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 Profiler 插入:
INSERT INTO config(scale_factor, min_neighbours) VALUES(0.0,0)
有谁知道为什么这些值为零?我是蟒蛇的新手。
解决方案
推荐阅读
- sql - 如何将行插入到具有自动递增的外键的表中,而无需对父表进行多次查询
- r - R使用带有循环的变异进行变量比较
- api - 有什么方法可以使用 Azure DevOps Rest API 针对任何/多个事件类型创建订阅?
- php - Yii2 - wrong order of loaded CSS - extension's CSS breaks the layout
- python-3.x - merging multiple columns into one column
- javascript - 单击按钮 1 周后不显示横幅?
- function - 依赖顺序验证的设计模式
- python - a dynamic dataframe range
- xml - Resharper - Format
- python - Total sum of a list of numbers with list iteration