Bug #77163 [NEW]: PDOException not thrown for SELECT FOR UPDATE with ATTR_EMULATE_PREPARES = 0
| From: | contact at bastiaangrutters dot nl | Date: | Thu, 15 Nov 2018 12:28:36 +0000 |
| Subject: | Bug #77163 [NEW]: PDOException not thrown for SELECT FOR UPDATE with ATTR_EMULATE_PREPARES = 0 | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-217973@lists.php.net to get a copy of this message | ||
From: contact at bastiaangrutters dot nl
Operating system: Linux
PHP version: 7.2.12
Package: PDO MySQL
Bug Type: Bug
Bug description:PDOException not thrown for SELECT FOR UPDATE with ATTR_EMULATE_PREPARES = 0
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 bug report at https://bugs.php.net/bug.php?id=77163&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77163&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77163&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77163&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=77163&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=77163&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=77163&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=77163&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=77163&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=77163&r=support
Expected behavior: https://bugs.php.net/fix.php?id=77163&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=77163&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=77163&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=77163&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77163&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=77163&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=77163&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=77163&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=77163&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=77163&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=77163&r=mysqlcfg