python - 无法将变量添加到表中
问题描述
所以,我试图将一个变量(字符串)添加到另一个变量(表)中。我的代码如下所示:
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 (?)", (tableName, testVariable))
推荐阅读
- linux - sed 在一行中更改未知字符串,其余部分保持不变
- erlang - Erlang- maps:iterator/1 & maps:next/1 已弃用?
- python - django 如何在单个字典中获取状态计数
- html - HTML 文本中的错误不在其块中
- node.js - 如何在 Meteor 应用程序中使用 Node JS 创建交互式 ssh 终端并从浏览器输入命令
- python-3.x - 无法在 RHEL7 的 Chrome 中使用 Selenium Python 中的 send_keys() 输入“/”
- python - 如何提高 Project Euler 练习的运行时间
- python - 访问放在 sys.path 数组中的包时出错
- javascript - 为什么 css 过渡不适用于 js
- python-3.x - 如何从显示的 Csv 程序中删除属性错误?