I don't think this will work. sqlite3_open and sqlite3_close return a status which, if they worked, is SQLITE_OK.
A simpler solution might be to set ppDB to NULL in your code every time you close the database. So add something like sqlite3_close(ppDB); ppDB = NULL ; Then the original test Simon suggested will work. Regards Andy Ling -----Original Message----- From: sqlite-users-bounces at mailinglists.sqlite.org [mailto:sqlite-users-boun...@mailinglists.sqlite.org] On Behalf Of a a Sent: Tue 01 March 2016 17:13 To: SQLite mailing list Subject: Re: [sqlite] How to check if connection to main database is still open or closed before new query ? Let me explain it better cause i got confused and i am a newbie also. I open a connection like this sqlite3 *ppDB; int dbcon; dbcon = sqlite3_open(databasename, &ppDB); /// i do my code i query the database i do some stuff and i close the database like this dbcon = sqlite3_close(ppDB); I want to check after a while if the connection is allready closed or not for the simple reason not to reopen the database but if is open to run a query or if it is closed to reopen the database and then run the query. so i think the dbcon is the one i have to check not the ppDB :/ it works now maby i didnt understand what ppDB you were reffering to if(dbcon){ //is open }else{ //is closed } :) thanks though it is tested and runs ok ________________________________________ From: sqlite-users-bounces at mailinglists.sqlite.org <sqlite-users-bounces at mailinglists.sqlite.org> on behalf of Simon Slavin <slav...@bigfraud.org> Sent: Tuesday, March 1, 2016 7:01 PM To: SQLite mailing list Subject: Re: [sqlite] How to check if connection to main database is still open or closed before new query ? On 1 Mar 2016, at 4:59pm, a a <NoCos30 at hotmail.com> wrote: > the sqlite3_close() <--- needs one argument if i pass sqlite3_close(NULL) it > actually closes again a closed connection ? No. If you pass it null it realises that the connection is closed and does nothing. Simon. _______________________________________________ sqlite-users mailing list sqlite-users at mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users _______________________________________________ sqlite-users mailing list sqlite-users at mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users --------------------------------------------------------------------------------------- This email has been scanned for email related threats and delivered safely by Mimecast. For more information please visit http://www.mimecast.com ---------------------------------------------------------------------------------------