python - 为什么 Sqlite 在我明明创建时告诉我不存在这样的列?

标签 python sqlite

在带有 sqlite3.version 2.4.1 的 Python 2.6.5 中,我使用以下代码:

c = conn.cursor()

# Create table
c.execute('''create table stocks
(date text, trans text, symbol text,
 qty real, price real)''')

# Insert a row of data
c.execute("""insert into stocks
          values ('2006-01-05','BUY','RHAT',100,35.14)""")

# Save (commit) the changes
conn.commit()

c.execute('''insert into stocks values(date=?, trans=?, symbol=?, qty=?, price=?
)''', ('08-26-1984', 'SELL', 'GOGL', 3, 400.00))

# We can also close the cursor 

if we are done with it
c.close()

它抛出一个错误:

Traceback (most recent call last):
  File "dbtest.py", line 18, in <module>
    c.execute('''insert into stocks values(date=?, trans=?, symbol=?, qty=?, price=?)''', ('08-26-1984', 'SELL', 'GOGL', 3, 400.00))
sqlite3.OperationalError: no such column: date

我的问题 - 到底是什么???我创建了一个名为“日期”的列!在过去的两个小时里,我一直在试图弄清楚世界上到底出了什么问题,我感到非常沮丧。此外,当我尝试通过命令行打开它时,我被告知:

Unable to open database "orders": file is encrypted or is not a database

任何帮助将不胜感激,因为我正要把我的电脑穿墙。

谢谢!

最佳答案

不正确 syntax对于那个插入语句。这将起作用:

>>> c.execute('''insert into stocks 
                 (date, trans, symbol, qty, price)values(?,?,?,?,?)''', 
                 ('08-26-1984', 'SELL', 'GOGL', 3, 400.00))

关于python - 为什么 Sqlite 在我明明创建时告诉我不存在这样的列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4190476/

相关文章:

sql - 我可以试运行/沙盒 sql 命令吗?

python - 在不缩放的情况下改进图像的 OCR(使用 PIL、pixbuf)?

python - 扩展 Django Oscar 时模特名称冲突?

python - 如何为字符串中的每个字母分配一个值,然后将这些值添加到另一个字符串中?”

android - 频繁更新 SQLite DB 和 Listview(效率)

SQLite:类似于 Oracle 解码或 MS "If"

java - 我想制作一个 recyclerview,将数据显示到 SQLITE 数据库中的新 Activity

python - 程序导致 OSX (Snow Leopard 10.6.4) 窗口服务器自发崩溃

python - Tensorflow 无法检测到我的 RTX 3050 笔记本 GPU

python - 使用 Sqlite3 的数据库