SOCI / soci

Official repository of the SOCI - The C++ Database Access Library
http://soci.sourceforge.net/
Boost Software License 1.0
1.41k stars 477 forks source link

Bulk/batch INSERT operations and prepared statements. #1167

Open wiluite opened 2 weeks ago

wiluite commented 2 weeks ago

Hello,

Suppose, I have a trivial insertion code (much more simpler than the one, provided in the documention):

CREATE TABLE table1( a DECIMAL NOT NULL );
...

std::vector<int> v (3, 1);
soci::statement stmt = (sql.prepare << "insert into table1 (a) values (:a)", soci::use(v));
v[0] = 1;
v[1] = 2;
v[2] = 3;
stmt.execute(1);
v[0] = 4;
v[1] = 5;
stmt.execute(1);

Now, the following SELECT says the sqlite3 and the Firebird backends worked it out as I'd expected:

a 1 2 3 4 5 3

While dealing with MySQL and PostgreSQL DBMS and their soci backends I got the following results:

a 1 2 3 1 2 3

So, actually, after the first insertion portion something refuses to accept actually changed data as changed. Could you please hint where to dig? (Or мaybe the problem lies on the surface?)

Thanks! The Firebird I used is 5. MySQL version is 8. The PostgreSQL is 14.

vadz commented 1 week ago

This looks like a bug, to be honest. We even have a unit test checking that this works for scalar inserts, see "Multiple use and into", but not for vectors, unfortunately.

I'd have to debug it to see what's going on here...

wiluite commented 1 week ago

OK! Look, if it's not too difficult. Yes, I'd seen the code you pointed to, but I thought you run it against the sqlite3 only (which emulates the bulk). If there were no problems with inserting scalars across all backends in this mode, then the error is probably somewhere during vector insertion.

As a helpful info: oracle and firebird backends for vectors works well. (maybe fixes for mysql and postgresql could be accomplished by analogy).