[sqlite] Re: Do I need to use sqlite3_close after a failed sqlite3_open?

2007-01-30 Thread Jef Driesen

Jef Driesen wrote:

[EMAIL PROTECTED] wrote:

Jef Driesen wrote:
I did. sqlite3_close is called automatically for SQLITE_NOMEM, but not 
for other cases. So I guess sqlite3_close is still needed. But then it 
shouldn't return an error, or am I wrong?

I don't think any error other than SQLITE_NOMEM is possible for
sqlite3_open().  Are you seeing some other kind of error come up?


I get SQLITE_CANTOPEN for a non-existing file (and no write permissions
to create it). Using sqlite3_close immediately afterwards returns the
same value. And sqlite3_errcode returns SQLITE_MISUSE.

I think this indicates there is definitely something wrong here. Either
the documentation is incorrect (with regards to the usage of
sqlite3_close after a failed sqlite3_open), or there is a bug in
sqlite3_open/close.

I'm using sqlite version 3.3.5 (Ubuntu Edgy package) if that matters.


I can only think of one reason why the sqlite3* handle is not released
automatically after a failure. If the handle is freed and set to null
(like is done for sqlite3_prepare), it's not possible to retrieve more
information about the error by means of the sqlite3_errcode and
sqlite3_errmsg functions.

SQLITE_NOMEM is the exception here, because a null handle is also
treated as SQLITE_NOMEM by the error functions. Releasing the handle has
no effect on the error reporting in this particular case.

_
Did you know that Windows Live Messenger is accesible on your mobile as from 
now? http://get.live.com/messenger/mobile



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



[sqlite] Re: Do I need to use sqlite3_close after a failed sqlite3_open?

2007-01-30 Thread Jef Driesen

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, );
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]
-