SQLITE_ERROR ("SQL error or missing database") should be split into two codes: "SQL error" and "missing database"

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

SQLITE_ERROR ("SQL error or missing database") should be split into two codes: "SQL error" and "missing database"

Yuri
Currently SQLITE_ERROR stands for two very different errors:

 > #define SQLITE_ERROR        1   /* SQL error or missing database */

It would make sense to have separate codes for them to avoid possible
confusion, because these two errors really have nothing in common.


Yuri


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

Re: SQLITE_ERROR ("SQL error or missing database") should be split into two codes: "SQL error" and "missing database"

Simon Slavin-3


On 7 Jul 2017, at 7:36pm, Yuri <[hidden email]> wrote:

> Currently SQLITE_ERROR stands for two very different errors:
>
> > #define SQLITE_ERROR        1   /* SQL error or missing database */
>
> It would make sense to have separate codes for them to avoid possible confusion, because these two errors really have nothing in common.

I note that the "extended result code" feature is relevent:

<https://sqlite.org/c3ref/c_ioerr_access.html>

You’re proposing two error codes like

SQLITE_FILE_NODATABBASE
SQLITE_FILE_NOTADATABBASE

for a missing database file, and for one which has the wrong text in the magic header area.

I’d suggest some of my own:

SQLITE_API_BADARGUMENT
SQLITE_API_WRONGORDER
SQLITE_SQL_BADSYNTAX
SQLITE_SQL_WRONGORDER

Does anyone want to contribute others ?

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

Re: SQLITE_ERROR ("SQL error or missing database") should be split into two codes: "SQL error" and "missing database"

Yuri
On 07/07/2017 12:04, Simon Slavin wrote:

> I note that the "extended result code" feature is relevent:
>
> <https://sqlite.org/c3ref/c_ioerr_access.html>
>
> You’re proposing two error codes like
>
> SQLITE_FILE_NODATABBASE
> SQLITE_FILE_NOTADATABBASE
>
> for a missing database file, and for one which has the wrong text in the magic header area.
>
> I’d suggest some of my own:
>
> SQLITE_API_BADARGUMENT
> SQLITE_API_WRONGORDER
> SQLITE_SQL_BADSYNTAX
> SQLITE_SQL_WRONGORDER
>
> Does anyone want to contribute others ?


There are some other problems in error definitions. For example, what
does SQLITE_FULL mean? How can database be full? Is it really a
disk-full condition?

 > #define SQLITE_FULL        13   /* Insertion failed because database
is full */

Also, what does
> #define SQLITE_IOERR_SHORT_READ        (SQLITE_IOERR | (2<<8))
really mean? How is it different from the case when database is corrupt/truncated? But there is SQLITE_CORRUPT for that.
Short read mean EOF, and EOF in unexpected place constitutes corrupt database file.


Yuri

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

Re: SQLITE_ERROR ("SQL error or missing database") should be split into two codes: "SQL error" and "missing database"

Rowan Worth-2
On 8 July 2017 at 03:28, Yuri <[hidden email]> wrote:

>
> There are some other problems in error definitions. For example, what does
> SQLITE_FULL mean? How can database be full? Is it really a disk-full
> condition?
> > #define SQLITE_FULL        13   /* Insertion failed because database is
> full */


Disk is full, or the database cannot hold more pages[1], or a table cannot
hold more rows (because all ROWIDs have been used).

[1] https://sqlite.org/limits.html#max_page_count


> Also, what does
>
>> #define SQLITE_IOERR_SHORT_READ        (SQLITE_IOERR | (2<<8))
>>
> really mean? How is it different from the case when database is
> corrupt/truncated? But there is SQLITE_CORRUPT for that.
> Short read mean EOF, and EOF in unexpected place constitutes corrupt
> database file.
>

SQLITE_IOERR_SHORT_READ is mostly of interest to the vfs layer rather than
regular sqlite users, because sqlite specifically requires that a vfs
implementation zero the remainder of the read buffer in the short read
scenario.

Interestingly sqlite works quite differently to your expectation in the
case of unexpected EOF. Sqlite doesn't automatically assume corruption - in
fact this is the one IOERR it ignores, instead proceeding to try and use
the data which was read.

Sometimes this will cause an SQLITE_CORRUPT return - eg. if the last page
is a btree interior page then zero-filling the end of the read buffer will
almost certainly result in nonsense. But in the case of a leaf page the
zero-filled buffer can still represent a "validly" formed database page and
sqlite will proceed without reporting any error. Via this vector it is
unfortunately possible for queries to return rows containing NULL in a
column that is explicitly NOT NULL. I've mentioned this before:

http://sqlite.1065341.n5.nabble.com/Null-returned-from-NOT-NULL-column-thanks-to-undetected-corruption-td93309.html

I'm still not sure why sqlite ignores short reads; maybe something to do
with creating databases (multi-process race when the file has been created
but the first DB page hasn't been written yet?).

Anyway this is the kind of detail most users don't care (or need to care)
about. If you get _any_ kind of SQLITE_IOERR returned by sqlite it's best
to assume your connection is hosed.

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