I am trying to insert data into mysql 5.6 db, trying to follow soci doc's example3.
Following code move's portions of record_data vector to record_data_temp and inserts them into db
std::vector<std::string> record_data_temp;
soci::statement st = (sql_imei.prepare << "INSERT INTO list_of_record_data VALUES(:record_data, " << id << ")", soci::use(record_data_temp));
std::vector<std::string> record_data;
#if TESTING_FILLER
for (unsigned long i = 0; i < SIZE_LIMIT; ++i)
record_data.push_back(std::to_string(i));
#endif
int partCount = std::stoi(argv[1]);
record_data_temp.resize(partCount);
auto v1_begin = record_data.begin();
auto v1_end = v1_begin + partCount;
int i=0;
while(i < record_data.size())
{
std::move(v1_begin, v1_end, record_data_temp.begin());
// To prevent extra elements in last iteration
if ((i + partCount) > record_data.size())
record_data_temp.resize(record_data.size() % partCount);
i += partCount;
v1_begin = v1_end;
if ((i + partCount) > record_data.size())
v1_end += record_data.size() % partCount;
else
v1_end += partCount;
#if DISPLAY_VEC
std::cout << "NEWt";
for(auto& str:record_data_temp)
std::cout << str << "t";
std::cout << std::endl;
#endif
st.execute(true);
std::cout << "updated :" << st.get_affected_rows() << std::endl;
}
for record_data with elements 0,1,2,3,4,5,6,7,8,9 with portion as 3 (partCount) my program outputs
NEW 0 1 2
updated :3
NEW 3 4 5
updated :3
NEW 6 7 8
updated :3
NEW 9
updated :0
But incorrectly inserts in database
mysql> SELECT * FROM list_of_record_data;
+--------+-----+
| msisdn | id |
+--------+-----+
| 0 | 123 |
| 1 | 123 |
| 2 | 123 |
| 0 | 123 |
| 1 | 123 |
| 2 | 123 |
| 0 | 123 |
| 1 | 123 |
| 2 | 123 |
| 0 | 123 |
+--------+-----+
10 rows in set (0.00 sec)
Where am I going wrong? I am using g++ (GCC) 5.2.0 on Red Hat Enterprise Linux Server release 6.6 (Santiago). The test performed with dummy data, actual record_data vector size will be over 50 million. Thanks for any help.
