Re: [sqlite] SQLITE_CANTOPEN_ISDIR and other extended error codes

2018-03-22 Thread Rowan Worth
On 20 March 2018 at 22:33, Deon Brewis  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
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] SQLITE_CANTOPEN_ISDIR and other extended error codes

2018-03-20 Thread Deon Brewis
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
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users