Bug #77163 [PATCH]: PDOException not thrown for SELECT FOR UPDATE with ATTR_EMULATE_PREPARES = 0
| From: | cmb@php.net | Date: | Tue, 01 Sep 2020 11:19:01 +0000 |
| Subject: | Bug #77163 [PATCH]: PDOException not thrown for SELECT FOR UPDATE with ATTR_EMULATE_PREPARES = 0 | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-228835@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77163&edit=1
ID: 77163
Patch added by: cmb@php.net
Reported by: contact at bastiaangrutters dot nl
Summary: PDOException not thrown for SELECT FOR UPDATE with
ATTR_EMULATE_PREPARES = 0
Status: Verified
Type: Bug
Package: PDO MySQL
Operating System: Linux
PHP Version: 7.4.5
Block user comment: N
Private report: N
New Comment:
The following pull request has been associated:
Patch Name: with ATTR_EMULATE_PREPARES = false, don't ignore deadlock errors
On GitHub: https://github.com/php/php-src/pull/5937
Patch: https://github.com/php/php-src/pull/5937.patch
Previous Comments:
------------------------------------------------------------------------
[2020-04-22 07:04:57] sjon@php.net
this is still broken
------------------------------------------------------------------------
[2018-11-15 12:28:36] contact at bastiaangrutters dot nl
Description:
------------
When using PDO MySQL to select rows for update with PDO::ATTR_EMULATE_PREPARES set to false and
PDO::ATTR_ERRMODE set to PDO::ERRMODE_EXCEPTION no exception is thrown when the rows are already
locked and a timeout occurs.
Note:
The exception is thrown when PDO::ATTR_EMULATE_PREPARES is not set/set to true or when a parameter
is used in the select query.
Instructions on reproducing this:
Open mysql on cli, and perform queries:
CREATE DATABASE testdb;
USE testdb;
CREATE TABLE test (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, value
VARCHAR(30) NOT NULL);
INSERT INTO test (value) VALUES ('test');
# Before starting the test script open a transaction and lock the table:
BEGIN;
SELECT * FROM test FOR UPDATE;
# Now run the script
Test script:
---------------
<?php
$pdo = new PDO('mysql:dbname=testdb;host=localhost', 'username',
'password');
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->beginTransaction();
$statement = $pdo->prepare('SELECT * FROM test FOR UPDATE');
$statement->execute();
var_dump(
$statement->fetchAll(),
$statement->errorCode()
);
$pdo->commit();
Expected result:
----------------
Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded;
try restarting transaction in test-pdo.php:14
Stack trace:
#0 test-pdo.php(14): PDOStatement->execute()
#1 {main} thrown in test-pdo.php on line 14
Actual result:
--------------
array(0) {
}
string(5) "00000"
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77163&edit=1