Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSqlTableModel and lock a record

QSqlTableModel and lock a record

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 642 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Selzig
    wrote on last edited by
    #1

    Hello,
    i am currently working on a mariadb database with simultaneous access management.

    I was wondering if it was possible to lock a record before editing it (or not) with a QSqlTableModel.

    Otherwise, currently I use the QSqlQuery of a QSqlQueryModel : "SELECT... FOR UPDATE".
    The problem is that a QSqlQueryModel is read only, so after an update, (a delete or even an insert) with the QSqlQuery, you have to completely redisplay the table and then reselect the adapted row.

    So with a QSqlTableModel is it possible to check that a record is not locked, and in this case, to lock and then unlock it, in a transaction obviously ?

    Thanks. Regards. Gilles

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      At the moment I don't think it's possible, it would require changing QSqlTableModelPrivate::exec.

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      1
      • S Offline
        S Offline
        Selzig
        wrote on last edited by
        #3

        Thank you for the link.
        In qsqltablemodel.h, 4 signals are declared :

        Q_SIGNALS:
        123 void primeInsert(int row, QSqlRecord &record);
        124
        125 void beforeInsert(QSqlRecord &record);
        126 void beforeUpdate(int row, QSqlRecord &record);
        127 void beforeDelete(int row);
        .... and there is a protected method
        139 void setQuery(const QSqlQuery &query);

        I wonder if there is any way to use them to solve my problem.

        Regards. Gilles

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          What I would try is to make the SELECT for UPDATE query in a slot connected to the beforeUpdate. You need a direct connection (which is the default unless you are using objects in different threads).

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved