Skip to content

Commit

Permalink
Merge branch 'dev' into aadUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
yitam committed Nov 19, 2021
2 parents ad91fa1 + 14aa449 commit b7480d8
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 5 deletions.
5 changes: 4 additions & 1 deletion source/pdo_sqlsrv/pdo_dbh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1598,6 +1598,9 @@ zend_string * pdo_sqlsrv_dbh_last_id(_Inout_ pdo_dbh_t *dbh, _In_ const zend_str

driver_stmt->~sqlsrv_stmt();
} catch( core::CoreException& ) {
// restore error handling to its previous mode
dbh->error_mode = prev_err_mode;

// copy any errors on the statement to the connection so that the user sees them, since the statement is released
// before this method returns
strcpy_s( dbh->error_code, sizeof( dbh->error_code ),
Expand All @@ -1613,7 +1616,7 @@ zend_string * pdo_sqlsrv_dbh_last_id(_Inout_ pdo_dbh_t *dbh, _In_ const zend_str
str[0] = '\0';
return str;
#else
return NULL;
return ZSTR_EMPTY_ALLOC();
#endif
}

Expand Down
8 changes: 4 additions & 4 deletions test/functional/pdo_sqlsrv/pdo_lastInsertId.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ try {


?>
--EXPECTREGEX--
string\(3\) "200"
string\(3\) "102"
(string\(0\) ""|bool\(false\))
--EXPECT--
string(3) "200"
string(3) "102"
string(0) ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
--TEST--
Confirm that PDO::ATTR_ERRMODE value should be restored whether PDO::lastInsertId() call succeeded or not.
--SKIPIF--
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
require_once("MsCommon_mid-refactor.inc");

try {
$conn = connect();

// create temporary tables
createTable($conn, "table1", array(new columnMeta("int", "id", "IDENTITY(100,2)"), "val" => "int"));
createTable($conn, "table2", array(new columnMeta("int", "id", "IDENTITY(200,2)"), "val" => "int"));
createTable($conn, "table3", array("id" => "int", "val" => "int"));

insertRow($conn, "table1", array("val" => 1), "exec");
insertRow($conn, "table2", array("val" => 2), "exec");
$conn->lastInsertId();
var_dump($conn->getAttribute(PDO::ATTR_ERRMODE));

insertRow($conn, "table2", array("val" => 3), "exec");
insertRow($conn, "table1", array("val" => 4), "exec");
$conn->lastInsertId();
var_dump($conn->getAttribute(PDO::ATTR_ERRMODE));

// Should restore original value even if PDO::lastInsertId() failed.
insertRow($conn, "table3", array("id" => 1, "val" => 1), "exec");
$conn->lastInsertId();
var_dump($conn->getAttribute(PDO::ATTR_ERRMODE));

dropTable($conn, "table1");
dropTable($conn, "table2");
dropTable($conn, "table3");

// Should trigger exception
$tsql = "SELECT * FROM dummy";
$conn->exec($tsql);

unset($conn);
} catch (PDOException $e) {
print_r($e->getMessage());
exit;
}


?>
--EXPECTREGEX--
int\(2\)
int\(2\)
int\(2\)
.*Invalid object name \'dummy\'\.

0 comments on commit b7480d8

Please sign in to comment.