PDA

View Full Version : SQLite + journal + lock



NoRulez
11th December 2009, 13:12
Hey @all,

i use SQLite for my application. Currently it seems that a database lock occurs.

What i'm trying to do is to delete multiple rows from the database. When I'm doing this, a FILE-journal file is created. But this file aren't removed when the delete process is finished. So it seems that this is a database lock.
When i restart the application, the rows that I removed before are still there.

I use a editable QSqlQueryModel for this.

Hope someone can help me

Thanks in advance

Best Regards
NoRulez

Tanuki-no Torigava
12th December 2009, 02:02
Hi, see my answer (http://www.qtcentre.org/forum/f-qt-programming-2/t-qsqlite-database-is-locked-26460.html) here. Looks like your problem as well.
Cheers,
-- Tanuki

NoRulez
13th December 2009, 16:40
Thank you, i've tried it, but it didn't solve the problem.

The filesize of the journal is, of the application is running 0 kb.
When I exit the application the file size of the journal file is >= 2kb and <= 23 kb.
The changes are also not made, after i restart the application :(

Best Regards
NoRulez

NoRulez
13th December 2009, 16:53
Ok, I think the problem has to do with the following message i noticed, when I exit the application:
[4580] QSqlDatabasePrivate::removeDatabase: connection 'qt_sql_default_connection' is still in use, all queries will cease to work.

How can i find out, on which point the database connection is still alive?

Best Regards
NoRulez

Tanuki-no Torigava
14th December 2009, 09:25
Nope. You see that message because database plugins in Qt implemented as static singletons. It is just warns you that it closes the db and will cease all current connections used by your app. But anyway, it is extremely strange if you cannot write anything in db because of locks. So if you will answer a couple of questions then maybe I could suggest you something.
1. Does your app the only one who use that db?
2. Which else apps are using it?

If your app is the only one, try to open just one connection with non-default name (see SessionName parameter in QSqlDatabase::addDatabase) and try to perform some stupid insert there. And don't forget to process the query errors. May be you have wrong syntax in query itself. Another possible issue is that if you use transactions - please be sure you either commit or rollback that before jumping to some other place of your app. So make it consistent like that:



QSqlDatabase m_db = QSqlDatabase::addDatabase("QSQLITE", "MyTestConnection");

// ... database verification code. I skip that but you can see the example in qt examples or my previous post.

// And query itself
bool batch = m_db.transaction ();
// ... Your batch queries
if (batch)
m_db.commit();


If you leave transaction block when you already started transaction and didn't finish it - yeah it will block. That's logical.

Best regards,
-- tanuki