You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The isTableMissing() method checks for the error code 1146 for MySQL when the table used to store the locks doesn't exists, but the code in PDOException is "42S02" for that server.
PHP documentation says that for the PDOException, the code is the SQLSTATE error code.
The stacktrace that PHP throws is:
PHP Fatal error: Uncaught PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'testdb.lock_keys' doesn't exist in /app/vendor/symfony/lock/Store/PdoStore.php:140
Stack trace:
#0 /app/vendor/symfony/lock/Store/PdoStore.php(140): PDOStatement->execute()
#1 /app/vendor/symfony/lock/Store/PdoStore.php(117): Symfony\Component\Lock\Store\PdoStore->putOffExpiration()
#2 /app/vendor/symfony/lock/Lock.php(85): Symfony\Component\Lock\Store\PdoStore->save()
#3 /app/lock_test.php(11): Symfony\Component\Lock\Lock->acquire()
#4 {main}
Next Symfony\Component\Lock\Exception\LockAcquiringException: Failed to acquire the "test-lock" lock. in /app/vendor/symfony/lock/Lock.php:116
Stack trace:
#0 /app/lock_test.php(11): Symfony\Component\Lock\Lock->acquire()
#1 {main}
thrown in /app/vendor/symfony/lock/Lock.php on line 116
As you can see, SQLSTATE is effectively 42S02
And if you inspect the $errorInfo array of the PDOException it has the content
This array contains the PDO::errorInfo() array which PHP manuals says that:
Element 0 is SQLSTATE error code (a five characters alphanumeric identifier defined in the ANSI SQL standard).
Element 1 is Driver-specific error code.
Element 2 is Driver-specific error message.
So, if we want to use the driver-specific error code (the 1146) we shouldn't check for the Exception code but the errorInfo array.
Thanks.
Ernesto
How to reproduce
I used Docker to test the component with this simple script:
PHP version 8.2.16
MySQL version 8.3.0
MariaDB version 11.3.2
Possible Solution
Either user the SQLSTATE error code for MySQL which is "42S02", or the second element of array erroInfo of the PDOException class which is 1146 as expected.
I consider that the most trivial solution is the first one 😄
Additional Context
No response
The text was updated successfully, but these errors were encountered:
…omato)
This PR was merged into the 5.4 branch.
Discussion
----------
[Lock] Check the correct SQLSTATE error code for MySQL
* Closes bug: #54091
| Q | A
| ------------- | ---
| Branch? | 5.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Issues | Fix#54091
| License | MIT
Commits
-------
7318816 [Lock] Check the correct SQLSTATE error code for MySQL
Symfony version(s) affected
5.4 and above
Description
The isTableMissing() method checks for the error code 1146 for MySQL when the table used to store the locks doesn't exists, but the code in PDOException is "42S02" for that server.
PHP documentation says that for the PDOException, the code is the SQLSTATE error code.
The stacktrace that PHP throws is:
As you can see, SQLSTATE is effectively 42S02
And if you inspect the $errorInfo array of the PDOException it has the content
This array contains the PDO::errorInfo() array which PHP manuals says that:
Element 0 is SQLSTATE error code (a five characters alphanumeric identifier defined in the ANSI SQL standard).
Element 1 is Driver-specific error code.
Element 2 is Driver-specific error message.
So, if we want to use the driver-specific error code (the 1146) we shouldn't check for the Exception code but the errorInfo array.
Thanks.
Ernesto
How to reproduce
I used Docker to test the component with this simple script:
PHP version 8.2.16
MySQL version 8.3.0
MariaDB version 11.3.2
Possible Solution
Either user the SQLSTATE error code for MySQL which is "42S02", or the second element of array erroInfo of the PDOException class which is 1146 as expected.
I consider that the most trivial solution is the first one 😄
Additional Context
No response
The text was updated successfully, but these errors were encountered: