I've got UPDATE problem again. This time I'm doing in one of my slots something like this:
ok = bdb.open();
if(ok)
{
zapytanie.clear();
zapytanie="UPDATE mesg SET cmp='1'";
zapytanie.append(" WHERE id='");
zapytanie.
append(QString::number(rec.
value(0).
toInt()));
zapytanie.append("'");
query.clear();
query.prepare(zapytanie);
ok = query.exec();
query.clear();
bdb.close();
}
ok = bdb.open();
if(ok)
{
zapytanie.clear();
zapytanie="UPDATE mesg SET cmp='1'";
zapytanie.append(" WHERE id='");
zapytanie.append(QString::number(rec.value(0).toInt()));
zapytanie.append("'");
query.clear();
query.prepare(zapytanie);
ok = query.exec();
query.clear();
bdb.close();
}
To copy to clipboard, switch view to plain text mode
At the beginning of the program I've got:
databaseName="mybase.db";
bdb.setDatabaseName(databaseName);
databaseName="mybase.db";
bdb = QSqlDatabase::addDatabase("QSQLITE");
bdb.setDatabaseName(databaseName);
To copy to clipboard, switch view to plain text mode
If I give a name to database:
bdb = QSqlDatabase::addDatabase("QSQLITE","databaseName");
To copy to clipboard, switch view to plain text mode
I can read from database but the update code above gives:
QSqlQuery::prepare: database not open
To copy to clipboard, switch view to plain text mode
When I remove name everything is OK. What's wrong? I know You've given me code and said that I can use It without open() but I need to close base after use because other programs uses the same database. And I want to give that database name.
thanks in advance
best regards
Tomasz
Bookmarks