Results 1 to 5 of 5

Thread: One database two programs

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default One database two programs

    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?
    In the near future - corporate networks reach out to the stars. Electrons and light flow throughout the universe.
    The advance of computerization however, has not yet wiped out nations and ethnic groups.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: One database two programs

    How does the problem manifest itself?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    Talei (16th February 2012)

  4. #3
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: One database two programs

    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.
    Last edited by Talei; 16th February 2012 at 16:57.
    In the near future - corporate networks reach out to the stars. Electrons and light flow throughout the universe.
    The advance of computerization however, has not yet wiped out nations and ethnic groups.

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: One database two programs

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #5
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: One database two programs

    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.
    In the near future - corporate networks reach out to the stars. Electrons and light flow throughout the universe.
    The advance of computerization however, has not yet wiped out nations and ethnic groups.

Similar Threads

  1. Install our programs into other pcs
    By gremboxic in forum Newbie
    Replies: 2
    Last Post: 10th June 2011, 13:38
  2. How to use SSE(2,3) in C++/QT programs
    By Ronayn in forum General Programming
    Replies: 1
    Last Post: 7th June 2011, 06:11
  3. Qt for programs on Windows CE
    By kyut in forum Newbie
    Replies: 20
    Last Post: 3rd March 2011, 12:32
  4. [SOLVED] database opened .. database not open
    By kapitanluffy in forum Qt Programming
    Replies: 1
    Last Post: 27th February 2011, 10:39
  5. Enterprise Programs
    By migizi in forum General Discussion
    Replies: 0
    Last Post: 23rd September 2010, 23:54

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.