Doesn't int rc = sqlite3_open ... open the database? I have a situation where a detail view executes a select statement based upon a row selected from the master. The Detail view and the Master open the database before executing their respective queries. I am receiving a SCHEMA_ERROR, I believe this is happening because the Master doesn't close it's connection before the Detail re-opens the db.
My log shows: Opening Database from Master ... Opening Database from Detail ... Problem with Database in Detail Result Code 17 Problem with Database in Detail Result Code 17 I want to check if the database is open before re-opening the database. ________________________________ From: Stephan Beal <sgb...@googlemail.com> To: General Discussion of SQLite Database <sqlite-users@sqlite.org> Sent: Tuesday, October 4, 2011 9:54 PM Subject: Re: [sqlite] How do you check if a sqlite database is open? On Wed, Oct 5, 2011 at 6:48 AM, James Brison <rman...@yahoo.com> wrote: > Does anyone know how to check if a sqlite database is open? I know > sqlite3_open method is used to open the database but is there a method to > check if it is already open? > > An app cannot use an sqlite3 handle unless open has succeeded, so there is no need for an is-opened function. That couldn't possibly work because sqlite3_open() allocates the sqlite3 handle, meaning the client cannot have a valid handle until after sqlite3_open() succeeds. To see if it's opened, check the pointer to see if it's NULL (which you of course must initialize it to, or else it has an unspecified value). sqlite3 * db = NULL; int rc = sqlite3_open(...., &db); if(rc) { ... error ... ; sqlite3_close(db); } else { sqlite3 is open } After you close it, assign it to NULL again, and there's your "is open" flag. -- ----- stephan beal http://wanderinghorse.net/home/stephan/ _______________________________________________ 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