Hi all,
i'm trying to merge two sqlite Databases via SQL statement ATTACH DATABASE pathToSecondDatabase AS toMerge.
When i try to execute i get the QSqlError "No query Unable to fetch row" . I'm coding with QtCreator with QT 4.8.1.
Probably it's a syntax error in the statement but i'm not sure whats wrong.
db.setDatabaseName(dir->filePath("data.sqlite")); //declarated in the header
db.open();
q
= QSqlQuery(db
);
//declarated in the header
q.prepare("ATTACH DATABASE " + path + " AS toMerge"); //here is the problem
if(!q.exec())
{
QSqlError error
= q.
lastError();
//throws "No query Unable to fetch row" qDebug() << error.text();
}
q.finish();
q.prepare("INSERT INTO Table SELECT * FROM toMerge.Table");
q.exec();
q.finish();
q.prepare("DETACH toMerge");
q.exec();
q.finish();
db.close();
db.setDatabaseName(dir->filePath("data.sqlite")); //declarated in the header
db.open();
q = QSqlQuery(db); //declarated in the header
q.prepare("ATTACH DATABASE " + path + " AS toMerge"); //here is the problem
if(!q.exec())
{
QSqlError error = q.lastError(); //throws "No query Unable to fetch row"
qDebug() << error.text();
}
q.finish();
q.prepare("INSERT INTO Table SELECT * FROM toMerge.Table");
q.exec();
q.finish();
q.prepare("DETACH toMerge");
q.exec();
q.finish();
db.close();
To copy to clipboard, switch view to plain text mode
Annotation:
database is open and valid
db and q are declarated in the header (other operations work fine)
path is a QString caontaining the path to the second data.sqlite file.
hope you can help me with the problem.
Thanks.
niebsi
Bookmarks