[odb-users] querying object and loading into a stack variable, then setting its id to 0 and persisting

Boris Kolpackov boris at codesynthesis.com
Wed Jul 31 09:47:56 EDT 2024


MM <finjulhich at gmail.com> writes:

> [...] the tracer shows that the INSERT INTO query still uses the
> 'id' column?
>
> From a first look as to how I wrote the Base::id  member pragma, do you
> think the generated SQL stmt should not use column id because the database
> will take care of that?

No, this is expected. In SQLite, to get an auto-generated id, you insert
a NULL value into the corresponding column (and if you insert a non-NULL
value, then SQLite uses your value, so you can have it both ways at the
same time).

I looked through the generated code for your example and I don't see
anything wrong with it. You can see the id image is unconditionally
set to NULL in the generated persist() function for Derived.

Are you actually observing wrong values in the database or are you
basing your assumption that something is wrong merely on the fact
that id is present in INSERT?



More information about the odb-users mailing list