sqlite_autocommit

mIRC SQLite

sqlite_autocommit
Turns on or off autocommit mode, or returns its current state.
Syntax
$sqlite_autocommit ( conn [, mode ] )
/sqlite_autocommit conn mode
Parameters
conn
The connection identifier.
mode
11 to enable autocommit mode, 0 to disable.
Return Value
If setting the autocommit mode, 1 on success, or $null if there was an error. If getting the autocommit mode, 1 if autocommit mode is enabled, otherwise 0.
Remarks
When auto-commit mode is enabled every SQL statement is automatically committed after they're executed, unless $sqlite_begin or BEGIN TRANSACTION is explicitly used to start a transaction. When disabled, changes to the database are deferred and only committed when $sqlite_commit or COMMIT TRANSACTION is used.

Using transactions when doing a batch of updates on database can greatly improve the performance. Disabling auto-commit mode means that you don't have to worry about remembering to start the transaction all the time, all you need to worry about is where you want all the pending changes to be committed.

Auto-commit is enabled by default for new database connections. SQLite doesn't remember the state of auto-commit mode when database is closed, thus you must call this function everytime for a newly opened connection, if you want to disable auto-commit mode by default for that connection.

Enabling auto-commit for a connection will commit all pending changes.

It is usually ok to ignore the return value of $sqlite_autocommit when used to set autocommit mode, because the only case an error is returned is when an invalid conn is specified.
Example
; Open a temporary database and disable auto-commit on it
var %db = $sqlite_open()
sqlite_autocommit %db 0

; Create a table and insert a row in it
sqlite_exec %db CREATE TABLE test (text)
sqlite_exec %db INSERT INTO test VALUES ('First row')
sqlite_commit %db

; Insert another row, but this time roll it back
sqlite_exec %db INSERT INTO test VALUES ('Second row')
sqlite_rollback %db

; Print all the rows in the table
var %res = $sqlite_query(%db, SELECT * FROM test), %i = 1
while ($sqlite_fetch_single(%res)) {
  echo -a %i - $v1
  inc %i
}

; Clean up
sqlite_free %res
sqlite_close %db

; Output:
; 1 - First row
; 2 - Second row