[prev in list] [next in list] [prev in thread] [next in thread] 

List:       sqlite-users
Subject:    [sqlite] Using sqlite3_errcode()
From:       Otto Wallenius <otwallen () gmail ! com>
Date:       2016-09-29 13:17:47
Message-ID: CAPcbFwhkCscZVT3=DuPayns_9Q9JcpmdQEzj+JngVOKTw=wDsg () mail ! gmail ! com
[Download RAW message or body]

Hello,

I'm writing a function to read from an sqlite3 database.

I'd like to use function sqlite3_column_blob() (and similar functions) to
read a column's value in a row. However I'm confused about how to check for
errors when using this function. The documentation
<https://www.sqlite.org/c3ref/column_blob.html> says

'''
If a memory allocation error occurs during the evaluation of any of these
routines, a default value is returned. The default value is either the
integer 0, the floating point number 0.0, or a NULL pointer. Subsequent
calls to sqlite3_errcode() will return SQLITE_NOMEM
<https://www.sqlite.org/rescode.html#nomem>.
'''

Then the documentation <https://www.sqlite.org/c3ref/errcode.html> for
sqlite3_errcode() says:

'''
If the most recent sqlite3_* API call associated with database connection
<https://www.sqlite.org/c3ref/sqlite3.html> D failed, then the
sqlite3_errcode(D) interface returns the numeric result code
<https://www.sqlite.org/rescode.html> or extended result code
<https://www.sqlite.org/rescode.html#extrc> for that API call. If the most
recent API call was successful, then the return value from
sqlite3_errcode() is *undefined*.
'''

To my understanding it follows that if you first call sqlite3_column_blob()
and then sqlite3_errcode(), the errcode might be SQLITE_NOMEM whether
memory allocation failed or not: either it failed and the error code was
set ot SQLITE_NOMEM, or it succeeded and the code happened to be
SQLITE_NOMEM because it is undefined.

Is this correct, and how can you check for errors in this case?

Best Regards,
Otto
<https://www.sqlite.org/c3ref/column_blob.html>
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic