We are using mysql connector for c++(official library), however there is no batchupdate
or batchinsert
method in the c++ library (Although in java those methods do exist).
For accomplishing this I've tried something like below and it worked. However in this case if we insert thousands of rows of data in every minute, in approximately 30 minutes mysql consumes all the memory in our computer(which has 32G of memory).
Is this usage wrong, if so what should we do? (We ran the code below in a loop):
try {
//autoClose parameter is false in our case
if (!autoClose) {
con->setAutoCommit(false);
}
stmt = con->prepareStatement(queryBuilder);
this->setPreparedStatements(insertData);
result = stmt->executeUpdate();
stmt->close();
if (getAutoGeneratedKey) {
std::string lastIdQuery = "SELECT LAST_INSERT_ID()";
stmt = con->prepareStatement(lastIdQuery);
ResultSet *rs = stmt->executeQuery();
while (rs->next()) {
result = rs->getInt(1);
}
rs->close();
delete rs;
stmt->close();
}
if (autoClose) { //autoClose parameter is false in our case
con->close();
}
Thanks