For the SQLite database, once we open it, it creates the database on the filesystem. For MySQL, we have to send MySQL commands to create the database. We construct the SQL query using QSqlQuery do this in MySQL. QSqlQuery takes the database object as an argument:
QSqlQuery query(db);
To send a query, we call the exec() function on the QSqlQuery object. It takes a String as a typical query syntax:
QString dbname = "MAEPQTdb";
if (!query.exec("CREATE DATABASE IF NOT EXISTS " + dbname)) {
qWarning() << "Database query error" << query.lastError().text();
}
dbname here is any String we want the database name to be; I am using MAEPQT db.
If this command fails, we issue a warning message. If it succeeds, then we go on and issue the command to USE it, so we call another query command:
query.exec("USE...