I am using sqlite to create and connect to a sqlite db foo.db
When I try to do an insert into the DB. I get the following AttributeError
AttributeError: 'sqlite3.Cursor' object attribute 'execute' is read-only
I can't seem to find any information on this error. Does anyone have any idea what this exception means?
I am using python 2.7 with virtualenv.
The following is the code I am trying to execute assume date is a string.
username = 'user'
pwdhash = some_hash_function()
email = '[email protected]'
date = '11/07/2011'
g.db = sqlite3.connect('foo.db')
cur = g.db.cursor()
cur.execute = ('insert into user_reg (username,pwdhash,email,initial_date)\
values (?,?,?,?)',
[username,
pwdhash,
email,
date])
g.db.commit()
g.db.close()
Thanks
You're trying to modify an attribute of the cursor. You want to call a method of the cursor.
It should be
cur.execute('insert into user_reg (username,pwdhash,email,initial_date)\
values (?,?,?,?)',
[username,
pwdhash,
email,
date])
Not
cur.execute = ('insert ...
Seems to be a simple syntax error. You are trying to set a value to the command execute while you have just to call it: remove the '=' and it should be fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With