SQLITE_CANTOPEN_ISDIR and other extended error codes

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

SQLITE_CANTOPEN_ISDIR and other extended error codes

deon
How do you actually get a SQLITE_CANTOPEN_ISDIR error?

In order to get an extended result code, we need to pass a sqlite3* connection, but you don't have that if the file can't be opened in the first place. Like... if it was a directory.

I see how this is implemented internally - it generally masks rc with db->errMask but in the case of openDatabase it returns just a hardcoded:
return rc & 0xff;

which truncates the 0x20e (SQLITE_CANTOPEN_ISDIR) error it had earlier into a SQLITE_CANTOPEN.

Is there some magic here that I'm missing? Shouldn't the default errMask be a DEFINE ?

- Deon


_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: SQLITE_CANTOPEN_ISDIR and other extended error codes

Rowan Worth-2
On 20 March 2018 at 22:33, Deon Brewis <[hidden email]> wrote:

> How do you actually get a SQLITE_CANTOPEN_ISDIR error?
>
> In order to get an extended result code, we need to pass a sqlite3*
> connection, but you don't have that if the file can't be opened in the
> first place.
>

I understand why you'd think that, but check the docs:

https://www.sqlite.org/capi3ref.html#sqlite3_open

> A database connection handle is usually returned in *ppDb, __even if an
error occurs__.
> The only exception is that if SQLite is unable to allocate memory to hold
the sqlite3 object,
> a NULL will be written into *ppDb instead of a pointer to the sqlite3
object.

So we're not looking at an "either an error or sqlite3* is returned" - you
can get both. The other thing to takeaway:

> Whether or not an error occurs when it is opened, resources associated
with the
> database connection handle should be released by passing it to
sqlite3_close()
> when it is no longer required.

-Rowan
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users