Re: [sqlite] Open the database - Creating the empty database
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Joanne Pham wrote: > The problem here is the database is not created but if the second process has >tried to access the database then the empty database is created which has the size of 0. If you use sqlite3_open_v2 then you can specify flags for creation. http://sqlite.org/c3ref/open.html However you still have a race condition as the first process may not have got around to creating a schema/content etc before the second tries to read the database. Roger -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAklGqcYACgkQmOOfHg372QRwtgCgjlkWDneHVbNPfD96S/oXwrRi dBMAoLL1u5GTo8vGjY/GkD+hrb7HkSxC =cKYG -END PGP SIGNATURE- ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Open the database - Creating the empty database
On Mon, Dec 15, 2008 at 1:43 PM, P Kishorwrote: > On 12/15/08, Joanne Pham wrote: > > Hi All, > > I have this problem about open the database. Here is the detail about > the problem. > > > > Our application have one process to create the database and another > process to open the database and creating the report. > > The problem here is the database is not created but if the second > process has tried to access the database then the empty database is created > which has the size of 0. So the question is there any way the open database > API should return an error message instead of creating the empty database > when the second process opens the database. > > > > Thanks, > > > A SQLite database is just a file on the hard disk. Test for the > existence of the file before trying to open it. > That is, unfortunately, a recipe for race conditions. Application A tests for whether the file exists and finds it doesn't. The operating system task switches to Application B which had previously determined that the file doesn't exist, and now creates it and adds some data. Task switch back to Application A which assumes that the file doesn't exist (since it had previously determined that) and scribbles over the data just written by Application B. An alternative is to open the database normally (sqlite3_open) and issue the queries BEGIN EXCLUSIVE; SELECT 1 FROM sqlite_master LIMIT 1; If you get back a value (1), then the database had already has tables (or triggers or ...) in it. If you get back NULL then you can go ahead and create the database tables et al. When done creating tables and doing whatever else you need to do before allowing other applications access, issue a COMMIT. Since you had an exclusive transaction, any other application trying to determine if the database is available or not will block until your transaction completes. Derrell ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Open the database - Creating the empty database
Thanks for the respond. I will test for the existence of the file before trying to open it. Once again thanks, JP From: P Kishor <punk.k...@gmail.com> To: General Discussion of SQLite Database <sqlite-users@sqlite.org> Sent: Monday, December 15, 2008 10:43:57 AM Subject: Re: [sqlite] Open the database - Creating the empty database On 12/15/08, Joanne Pham <joannekp...@yahoo.com> wrote: > Hi All, > I have this problem about open the database. Here is the detail about the >problem. > > Our application have one process to create the database and another process >to open the database and creating the report. > The problem here is the database is not created but if the second process >has tried to access the database then the empty database is created which has >the size of 0. So the question is there any way the open database API should >return an error message instead of creating the empty database when the second >process opens the database. > > Thanks, A SQLite database is just a file on the hard disk. Test for the existence of the file before trying to open it. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Open the database - Creating the empty database
On 12/15/08, Joanne Phamwrote: > Hi All, > I have this problem about open the database. Here is the detail about the > problem. > > Our application have one process to create the database and another process > to open the database and creating the report. > The problem here is the database is not created but if the second process > has tried to access the database then the empty database is created which has > the size of 0. So the question is there any way the open database API should > return an error message instead of creating the empty database when the > second process opens the database. > > Thanks, A SQLite database is just a file on the hard disk. Test for the existence of the file before trying to open it. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] Open the database - Creating the empty database
Hi All, I have this problem about open the database. Here is the detail about the problem. Our application have one process to create the database and another process to open the database and creating the report. The problem here is the database is not created but if the second process has tried to access the database then the empty database is created which has the size of 0. So the question is there any way the open database API should return an error message instead of creating the empty database when the second process opens the database. Thanks, JP ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users