PDA

View Full Version : Weird bug with SQLite



RavenS
28th March 2009, 17:27
Hello peoples.
I have very weird bug with my sqlite db. I can open database, i can write data to it, and can correctly close it, but when i'm trying to open this database again, it's empty. O_o
When i perform "db.open()" it becomes clean... What can it be?

Lykurg
28th March 2009, 17:30
Can you show us some code? (Maybe you create the database in RAM?)

RavenS
28th March 2009, 17:37
bool DBWorker::OpenDB() {
db = QSqlDatabase::addDatabase("QSQLITE");
db.setHostName("localhost");
db.setDatabaseName("data");
db.setUserName("maryjane");

if (db.open() == false) {
qDebug() << "Error. Database not opened.";
return false;
}

...
QUERIES KINDA "CREATE TABLE ... IF NOT EXISTS"
...

return true;
}

DBWorker::~DBWorker() {
db.close()
}


In other function i have inserting data. It's really inserting, 'cause when i'm closing application, db size are growing.
So, when i'm performing this instruction at the next application start


if (db.open() == false) {

db becomes clean.

RavenS
28th March 2009, 17:45
In debug i found this string:

"QSqlDatabasePrivate::removeDatabase: connection 'qt_sql_default_connection' is still in use, all queries will cease to work."
But i'm closing database. What's the problem?