two databases opened at the same time
Hi!
Me again with my database based problems.
I have opened two databases in order to transfer data from one database to another. I declare first query as:
Code:
QSqlQuery query_read
("SELECT * FROM groups", db1
);
int is_kat = query_read.record().indexOf("group");
while(query_read.next()) {
QString s_kat
= query_read.
value(is_kat
).
toString();
//some code + declaration for another query
}
The second query is declared inside the marked area like this:
Code:
query_write.prepare("INSERT INTO kat (kategories) VALUES (:kategorie)");
query_write.bindValue(":kategorija", s_kat);
query_write.exec();
Compiling does not return any error, but the data is not transfered. Where is the error?
Regards,
Luka
Re: two databases opened at the same time
":kategorie" and ":kategorija" -- they should be the same.
Re: two databases opened at the same time
tnx... :o I'm ashamed... :o i stared for two hours at the screen but i never see that error... now it works fine!
tnx again!
Luka
Re: two databases opened at the same time
I try to open two seperate SQLite databases at the same time using code below. Why do I get message that the first DB is not opened?
Code:
base1.setDatabaseName(pot);
base1.open();
base2.setDatabaseName(qApp->applicationDirPath() + "/base.db");
base2.open();
if (base1.isOpen() != TRUE) {
QMessageBox::critical(this,
"Dnevnik",
"Error opening DB 1");
}
else {
if(base2.isOpen() != TRUE){
QMessageBox::critical(this,
"Dnevnik",
"Error opening DB 2");
}
else {
//some code to execute
}
}
base2.close();
base1.close();
If I use code below everything works just fine...
Code:
base1.setDatabaseName(pot);
base1.open();
if (base1.isOpen() != TRUE) {
QMessageBox::critical(this,
"Dnevnik",
"Error opening DB 1");
}
else {
base2.setDatabaseName(qApp->applicationDirPath() + "/base.db");
base2.open();
if(base2.isOpen() != TRUE){
QMessageBox::critical(this,
"Dnevnik",
"Error opening DB 2");
}
else {
//some code to execute
}
base2.close();
}
base1.close();
Can somebody explain what I do with the first and what with the second code?
Regards,
Luka
Re: two databases opened at the same time
try use QSqlDatabase::lastError, for finding solution
Re: two databases opened at the same time
Quote:
Originally Posted by whoops.slo
I try to open two seperate SQLite databases at the same time using code below. Why do I get message that the first DB is not opened?
Quote:
From Qt docs:
QSqlDatabase QSqlDatabase::addDatabase ( const QString & type, const QString & connectionName = QLatin1String( defaultConnection ) ) [static]
Adds a database to the list of database connections using the driver type and the connection name connectionName. If there already exists a database connection called connectionName, that connection is removed.
You open the same connection twice.
Try: