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. Mysql table locking error
Forum Updated to NodeBB v4.3 + New Features

Mysql table locking error

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 5 Posters 1.4k Views 2 Watching
  • 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.
  • JonBJ JonB

    @Kutyus
    Probably show your code so we can see (including where "unlock tables" gives a false result but no lastError() information). Also read through e.g. https://dev.mysql.com/doc/refman/8.0/en/lock-tables.html#table-lock-release to make sure you are complying with unlock requirements/behaviour.

    KutyusK Offline
    KutyusK Offline
    Kutyus
    wrote on last edited by
    #5

    @JonB
    If I run a QSqlQuery::clear() before the "unlock tables", it is working, but I do not know why?

    JonBJ 1 Reply Last reply
    0
    • KutyusK Kutyus

      @JonB
      If I run a QSqlQuery::clear() before the "unlock tables", it is working, but I do not know why?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #6

      @Kutyus
      This is purely a guess.

      While you have some existing SQL query around/open which has a LOCK TABLES or is in a transaction with such, locks can't be released? You need to finish reading/close/terminate/clear the query to release the result set/previous query so that unlocking can proceed?

      KutyusK 1 Reply Last reply
      0
      • JonBJ JonB

        @Kutyus
        This is purely a guess.

        While you have some existing SQL query around/open which has a LOCK TABLES or is in a transaction with such, locks can't be released? You need to finish reading/close/terminate/clear the query to release the result set/previous query so that unlocking can proceed?

        KutyusK Offline
        KutyusK Offline
        Kutyus
        wrote on last edited by Kutyus
        #7

        @JonB
        Yes that is how it works.

        If I comment out the query between lock and unlock, it works that way.

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

          Hi,

          Can you show the code your using ?

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

          KutyusK 1 Reply Last reply
          0
          • Christian EhrlicherC Online
            Christian EhrlicherC Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #9

            @JonB said in Mysql table locking error:

            LOCK TABLES

            Why do you need it at all?

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            JonBJ 1 Reply Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              @JonB said in Mysql table locking error:

              LOCK TABLES

              Why do you need it at all?

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #10

              @Christian-Ehrlicher
              It's not me, it's the OP!

              @Kutyus wrote:

              The "lock table tablename" is fine, but executing the "unlock tables" gives a false result and the database is stayed in locked state.

              I believe the OP is using LOCK/UNLOCK TABLES. Whether that is a good idea is another matter :) Perhaps they will explain.

              1 Reply Last reply
              0
              • SGaistS SGaist

                Hi,

                Can you show the code your using ?

                KutyusK Offline
                KutyusK Offline
                Kutyus
                wrote on last edited by
                #11

                @SGaist

                I derived QSqlQuery and there is an error when I call prepare (), but the factory QSqlQuery also produces an error when prepare () is called but clear () is not.

                QSqlQuery query = QSqlQuery(db);
                
                query.prepare(QString("lock table categories write"));
                query.exec();
                
                query.prepare(QString("update categories set name = '%1' where id = %2").arg(name.text()).arg(id));
                query.exec();
                
                query.clear();
                query.prepare(QString("unlock tables"));
                query.exec();
                
                JonBJ 1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #12

                  You should check the outcome of each of your queries and print the error if any occurs. That should give you more insight about what is going on.

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

                  KutyusK 1 Reply Last reply
                  0
                  • KutyusK Kutyus

                    @SGaist

                    I derived QSqlQuery and there is an error when I call prepare (), but the factory QSqlQuery also produces an error when prepare () is called but clear () is not.

                    QSqlQuery query = QSqlQuery(db);
                    
                    query.prepare(QString("lock table categories write"));
                    query.exec();
                    
                    query.prepare(QString("update categories set name = '%1' where id = %2").arg(name.text()).arg(id));
                    query.exec();
                    
                    query.clear();
                    query.prepare(QString("unlock tables"));
                    query.exec();
                    
                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by
                    #13

                    @Kutyus said in Mysql table locking error:

                    query.prepare(QString("lock table categories write"));

                    You're supposed to take the time to read the documentation (https://dev.mysql.com/doc/refman/8.0/en/lock-tables.html) of your database backend before asking for Qt help here. There is no lock table statement.

                    1 Reply Last reply
                    1
                    • SGaistS SGaist

                      You should check the outcome of each of your queries and print the error if any occurs. That should give you more insight about what is going on.

                      KutyusK Offline
                      KutyusK Offline
                      Kutyus
                      wrote on last edited by
                      #14

                      @SGaist
                      I found a solution, the lock table and the unlock tables statements cannot be prepared, I received the following message:
                      "This command is not supported in the prepared statement protocol yet QMYSQL3: Unable to prepare statement"

                      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