SQLite User Forum

C Functions for BEGIN and END transaction
Login

C Functions for BEGIN and END transaction

(1) By Dmitry (far-far) on 2024-05-28 05:19:27 [source]

Hi. I ask the developers of SQLite to implement C functions to start and finsh transaction. In my opinion it is to ungly invoke sqlite3_exec() for that.

sqlite3_exec(pDB, "BEGIN", NULL, NULL, NULL); sqlite3_exec(pDB, "END", NULL, NULL, NULL);

(2) By jose isaias cabrera (jicman) on 2024-05-31 14:11:34 in reply to 1 [link] [source]

Adding more functions to the SQLite library may add to the size of the library. As the About SQLite page, beginning on the 3rd paragraph says, "SQLite is a compact library. With all features enabled, the library size can be less than 750KiB,..." So, mayhaps (as Keith used to say), this is something that you want to think about.

(3) By Joshua Wise (wisej12) on 2024-05-31 15:44:52 in reply to 1 [link] [source]

You can just implement a simple function for this yourself, and use it in your own programs, if you wish:

int transaction_begin(sqlite3 *pDB) {
    return sqlite3_exec(pDB, "BEGIN", NULL, NULL, NULL);
}

int transaction_end(sqlite3 *pDB) {
    return sqlite3_exec(pDB, "END", NULL, NULL, NULL);
}

(4) By John Boncek (jboncek) on 2024-05-31 16:10:12 in reply to 1 [link] [source]

Not worth doing in my opinion. There is already a one-line function that performs each operation. Adding them would expand the bulk of the documentation to wade thru for little gain.

(5) By Rico Mariani (rmariani) on 2024-06-01 01:48:09 in reply to 1 [link] [source]

It's pretty trivial to roll your own... and your own aren't any worse/better than what they would do. If you really care you could prepare begin/end statements and just run them also.

(6) By Simon Slavin (slavin) on 2024-06-01 16:11:21 in reply to 1 [link] [source]

The SQLite API is already written in C. So presumably there are functions which do start and commit transactions, and SQLite just calls them when it figures out you passed it 'BEGIN' or 'COMMIT'. You might be able to find them when reading the source code.

(7) By David Jones (vman59) on 2024-06-02 00:06:59 in reply to 6 [link] [source]

I'm guessing transaction functions are handled solely by the VDBE. "EXPLAIN BEGIN;" and "EXPLAIN COMMIT;" both execute an Autocommit opcode, so there is no way around preparing SQL statements unless you really want to get into the weeds modifying VDBE state.

(8) By Bo Lindbergh (_blgl_) on 2024-06-02 09:44:08 in reply to 7 [link] [source]

And if you run explain begin immediate; you'll see a Transaction opcode for each database (main, temp, and any attached).

Summary: just use sqlite3_prepare_v2 and sqlite3_step.