SQLite

View Ticket
Login
Ticket Hash: 19b44e35753baae47ad997559f4dc333441930c6
Title: sqlite3_bind_text inconsistent with NULL pointers, zero length etc
Status: Fixed Type: Feature_Request
Severity: Important Priority: Immediate
Subsystem: Virtual_Machine Resolution: Fixed
Last Modified: 2013-04-30 14:26:35
Version Found In: 3.6.18
Description:
http://www.sqlite.org/cvstrac/tktview?tn=4040

The OP is having problems because a sqlite3_bind_text with parameters of (NULL, 0) actually appears to bind null instead. H13533 is somewhat woolly about this.

On examining the code the ultimate cause is clear in bindText (also called to bind a blob). The binding is first cleared (ie set to null).

If the pointer is NULL then nothing else is done, irrespective of the length passed in. The interface requirements do not cover this situation.

I suggest that if the pointer is NULL then SQLITE_MISUSE is returned no matter what the length passed in is. (This is obviously a bug in the application. SQLite would be well within its rights to crash.)

Trying to do clever things (eg ignoring pointer if length is 0) leads to more complications like what the destructor should be etc.

User Comments:
drh added on 2013-04-30 14:26:35:

Documentation updated to explain that an setting the 3rd parameter of sqlite3_bind_text(), sqlite3_bind_text16() or sqlite3_bind_blob() to a NULL pointer is the same as calling sqlite3_bind_null().