Skip to main content
 首页 » 编程设计

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

2025年05月04日14emanlee

在带有 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))