I still don't understand why you can't use transactions. A SELECT statement will still return up-to-date data, even in the middle of a transaction. A disk database with transactions will easily support 10,000 simple inserts a second, so you could skip the in-memory database. Anyway, here is a sample of using ATTACH. I doubt it's much faster than doing it in Qt, but it is a bit more elegant.
Qt Code:
  1. void setupDiskDb()
  2. {
  3. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", "disk");
  4. db.setDatabaseName("CatchyName");
  5. db.open();
  6.  
  7. QSqlQuery query(db);
  8. query.exec("CREATE TABLE T1(F1, F2, F3)");
  9. }
  10.  
  11. void doSqLiteTest2()
  12. {
  13. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", "mem");
  14. db.setDatabaseName(":memory:");
  15. db.open();
  16.  
  17. QSqlQuery query(db);
  18. query.exec("CREATE TABLE T1(F1, F2, F3)");
  19.  
  20. query.prepare("INSERT INTO T1 (F1, F2, F3) "
  21. "VALUES (:1, :2, :3)");
  22.  
  23. for (int i = 0; i < 50000; i++)
  24. {
  25. query.bindValue(":1", i + 0);
  26. query.bindValue(":2", i + 1);
  27. query.bindValue(":3", i + 2);
  28. query.exec();
  29. }
  30.  
  31. qDebug() << query.exec("ATTACH DATABASE 'CatchyName' AS Catchy");
  32. qDebug() << query.exec("INSERT INTO Catchy.T1(F1, F2, F3) SELECT F1, F2, F3 FROM T1");
  33. }
  34.  
  35. int main(int argc, char * argv[])
  36. {
  37. QApplication a(argc, argv);
  38.  
  39. setupDiskDb();
  40. doSqLiteTest2();
  41.  
  42. return a.exec();
  43. }
To copy to clipboard, switch view to plain text mode