PDA

View Full Version : One database two programs



Talei
16th February 2012, 16:30
Hello,
I have two programs that access same database (sqlite 3). One program Write to database, other one only Reads from db (no write).

And problem is that program 1 (that WRITE/READ to/from db) don't write information to db when program 2 (only READ) opens db.

In program 2 I have set QSqlDatabase.setConnectOptions( "QSQLITE_OPEN_READONLY" );

Any idea how to open same db twice, once in WRITE/READ and second one only in READ ONLY, so in second program I can query all changes etc., and in first one I can still write data to db, or is it impossible?

wysota
16th February 2012, 16:34
How does the problem manifest itself?

Talei
16th February 2012, 16:53
Program 1 (that writes data to db) can't write data to db, unfortunately I don't have src for program 1 so I can't tell what's going on there.

This situation occur when program 2, my program, opens db first (db READ ONLY).

On the second thought I have in my program, program 2 that's READ_ONLY from db, QFileSystemWatcher on that db file, and I start suspecting that QFileSystemWatcher do a lock on that file, so program 1 can't write. Is it possible that QFileSystemWatcher do such a thing?

EDIT: I can't rename file *.db, when QFileSystemWatcher has it monitored, so I assume that lock is done and program 1 can't also read from file.
EDIT2: I can write, using i.e. notepad to .db file and changes are saved.
EDIT3: It's strange but program 1 can read from .db but can't write to it.

wysota
16th February 2012, 16:57
QFileSystemWatcher doesn't lock files, as far as I know. It could be that the other program wants an exclusive lock on the database file and since you have it open for reading, it can't get it and fails. If you can't modify the other program (does it use Qt to access the database?) I'm afraid there is not much you can do about it.

Talei
16th February 2012, 17:19
Yes, program 1 is Qt program.

It seams that this is indeed QFileSystemWatcher problem.

I use QFileSystemWatcher to know when changes are made to .db file. I modified my program to use QTimer to access db periodically and there is no problem with write from program 1.

QFileSystemWatcher has some serious problem IMHO, i wrote here also a bug on Linux with removing files from QFileSystemWatcher when filechange() signal is emited, so probably this is another problem with QFileSystemWatcher.

In free time I will investigate this problem more.