You can tell if you are in a transaction by the in_transaction property of the 
connection.  This tracks whether or not a BEGIN of some kind has been issued by 
the wrapper (either through magic or because you explicitly issued a command to 
BEGIN a transaction).  If in_transaction is True, then you need to issue a 
commit or rollback to end that transaction.  This property reflects the what 
the WRAPPER thinks is the transaction state, and not the underlying SQLite3 
database transaction state.

So, if you are issuing multiple SELECTs and you need repeatable read for these 
SELECTs, then you need to issue the BEGIN explicitly.

If you want something that allows Python to use SQLite3 as SQLite3 (rather than 
as a dbapi compliant generic database) then you should look at APSW instead.

-- 
The fact that there's a Highway to Hell but only a Stairway to Heaven says a 
lot about anticipated traffic volume.

>-----Original Message-----
>From: sqlite-users <sqlite-users-boun...@mailinglists.sqlite.org> On
>Behalf Of Peng Yu
>Sent: Friday, 25 October, 2019 14:13
>To: SQLite mailing list <sqlite-users@mailinglists.sqlite.org>
>Subject: Re: [sqlite] What does commit actually do?
>
>The manual says this.
>
>"The Python sqlite3 module by default issues a BEGIN statement
>implicitly before a Data Modification Language (DML) statement (i.e.
>INSERT/UPDATE/DELETE/REPLACE)."
>> If you did NOT specify "isolation_level = None" in the .connect() call
>then
>> you probably ARE in a transaction if you've been running queries.
>
>I just use the default .connect() without specifying isolation_level
>explicitly. Then I am in a transaction?
>
>import sqlite3
>conn=sqlite3.connect(f)
>c=conn.cursor()
>import zlib
>c.execute('SELECT name FROM sqlar')
>result = c.fetchall()
>for x in result:
>       print(x[0])
>
>> But why do I need to commit my transaction if I'm just reading?
>
>Is there any .commit() implied in the SELECT statement?
>
>> If you're just reading then you can commit or rollback.
>
>So I should close the `conn` immediately after `c.fetchall()` to
>release resources used by sqlite3?
>
>> If the database is not in WAL mode
>
>In the above example, should I use WAL mode or not?
>
>https://charlesleifer.com/blog/going-fast-with-sqlite-and-python/
>
>--
>Regards,
>Peng
>_______________________________________________
>sqlite-users mailing list
>sqlite-users@mailinglists.sqlite.org
>http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users



_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to