[odb-users] std::map key as part of primary key

Boris Kolpackov boris at codesynthesis.com
Wed Aug 21 07:33:59 EDT 2013


Hi Alessandro,

Alessandro Bellina <abellina at gmail.com> writes:

> #pragma db object
> struct Test
> {
> ...
> std::map<std::string, int> my_values;
> #pragma db id
> unsigned long id;
> };
> 
> First, I insert an item in Test, and that works as expected. But an update
> deletes everything for that foreign key and then reinserts. I thought it
> would match on the foreign key (Test::id), then the std::map key, and
> update that row.

The problem is, std::map doesn't store any information about whether
this is a new row, an updated row, or an unchanged row. In other words,
it  doesn't keep any change information.

In ODB, we address this with special change-tracking containers. See
Section 5.4, "Change-Tracking Containers" for more information. While
there is no change-tracking equivalent for std::map yet, it is definitely
possible to implement one and we will probably do it in near future.
There is an std::vector equivalent which you maybe can use in the
meantime.

Boris



More information about the odb-users mailing list