【发布时间】:2019-06-13 08:09:10
【问题描述】:
您好,我正在尝试通过 python3 中的 sqlite3 在 sqlite 中创建表。 到目前为止我得到的代码是:
import sqlite3
text="hello"
db = sqlite3.connect('C:/DB.db')
c = db.cursor()
c.execute("CREATE TABLE %s (sida)" % name)
for i in range(10):
c.execute("INSERT INTO %s VALUES (%s)" % (name, str(text))) # This does not work
db.commit()
db.close()
c.close
将值从 str(text) 更改为 i 有效;
c.execute("INSERT INTO %s VALUES (%s)" % (name, i)) # This works
传递整数作为值有效,但不是字符串。我一直在努力寻找解决方案,但我被困住了。
我得到的错误是:
c.execute("INSERT INTO %s VALUES (%s)" % (name, str(text))) sqlite3.OperationalError:靠近“a2”:语法错误
【问题讨论】:
标签: sql python-3.x sqlite