Jef Driesen wrote:
Do I need to use sqlite3_close if the call to sqlite3_open indicated an
error? The documentation for sqlite3_open says "An sqlite3* handle is
returned in *ppDb, even if an error occurs." So I assumed the answer is yes.

But if I try this code (on a non-existing file and no write permissions):

int rc_o = sqlite3_open (filename, &db);
if (rc_o != SQLITE_OK) {
     printf("ERROR: %i, %i, %s\n",
        rc_o, sqlite3_errcode(db), sqlite3_errmsg(db));
     int rc_c = sqlite3_close (db);
     if (rc_c != SQLITE_OK) {
        printf("ERROR: %i, %i, %s\n",
           rc_c, sqlite3_errcode(db), sqlite3_errmsg(db));
     }
}

I get:

ERROR: SQLITE_CANTOPEN, SQLITE_CANTOPEN, unable to open database file
ERROR: SQLITE_CANTOPEN, SQLITE_MISUSE, library routine called out of
sequence

Shouldn't sqlite3_close return SQLITE_OK?

And why is the rc_c different from the return value of the
sqlite3_errcode function? Isn't that function supposed to return the
error code of the last sqlite3_* function? Which is sqlite3_close in my
code.

I made a mistake in my real code. (I checked rc_o in the second comparison, instead of rc_c.) sqlite3_close does return SQLITE_OK in my
example.

But the error code obtained from sqlite3_errcode returns a different
value (SQLITE_MISUSE), which seems to indicate that calling
sqlite3_close was not needed after all. I think this is still wrong.

-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to