sqlite3_column_type returns NOT SQLITE_NULL and the following sqlite3_column_text returns with nullptr

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

sqlite3_column_type returns NOT SQLITE_NULL and the following sqlite3_column_text returns with nullptr

heribert
I've a prepared select statement (the database is in :memory: based.).
After binding the input values, calling next, checking the result type
of a text column, sometimes the follwing sqlite3_column_text returns
with a nullptr.

The stange thing is: the prior called sqlite3_column_type do not return
with SQLITE_NULL.

if  (sqlite3_column_type(_sqlite3_stmt, Field) == SQLITE_NULL)
     return false;

  LPCSTR cp = (LPCSTR)sqlite3_column_text(_sqlite3_stmt, Field);
if (cp == nullptr)
{
     ASSERT(false);
     return false;
}

Is that correct? May it be possible that sqlite3_column_type returns NOT
SQLITE_NULL and the following sqlite3_column_text returns with nullptr?

Thx for any hint
heribert
_______________________________________________
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: [EXTERNAL] sqlite3_column_type returns NOT SQLITE_NULL and the following sqlite3_column_text returns with nullptr

Hick Gunter
You are assuming that the column is either NULL or a SQLITE_TEXT value. This assumption is obviously violated by the real data returned by your query (which you do not show).

A second possibility would be that another thread has done something to your prepared statement between retrieving the column type and retrieving the data.

-----Ursprüngliche Nachricht-----
Von: sqlite-users [mailto:[hidden email]] Im Auftrag von heribert
Gesendet: Dienstag, 11. September 2018 13:59
An: SQLite mailing list <[hidden email]>
Betreff: [EXTERNAL] [sqlite] sqlite3_column_type returns NOT SQLITE_NULL and the following sqlite3_column_text returns with nullptr

I've a prepared select statement (the database is in :memory: based.).
After binding the input values, calling next, checking the result type of a text column, sometimes the follwing sqlite3_column_text returns with a nullptr.

The stange thing is: the prior called sqlite3_column_type do not return with SQLITE_NULL.

if  (sqlite3_column_type(_sqlite3_stmt, Field) == SQLITE_NULL)
     return false;

  LPCSTR cp = (LPCSTR)sqlite3_column_text(_sqlite3_stmt, Field); if (cp == nullptr) {
     ASSERT(false);
     return false;
}

Is that correct? May it be possible that sqlite3_column_type returns NOT SQLITE_NULL and the following sqlite3_column_text returns with nullptr?

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


___________________________________________
 Gunter Hick | Software Engineer | Scientific Games International GmbH | Klitschgasse 2-4, A-1130 Vienna | FN 157284 a, HG Wien, DVR: 0430013 | (O) +43 1 80100 - 0

May be privileged. May be confidential. Please delete if not the addressee.
_______________________________________________
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_column_type returns NOT SQLITE_NULL and the following sqlite3_column_text returns with nullptr

heribert
In reply to this post by heribert
Thx Gunter...
that's the problem. I've capsuled the sqlite access in some database
classes. So i have only the call a function named getProperty with some
parameters.
But in some cases it may be possible that the instance of the object
calls this function from another thread (with the same stmt).
The main thread reads...  meanwhile the other thread access resets the
stmt results...

Thx again!

Am 11.09.2018 um 13:58 schrieb heribert:

> I've a prepared select statement (the database is in :memory: based.).
> After binding the input values, calling next, checking the result type
> of a text column, sometimes the follwing sqlite3_column_text returns
> with a nullptr.
>
> The stange thing is: the prior called sqlite3_column_type do not
> return with SQLITE_NULL.
>
> if  (sqlite3_column_type(_sqlite3_stmt, Field) == SQLITE_NULL)
>     return false;
>
>  LPCSTR cp = (LPCSTR)sqlite3_column_text(_sqlite3_stmt, Field);
> if (cp == nullptr)
> {
>     ASSERT(false);
>     return false;
> }
>
> Is that correct? May it be possible that sqlite3_column_type returns
> NOT SQLITE_NULL and the following sqlite3_column_text returns with
> nullptr?
>
> Thx for any hint
> heribert
> _______________________________________________
> 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
Reply | Threaded
Open this post in threaded view
|

Re: sqlite3_column_type returns NOT SQLITE_NULL and the following sqlite3_column_text returns with nullptr

Richard Hipp-3
In reply to this post by heribert
On 9/11/18, heribert <[hidden email]> wrote:
> I've a prepared select statement (the database is in :memory: based.).
> After binding the input values, calling next, checking the result type
> of a text column, sometimes the follwing sqlite3_column_text returns
> with a nullptr.
>
> The stange thing is: the prior called sqlite3_column_type do not return
> with SQLITE_NULL.

That can happen when SQLite needs to do a type conversion (INTEGER to
TEXT, or UTF-16 to UTF-8, for example) and it is unable to allocate
sufficient memory to carry out the conversion.

How big is your text string?
--
D. Richard Hipp
[hidden email]
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users