From c5af000e564a33417418442f37ec890f8128c9fb Mon Sep 17 00:00:00 2001 From: Hadis Kakanejadi Fard Date: Wed, 3 May 2017 14:41:19 -0700 Subject: [PATCH 1/3] fixed issue #378 --- source/shared/core_stmt.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/shared/core_stmt.cpp b/source/shared/core_stmt.cpp index 1a1fe359..c12f7c99 100644 --- a/source/shared/core_stmt.cpp +++ b/source/shared/core_stmt.cpp @@ -734,7 +734,7 @@ SQLRETURN core_sqlsrv_execute( sqlsrv_stmt* stmt TSRMLS_DC, const char* sql, int // if the statement executed but failed in a subsequent operation before returning, // we need to cancel the statement and deref the output and stream parameters if ( stmt->send_streams_at_exec ) { - zend_hash_clean( Z_ARRVAL( stmt->output_params )); + finalize_output_parameters( stmt TSRMLS_CC ); zend_hash_clean( Z_ARRVAL( stmt->param_streams )); } if( stmt->executed ) { From 4d06de4aaf99634c98ac80b5064f4414c56e43a1 Mon Sep 17 00:00:00 2001 From: Hadis Kakanejadi Fard Date: Wed, 3 May 2017 14:44:43 -0700 Subject: [PATCH 2/3] added tests --- test/pdo_sqlsrv/pdo_378_out_param_error.phpt | 60 ++++++++++++++++++++ test/sqlsrv/sqlsrv_378_out_param_error.phpt | 58 +++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 test/pdo_sqlsrv/pdo_378_out_param_error.phpt create mode 100644 test/sqlsrv/sqlsrv_378_out_param_error.phpt diff --git a/test/pdo_sqlsrv/pdo_378_out_param_error.phpt b/test/pdo_sqlsrv/pdo_378_out_param_error.phpt new file mode 100644 index 00000000..46e787fc --- /dev/null +++ b/test/pdo_sqlsrv/pdo_378_out_param_error.phpt @@ -0,0 +1,60 @@ +--TEST-- +This test verifies that GitHub issue #378 is fixed in pdo_sqlsrv. +--DESCRIPTION-- +GitHub issue #378 - output parameters appends garbage info when variable is initialized with different data type +steps to reproduce the issue: +1- create a store procedure with print and output parameter +2- initialize output parameters to a different data type other than the type declared in sp. +3 - call sp. +--FILE-- +errorInfo()); +} + +//----------------Main--------------------------- +$procName = GetTempProcName(); +createSP($conn, $procName); +executeSP($conn, $procName); +$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); +executeSP($conn, $procName); +echo "Done"; + +//-------------------functions------------------- +function createSP($conn, $procName){ + + $sp_sql="create proc $procName @p1 integer, @p2 integer, @p3 integer output + as + begin + select @p3 = @p1 + @p2 + print @p3 + end + "; + $stmt = $conn->exec($sp_sql); + if ($stmt === false) { print("Failed to create stored procedure"); } +} + +function executeSP($conn, $procName){ + $expected = 3; + $stmt = $conn->prepare("{call $procName( ?, ?, ? )}"); + $stmt->bindParam(1, $v1); + $stmt->bindParam(2, $v2); + $stmt->bindParam(3, $v3, PDO::PARAM_INT, 10); + $v1 = 1; + $v2 = 2; + $v3 = 'str'; + $stmt->execute(); + if (!$stmt) { + print_r($stmt->errorInfo()); + } + if ( $v3 != $expected ) { + print("The expected value is $expected, actual value is $v3\n"); + } +} +?> +--EXPECT-- +Done \ No newline at end of file diff --git a/test/sqlsrv/sqlsrv_378_out_param_error.phpt b/test/sqlsrv/sqlsrv_378_out_param_error.phpt new file mode 100644 index 00000000..4f5d9c04 --- /dev/null +++ b/test/sqlsrv/sqlsrv_378_out_param_error.phpt @@ -0,0 +1,58 @@ +--TEST-- +This test verifies that GitHub issue #378 is fixed. +--DESCRIPTION-- +GitHub issue #378 - output parameters appends garbage info when variable is initialized with different data type +steps to reproduce the issue: +1- create a store procedure with print and output parameter +2- initialize output parameters to a different data type other than the type declared in sp. +3- set the WarningsReturnAsErrors to true +4 - call sp. +--FILE-- + +--EXPECT-- +Done \ No newline at end of file From 1db0a5a38c0cba4ced1db240903b6ff2faf9bb10 Mon Sep 17 00:00:00 2001 From: Hadis Kakanejadi Fard Date: Wed, 3 May 2017 14:47:58 -0700 Subject: [PATCH 3/3] fixed indentation in pdo test --- test/pdo_sqlsrv/pdo_378_out_param_error.phpt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/pdo_sqlsrv/pdo_378_out_param_error.phpt b/test/pdo_sqlsrv/pdo_378_out_param_error.phpt index 46e787fc..2bec70ed 100644 --- a/test/pdo_sqlsrv/pdo_378_out_param_error.phpt +++ b/test/pdo_sqlsrv/pdo_378_out_param_error.phpt @@ -49,12 +49,12 @@ function executeSP($conn, $procName){ $v3 = 'str'; $stmt->execute(); if (!$stmt) { - print_r($stmt->errorInfo()); - } + print_r($stmt->errorInfo()); + } if ( $v3 != $expected ) { print("The expected value is $expected, actual value is $v3\n"); } } ?> --EXPECT-- -Done \ No newline at end of file +Done