Reputation: 1614
When I run this code:
path = '~/Scripts/wallpapers/single.png'
conn = sqlite3.connect('/Users/Heaven/Library/Application Support/Dock/desktoppicture.db')
cur = conn.cursor();
cur.execute("insert into data values ('" + path + "');")
cur.commit()
I receive the following error
AttributeError: 'sqlite3.Cursor' object has no attribute 'commit'
and I have absolutely no idea why.
Upvotes: 16
Views: 32632
Reputation: 1477
commit()
is a member method of sqlite3.Connection
not sqlite3.Cursor
. Here it is in the docs.
Upvotes: 25
Reputation: 6332
From the answer from sir_charles804 (sorry not enough points to add this as comment) follows it should be:
conn.commit()
instead of
cur.commit()
Upvotes: 12
Reputation:
It's
conn.commit()
conn.close() //if you intend to close it afterwards
Explanation: The cursor is only used to pass instructions to sqlite, while you have to commit or close with the instance you've made to connect to your database.
Upvotes: 11