Re: [sqlite] Atomic database structure initialization

2014-09-22 Thread Paul
Thank you for help, guys! I knew that sqlite is a great piece of software, now I have even more proofs :) ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Re: [sqlite] Atomic database structure initialization

2014-09-22 Thread Keith Medcalf
>> Correct me if I have a wrong model of transaction in mind. >> Maybe sqlite does not write a byte to disk if inside a transaction >> there are only selects? >So, the answer to my question is: NO. >SQLite does no writes, the begin of a transaction is simply an >acquisition of write lock.

Re: [sqlite] Atomic database structure initialization

2014-09-22 Thread Clemens Ladisch
Paul wrote: Please note that *all* accesses to the database file are done with transactions, including reading and writing the user_version value. > > I suspect that no, not all accesses to the database file are done using > transactions. Read-only transactions just lock the database

Re: [sqlite] Atomic database structure initialization

2014-09-22 Thread RSmith
On 2014/09/22 15:03, Paul wrote: I suspect that no, not all accesses to the database file are done using transactions. What about read-only databases? Moreover, what about read-only medium? A transaction does not necessarily imply a write, only if there is an update of actual data, which

Re: [sqlite] Atomic database structure initialization

2014-09-22 Thread Paul
> > > Paul wrote: > > > I can check whether user_version matches magic number without transaction. > > > > No. Executing "PRAGMA user_version" will start an automatic transaction > > if you didn't already start an explicit one. > > > > > Only when user_version does not match magic number I

Re: [sqlite] Atomic database structure initialization

2014-09-22 Thread Paul
> > On 22 Sep 2014, at 1:13pm, Paul wrote: > > > The only thing I am worried about is whether > > > > pragma user_version=n; > > > > respects transactions and will be rolled back automatically in case > > if something happens between that statement and COMMIT. > > SQLite

Re: [sqlite] Atomic database structure initialization

2014-09-22 Thread Paul
> Paul wrote: > > I can check whether user_version matches magic number without transaction. > > No. Executing "PRAGMA user_version" will start an automatic transaction > if you didn't already start an explicit one. > > > Only when user_version does not match magic number I start transaction.

Re: [sqlite] Atomic database structure initialization

2014-09-22 Thread Simon Slavin
On 22 Sep 2014, at 1:13pm, Paul wrote: > The only thing I am worried about is whether > > pragma user_version=n; > > respects transactions and will be rolled back automatically in case > if something happens between that statement and COMMIT. SQLite version 3.8.5

Re: [sqlite] Atomic database structure initialization

2014-09-22 Thread Clemens Ladisch
Paul wrote: > I can check whether user_version matches magic number without transaction. No. Executing "PRAGMA user_version" will start an automatic transaction if you didn't already start an explicit one. > Only when user_version does not match magic number I start transaction. This will

Re: [sqlite] Atomic database structure initialization

2014-09-22 Thread Paul
> Paul wrote: > >> pragma user_version; > >> > >> returns a single row with a single value which is the version, and the > >> command, > >> > >> pragma user_version=n; > >> > >> lets you change it to n. Perhaps you can use this as a flag to tell > >> yourself > >> that you are working with an

Re: [sqlite] Atomic database structure initialization

2014-09-22 Thread Paul
> Paul wrote: > >> pragma user_version; > >> > >> returns a single row with a > single value which is the version, and the command, > >> > >> pragma > user_version=n; > >> > >> lets you change it to n. Perhaps you can use this > as a flag to tell yourself > >> that you are working with an

Re: [sqlite] Atomic database structure initialization

2014-09-22 Thread Clemens Ladisch
Paul wrote: >> pragma user_version; >> >> returns a single row with a single value which is the version, and the >> command, >> >> pragma user_version=n; >> >> lets you change it to n. Perhaps you can use this as a flag to tell yourself >> that you are working with an uninitialized database

Re: [sqlite] Atomic database structure initialization

2014-09-22 Thread Paul
> > There is also a PRAGMA user_version (see > http://www.sqlite.org/pragma.html#pragma_schema_version) which will let you > store a number in the database header so you can keep track of what version > of the "user schema" you have implemented in the database. Initially, when > the database

Re: [sqlite] Atomic database structure initialization

2014-09-19 Thread Keith Medcalf
There is also a PRAGMA user_version (see http://www.sqlite.org/pragma.html#pragma_schema_version) which will let you store a number in the database header so you can keep track of what version of the "user schema" you have implemented in the database. Initially, when the database is created

Re: [sqlite] Atomic database structure initialization

2014-09-19 Thread Clemens Ladisch
Paul wrote: >> Paul wrote: >>> How do you check if structure is initializad in an abstract databse? > > struct SqliteDatabase { > ... > > /// Callback is called once database is created. Strictly one time. > virtual bool on_create(); > ... > }; > > struct FooDatabase : public SqliteDatabase >

Re: [sqlite] Atomic database structure initialization

2014-09-19 Thread Paul
> > On 19 Sep 2014, at 8:34am, Paul wrote: > > > if database file is missing it must be created and initialized. > > For that purpose I need to provide a guarantee that *on_create* callback > > will be called strictly once. > > Can you check to see whether the database file

Re: [sqlite] Atomic database structure initialization

2014-09-19 Thread Simon Slavin
On 19 Sep 2014, at 8:34am, Paul wrote: > if database file is missing it must be created and initialized. > For that purpose I need to provide a guarantee that *on_create* callback > will be called strictly once. Can you check to see whether the database file exists using

Re: [sqlite] Atomic database structure initialization

2014-09-19 Thread Paul
> Paul wrote: > >> Paul wrote: > >>> My goal is to make structure initialization of an *abstract* database > >>> atomic. > >>> [...] if database file is missing it must be created and initialized. > >> > >> > >> > >> Just do the check for the database

Re: [sqlite] Atomic database structure initialization

2014-09-19 Thread Dan Kennedy
On 09/19/2014 02:53 PM, Paul wrote: Paul wrote: My goal is to make structure initialization of an *abstract* database atomic. [...] if database file is missing it must be created and initialized. Just do the check for the database structure and the

Re: [sqlite] Atomic database structure initialization

2014-09-19 Thread Clemens Ladisch
Paul wrote: >> Paul wrote: >>> My goal is to make structure initialization of an *abstract* database >>> atomic. >>> [...] if database file is missing it must be created and initialized. >> >> >> >> Just do the check for the database structure and the

Re: [sqlite] Atomic database structure initialization

2014-09-19 Thread Paul
> Paul wrote: > > My goal is to make structure initialization of an *abstract* database > > atomic. > > [...] if database file is missing it must be created and initialized. > > > > Just do the check for the database structure and the initialization

Re: [sqlite] Atomic database structure initialization

2014-09-19 Thread Clemens Ladisch
Paul wrote: > My goal is to make structure initialization of an *abstract* database atomic. > [...] if database file is missing it must be created and initialized. Just do the check for the database structure and the initialization inside a transaction.

[sqlite] Atomic database structure initialization

2014-09-19 Thread Paul
My goal is to make structure initialization of an *abstract* database atomic. Why abstract is because I am dealing with C++ wrapper I am gonna use for several differents storages. All these storages  are accessed concurently, and if database file is missing it must be created and initialized.