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

Boris Kolpackov boris at codesynthesis.com
Tue Aug 6 08:38:06 EDT 2024


MM <finjulhich at gmail.com> writes:

> I load 1 object with
> Derived d;
> db.query_one(..., d)
> which returns true, and a Derived object is loaded.
> 
> Then I change d's attributes, in particular I set d.id to 0, and other
> attributes, then call
> 
> db.persist(d);
> 
> This inserted a row with id 0, then the next time around "duplicate"
> because id is already present
> 
> I mean this is really the crux of the question.  How do I load a row into
> d, "copy" it to another row, with the id being automatic, how to set id to
> NULL?
> 
> The question is both sqlite and portsgresl. the id is of c++ type
> std::uint64_t

This should not be happening. There must be something special (or
broken) about your setup. I will need a complete reproducer to
investigate this:

- a header with the persistent object definitions
- the ODB compiler command line used to compile this header
- and the driver source file that reproduces the problem

I should be able to do:

odb ... test.hxx
g++ ... -o driver driver.cxx test-odb.cxx
./driver # This should cause the duplicate id.



More information about the odb-users mailing list