Results 1 to 9 of 9

Thread: Does QDataWidgetMapper lock sqlite and prevent write by other applications?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2009
    Posts
    47
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: QSqlTableModel locks sqlite and prevents write by other applications

    Agreed. As QSqlTableModel implements many things that are ok for me, this looks like an overkill. And since the application uses QSqlRelationalTableModel, I would even need to reimplement this class.


    Added after 1 9 minutes:


    QSqlQueryModel::setQuery(const QSqlQuery &query) is the function that leads to the lock. In turn, this function calls
    Qt Code:
    1. void fetchMore(const QModelIndex &parent)
    2. void QSqlQueryModelPrivate::prefetch(int limit)
    3. bool QSqlQuery::seek(int index, bool relative)
    4. bool QSqlCachedResult::fetch(int i)
    5. bool QSqlCachedResult::cacheNext() // called repeatedly until requested record has been fetched
    6. bool QSqliteResult::gotoNext()
    7. bool QSQLiteResultPrivate::fetchNext(QSqlCachedResult::ValueCache &values, int idx, bool initialFetch)
    To copy to clipboard, switch view to plain text mode 
    Only when sqlite3_step(sqlite3_stmt*) returns SQLITE_DONE a call to sqlite3_reset(stmt) is made, i.e., only when there is no more data to fetch. Thus, the lock on the database is only released once all data has been fetched; which is the (undesirable) behaviour I observed.

    So, the issue is in the QSQLITE driver. And indeed, after realizing this, I find it described in the Qt docs, see qthelp://org.qt-project.qtsql.520/qtsql/sql-driver.html#general-information-about-qsqlite: "The driver is locked for updates while a select is executed. This may cause problems when using QSqlTableModel because Qt's item views fetch data as needed (with QSqlQuery::fetchMore() in the case of QSqlTableModel)."
    Last edited by Al_; 9th March 2014 at 15:10.

Similar Threads

  1. Replies: 1
    Last Post: 25th April 2013, 14:55
  2. Replies: 2
    Last Post: 14th November 2011, 11:24
  3. sqlite read lock.
    By gilgm in forum Qt Programming
    Replies: 6
    Last Post: 18th June 2010, 05:58
  4. sqlite write security
    By lesat in forum Qt Programming
    Replies: 0
    Last Post: 28th April 2010, 05:05
  5. SQLite + journal + lock
    By NoRulez in forum Qt Programming
    Replies: 4
    Last Post: 14th December 2009, 08:25

Tags for this Thread

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.