[odb-users] data corruption when persisting object

Anton Paymyshev anton.paymyshev at gmail.com
Thu Nov 24 05:01:07 EST 2016


Hello,
I'm having issues with
odb 2.5.0.a7
sqlite 3.13.0
vs2015 update 3
windows 10
both release and debug

Schema and code below.

When I run given code I get expected results: row with 10 'A's, row
with 256 'B's and row with 100 'C' in sqlite db on disk.
Now if I change 256 to 257 for objB I get correct content row for
objA(10 'A's) and garbage for objB and objC (but with correct sizes).

Also if I move "val" out of section the code works fine in both cases.


//-----schema:
#pragma db value
struct TestValue
{
#pragma db type("BLOB")
std::vector<uint8_t> data;
};

#pragma db object
struct TestObject
{
#pragma db id auto
int id;

#pragma db section(testsection)
TestValue val;

#pragma db load(lazy)
odb::section testsection;
};


//-----code:

transaction t(db.begin());

TestObject objA;
objA.val.data = vector<uint8_t>(10, 'A');
db.persist(objA);

TestObject objB;
objB.val.data = vector<uint8_t>(256, 'B'); //257 here causes garbage
for objB and objC
db.persist(objB);

TestObject objC;
objC.val.data = vector<uint8_t>(100, 'C');
db.persist(objC);

t.commit();



More information about the odb-users mailing list