sqlite add tag
Chris Barry
According to the sqlite manual:

> An implicit transaction (a transaction that is started automatically, not a transaction started by BEGIN) is committed automatically when the last active statement finishes. A statement finishes when its last cursor closes, …

However, if I run this program:

```
import sqlite3

conn = sqlite3.connect('test.db')
cur = conn.cursor()
cur.execute('CREATE TABLE test (x TEXT);')
cur.execute('INSERT INTO test (x) VALUES (\'abc\');')
# cur.execute('COMMIT;')
cur.close()
```
then use the program *sqlite3* to run the query

```SELECT * FROM test;```

it shows an empty table. If I include the *COMMIT* command then the row is found.

Have I misunderstood the manual? I see that *sqlite3.Cursor* does not have an *\_\_enter__* method, although *sqlite3.Connection* does, so, presumably, the implementor of the Python API did not expect that closing a cursor would do anything particularly useful.

My reason for wanting this to work is this:

Suppose I create a procedure which obtains a cursor, writes a single row, then closes the cursor. This would then automatically commit the change.

If I want to update several rows then I can create a procedure that obtains its own cursor, repeatedly calls the single row write procedure, then closes its cursor. This should result in a commit only occurring after the batch of updates was complete.

Incidentally, is there a difference between executing an SQL *COMMIT* command and calling conn.commit()?

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.