]> granicus.if.org Git - php/commitdiff
Allow \PDO::setAttribute() to set pdo_dblib query timeouts
authorAdam Baratz <adambaratz@php.net>
Tue, 13 Sep 2016 19:24:28 +0000 (15:24 -0400)
committerAdam Baratz <adambaratz@php.net>
Tue, 13 Sep 2016 20:13:26 +0000 (16:13 -0400)
ext/pdo_dblib/dblib_driver.c
ext/pdo_dblib/tests/timeout.phpt

index 64a3646b324660c4cc887199673022b42d07adfc..13ddd8a4723f7e1553f0e839d8ffdbd0a8162bdd 100644 (file)
@@ -253,14 +253,13 @@ static int dblib_set_attr(pdo_dbh_t *dbh, zend_long attr, zval *val)
 {
        switch(attr) {
                case PDO_ATTR_TIMEOUT:
-                       return 0;
-
+               case PDO_DBLIB_ATTR_QUERY_TIMEOUT:
+                       return SUCCEED == dbsettime(zval_get_long(val)) ? 1 : 0;
                case PDO_DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER:
                        ((pdo_dblib_db_handle *)dbh->driver_data)->stringify_uniqueidentifier = zval_get_long(val);
                        return 1;
-
                default:
-                       return 1;
+                       return 0;
        }
 }
 
index f92a7da72f18ac37f1cd8dad9933dfc556788e00..d711f2a3a01b250b9c3eac0431c2a6d099bcf674 100644 (file)
@@ -18,6 +18,32 @@ if ($stmt->execute()) {
        echo "OK\n";
 }
 
+// regular timeout attribute, set after instance created, will affect query timeout, causing this query to fail
+$db = new PDO($dsn, $user, $pass);
+$db->setAttribute(PDO::ATTR_TIMEOUT, 1);
+$stmt = $db->prepare($sql);
+if (!$stmt->execute()) {
+       echo "OK\n";
+
+       // expect some kind of error code
+       if ($stmt->errorCode() != '00000') {
+               echo "OK\n";
+       }
+}
+
+// pdo_dblib-specific timeout attribute, set after instance created, will control query timeout, causing this query to fail
+$db = new PDO($dsn, $user, $pass);
+$db->setAttribute(PDO::DBLIB_ATTR_QUERY_TIMEOUT, 1);
+$stmt = $db->prepare($sql);
+if (!$stmt->execute()) {
+       echo "OK\n";
+
+       // expect some kind of error code
+       if ($stmt->errorCode() != '00000') {
+               echo "OK\n";
+       }
+}
+
 // regular timeout attribute will affect query timeout, causing this query to fail
 $db = new PDO($dsn, $user, $pass, [PDO::ATTR_TIMEOUT => 1]);
 $stmt = $db->prepare($sql);
@@ -49,3 +75,7 @@ OK
 OK
 OK
 OK
+OK
+OK
+OK
+OK