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 Update on Tuesday, May 27th 2025

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.
  • J JonB
    7 Feb 2020, 13:35

    @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.

    K Offline
    K Offline
    Kutyus
    wrote on 7 Feb 2020, 13:52 last edited by
    #5

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

    J 1 Reply Last reply 7 Feb 2020, 14:03
    0
    • K Kutyus
      7 Feb 2020, 13:52

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

      J Online
      J Online
      JonB
      wrote on 7 Feb 2020, 14:03 last edited by JonB 2 Jul 2020, 14:04
      #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?

      K 1 Reply Last reply 7 Feb 2020, 14:07
      0
      • J JonB
        7 Feb 2020, 14:03

        @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?

        K Offline
        K Offline
        Kutyus
        wrote on 7 Feb 2020, 14:07 last edited by Kutyus 2 Jul 2020, 14:09
        #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
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 7 Feb 2020, 20:00 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

          K 1 Reply Last reply 10 Feb 2020, 08:13
          0
          • C Online
            C Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on 7 Feb 2020, 20:15 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

            J 1 Reply Last reply 7 Feb 2020, 23:14
            0
            • C Christian Ehrlicher
              7 Feb 2020, 20:15

              @JonB said in Mysql table locking error:

              LOCK TABLES

              Why do you need it at all?

              J Online
              J Online
              JonB
              wrote on 7 Feb 2020, 23:14 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
              • S SGaist
                7 Feb 2020, 20:00

                Hi,

                Can you show the code your using ?

                K Offline
                K Offline
                Kutyus
                wrote on 10 Feb 2020, 08:13 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();
                
                J 1 Reply Last reply 10 Feb 2020, 09:43
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 10 Feb 2020, 08:22 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

                  K 1 Reply Last reply 11 Feb 2020, 08:22
                  0
                  • K Kutyus
                    10 Feb 2020, 08:13

                    @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();
                    
                    J Online
                    J Online
                    JonB
                    wrote on 10 Feb 2020, 09:43 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
                    • S SGaist
                      10 Feb 2020, 08:22

                      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.

                      K Offline
                      K Offline
                      Kutyus
                      wrote on 11 Feb 2020, 08:22 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

                      14/14

                      11 Feb 2020, 08:22

                      • Login

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