QSqlQuery Insert multiple rows (MySQL)
-
MySql allows for insertion of multiple rows using a single
INSERT INTOstatement,INSERT INTO table(c1,c2,...) VALUES (v11,v12,...), (v21,v22,...), ... (vnn,vn2,...);Is there any way to duplicate this using
QSqlQuery? At the moment I can only...- Add rows one-at-a-time
- Prepare my own long
INSERT INTOstatement (UsingQString)
I was hoping this could be handled by adding a
std::vector(or other valid container type) during thebindValuemethod call... Is this possible? -
See https://doc.qt.io/qt-5/qsqlquery.html#execBatch - don't know if the driver supports it.
But using a transaction + a simple loop will do the same. It will be a little bit slower I would guess but as long as you don't insert thousands of rows it's not measurable.