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.
Connect To Database#!/usr/bin/python import sqlite3 conn = sqlite3. connect('test. db') print "Opened database successfully"; Here, you can also supply database name as the special name :memory: to create a database in RAM.
Step 1 − Go to SQLite download page, and download precompiled binaries from Windows section. Step 2 − Download sqlite-shell-win32-*. Step 3 − Create a folder C:\>sqlite and unzip above two zipped files in this folder, which will give you sqlite3.
You can fetch data from MYSQL using the fetch() method provided by the sqlite python module. The sqlite3. Cursor class provides three methods namely fetchall(), fetchmany() and, fetchone() where, The fetchall() method retrieves all the rows in the result set of a query and returns them as list of tuples.
commit()
is a member method of sqlite3.Connection
not sqlite3.Cursor
. Here it is in the docs.
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()
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