[odb-users] Sqlite auto ID persists with ID=NULL returns NULL?
boris at codesynthesis.com
Wed Dec 11 00:07:51 EST 2013
Arnoud van-der-Wal <arnoud.van-der-wal at nz.abb.com> writes:
> When doing a persists() and selecting NULL for ID in ODB 2.3.0 then
> Sqlite assigns an correct ID and writes the table rows in the database.
> But for some reason the db->persists() does not return the assigned ID
> and it just returns the id as NULL ( null_ set true).
The reason for this is that without auto ODB doesn't know that you are
using database-generated IDs.
The ODB way of doing what you want is to use the --sqlite-lax-auto-id
option. Quoting the documentation:
"Do not force monotonically increasing automatically-assigned object ids. In
this mode the generated database schema omits the AUTOINCREMENT keyword which
results in faster object persistence but may lead to automatically-assigned
ids not being in a strictly ascending order. Refer to the SQLite
documentation for details."
The good thing with this approach is that you don't need to mess with NULLs;
ODB will do everything automatically for you.
More information about the odb-users