Bug #74613 [NEW]: PDO Exceptions not thrown when OUTPUT clause used in a failed query

From: Date: Thu, 18 May 2017 15:00:39 +0000
Subject: Bug #74613 [NEW]: PDO Exceptions not thrown when OUTPUT clause used in a failed query
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-209185@lists.php.net to get a copy of this message
From:             dan dot marra at gmail dot com
Operating system: Linux
PHP version:      Irrelevant
Package:          PDO related
Bug Type:         Bug
Bug description:PDO Exceptions not thrown when OUTPUT clause used in a failed query

Description:
------------
---
From manual page: http://www.php.net/language.control-structures
---

When you have an error in a t-sql query, but that query ALSO has an
OUTPUT clause in it, PDO does not throw an exception when expected
(likely because there is a return value).

Test script:
---------------
/* in MSSQL */
CREATE TABLE foobar (
foo int not null
);

ALTER TABLE foobar
ADD CONSTRAINT unique_foo UNIQUE (foo);   
GO 

insert into foobar (foo) values (1);
go


/* IN PHP */
<?php

$conn = new PDO('dblib:host='.$hostname.';dbname='.$database, $username,
$password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$stmt = $conn->prepare("insert into foobar (foo) output INSERTED.foo
values (1)");
try {
    $stmt->execute();
    $foo = $stmt->fetchColumn();
} catch (PDOException $ex) {
    // THIS DOES NOT GET HIT, But it *should* because a unique
constraint is violated. 
    die("you dun goofed son");
}

echo "all is good";

?>

Expected result:
----------------
what SHOULD happen is that an exception should be thrown due to the
unique constraint violation. Instead, it is ignored.

If you remove the output clause from the query, this works as expected.

Actual result:
--------------
Error from mssql is ignored

-- 
Edit bug report at https://bugs.php.net/bug.php?id=74613&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=74613&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=74613&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=74613&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=74613&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=74613&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=74613&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=74613&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=74613&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=74613&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=74613&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=74613&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=74613&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=74613&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74613&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=74613&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=74613&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=74613&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=74613&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=74613&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=74613&r=mysqlcfg



Thread (4 messages)

« previous php.bugs (#209185) next »