我在 sqlite3 中创建了一个表,结构如下:
cid name type notnull pk
0 wheelId INTEGER 1 1
1 wheelName VARCHAR 1 0
2 paraDiam INTEGER 0 0
3 paraWidth FLOAT 0 0
4 paraEt FLOAT 0 0
5 paraHole INTEGER 0 0
6 factParaHole INTEGER 0 0
7 paraCenterhole FLOAT 0 0
8 wheelColorName VARCHAR 0 0
9 wheelColorNameShow TEXT 0 0
10 paraWeight FLOAT 0 0
11 vpPrice INTEGER 0 0
12 ntStock INTEGER 0 0
13 wheelURL VARCHAR 0 0
14 wheelImg VARCHAR 0 0
15 wheelRank INTEGER 0 0
现在,我使用python向表中插入一条记录,我只想插入列值'wheelName','wheelImg'并将其他列保持为空,(第一个是wheelId
,我希望它可以增加自动)。
我几乎使用了网站上可以找到的所有方法:
cursor.execute("""INSERT INTO WHEELS (wheelName,wheelImg) VALUES (%s,%s)""" , (WHEELNAME,WHEELIMG))
Python 抛出
sqlite3.OperationalError: near "%": syntax error
cursor.execute("""INSERT INTO WHEELS(WHEELID,WHEELNAME, PARADIAM, PARAWIDTH, PARAET,PARAHOLE,FACTPARAHOLE, PARACENTERHOLE,WHEELCOLORNAME,WHEELCOLORNAMESHOW,PARAWEIGHT,VPPRICE,NTSTOCK, WHEELURL,WHEELIMG,WHEELRANK) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)""" , (WHEELID, WHEELNAME, PARADIAM, PARAWIDTH, PARAET,PARAHOLE,FACTPARAHOLE, PARACENTERHOLE,WHEELCOLORNAME,WHEELCOLORNAMESHOW,PARAWEIGHT,VPPRICE,NTSTOCK, WHEELURL,WHEELIMG,WHEELRANK))
我将其他值设置为None
:
PARADIAM = None
PARAWIDTH = None
PARAET = None
PARAHOLE = None
和 python 再次抛出sqlite3.OperationalError: near "%": syntax error
.