const QString SQL_INSERT_LANGUAGE
= "INSERT INTO languages VALUES ("
"null, :language, :abbreviation"
")";
const QString SQL_CREATE_TABLE_WORD
= "CREATE TABLE :table ("
"word VARCHAR UNIQUE, "
"a INT, b INT, c INT, d INT, e INT, f INT, g INT, h INT, "
"i INT, j INT, k INT, l INT, m INT, n INT, o INT, p INT, "
"q INT, r INT, s INT, t INT, u INT, v INT, w INT, x INT, "
"y INT, z INT, "
"len INT"
")";
{
query.prepare(SQL_INSERT_LANGUAGE);
query.bindValue(":language", language);
query.bindValue(":abbreviation", abbreviation);
if (query.exec() == false) {
qDebug() << "ERROR 1 = " << query.lastError();
return false;
}
query.prepare(SQL_CREATE_TABLE_WORD);
query.bindValue(":table", abbreviation);
if (query.exec() == false) { // The error is in this query
qDebug() << "ERROR 2 = " << query.lastError();
qDebug() << "SQL = " << query.executedQuery();
return false;
}
return true;
}
const QString SQL_INSERT_LANGUAGE =
"INSERT INTO languages VALUES ("
"null, :language, :abbreviation"
")";
const QString SQL_CREATE_TABLE_WORD =
"CREATE TABLE :table ("
"word VARCHAR UNIQUE, "
"a INT, b INT, c INT, d INT, e INT, f INT, g INT, h INT, "
"i INT, j INT, k INT, l INT, m INT, n INT, o INT, p INT, "
"q INT, r INT, s INT, t INT, u INT, v INT, w INT, x INT, "
"y INT, z INT, "
"len INT"
")";
bool DB::addLanguage(const QVariant & language, const QVariant & abbreviation)
{
QSqlQuery query((*mDatabase));
query.prepare(SQL_INSERT_LANGUAGE);
query.bindValue(":language", language);
query.bindValue(":abbreviation", abbreviation);
if (query.exec() == false) {
qDebug() << "ERROR 1 = " << query.lastError();
return false;
}
query.prepare(SQL_CREATE_TABLE_WORD);
query.bindValue(":table", abbreviation);
if (query.exec() == false) { // The error is in this query
qDebug() << "ERROR 2 = " << query.lastError();
qDebug() << "SQL = " << query.executedQuery();
return false;
}
return true;
}
To copy to clipboard, switch view to plain text mode
Bookmarks