Hi,
I am having trouble with ORM. I have code like the following:
// Function that fills object with values
void FillObject(Object &obj, int i);
// Start postgres session
soci::session sql(soci::postgresql, ...);
// Declare "use" object
Object obj;
// Prepare statement
soci::statement st_put = (sql.prepare << "insert into tbl (col1, col2)
values (:c1, :c2)", soci::use(obj));
// Insert 10 objects into the database
for (int i=0; i < 10; i++) {
// Get the data for object i
FillObject(obj, i);
// Execute SQL
st_put.execute(true); // <--- Throws exception due to bad foreign key (= 0)
}
The exception is thrown because the table I am inserting into has a
foreign key constraint on (say) col1. The error message says the value
I am putting into col1 is 0, but I can see using the debugger that the
value in obj is not 0 and is OK. The ORM works for "Object"'s, if
instead of the st_put.execute line I put the whole statement
construction inside the loop, so I suspect I am violating the "object
lifetime" restrictions but I don't see how. Is there anything
obviously wrong with what I am doing here? I can flesh out the example
more if that would help. Thanks,
Matt
------------------------------------------------------------------------------
_______________________________________________
Soci-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/soci-users