Sqlite query
-
It's not supported atm.
-
@apfal QSqlQuery does not support running multiple queries at once.
What you can do is (if statements are static) is to wrap them up in QStringList and run one by one in series. You gain additional advantage of being able to check if each has been successful and react/break if not.
If you construct them dynamically you obviously have to do a little more work but the principal idea remains the same. -
Something like:
QStringList queries = { QStringLiteral("create table foo ( ... )"), QStringLiteral("insert into foo value ( ... )"), QStringLiteral("insert into foo value ( ... )"), QStringLiteral("drop table bar") }; QSqluery query; for (const QString &strQuery: queries) { if (!query.exec(strQuery) { qDebug() << "You broke it :("); } }
-
@apfal like @ChrisW67 suggests.
If you get the strings as a dump from some tool, you can (after making sure each statement occupies one line) attach a text file with queries into the resource, then load it from file and execute line by line. I used to do so when db to be created/deployed was complex, like hundreds of lines. Gives you an advantage when db changes - all you have to do is replace the file and test, instead of search&replacing literals.
But that's just a separate can of worms, for what you asked the advice above is sound.