On 10 Nov 2013, at 11:30pm, L. Wood <lwoo...@live.com> wrote:

>> Simon Slavin <slav...@bigfraud.org> wrote:
>> No.
> 
> So by "no", you mean that the only other alternative is that the C calls I 
> mentioned can constitute ZERO transactions, and this case happens only if
> 
> * the (current) prepared statement contains BEGIN
> OR
> * some old prepared statement contained BEGIN and no END has yet occurred
> 
> -AND-
> 
> * the (current) prepared statement doesn't contain END

I'll expand my explanation.  There are two different kinds of SQL commands 
(actually more, but we only care about two here).

Some statements do stuff with the database: read or write it.
Other statements start a transaction (BEGIN) or stop a transaction (END/COMMIT, 
ROLLBACK).

The _prepare, _step, _finalize sequence are used to execute both kinds of 
statement.  You can use _exec() too, but internally that just calls _prepare, 
_step, _finalize itself.

Theoretically you cannot access the database unless you're in a transaction.  
For example, if you were to do a SELECT and hadn't done a BEGIN yet, SQLite 
could return an error message and tell you that you'd forgotten to start a 
transaction.  However, makes programming code very bulky, so instead of doing 
that when SQLite notices you accessing the database outside a transaction it 
helpfully wraps the transaction in a BEGIN and END for you.

So here's your original question:

> For instance, can we safely say that the successive calls
> 
> _prepare_v2()
> _step()
> ...
> _step()
> _finalize()
> 
> always and everywhere constitute one transaction and hence, involve a single 
> -journal file?

Your example would involve a single journal file (== transaction) just for that 
one command if and only if you had not properly started a transaction yourself. 
 For instance, a SELECT or INSERT without a BEGIN before it.  In fact, I think 
it holds for any database access in which you never declare a BEGIN yourself.  
Here are some other possibilities:

BEGIN
SELECT ...
INSERT ...
INSERT ...
END

Here one journal file is created with the BEGIN and lasts until the END.  All 
five things are done while it lasts.

BEGIN EXCLUSIVE
pause for 20 seconds
END

Here you have a journal file which is created and destroyed but the database is 
never accessed during it.  Technically, the BEGIN and END commands are both 
processed using _prepare, _step, _finalize.  So the journal file is still 
created and lasts for both commands even though no database access occurs.

I have handwaved some complications.  Sorry.  Does it help ?

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

Reply via email to