SQLite Forum

Integer becomes blob
Login
The binding is based on the type of the python object that is passed into the wrapper (both for sqlite3 and apsw).

If that object is a Python int or long that will fit into a 32-bit signed integer, then it is converted to a C 32-bit signed integer and that integer is used in the `sqlite3_bind_integer` call,

Elseif that object is a Python int or long that is bigger than will fit in a 32-bit signed integer but will fit into a 64-bit signed integer, then it is converted to a C 64-bit signed integer and that integer is used in the `sqlite3_bind_int64` call,

Elseif that object is a Python float, then it is converted to a double precision IEEE-754 floating point number and used in the `sqlite3_bind_double` call,

Elseif that object is str or unicode, then it is converted to a utf-8 C style string and used in the `sqlite3_bind_text` call,

Elseif that object is None, then the `sqlite3_bind_null` call is used,

Elseif that object supports the buffer protocol or is a byte string or bytes array, then the `sqlite3_bind_blob` call is used,

Else an error is thrown.

The "column affinity" is irrelevant.


For retrieving columns a similar strategy is used.

If the type is `SQLITE_NONE`, then the Python None object is returned,  
Elseif the type is `SQLITE_TEXT`, then a Python unicode string is returned,  
Elseif the type is `SQLITE_INTEGER`, then a Python integer (or long) is returned,  
Elseif the type is `SQLITE_FLOAT`, then a Python float is returned,  
Elseif the type is `SQLITE_BLOB`, then a Python buffer/byte string is returned.

The declared "column affinity" is irrelevant.


The only case wherein the "column type" is of any significance is that you may tell the sqlite3 wrapper to "preprocess" inputs and "postprocess" outputs of the above process based on "character sequences" in the "column type" or the "column name".  That is, you could specify a "column type" of "datetime" which could, for example, cause the preprocessing objects to be stored into this field using some function -- for example to convert python datetime objects into iso time strings, and similarly to attempt to construct Python datetime objects from the data retrieved in that column.  In all cases the data retrieval and storage is independant of such trivialities -- they merely specify pre and post processing.,

The problem was that when some of the arguments were asked "What are you?" they replied "I am a buffer (basket of bytes)", so they were stored as BLOBs.