"DeltaSeq integer)");
db_unlock(this);
+ /*
+ * Keep track of the number of changes in batch mode.
+ */
+ changes = 0;
+
return retval;
}
{
m_status = 0;
+ /*
+ * Flush any pending inserts.
+ */
+ if (changes) {
+ return sql_query(cmd);
+ }
+
return true;
}
digest = ar->Digest;
}
- Mmsg(cmd, "INSERT INTO batch VALUES "
- "(%u,%s,'%s','%s','%s','%s',%u)",
- ar->FileIndex, edit_int64(ar->JobId,ed1), esc_path,
- esc_name, ar->attr, digest, ar->DeltaSeq);
+ /*
+ * Try to batch up multiple inserts using multi-row inserts.
+ */
+ if (changes == 0) {
+ Mmsg(cmd, "INSERT INTO batch VALUES "
+ "(%u,%s,'%s','%s','%s','%s',%u)",
+ ar->FileIndex, edit_int64(ar->JobId,ed1), esc_path,
+ esc_name, ar->attr, digest, ar->DeltaSeq);
+ changes++;
+ } else {
+ /*
+ * We use the esc_obj for temporary storage otherwise
+ * we keep on copying data.
+ */
+ Mmsg(esc_obj, ",(%u,%s,'%s','%s','%s','%s',%u)",
+ ar->FileIndex, edit_int64(ar->JobId,ed1), esc_path,
+ esc_name, ar->attr, digest, ar->DeltaSeq);
+ pm_strcat(cmd, esc_obj);
+ changes++;
+ }
- return sql_query(cmd);
+ /*
+ * See if we need to flush the query buffer filled
+ * with multi-row inserts.
+ */
+ if ((changes % MYSQL_CHANGES_PER_BATCH_INSERT) == 0) {
+ if (!sql_query(cmd)) {
+ changes = 0;
+ return false;
+ } else {
+ changes = 0;
+ }
+ } else {
+ return true;
+ }
}
/*