QString insertQuery = "INSERT INTO data_waveform (ID, Point, IndexN, Type, Timestamp, CH1, CH2, CH3, CH4) VALUES "; QStringList valueStrings; for (auto data:*dataVec) { valueStrings.append(QString("(\"%1\", %2, %3, %4, \"%5\", %6, %7, %8, %9)") .arg(data.id).arg(data.Point).arg(data.indexN).arg(data.type).arg(data.timestamp) .arg(data.CH1).arg(data.CH2).arg(data.CH3).arg(data.CH4)); } insertQuery += valueStrings.join(", "); insertData(insertQuery);
void SqliteDbManager::insertData( const QString& sql ) { m_db.transaction(); // 开启事务 // 执行插入操作 QSqlQuery query(m_db); if (!query.exec(sql)) { qDebug() << "Error:" << query.lastError().text(); m_db.commit(); // 提交事务 return; } else { qDebug() << "Data inserted successfully!"; } m_db.commit(); // 提交事务 }
标签:sqlite,valueStrings,批量,插入,QString,arg,insertQuery,data From: https://www.cnblogs.com/RedWetPlace/p/18245317