Mysql table locking error
-
wrote on 7 Feb 2020, 10:25 last edited by
Hi!
In qt 5.13.2 I using mysql database plugin but table locking not working property.
The "lock table tablename" is fine, but executing the "unlock tables" gives a false result and the database is stayed in locked state.
Thanks
-
Hi!
In qt 5.13.2 I using mysql database plugin but table locking not working property.
The "lock table tablename" is fine, but executing the "unlock tables" gives a false result and the database is stayed in locked state.
Thanks
@Kutyus What does https://doc.qt.io/qt-5/qsqlquery.html#lastError return after "unlock tables"?
-
@Kutyus What does https://doc.qt.io/qt-5/qsqlquery.html#lastError return after "unlock tables"?
-
wrote on 7 Feb 2020, 13:35 last edited by JonB 2 Jul 2020, 13:37
@Kutyus
Probably show your code so we can see (including where "unlock tables" gives a false result but nolastError()
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. -
@Kutyus
Probably show your code so we can see (including where "unlock tables" gives a false result but nolastError()
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. -
@JonB
If I run a QSqlQuery::clear() before the "unlock tables", it is working, but I do not know why?wrote on 7 Feb 2020, 14:03 last edited by JonB 2 Jul 2020, 14:04@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? -
@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? -
Hi,
Can you show the code your using ?
-
-
wrote on 7 Feb 2020, 23:14 last edited by
@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. -
wrote on 10 Feb 2020, 08:13 last edited by
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();
-
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.
-
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();
wrote on 10 Feb 2020, 09:43 last edited by@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. -
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.
wrote on 11 Feb 2020, 08:22 last edited by@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"
8/14