【发布时间】:2018-02-24 00:27:03
【问题描述】:
使用时:
import datetime
import sqlite3
db = sqlite3.connect('mydb.sqlite', detect_types=sqlite3.PARSE_DECLTYPES)
c = db.cursor()
db.text_factory = str
c.execute('create table if not exists mytable (date timestamp, title str, \
custom str, x float, y float, z char default null, \
postdate timestamp default null, id integer primary key autoincrement, \
url text default null)')
c.execute('insert into mytable values(?, ?, ?, ?, ?)', \
(datetime.datetime(2018,4,23,23,00), 'Test', 'Test2', 2.1, 11.1))
我有:
sqlite3.OperationalError: table mytable 有 9 列但提供了 5 个值
为什么 SQlite 不采用默认值(在表创建期间指定)来考虑填充新行?
(另外,当我重新打开我几年前写的一个项目时,我在 sqlite3 文档中找不到 str、char 数据类型了,它仍然相关吗?)
【问题讨论】: