[odb-users] Problem with 'char' field using ODB w/ SQLite

Boris Kolpackov boris at codesynthesis.com
Wed Jan 16 07:13:44 EST 2013


Hi Tuxedo,

Tuxedo F. Catus <tuxedo.catus at gmail.com> writes:

> INSERT INTO "ShockParameters"
> VALUES('SIRI','T',0.65,0.15,0.95,0.6,0.5,0.1,0.1,0.75);
> 
> [...]
> 
> m_EventType = 0 '\000'},

I believe this is because of the SQLite dynamic type system. Even though
the database schema specifies that the EventType type is INTEGER, SQLite
will store pretty much anything in that column. And the above INSERT
statement inserts a string, not an integer. Here is simple illustration:

$ sqlite test.db
sqlite> CREATE TABLE foo (v INTEGER NOT NULL);
sqlite> INSERT INTO foo VALUES('T');
sqlite> INSERT INTO foo VALUES(123);
sqlite> SELECT v FROM foo;
T
123
sqlite> SELECT CAST(v AS INTEGER) FROM foo;
0
123

ODB extracts EventType as integer (equivalent to the second SELECT
statement), so what you get is 0.

An obvious way to fix this would be to specify an actual integer
value instead of a string in the INSERT statement.

Alternatively, if you want to continue using 'T' as the value, then
you would need to map the EventType column to TEXT. ODB does not yet
support mapping char (and char arrays; coming in the next release)
to TEXT so you will need to use std::string instead of char (or
implement your own mapping; which is also doable).

Boris



More information about the odb-users mailing list