开发者

Why does Sqlite tell me no such column exists when I plainly created it?

in Python 2.6.5 with sqlite3.version 2.4.1, I use the following code:

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 valu开发者_StackOverflowes(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()

And it throws an error:

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

My question - what the heck??? I created a column with the name "date"! I've spend the last two hours trying to figure out what in the world is wrong and I'm getting really frustrated. Also, when I try to open it by command line, I'm told:

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

ANY help would be greatly appreciated as I'm about to put my computer through a wall.

Thanks!


Incorrect syntax for that insert statement. This will work:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜