Hello again!
I have strange problem while dealing with SQLite database. Everything seem so be all right when I open it like this:
QString dbase_path
= app_path
+ "/base.bz";
{
base.setDatabaseName(dbase_path);
base.open();
if(base.isOpen() != true){
QMessageBox::critical(this,
"Error",
"Base is not open.");
}
else {
// the database is opened
// create data table
QSqlQuery sql_create_table
("CREATE TABLE IF NOT EXISTS data (id INTEGER PRIMARY KEY, date TEXT, ...)");
...
}
base.close();
}
QString app_path = QApplication::applicationDirPath();
QString dbase_path = app_path + "/base.bz";
{
QSqlDatabase base = QSqlDatabase::addDatabase("QSQLITE");
base.setDatabaseName(dbase_path);
base.open();
if(base.isOpen() != true){
QMessageBox::critical(this, "Error", "Base is not open.");
}
else {
// the database is opened
// create data table
QSqlQuery sql_create_table("CREATE TABLE IF NOT EXISTS data (id INTEGER PRIMARY KEY, date TEXT, ...)");
...
}
base.close();
}
To copy to clipboard, switch view to plain text mode
Except when I try to reconnect I get alert:
QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connection removed.
Data is correctly writen and extracted to and from database.
In docs it is writen, that I must use connectionName to avoid this error. I change:
QSqlDatabase base = QSqlDatabase::addDatabase("QSQLITE", "conn_name");
To copy to clipboard, switch view to plain text mode
and add
QSqlDatabase::removeDatabase("conn_name");
To copy to clipboard, switch view to plain text mode
after I close the database. The alert now say:
QSqlQuery::exec: database not open
, nothing is writen to the database. base.isDriverAvailable say, it is not...query.lastError() say Driver not loaded. However base.isOpen() say it is open!
What am I doing wrong? I am using Qt 4.5 that came with Fedora 12, sqlite driver is present (at least it was instaled with fedora and in use without connectionName it is working).
Regards,
Luka
Bookmarks