14

I'm trying to insert all values of a list to my sqlite3 database. When I simulate this query by using the python interactive interpreter, I am able to insert the single value to DB properly. But my code fails while using an iteration:

... connection=lite.connect(db_name) cursor=connection.cursor() for name in match: cursor.execute("""INSERT INTO video_dizi(name) VALUES (?)""",(name,)) connection.commit() ... error:cursor.execute("""INSERT INTO video_dizi(name) VALUES (?)""",(name,)) sqlite3.OperationalError: database is locked 

Any way to overcome this problem?

2

3 Answers 3

14

Do you have another connection elsewhere in your code that you use to begin a transaction that is still active (not committed) when you try to commit the operation that fails?

Sign up to request clarification or add additional context in comments.

4 Comments

Only code related with sqlite3: import sqlite3 as lite db_name="diziport.sqlite"
Sir, I'm really sorry but it is working now after closing interactive interpreter (in active mode)
@hasseg it would be nice to know how to fix it without having to restart Python. I have tried cursor.close() and connection.close(), del(cursor), del(connection). Still get this error.
Note python's sqlite3 module by default gives you a connection where you have to commit every change. This means an uncommitted change is easy to do. If you want "autocommit mode" (no explicit commits required), connect with isolation_level=None.
1

As this error can happen because you have opened your site.db or database file in DBbrowser type application to view in interactive database interface. Just close that it will work fine.

Comments

-1

Because your database is use by another process or connection. If you need real concurrency, use a real RDBMS.

2 Comments

Not necessarily true. Berkeley DB's SQL API supports both the easy-to-use SQLite API as well as concurrent read-write operations. You can read about it here: bit.ly/hY6MTm.
Sqlite can support better concurrency by turning on WAL mode and increasing timeouts.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.