sqlite3_errcode()

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

sqlite3_errcode()

Bart Smissaert
This is in the documentation of sqlite3_errcode():

If the most recent API call was successful, then the return value from
sqlite3_errcode() is undefined.

I can see that if there is no error then then return value of
sqlite3_errcode() can be SQLITE_ROW (100) or SQLITE_DONE (101). So, to
check if there is an error (other than looking at all the
return values) do I need to check that sqlite3_errcode() returns something
other than 0, 100 or 101 or are there other values that could be returned
that don't indicate an error?


RBS
_______________________________________________
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: sqlite3_errcode()

Igor Tandetnik-2
On 10/1/2017 1:56 PM, Bart Smissaert wrote:
> This is in the documentation of sqlite3_errcode():
>
> If the most recent API call was successful, then the return value from
> sqlite3_errcode() is undefined.
>
> I can see that if there is no error then then return value of
> sqlite3_errcode() can be SQLITE_ROW (100) or SQLITE_DONE (101). So, to
> check if there is an error (other than looking at all the
> return values)

There is no other way to check if there is an error than by looking at all the return values. That's what the documentation is telling you: the value returned by sqlite3_errcode() is only meaningful if the return value of the most recent API call indicated that that call has failed.
--
Igor Tandetnik

_______________________________________________
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: sqlite3_errcode()

Simon Slavin-3
In reply to this post by Bart Smissaert


On 1 Oct 2017, at 6:56pm, Bart Smissaert <[hidden email]> wrote:

> I can see that if there is no error then then return value of
> sqlite3_errcode() can be SQLITE_ROW (100) or SQLITE_DONE (101). So, to
> check if there is an error (other than looking at all the
> return values) do I need to check that sqlite3_errcode() returns something
> other than 0, 100 or 101 or are there other values that could be returned
> that don't indicate an error?

There’s no good way to do this.  You have to check the code returned by each function call as it is returned.

You could check sqlite3_errcode() and find it give you an error code.  But you don’t know if that error was caused by the most recent function call or one five calls ago.  And sqlite3_errcode() might theoretically return 100, but that doesn’t mean there wasn’t an error before the last successful call to sqlite3_step().

If you check the codes returned by each function call instead, then your list is correct: 0, 100 and 101 indicate success (of a kind).  Any other value means a failure.  However, in theory all values from 1 to 99 would be errors, and using this range might help to future-proof your code.

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
|

Re: sqlite3_errcode()

Bart Smissaert
In reply to this post by Igor Tandetnik-2
Ok, thanks. All cleared up.

RBS

On 1 Oct 2017 19:32, "Igor Tandetnik" <[hidden email]> wrote:

On 10/1/2017 1:56 PM, Bart Smissaert wrote:

> This is in the documentation of sqlite3_errcode():
>
> If the most recent API call was successful, then the return value from
> sqlite3_errcode() is undefined.
>
> I can see that if there is no error then then return value of
> sqlite3_errcode() can be SQLITE_ROW (100) or SQLITE_DONE (101). So, to
> check if there is an error (other than looking at all the
> return values)
>

There is no other way to check if there is an error than by looking at all
the return values. That's what the documentation is telling you: the value
returned by sqlite3_errcode() is only meaningful if the return value of the
most recent API call indicated that that call has failed.
--
Igor Tandetnik


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