因此,我试图将一个变量(字符串)添加到另一个变量(表)中。我的代码如下所示:
tableName = '123456789'
testVariable = 'test'
c.execute('INSERT INTO ' + tableName + ' (testColumn) VALUES (' + testVariable + ')')
conn.commit()
但出于某种原因,它给了我这个错误
c.execute('INSERT INTO ' + tableName + ' (testColumn) VALUES (' + testVariable + ')')
sqlite3.OperationalError: near "123456789": syntax error
我该怎么办
好的,我自己设法修好了。我必须在变量的开头和结尾添加单引号,然后使用:
c.execute("INSERT INTO {} (testColumn) VALUES ({})".format(tableName, testVariable))
谢谢你的回答
试试这个
相关问题 更多 >
编程相关推荐