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

Reply via email to