Keith,

On Tue, Dec 13, 2016 at 8:34 PM, Keith Medcalf <[email protected]> wrote:
>
>     int res = sqlite3_close( m_db );
>     if( res == SQLITE_OK )
>         m_db = NULL;
>     else
>     {
> // error handling
>     }
> #ifdef DEBUG
>     sqlite3_stmt *statement = sqlite3_next_stmt( m_db, NULL );
>     if( statement )
>         const char *query = sqlite3_sql( statement );
> #endif

Is it OK to pass NULL as a first parameter to sqlite3_next_stmt()?
Upon checking the documentation it looks like the call will fail if
m_db is NULL.

Thank you.

>
> Then you simply do:
>
> if (!m_db)
> {
> // the pointer does not point to anything error handling
> }
>
> or conversely:
>
> if (m_db)
> {
> // do stuff with the connection
> }
> else
> {
> // database is not open error
> }
>
>
>> -----Original Message-----
>> From: sqlite-users [mailto:[email protected]]
>> On Behalf Of Igor Korot
>> Sent: Tuesday, 13 December, 2016 17:55
>> To: Discussion of SQLite Database; General Discussion of SQLite Database
>> Subject: [sqlite] How do I check if the DB is open?
>>
>> Hi, ALL,
>> I'm using following code to check for errors in debug mode:
>>
>>     int res = sqlite3_close( m_db );
>>     if( res != SQLITE_OK )
>>     {
>> // error handling
>>     }
>> #ifdef DEBUG
>>     sqlite3_stmt *statement = sqlite3_next_stmt( m_db, NULL );
>>     if( statement )
>>         const char *query = sqlite3_sql( statement );
>> #endif
>>
>> However the call to sqlite3_close() make the 'm_db' pointer invalid if
>> everything is successful and hence the sqlite3_next_stmt() crashes.
>>
>> How do I properly check if the DB is still open?
>> Or maybe I should put the code inside #ifdef....#endif before DB closing?
>>
>> Thank you.
>> _______________________________________________
>> sqlite-users mailing list
>> [email protected]
>> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>
>
>
> _______________________________________________
> sqlite-users mailing list
> [email protected]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
[email protected]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to