From aeacaf7a5069ee0db00e80a9931da3e7d7d22cda Mon Sep 17 00:00:00 2001 From: yitam Date: Tue, 7 Mar 2017 15:05:53 -0800 Subject: [PATCH 1/8] part 1 with utf8 data --- .../pdo_utf8_stored_proc_surrogate.phpt | 61 +++++++++++++++++++ .../pdo_utf8_stored_proc_unicode.phpt | 61 +++++++++++++++++++ test/pdo_sqlsrv/pdo_utf8_stored_proc_xml.phpt | 61 +++++++++++++++++++ 3 files changed, 183 insertions(+) create mode 100644 test/pdo_sqlsrv/pdo_utf8_stored_proc_surrogate.phpt create mode 100644 test/pdo_sqlsrv/pdo_utf8_stored_proc_unicode.phpt create mode 100644 test/pdo_sqlsrv/pdo_utf8_stored_proc_xml.phpt diff --git a/test/pdo_sqlsrv/pdo_utf8_stored_proc_surrogate.phpt b/test/pdo_sqlsrv/pdo_utf8_stored_proc_surrogate.phpt new file mode 100644 index 000000000..5f297a3f0 --- /dev/null +++ b/test/pdo_sqlsrv/pdo_utf8_stored_proc_surrogate.phpt @@ -0,0 +1,61 @@ +--TEST-- +call a stored procedure with NVARCHAR input to get output back as NVARCHAR +--SKIPIF-- + +--FILE-- +exec("CREATE PROC $procName (@p1 NVARCHAR(1000), @p2 NVARCHAR(1000) OUTPUT) + AS BEGIN SELECT @p2 = CONVERT(NVARCHAR(1000), @p1) END"); + + $stmt = $conn->prepare("{CALL $procName (?, ?)}"); + $stmt->bindValue(1, $inValue1); + $stmt->bindParam(2, $outValue1, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT, 1000); + $stmt->execute(); + + var_dump ($outValue1); + + $stmt = null; + $conn = null; +} + +function Repro() +{ + StartTest("pdo_utf8_stored_proc_surrogate"); + try + { + StoredProc_Surrogate(); + } + catch (Exception $e) + { + echo $e->getMessage(); + } + echo "\nDone\n"; + EndTest("pdo_utf8_stored_proc_surrogate"); +} + +Repro(); + +?> +--EXPECT-- + +...Starting 'pdo_utf8_stored_proc_surrogate' test... +string(304) "򔀀��􏺃�����􏰀���󒦃�𐀋𐀀𐊃���􏿿��𐀋𐆃�􏿿򔈀�𠏿�󒨀𠊃򔀋𐈀����􏰀􏶃�𐀀�󒪃􏶃�򔀀򔊃�𠀀󒨀�򔏿����􏶃���􏿿𐀀����􏿿�􏸀𐆃󒠀𐏿�����򔏿�𐆃�𠊃􏺃�􏰋" + +Done +...Test 'pdo_utf8_stored_proc_surrogate' completed successfully. + diff --git a/test/pdo_sqlsrv/pdo_utf8_stored_proc_unicode.phpt b/test/pdo_sqlsrv/pdo_utf8_stored_proc_unicode.phpt new file mode 100644 index 000000000..035878037 --- /dev/null +++ b/test/pdo_sqlsrv/pdo_utf8_stored_proc_unicode.phpt @@ -0,0 +1,61 @@ +--TEST-- +call a stored procedure with NVARCHAR input to get output back as NCHAR +--SKIPIF-- + +--FILE-- +exec("CREATE PROC $procName (@p1 NVARCHAR(MAX), @p2 NCHAR(1024) OUTPUT) + AS BEGIN SELECT @p2 = CONVERT(NCHAR(1024), @p1) END"); + + $stmt = $conn->prepare("{CALL $procName (?, ?)}"); + $stmt->bindValue(1, $inValue1); + $stmt->bindParam(2, $outValue1, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT, 1500); + $stmt->execute(); + + var_dump ($outValue1); + + $stmt = null; + $conn = null; +} + +function Repro() +{ + StartTest("pdo_utf8_stored_proc_unicode"); + try + { + StoredProc_Unicode(); + } + catch (Exception $e) + { + echo $e->getMessage(); + } + echo "\nDone\n"; + EndTest("pdo_utf8_stored_proc_unicode"); +} + +Repro(); + +?> +--EXPECT-- + +...Starting 'pdo_utf8_stored_proc_unicode' test... +string(1209) "验嗿ァチýІßІöÜハý衤öバäðª熇ð‍洐ıㅯタ鷗鷗לßÃگグ嗿ソグ倀чüゼㅯҐ熇チîゼ鷗‌ûi舳אґクЧ倀Ü曂ґÄýіポ衤îゼü衤タҐ‏ダİчåポソクÖグタöÖЧㅰハãªِчöûÄðÐяゾİゼІßハ侃ゼÄソלüßタゼ‍倀倁іÄההöяîöژ曂洐îゾگҐ " + +Done +...Test 'pdo_utf8_stored_proc_unicode' completed successfully. + diff --git a/test/pdo_sqlsrv/pdo_utf8_stored_proc_xml.phpt b/test/pdo_sqlsrv/pdo_utf8_stored_proc_xml.phpt new file mode 100644 index 000000000..172efb3e8 --- /dev/null +++ b/test/pdo_sqlsrv/pdo_utf8_stored_proc_xml.phpt @@ -0,0 +1,61 @@ +--TEST-- +call a stored procedure with XML input to get output back as characters +--SKIPIF-- + +--FILE-- +exec("CREATE PROC $procName (@p1 XML, @p2 CHAR(512) OUTPUT) + AS BEGIN SELECT @p2 = CONVERT(CHAR(512), @p1) END"); + + $stmt = $conn->prepare("{CALL $procName (?, ?)}"); + $stmt->bindValue(1, $inValue1); + $stmt->bindParam(2, $outValue1, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT, 512); + $stmt->execute(); + + var_dump($outValue1); + + $stmt = null; + $conn = null; +} + +function Repro() +{ + StartTest("pdo_utf8_stored_proc_xml"); + try + { + StoredProc_Xml(); + } + catch (Exception $e) + { + echo $e->getMessage(); + } + echo "\nDone\n"; + EndTest("pdo_utf8_stored_proc_xml"); +} + +Repro(); + +?> +--EXPECT-- + +...Starting 'pdo_utf8_stored_proc_xml' test... +string(516) "Je préfère l'été " + +Done +...Test 'pdo_utf8_stored_proc_xml' completed successfully. + From 85391e6478c0fa80b79194b74149cd25b0791c42 Mon Sep 17 00:00:00 2001 From: yitam Date: Tue, 7 Mar 2017 16:47:38 -0800 Subject: [PATCH 2/8] part 2 testing diff API --- test/pdo_sqlsrv/pdo_connection_quote.phpt | 74 ++++++++++++++ test/pdo_sqlsrv/pdo_nested_query_mars.phpt | 108 +++++++++++++++++++++ test/pdo_sqlsrv/pdo_query_timeout.phpt | 93 ++++++++++++++++++ 3 files changed, 275 insertions(+) create mode 100644 test/pdo_sqlsrv/pdo_connection_quote.phpt create mode 100644 test/pdo_sqlsrv/pdo_nested_query_mars.phpt create mode 100644 test/pdo_sqlsrv/pdo_query_timeout.phpt diff --git a/test/pdo_sqlsrv/pdo_connection_quote.phpt b/test/pdo_sqlsrv/pdo_connection_quote.phpt new file mode 100644 index 000000000..b05d6a322 --- /dev/null +++ b/test/pdo_sqlsrv/pdo_connection_quote.phpt @@ -0,0 +1,74 @@ +--TEST-- +testing the quote method with different inputs and then test with a empty query +--SKIPIF-- + +--FILE-- +quote("1'2'3'4'5'6'7'8", PDO::PARAM_INT); + var_dump($output1); + + $output2 = $conn->quote("{ABCD}'{EFGH}", PDO::PARAM_STR); + var_dump($output2); + + $output3 = $conn->quote("The quick brown fox jumps over the lazy dog0123456789"); + var_dump($output3); + + $stmt = $conn->query(""); + if ($stmt != false) + { + echo("Empty query was expected to fail!\n"); + } + + $stmt1 = $conn->prepare($output2); + $result = $stmt1->execute(); + if ($result != false) + { + echo("This query was expected to fail!\n"); + } + $stmt1 = null; + + $stmt2 = $conn->query($output3); + if ($stmt2 != false) + { + echo("This query was expected to fail!\n"); + } + + $conn = null; +} + +function Repro() +{ + StartTest("pdo_connection_quote"); + try + { + Quote(); + } + catch (Exception $e) + { + echo $e->getMessage(); + } + echo "\nDone\n"; + EndTest("pdo_connection_quote"); +} + +Repro(); + +?> +--EXPECT-- + +...Starting 'pdo_connection_quote' test... +string(24) "'1''2''3''4''5''6''7''8'" +string(16) "'{ABCD}''{EFGH}'" +string(118) "'The quick brown fox jumps over the lazy dog0123456789'" + +Done +...Test 'pdo_connection_quote' completed successfully. diff --git a/test/pdo_sqlsrv/pdo_nested_query_mars.phpt b/test/pdo_sqlsrv/pdo_nested_query_mars.phpt new file mode 100644 index 000000000..26cf0c7a2 --- /dev/null +++ b/test/pdo_sqlsrv/pdo_nested_query_mars.phpt @@ -0,0 +1,108 @@ +--TEST-- +fetch multiple result sets with MARS on and then off +--SKIPIF-- + +--FILE-- +SetAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + $stmt = $conn->exec("CREATE TABLE $tableName ([c1_int] int, [c2_varchar] varchar(20))"); + + $query = "INSERT INTO $tableName ([c1_int], [c2_varchar]) VALUES (1, 'Dummy value 1')"; + $stmt = $conn->query($query); + + $query = "INSERT INTO $tableName ([c1_int], [c2_varchar]) VALUES (2, 'Dummy value 2')"; + $stmt = $conn->query($query); + + $query = "SELECT * FROM $tableName ORDER BY [c1_int]"; + $stmt = $conn->query($query); + $numRows = 0; + while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) + $numRows++; + + if ($numRows !== 2) echo "Number of rows is unexpected!\n"; + $stmt = null; + + // more than one active results + $stmt1 = $conn->query($query); + $stmt2 = $conn->prepare($query); + $stmt2->execute(); + + echo "\nNumber of columns in First set: " . $stmt2->columnCount() . "\n"; + while ($row = $stmt1->fetch(PDO::FETCH_ASSOC)) + { + print_r($row); + } + + echo "\nNumber of columns in Second set: " . $stmt1->columnCount() . "\n\n"; + while ($row = $stmt2->fetch(PDO::FETCH_OBJ)) + { + print_r($row); + } + + $stmt1 = null; + $stmt2 = null; + $conn = null; +} + +function Repro() +{ + StartTest("pdo_nested_query_mars"); + try + { + NestedQuery_Mars(true); + NestedQuery_Mars(false); + } + catch (Exception $e) + { + echo $e->getMessage(); + } + echo "\nDone\n"; + EndTest("pdo_nested_query_mars"); +} + +Repro(); + +?> +--EXPECT-- + +...Starting 'pdo_nested_query_mars' test... + +Number of columns in First set: 2 +Array +( + [c1_int] => 1 + [c2_varchar] => Dummy value 1 +) +Array +( + [c1_int] => 2 + [c2_varchar] => Dummy value 2 +) + +Number of columns in Second set: 2 + +stdClass Object +( + [c1_int] => 1 + [c2_varchar] => Dummy value 1 +) +stdClass Object +( + [c1_int] => 2 + [c2_varchar] => Dummy value 2 +) +SQLSTATE[IMSSP]: The connection cannot process this operation because there is a statement with pending results. To make the connection available for other queries, either fetch all results or cancel or free the statement. For more information, see the product documentation about the MultipleActiveResultSets connection option. +Done +...Test 'pdo_nested_query_mars' completed successfully. diff --git a/test/pdo_sqlsrv/pdo_query_timeout.phpt b/test/pdo_sqlsrv/pdo_query_timeout.phpt new file mode 100644 index 000000000..86546aab9 --- /dev/null +++ b/test/pdo_sqlsrv/pdo_query_timeout.phpt @@ -0,0 +1,93 @@ +--TEST-- +test query time out on connection level and statement level +--SKIPIF-- + +--FILE-- +SetAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); + + $stmt = $conn->exec("CREATE TABLE $tableName ([c1_int] int, [c2_varchar] varchar(25))"); + + $query = "INSERT INTO $tableName ([c1_int], [c2_varchar]) VALUES (1, 'QueryTimeout 1')"; + $stmt = $conn->query($query); + + $query = "INSERT INTO $tableName ([c1_int], [c2_varchar]) VALUES (2, 'QueryTimeout 2')"; + $stmt = $conn->query($query); + + $query = "SELECT * FROM $tableName"; + + if ($connLevel) + { + echo "Setting query timeout as an attribute in connection\n"; + $conn->setAttribute(constant('PDO::SQLSRV_ATTR_QUERY_TIMEOUT'), 1); + $stmt = $conn->query("WAITFOR DELAY '00:00:03'; $query"); + + var_dump($conn->errorInfo()); + } + else + { + echo "Setting query timeout in the statement\n"; + $stmt = $conn->prepare("WAITFOR DELAY '00:00:03'; $query", array(constant('PDO::SQLSRV_ATTR_QUERY_TIMEOUT') => 1)); + $stmt->execute(); + + var_dump($stmt->errorInfo()); + } + + $stmt = null; + $conn = null; +} + +function Repro() +{ + StartTest("pdo_query_timeout"); + try + { + QueryTimeout(true); + QueryTimeout(false); + } + catch (Exception $e) + { + echo $e->getMessage(); + } + echo "\nDone\n"; + EndTest("pdo_query_timeout"); +} + +Repro(); + +?> +--EXPECT-- + +...Starting 'pdo_query_timeout' test... +Setting query timeout as an attribute in connection +array(3) { + [0]=> + string(5) "HYT00" + [1]=> + int(0) + [2]=> + string(63) "[Microsoft][ODBC Driver 13 for SQL Server]Query timeout expired" +} +Setting query timeout in the statement +array(3) { + [0]=> + string(5) "HYT00" + [1]=> + int(0) + [2]=> + string(63) "[Microsoft][ODBC Driver 13 for SQL Server]Query timeout expired" +} + +Done +...Test 'pdo_query_timeout' completed successfully. From e53ca834d3dd259eedcdc8a4878c50dd0c1e9199 Mon Sep 17 00:00:00 2001 From: yitam Date: Tue, 7 Mar 2017 17:25:39 -0800 Subject: [PATCH 3/8] part 3 testing rowCount --- test/pdo_sqlsrv/pdo_query_timeout.phpt | 3 +- .../pdo_statement_rowcount_query.phpt | 111 ++++++++++++++++++ 2 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 test/pdo_sqlsrv/pdo_statement_rowcount_query.phpt diff --git a/test/pdo_sqlsrv/pdo_query_timeout.phpt b/test/pdo_sqlsrv/pdo_query_timeout.phpt index 86546aab9..ec56fbfb8 100644 --- a/test/pdo_sqlsrv/pdo_query_timeout.phpt +++ b/test/pdo_sqlsrv/pdo_query_timeout.phpt @@ -1,5 +1,5 @@ --TEST-- -test query time out on connection level and statement level +test query time out at the connection level and statement level --SKIPIF-- --FILE-- @@ -15,7 +15,6 @@ function QueryTimeout($connLevel) $tableName = GetTempTableName(); $conn = new PDO( "sqlsrv:server=$serverName;Database=$database", $username, $password); - //$conn->SetAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); $stmt = $conn->exec("CREATE TABLE $tableName ([c1_int] int, [c2_varchar] varchar(25))"); diff --git a/test/pdo_sqlsrv/pdo_statement_rowcount_query.phpt b/test/pdo_sqlsrv/pdo_statement_rowcount_query.phpt new file mode 100644 index 000000000..1ef72caef --- /dev/null +++ b/test/pdo_sqlsrv/pdo_statement_rowcount_query.phpt @@ -0,0 +1,111 @@ +--TEST-- +test rowCount() with different querying method +--SKIPIF-- + +--FILE-- +exec("CREATE TABLE $tableName ([c1_int] int, [c2_real] real)"); + + for ($i = 1; $i < 5; $i++) + { + InsertData($conn, $tableName, $i); + } + + for ($i = 1; $i < 5; $i++) + { + UpdateData($conn, $tableName, $i, $exec); + } + + DeleteData($conn, $tableName, $exec); + + $stmt = null; + $conn = null; +} + +function InsertData($conn, $tableName, $value) +{ + $query = "INSERT INTO $tableName VALUES ($value, $value * 1.0)"; + $stmt = $conn->query($query); +} + +function UpdateData($conn, $tableName, $value, $exec) +{ + $newValue = $value * 100; + $query = "UPDATE $tableName SET c1_int = $newValue WHERE (c1_int = $value)"; + $rowCount = 0; + + if ($exec){ + $rowCount = $conn->exec($query); + } + else { + $stmt = $conn->prepare($query); + $rowCount = $stmt->rowCount(); + if ($rowCount > 0) + echo "Number of rows affected prior to execution should be 0!\n"; + + $stmt->execute(); + $rowCount = $stmt->rowCount(); + } + + if ($rowCount !== 1) + echo "Number of rows affected should be 1!\n"; + + $stmt = null; +} + +function DeleteData($conn, $tableName, $exec) +{ + $query = "DELETE TOP(3) FROM $tableName"; + $rowCount = 0; + + if ($exec){ + $rowCount = $conn->exec($query); + } + else { + $stmt = $conn->query($query); + $rowCount = $stmt->rowCount(); + } + + if ($rowCount <= 0) + echo "Number of rows affected should be > 0!\n"; + + $stmt = null; +} + +function Repro() +{ + StartTest("pdo_statement_rowcount_query"); + try + { + RowCount_Query(true); + RowCount_Query(false); + } + catch (Exception $e) + { + echo $e->getMessage(); + } + echo "\nDone\n"; + EndTest("pdo_statement_rowcount_query"); +} + +Repro(); + +?> +--EXPECT-- + +...Starting 'pdo_statement_rowcount_query' test... + +Done +...Test 'pdo_statement_rowcount_query' completed successfully. From 45ea247c3f6e06742468ed9c05ed8e0598335f6d Mon Sep 17 00:00:00 2001 From: yitam Date: Wed, 8 Mar 2017 09:55:29 -0800 Subject: [PATCH 4/8] part 4 fetching various types --- .../pdo_statement_rowcount_query.phpt | 84 ++++- .../pdo_stored_proc_fetch_datatypes.phpt | 300 ++++++++++++++++++ 2 files changed, 377 insertions(+), 7 deletions(-) create mode 100644 test/pdo_sqlsrv/pdo_stored_proc_fetch_datatypes.phpt diff --git a/test/pdo_sqlsrv/pdo_statement_rowcount_query.phpt b/test/pdo_sqlsrv/pdo_statement_rowcount_query.phpt index 1ef72caef..f0c8fe7ce 100644 --- a/test/pdo_sqlsrv/pdo_statement_rowcount_query.phpt +++ b/test/pdo_sqlsrv/pdo_statement_rowcount_query.phpt @@ -1,5 +1,5 @@ --TEST-- -test rowCount() with different querying method +test rowCount() with different querying method and test nextRowset() with different fetch --SKIPIF-- --FILE-- @@ -18,12 +18,15 @@ function RowCount_Query($exec) $stmt = $conn->exec("CREATE TABLE $tableName ([c1_int] int, [c2_real] real)"); - for ($i = 1; $i < 5; $i++) + $numRows = 5; + for ($i = 1; $i <= $numRows; $i++) { InsertData($conn, $tableName, $i); } - for ($i = 1; $i < 5; $i++) + FetchRowsets($conn, $tableName, $numRows); + + for ($i = 1; $i <= $numRows; $i++) { UpdateData($conn, $tableName, $i, $exec); } @@ -46,10 +49,12 @@ function UpdateData($conn, $tableName, $value, $exec) $query = "UPDATE $tableName SET c1_int = $newValue WHERE (c1_int = $value)"; $rowCount = 0; - if ($exec){ + if ($exec) + { $rowCount = $conn->exec($query); } - else { + else + { $stmt = $conn->prepare($query); $rowCount = $stmt->rowCount(); if ($rowCount > 0) @@ -65,15 +70,80 @@ function UpdateData($conn, $tableName, $value, $exec) $stmt = null; } +function CompareValues($actual, $expected) +{ + if ($actual != $expected) + { + echo "Unexpected value $value returned! Expected $expected.\n"; + } +} + +function FetchRowsets($conn, $tableName, $numRows) +{ + $query = "SELECT [c1_int] FROM $tableName ORDER BY [c1_int]"; + $queries = $query . ';' . $query . ';' . $query; + $stmt = $conn->query($queries); + + $i = 0; + while ($row = $stmt->fetch(PDO::FETCH_LAZY)) + { + $value = (int)$row['c1_int']; + CompareValues($value, ++$i); + } + + if ($i != $numRows) + { + echo "Number of rows fetched $i is unexpected!\n"; + } + + $result = $stmt->nextRowset(); + if ($result == false) + { + echo "Missing result sets!\n"; + } + + $rows = $stmt->fetchAll(PDO::FETCH_NUM); + $i = 0; + foreach ($rows as $row) + { + foreach ($row as $key => $value) + { + $value = (int)$value; + CompareValues($value, ++$i); + } + } + + $result = $stmt->nextRowset(); + if ($result == false) + { + echo "Missing result sets!\n"; + } + + $stmt->bindColumn('c1_int', $value); + $i = 0; + while ($row = $stmt->fetch(PDO::FETCH_BOUND)) + { + CompareValues($value, ++$i); + } + + $result = $stmt->nextRowset(); + if ($result != false) + { + echo "Number of result sets exceeding expectation!\n"; + } +} + function DeleteData($conn, $tableName, $exec) { $query = "DELETE TOP(3) FROM $tableName"; $rowCount = 0; - if ($exec){ + if ($exec) + { $rowCount = $conn->exec($query); } - else { + else + { $stmt = $conn->query($query); $rowCount = $stmt->rowCount(); } diff --git a/test/pdo_sqlsrv/pdo_stored_proc_fetch_datatypes.phpt b/test/pdo_sqlsrv/pdo_stored_proc_fetch_datatypes.phpt new file mode 100644 index 000000000..4afab3454 --- /dev/null +++ b/test/pdo_sqlsrv/pdo_stored_proc_fetch_datatypes.phpt @@ -0,0 +1,300 @@ +--TEST-- +call stored procedures with inputs of ten different datatypes to get outputs of various types +--SKIPIF-- + +--FILE-- +exec("CREATE PROC $procName (@p1 BIGINT, @p2 BIGINT, @p3 NCHAR(128) OUTPUT) + AS BEGIN SELECT @p3 = CONVERT(NCHAR(128), @p1 + @p2) END"); + + $inValue1 = '12345678'; + $inValue2 = '11111111'; + $outValue = '0'; + + $stmt = $conn->prepare("{CALL $procName (?, ?, ?)}"); + $stmt->bindValue(1, $inValue1); + $stmt->bindValue(2, $inValue2); + $stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300); + $stmt->execute(); + + if (strncasecmp($outValue, "23456789", 8)) + { + echo "Output value $outValue is unexpected!\n"; + } + + $stmt = null; +} + +function ProcFetch_Decimal($conn) +{ + $procName = GetTempProcName(); + + $stmt = $conn->exec("CREATE PROC $procName (@p1 DECIMAL, @p2 DECIMAL, @p3 CHAR(128) OUTPUT) + AS BEGIN SELECT @p3 = CONVERT(CHAR(128), @p1 + @p2) END"); + + $inValue1 = '2.1'; + $inValue2 = '5.3'; + $outValue = '0'; + + $stmt = $conn->prepare("{CALL $procName (?, ?, ?)}"); + $stmt->bindValue(1, $inValue1); + $stmt->bindValue(2, $inValue2); + $stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300); + $stmt->execute(); + + if (strncasecmp($outValue, "7", 1)) + { + echo "Output value $outValue is unexpected!\n"; + } + + $stmt = null; +} + +function ProcFetch_Float($conn) +{ + $procName = GetTempProcName(); + + $stmt = $conn->exec("CREATE PROC $procName (@p1 FLOAT, @p2 FLOAT, @p3 FLOAT OUTPUT) + AS BEGIN SELECT @p3 = CONVERT(FLOAT, @p1 + @p2) END"); + + $inValue1 = '2.25'; + $inValue2 = '5.5'; + $outValue = '0'; + + $stmt = $conn->prepare("{CALL $procName (?, ?, ?)}"); + $stmt->bindValue(1, $inValue1); + $stmt->bindValue(2, $inValue2); + $stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300); + $stmt->execute(); + + if (strncasecmp($outValue, "7.75", 4)) + { + echo "Output value $outValue is unexpected!\n"; + } + + $stmt = null; +} + +function ProcFetch_Int($conn) +{ + $procName = GetTempProcName(); + + $stmt = $conn->exec("CREATE PROC $procName (@p1 INT, @p2 INT, @p3 INT OUTPUT) + AS BEGIN SELECT @p3 = CONVERT(INT, @p1 + @p2) END"); + + $inValue1 = '1234'; + $inValue2 = '5678'; + $outValue = '0'; + + $stmt = $conn->prepare("{CALL $procName (?, ?, ?)}"); + $stmt->bindValue(1, $inValue1); + $stmt->bindValue(2, $inValue2); + $stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300); + $stmt->execute(); + + if (strncasecmp($outValue, "6912", 4)) + { + echo "Output value $outValue is unexpected!\n"; + } + + $stmt = null; +} + +function ProcFetch_Money($conn) +{ + $procName = GetTempProcName(); + + $stmt = $conn->exec("CREATE PROC $procName (@p1 MONEY, @p2 MONEY, @p3 MONEY OUTPUT) + AS BEGIN SELECT @p3 = CONVERT(MONEY, @p1 + @p2) END"); + + $inValue1 = '22.3'; + $inValue2 = '16.1'; + $outValue = '0'; + + $stmt = $conn->prepare("{CALL $procName (?, ?, ?)}"); + $stmt->bindValue(1, $inValue1, PDO::PARAM_STR); + $stmt->bindParam(2, $inValue2, PDO::PARAM_STR); + $stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300); + $stmt->execute(); + + if (strncasecmp($outValue, "38.40", 5)) + { + echo "Output value $outValue is unexpected!\n"; + } + + $stmt = null; +} + +function ProcFetch_Numeric($conn) +{ + $procName = GetTempProcName(); + + $stmt = $conn->exec("CREATE PROC $procName (@p1 NUMERIC, @p2 NUMERIC, @p3 NCHAR(128) OUTPUT) + AS BEGIN SELECT @p3 = CONVERT(NCHAR(128), @p1 + @p2) END"); + + $inValue1 = '2.8'; + $inValue2 = '5.4'; + $outValue = '0'; + + $stmt = $conn->prepare("{CALL $procName (?, ?, ?)}"); + $stmt->bindValue(1, $inValue1); + $stmt->bindParam(2, $inValue2); + $stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300); + $stmt->execute(); + + if (strncasecmp($outValue, "8", 1)) + { + echo "Output value $outValue is unexpected!\n"; + } + + $stmt = null; +} + +function ProcFetch_Real($conn) +{ + $procName = GetTempProcName(); + + $stmt = $conn->exec("CREATE PROC $procName (@p1 REAL, @p2 REAL, @p3 REAL OUTPUT) + AS BEGIN SELECT @p3 = CONVERT(REAL, @p1 + @p2) END"); + + $inValue1 = '3.4'; + $inValue2 = '6.6'; + $outValue = '0'; + + $stmt = $conn->prepare("{CALL $procName (?, ?, ?)}"); + $stmt->bindValue(1, $inValue1); + $stmt->bindParam(2, $inValue2); + $stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300); + $stmt->execute(); + + if (strncasecmp($outValue, "10", 2)) + { + echo "Output value $outValue is unexpected!\n"; + } + + $stmt = null; +} + +function ProcFetch_SmallInt($conn) +{ + $procName = GetTempProcName(); + + $stmt = $conn->exec("CREATE PROC $procName (@p1 SMALLINT, @p2 SMALLINT, @p3 NCHAR(32) OUTPUT) + AS BEGIN SELECT @p3 = CONVERT(NCHAR(32), @p1 + @p2) END"); + + $inValue1 = '34'; + $inValue2 = '56'; + $outValue = '0'; + + $stmt = $conn->prepare("{CALL $procName (?, ?, ?)}"); + $stmt->bindValue(1, $inValue1); + $stmt->bindParam(2, $inValue2); + $stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300); + $stmt->execute(); + + if (strncasecmp($outValue, "90", 2)) + { + echo "Output value $outValue is unexpected!\n"; + } + + $stmt = null; +} + +function ProcFetch_SmallMoney($conn) +{ + $procName = GetTempProcName(); + + $stmt = $conn->exec("CREATE PROC $procName (@p1 SMALLMONEY, @p2 SMALLMONEY, @p3 SMALLMONEY OUTPUT) + AS BEGIN SELECT @p3 = CONVERT(SMALLMONEY, @p1 + @p2) END"); + + $inValue1 = '10'; + $inValue2 = '11.7'; + $outValue = '0'; + + $stmt = $conn->prepare("{CALL $procName (?, ?, ?)}"); + $stmt->bindValue(1, $inValue1, PDO::PARAM_STR); + $stmt->bindParam(2, $inValue2, PDO::PARAM_STR); + $stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300); + $stmt->execute(); + + if (strncasecmp($outValue, "21.70", 5)) + { + echo "Output value $outValue is unexpected!\n"; + } + + $stmt = null; +} + +function ProcFetch_TinyInt($conn) +{ + $procName = GetTempProcName(); + + $stmt = $conn->exec("CREATE PROC $procName (@p1 TINYINT, @p2 TINYINT, @p3 CHAR(32) OUTPUT) + AS BEGIN SELECT @p3 = CONVERT(CHAR(32), @p1 + @p2) END"); + + $inValue1 = '11'; + $inValue2 = '12'; + $outValue = '0'; + + $stmt = $conn->prepare("{CALL $procName (?, ?, ?)}"); + $stmt->bindValue(1, $inValue1); + $stmt->bindParam(2, $inValue2); + $stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300); + $stmt->execute(); + + if (strncasecmp($outValue, "23", 2)) + { + echo "Output value $outValue is unexpected!\n"; + } + + $stmt = null; +} + +function Repro() +{ + set_time_limit(0); + StartTest("pdo_stored_proc_fetch_datatypes"); + try + { + require_once("autonomous_setup.php"); + $database = "tempdb"; + $conn = new PDO( "sqlsrv:server=$serverName;Database=$database", $username, $password); + + ProcFetch_BigInt($conn); + ProcFetch_Decimal($conn); + ProcFetch_Float($conn); + ProcFetch_Int($conn); + ProcFetch_Money($conn); + ProcFetch_Numeric($conn); + ProcFetch_Real($conn); + ProcFetch_SmallInt($conn); + ProcFetch_SmallMoney($conn); + ProcFetch_TinyInt($conn); + + $conn = null; + } + catch (Exception $e) + { + echo $e->getMessage(); + } + echo "\nDone\n"; + EndTest("pdo_stored_proc_fetch_datatypes"); +} + +Repro(); + +?> +--EXPECT-- + +...Starting 'pdo_stored_proc_fetch_datatypes' test... + +Done +...Test 'pdo_stored_proc_fetch_datatypes' completed successfully. + From 194f37f8d5203162e7a41cd204d8b44b0a87a6f4 Mon Sep 17 00:00:00 2001 From: yitam Date: Wed, 8 Mar 2017 14:17:21 -0800 Subject: [PATCH 5/8] part 5 new sqlsrv tests --- .../sqlsrv_fetch_datetime_as_strings.phpt | 116 ++++++++++++++++++ .../sqlsrv/sqlsrv_param_query_data_types.phpt | 66 ++++++++++ .../sqlsrv_statement_query_timeout.phpt | 78 ++++++++++++ ...v_statement_query_timeout_transaction.phpt | 91 ++++++++++++++ 4 files changed, 351 insertions(+) create mode 100644 test/sqlsrv/sqlsrv_fetch_datetime_as_strings.phpt create mode 100644 test/sqlsrv/sqlsrv_param_query_data_types.phpt create mode 100644 test/sqlsrv/sqlsrv_statement_query_timeout.phpt create mode 100644 test/sqlsrv/sqlsrv_statement_query_timeout_transaction.phpt diff --git a/test/sqlsrv/sqlsrv_fetch_datetime_as_strings.phpt b/test/sqlsrv/sqlsrv_fetch_datetime_as_strings.phpt new file mode 100644 index 000000000..dcfa8efdd --- /dev/null +++ b/test/sqlsrv/sqlsrv_fetch_datetime_as_strings.phpt @@ -0,0 +1,116 @@ +--TEST-- +Test fetching datatime fields as strings +--FILE-- +c3_datetime; + $value2 = $row['c3_datetime']; + + if ($value1 !== $value2) + echo "Data corrupted: $value1 !== $value2\n"; + + } while (++$rowFetched < $numRows); +} + +function GetQuery($tableName, $index) +{ + $query = ""; + switch ($index) + { + case 1: + $query = "INSERT INTO $tableName ([c1_int], [c3_datetime], [c4_smalldatetime]) VALUES ((2073189157), ('1753-01-01 00:00:00.000'), (null))"; + break; + case 2: + $query = "INSERT INTO $tableName ([c1_int], [c3_datetime], [c4_smalldatetime]) VALUES ((-920147222), ('3895-08-29 00:41:03.351'), ('1936-01-05 21:34:00'))"; + break; + case 3: + $query = "INSERT INTO $tableName ([c1_int], [c3_datetime], [c4_smalldatetime]) VALUES ((-2147483648), ('1753-01-01 00:00:00.000'), ('1915-11-08 19:46:00'))"; + break; + case 4: + $query = "INSERT INTO $tableName ([c1_int], [c3_datetime], [c4_smalldatetime]) VALUES ((1269199053), (null), ('2075-04-27 22:16:00'))"; + break; + default: + break; + } + return $query; +} + +function Repro() +{ + StartTest("sqlsrv_fetch_datetime_as_strings"); + try + { + set_time_limit(0); + sqlsrv_configure('WarningsReturnAsErrors', 1); + sqlsrv_get_config('WarningsReturnAsErrors'); + + require_once("autonomous_setup.php"); + + // Connect + $connectionInfo = array("UID"=>$username, "PWD"=>$password, 'ReturnDatesAsStrings'=>true); + $conn = sqlsrv_connect($serverName, $connectionInfo); + if( !$conn ) { FatalError("Could not connect.\n"); } + + FetchDateTime_AsString($conn); + + sqlsrv_close($conn); + } + catch (Exception $e) + { + echo $e->getMessage(); + } + echo "\nDone\n"; + EndTest("sqlsrv_fetch_datetime_as_strings"); +} + +Repro(); + +?> +--EXPECT-- + +...Starting 'sqlsrv_fetch_datetime_as_strings' test... + +Done +...Test 'sqlsrv_fetch_datetime_as_strings' completed successfully. diff --git a/test/sqlsrv/sqlsrv_param_query_data_types.phpt b/test/sqlsrv/sqlsrv_param_query_data_types.phpt new file mode 100644 index 000000000..8b98aae36 --- /dev/null +++ b/test/sqlsrv/sqlsrv_param_query_data_types.phpt @@ -0,0 +1,66 @@ +--TEST-- +Test insert various numeric data types and fetch them back as strings +--FILE-- +$username, "PWD"=>$password); + $conn = sqlsrv_connect($serverName, $connectionInfo); + if( !$conn ) { FatalError("Could not connect.\n"); } + + ParamQuery($conn, "float", SQLSRV_SQLTYPE_FLOAT, 12.345); + ParamQuery($conn, "money", SQLSRV_SQLTYPE_MONEY, 56.78); + ParamQuery($conn, "numeric(32,4)", SQLSRV_SQLTYPE_NUMERIC(32, 4), 12.34); + ParamQuery($conn, "real", SQLSRV_SQLTYPE_REAL, 98.760); + ParamQuery($conn, "smallmoney", SQLSRV_SQLTYPE_SMALLMONEY, 56.78); + + sqlsrv_close($conn); + } + catch (Exception $e) + { + echo $e->getMessage(); + } + echo "\nDone\n"; + EndTest("sqlsrv_param_query_data_types"); +} + +Repro(); + +?> +--EXPECT-- + +...Starting 'sqlsrv_param_query_data_types' test... + +Done +...Test 'sqlsrv_param_query_data_types' completed successfully. diff --git a/test/sqlsrv/sqlsrv_statement_query_timeout.phpt b/test/sqlsrv/sqlsrv_statement_query_timeout.phpt new file mode 100644 index 000000000..46c7e4058 --- /dev/null +++ b/test/sqlsrv/sqlsrv_statement_query_timeout.phpt @@ -0,0 +1,78 @@ +--TEST-- +Test sending queries (query or prepare) with a timeout specified. Errors are expected. +--FILE-- + 1)); + } + else + { + $stmt = sqlsrv_prepare($conn, "WAITFOR DELAY '00:00:05'; SELECT * FROM $tableName", array(), array('QueryTimeout' => 1)); + sqlsrv_execute($stmt); + } + + $errors = sqlsrv_errors(SQLSRV_ERR_ALL); + $e = $errors[0]; + + print($e['message'] . "\n"); + print($e['code'] . "\n"); + print($e['SQLSTATE'] . "\n"); + +} + +function Repro() +{ + StartTest("sqlsrv_statement_query_timeout"); + try + { + set_time_limit(0); + sqlsrv_configure('WarningsReturnAsErrors', 1); + sqlsrv_get_config('WarningsReturnAsErrors'); + + require_once("autonomous_setup.php"); + $database = "tempdb"; + + // Connect + $connectionInfo = array("UID"=>$username, "PWD"=>$password); + $conn = sqlsrv_connect($serverName, $connectionInfo); + if( !$conn ) { FatalError("Could not connect.\n"); } + + QueryTimeout($conn, true); + QueryTimeout($conn, false); + + sqlsrv_close($conn); + + } + catch (Exception $e) + { + echo $e->getMessage(); + } + echo "\nDone\n"; + EndTest("sqlsrv_statement_query_timeout"); +} + +Repro(); + +?> +--EXPECT-- + +...Starting 'sqlsrv_statement_query_timeout' test... +[Microsoft][ODBC Driver 13 for SQL Server]Query timeout expired +0 +HYT00 +[Microsoft][ODBC Driver 13 for SQL Server]Query timeout expired +0 +HYT00 + +Done +...Test 'sqlsrv_statement_query_timeout' completed successfully. diff --git a/test/sqlsrv/sqlsrv_statement_query_timeout_transaction.phpt b/test/sqlsrv/sqlsrv_statement_query_timeout_transaction.phpt new file mode 100644 index 000000000..7ac329c6b --- /dev/null +++ b/test/sqlsrv/sqlsrv_statement_query_timeout_transaction.phpt @@ -0,0 +1,91 @@ +--TEST-- +Test sending queries (query or prepare) with a timeout specified using transactions. Errors are expected. +--FILE-- + 1)); + $errors = sqlsrv_errors(SQLSRV_ERR_ALL); + $e = $errors[0]; + + print($e['message'] . "\n"); + print($e['code'] . "\n"); + print($e['SQLSTATE'] . "\n"); + + if ($commit) + sqlsrv_commit($conn1); + else + sqlsrv_rollback($conn1); + + sqlsrv_query($conn2, "DROP TABLE $tableName"); +} + +function Repro() +{ + StartTest("sqlsrv_statement_query_timeout_transaction"); + try + { + set_time_limit(0); + sqlsrv_configure('WarningsReturnAsErrors', 1); + sqlsrv_get_config('WarningsReturnAsErrors'); + + require_once("autonomous_setup.php"); + + // Connect + $connectionInfo = array("UID"=>$username, "PWD"=>$password, 'ConnectionPooling'=>0); + $conn1 = sqlsrv_connect($serverName, $connectionInfo); + if( !$conn1 ) { FatalError("Could not connect.\n"); } + + $conn2 = sqlsrv_connect($serverName, $connectionInfo); + if( !$conn2 ) { FatalError("Could not connect.\n"); } + + QueryTimeout($conn1, $conn2, true); + QueryTimeout($conn1, $conn2, false); + + sqlsrv_close($conn1); + sqlsrv_close($conn2); + } + catch (Exception $e) + { + echo $e->getMessage(); + } + echo "\nDone\n"; + EndTest("sqlsrv_statement_query_timeout_transaction"); +} + +Repro(); + +?> +--EXPECT-- + +...Starting 'sqlsrv_statement_query_timeout_transaction' test... +[Microsoft][ODBC Driver 13 for SQL Server]Query timeout expired +0 +HYT00 +[Microsoft][ODBC Driver 13 for SQL Server]Query timeout expired +0 +HYT00 + +Done +...Test 'sqlsrv_statement_query_timeout_transaction' completed successfully. From 9f91c815a46434f4fe0f8862af222d7517bf89c1 Mon Sep 17 00:00:00 2001 From: yitam Date: Wed, 8 Mar 2017 14:34:56 -0800 Subject: [PATCH 6/8] removed redundant tests --- .../pdo_utf8_stored_proc_surrogate.phpt | 61 ---------- .../pdo_utf8_stored_proc_unicode.phpt | 61 ---------- .../pdo_utf8_stored_proc_unicode_chars.phpt | 105 ++++++++++++++++++ test/pdo_sqlsrv/pdo_utf8_stored_proc_xml.phpt | 61 ---------- 4 files changed, 105 insertions(+), 183 deletions(-) delete mode 100644 test/pdo_sqlsrv/pdo_utf8_stored_proc_surrogate.phpt delete mode 100644 test/pdo_sqlsrv/pdo_utf8_stored_proc_unicode.phpt create mode 100644 test/pdo_sqlsrv/pdo_utf8_stored_proc_unicode_chars.phpt delete mode 100644 test/pdo_sqlsrv/pdo_utf8_stored_proc_xml.phpt diff --git a/test/pdo_sqlsrv/pdo_utf8_stored_proc_surrogate.phpt b/test/pdo_sqlsrv/pdo_utf8_stored_proc_surrogate.phpt deleted file mode 100644 index 5f297a3f0..000000000 --- a/test/pdo_sqlsrv/pdo_utf8_stored_proc_surrogate.phpt +++ /dev/null @@ -1,61 +0,0 @@ ---TEST-- -call a stored procedure with NVARCHAR input to get output back as NVARCHAR ---SKIPIF-- - ---FILE-- -exec("CREATE PROC $procName (@p1 NVARCHAR(1000), @p2 NVARCHAR(1000) OUTPUT) - AS BEGIN SELECT @p2 = CONVERT(NVARCHAR(1000), @p1) END"); - - $stmt = $conn->prepare("{CALL $procName (?, ?)}"); - $stmt->bindValue(1, $inValue1); - $stmt->bindParam(2, $outValue1, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT, 1000); - $stmt->execute(); - - var_dump ($outValue1); - - $stmt = null; - $conn = null; -} - -function Repro() -{ - StartTest("pdo_utf8_stored_proc_surrogate"); - try - { - StoredProc_Surrogate(); - } - catch (Exception $e) - { - echo $e->getMessage(); - } - echo "\nDone\n"; - EndTest("pdo_utf8_stored_proc_surrogate"); -} - -Repro(); - -?> ---EXPECT-- - -...Starting 'pdo_utf8_stored_proc_surrogate' test... -string(304) "򔀀��􏺃�����􏰀���󒦃�𐀋𐀀𐊃���􏿿��𐀋𐆃�􏿿򔈀�𠏿�󒨀𠊃򔀋𐈀����􏰀􏶃�𐀀�󒪃􏶃�򔀀򔊃�𠀀󒨀�򔏿����􏶃���􏿿𐀀����􏿿�􏸀𐆃󒠀𐏿�����򔏿�𐆃�𠊃􏺃�􏰋" - -Done -...Test 'pdo_utf8_stored_proc_surrogate' completed successfully. - diff --git a/test/pdo_sqlsrv/pdo_utf8_stored_proc_unicode.phpt b/test/pdo_sqlsrv/pdo_utf8_stored_proc_unicode.phpt deleted file mode 100644 index 035878037..000000000 --- a/test/pdo_sqlsrv/pdo_utf8_stored_proc_unicode.phpt +++ /dev/null @@ -1,61 +0,0 @@ ---TEST-- -call a stored procedure with NVARCHAR input to get output back as NCHAR ---SKIPIF-- - ---FILE-- -exec("CREATE PROC $procName (@p1 NVARCHAR(MAX), @p2 NCHAR(1024) OUTPUT) - AS BEGIN SELECT @p2 = CONVERT(NCHAR(1024), @p1) END"); - - $stmt = $conn->prepare("{CALL $procName (?, ?)}"); - $stmt->bindValue(1, $inValue1); - $stmt->bindParam(2, $outValue1, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT, 1500); - $stmt->execute(); - - var_dump ($outValue1); - - $stmt = null; - $conn = null; -} - -function Repro() -{ - StartTest("pdo_utf8_stored_proc_unicode"); - try - { - StoredProc_Unicode(); - } - catch (Exception $e) - { - echo $e->getMessage(); - } - echo "\nDone\n"; - EndTest("pdo_utf8_stored_proc_unicode"); -} - -Repro(); - -?> ---EXPECT-- - -...Starting 'pdo_utf8_stored_proc_unicode' test... -string(1209) "验嗿ァチýІßІöÜハý衤öバäðª熇ð‍洐ıㅯタ鷗鷗לßÃگグ嗿ソグ倀чüゼㅯҐ熇チîゼ鷗‌ûi舳אґクЧ倀Ü曂ґÄýіポ衤îゼü衤タҐ‏ダİчåポソクÖグタöÖЧㅰハãªِчöûÄðÐяゾİゼІßハ侃ゼÄソלüßタゼ‍倀倁іÄההöяîöژ曂洐îゾگҐ " - -Done -...Test 'pdo_utf8_stored_proc_unicode' completed successfully. - diff --git a/test/pdo_sqlsrv/pdo_utf8_stored_proc_unicode_chars.phpt b/test/pdo_sqlsrv/pdo_utf8_stored_proc_unicode_chars.phpt new file mode 100644 index 000000000..1bc223ac1 --- /dev/null +++ b/test/pdo_sqlsrv/pdo_utf8_stored_proc_unicode_chars.phpt @@ -0,0 +1,105 @@ +--TEST-- +call a stored procedure with unicode input to get output back as unicode; also test with xml data +--SKIPIF-- + +--FILE-- +exec("CREATE PROC $procName (@p1 XML, @p2 CHAR(512) OUTPUT) + AS BEGIN SELECT @p2 = CONVERT(CHAR(512), @p1) END"); + + $stmt = $conn->prepare("{CALL $procName (?, ?)}"); + $stmt->bindValue(1, $inValue1); + $stmt->bindParam(2, $outValue1, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT, 512); + $stmt->execute(); + + var_dump(trim($outValue1)); + + $stmt = null; +} + +function StoredProc_Surrogate($conn) +{ + $inValue1 = pack('H*', 'F2948080EFBFBDEFBFBDF48FBA83EFBFBDEFBFBDEFBFBDEFBFBDEFBFBDF48FB080EFBFBDEFBFBDEFBFBDF392A683EFBFBDF090808BF0908080F0908A83EFBFBDEFBFBDEFBFBDF48FBFBFEFBFBDEFBFBDF090808BF0908683EFBFBDF48FBFBFF2948880EFBFBDF0A08FBFEFBFBDF392A880F0A08A83F294808BF0908880EFBFBDEFBFBDEFBFBDEFBFBDF48FB080F48FB683EFBFBDF0908080EFBFBDF392AA83F48FB683EFBFBDF2948080F2948A83EFBFBDF0A08080F392A880EFBFBDF2948FBFEFBFBDEFBFBDEFBFBDEFBFBDF48FB683EFBFBDEFBFBDEFBFBDF48FBFBFF0908080EFBFBDEFBFBDEFBFBDEFBFBDF48FBFBFEFBFBDF48FB880F0908683F392A080F0908FBFEFBFBDEFBFBDEFBFBDEFBFBDEFBFBDF2948FBFEFBFBDF0908683EFBFBDF0A08A83F48FBA83EFBFBDF48FB08B'); + $outValue1 = "TEST"; + + $procName = GetTempProcName(); + $stmt = $conn->exec("CREATE PROC $procName (@p1 NVARCHAR(1000), @p2 NVARCHAR(1000) OUTPUT) + AS BEGIN SELECT @p2 = CONVERT(NVARCHAR(1000), @p1) END"); + + $stmt = $conn->prepare("{CALL $procName (?, ?)}"); + $stmt->bindValue(1, $inValue1); + $stmt->bindParam(2, $outValue1, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT, 1000); + $stmt->execute(); + + var_dump ($outValue1 === $inValue1); + + $stmt = null; +} + +function StoredProc_Unicode($conn) +{ + $inValue1 = pack('H*', 'E9AA8CE597BFE382A1E38381C3BDD086C39FD086C3B6C39CE3838FC3BDE8A1A4C3B6E38390C3A4C3B0C2AAE78687C3B0E2808DE6B490C4B1E385AFE382BFE9B797E9B797D79CC39FC383DAAFE382B0E597BFE382BDE382B0E58080D187C3BCE382BCE385AFD290E78687E38381C3AEE382BCE9B797E2808CC3BB69E888B3D790D291E382AFD0A7E58080C39CE69B82D291C384C3BDD196E3839DE8A1A4C3AEE382BCC3BCE8A1A4E382BFD290E2808FE38380C4B0D187C3A5E3839DE382BDE382AFC396E382B0E382BFC3B6C396D0A7E385B0E3838FC3A3C2AAD990D187C3B6C3BBC384C3B0C390D18FE382BEC4B0E382BCD086C39FE3838FE4BE83E382BCC384E382BDD79CC3BCC39FE382BFE382BCE2808DE58080E58081D196C384D794D794C3B6D18FC3AEC3B6DA98E69B82E6B490C3AEE382BEDAAFD290'); + $outValue1 = "TEST"; + + $procName = GetTempProcName(); + $stmt = $conn->exec("CREATE PROC $procName (@p1 NVARCHAR(MAX), @p2 NCHAR(1024) OUTPUT) + AS BEGIN SELECT @p2 = CONVERT(NCHAR(1024), @p1) END"); + + $stmt = $conn->prepare("{CALL $procName (?, ?)}"); + $stmt->bindValue(1, $inValue1); + $stmt->bindParam(2, $outValue1, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT, 1500); + $stmt->execute(); + + $outValue1 = trim($outValue1); + var_dump ($outValue1 === $inValue1); + + $stmt = null; +} + +function Repro() +{ + StartTest("pdo_utf8_stored_proc_unicode_chars"); + try + { + require_once("autonomous_setup.php"); + + set_time_limit(0); + $database = "tempdb"; + + $conn = new PDO( "sqlsrv:server=$serverName;Database=$database", $username, $password); + + StoredProc_Xml($conn); + StoredProc_Surrogate($conn); + StoredProc_Unicode($conn); + + $conn = null; + } + catch (Exception $e) + { + echo $e->getMessage(); + } + echo "\nDone\n"; + EndTest("pdo_utf8_stored_proc_unicode_chars"); +} + +Repro(); + +?> +--EXPECT-- + +...Starting 'pdo_utf8_stored_proc_unicode_chars' test... +string(47) "Je préfère l'été" +bool(true) +bool(true) + +Done +...Test 'pdo_utf8_stored_proc_unicode_chars' completed successfully. + diff --git a/test/pdo_sqlsrv/pdo_utf8_stored_proc_xml.phpt b/test/pdo_sqlsrv/pdo_utf8_stored_proc_xml.phpt deleted file mode 100644 index 172efb3e8..000000000 --- a/test/pdo_sqlsrv/pdo_utf8_stored_proc_xml.phpt +++ /dev/null @@ -1,61 +0,0 @@ ---TEST-- -call a stored procedure with XML input to get output back as characters ---SKIPIF-- - ---FILE-- -exec("CREATE PROC $procName (@p1 XML, @p2 CHAR(512) OUTPUT) - AS BEGIN SELECT @p2 = CONVERT(CHAR(512), @p1) END"); - - $stmt = $conn->prepare("{CALL $procName (?, ?)}"); - $stmt->bindValue(1, $inValue1); - $stmt->bindParam(2, $outValue1, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT, 512); - $stmt->execute(); - - var_dump($outValue1); - - $stmt = null; - $conn = null; -} - -function Repro() -{ - StartTest("pdo_utf8_stored_proc_xml"); - try - { - StoredProc_Xml(); - } - catch (Exception $e) - { - echo $e->getMessage(); - } - echo "\nDone\n"; - EndTest("pdo_utf8_stored_proc_xml"); -} - -Repro(); - -?> ---EXPECT-- - -...Starting 'pdo_utf8_stored_proc_xml' test... -string(516) "Je préfère l'été " - -Done -...Test 'pdo_utf8_stored_proc_xml' completed successfully. - From 497797ec610b9f3bf1541c8adb2b0fc909158687 Mon Sep 17 00:00:00 2001 From: yitam Date: Wed, 8 Mar 2017 15:53:59 -0800 Subject: [PATCH 7/8] fixed some tests --- .../sqlsrv_fetch_datetime_as_strings.phpt | 6 +- .../sqlsrv_fetch_field_twice_data_types.phpt | 141 ++++++++++++++++++ .../sqlsrv/sqlsrv_param_query_data_types.phpt | 1 - .../sqlsrv_statement_query_timeout.phpt | 1 - ...v_statement_query_timeout_transaction.phpt | 1 - 5 files changed, 146 insertions(+), 4 deletions(-) create mode 100644 test/sqlsrv/sqlsrv_fetch_field_twice_data_types.phpt diff --git a/test/sqlsrv/sqlsrv_fetch_datetime_as_strings.phpt b/test/sqlsrv/sqlsrv_fetch_datetime_as_strings.phpt index dcfa8efdd..8e8c34950 100644 --- a/test/sqlsrv/sqlsrv_fetch_datetime_as_strings.phpt +++ b/test/sqlsrv/sqlsrv_fetch_datetime_as_strings.phpt @@ -51,6 +51,11 @@ function FetchData($stmt1, $stmt2, $numRows) if ($value1 !== $value2) echo "Data corrupted: $value1 !== $value2\n"; + $value1 = $obj->c4_smalldatetime; + $value2 = $row['c4_smalldatetime']; + + if ($value1 !== $value2) + echo "Data corrupted: $value1 !== $value2\n"; } while (++$rowFetched < $numRows); } @@ -84,7 +89,6 @@ function Repro() { set_time_limit(0); sqlsrv_configure('WarningsReturnAsErrors', 1); - sqlsrv_get_config('WarningsReturnAsErrors'); require_once("autonomous_setup.php"); diff --git a/test/sqlsrv/sqlsrv_fetch_field_twice_data_types.phpt b/test/sqlsrv/sqlsrv_fetch_field_twice_data_types.phpt new file mode 100644 index 000000000..54ca0ff0f --- /dev/null +++ b/test/sqlsrv/sqlsrv_fetch_field_twice_data_types.phpt @@ -0,0 +1,141 @@ +--TEST-- +Test calling sqlsrv_get_field twice in a row. Intentionally trigger various error messages. +--FILE-- += count($metadata)) + { + $value1 = sqlsrv_get_field($stmt, $idx); + PrintError(true); // errors expected because the idx is out of bound + } + else + { + $colType = $metadata[$idx]['Type']; + + if (IsDateTime($colType)) + { + $value1 = sqlsrv_get_field($stmt, $idx, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR)); + } + else + { + $value1 = sqlsrv_get_field($stmt, $idx); + } + var_dump($value1); + + PrintError($errorExpected); + } +} + +function PrintError($errorExpected = true) +{ + $errors = sqlsrv_errors(SQLSRV_ERR_ALL); + if (count($errors) > 0) + { + $e = $errors[0]; + var_dump($e['message']); + } + else if ($errorExpected) + { + echo "An error is expected!\n"; + } +} + +function Repro() +{ + StartTest("sqlsrv_fetch_field_twice_data_types"); + try + { + set_time_limit(0); + sqlsrv_configure('WarningsReturnAsErrors', 1); + + require_once("autonomous_setup.php"); + + // Connect + $connectionInfo = array("UID"=>$username, "PWD"=>$password); + $conn = sqlsrv_connect($serverName, $connectionInfo); + if( !$conn ) { FatalError("Could not connect.\n"); } + + FetchFieldTwice($conn); + + sqlsrv_close($conn); + } + catch (Exception $e) + { + echo $e->getMessage(); + } + echo "\nDone\n"; + EndTest("sqlsrv_fetch_field_twice_data_types"); +} + +Repro(); + +?> +--EXPECT-- + +...Starting 'sqlsrv_fetch_field_twice_data_types' test... +string(79) "A statement must be prepared with sqlsrv_prepare before calling sqlsrv_execute." +string(63) "The statement must be executed before results can be retrieved." +string(52) "An invalid parameter was passed to sqlsrv_get_field." +string(52) "An invalid parameter was passed to sqlsrv_get_field." +int(968580013) +bool(false) +string(25) "Field 0 returned no data." +float(1.09) +bool(false) +string(25) "Field 1 returned no data." +float(3.4379999637604) +bool(false) +string(25) "Field 2 returned no data." +string(23) "1756-04-16 23:27:09.130" +bool(false) +string(25) "Field 3 returned no data." +string(52) "An invalid parameter was passed to sqlsrv_get_field." +string(52) "An invalid parameter was passed to sqlsrv_get_field." + +Done +...Test 'sqlsrv_fetch_field_twice_data_types' completed successfully. diff --git a/test/sqlsrv/sqlsrv_param_query_data_types.phpt b/test/sqlsrv/sqlsrv_param_query_data_types.phpt index 8b98aae36..0f319efe7 100644 --- a/test/sqlsrv/sqlsrv_param_query_data_types.phpt +++ b/test/sqlsrv/sqlsrv_param_query_data_types.phpt @@ -29,7 +29,6 @@ function Repro() { set_time_limit(0); sqlsrv_configure('WarningsReturnAsErrors', 1); - sqlsrv_get_config('WarningsReturnAsErrors'); require_once("autonomous_setup.php"); $database = "tempdb"; diff --git a/test/sqlsrv/sqlsrv_statement_query_timeout.phpt b/test/sqlsrv/sqlsrv_statement_query_timeout.phpt index 46c7e4058..2416463f0 100644 --- a/test/sqlsrv/sqlsrv_statement_query_timeout.phpt +++ b/test/sqlsrv/sqlsrv_statement_query_timeout.phpt @@ -37,7 +37,6 @@ function Repro() { set_time_limit(0); sqlsrv_configure('WarningsReturnAsErrors', 1); - sqlsrv_get_config('WarningsReturnAsErrors'); require_once("autonomous_setup.php"); $database = "tempdb"; diff --git a/test/sqlsrv/sqlsrv_statement_query_timeout_transaction.phpt b/test/sqlsrv/sqlsrv_statement_query_timeout_transaction.phpt index 7ac329c6b..9eacc6aca 100644 --- a/test/sqlsrv/sqlsrv_statement_query_timeout_transaction.phpt +++ b/test/sqlsrv/sqlsrv_statement_query_timeout_transaction.phpt @@ -48,7 +48,6 @@ function Repro() { set_time_limit(0); sqlsrv_configure('WarningsReturnAsErrors', 1); - sqlsrv_get_config('WarningsReturnAsErrors'); require_once("autonomous_setup.php"); From a10fe30fd58430d33b2f5406c68f429816788f6f Mon Sep 17 00:00:00 2001 From: yitam Date: Wed, 8 Mar 2017 16:13:57 -0800 Subject: [PATCH 8/8] modified a failing test --- .../pdo_stored_proc_fetch_datatypes.phpt | 62 ++++++++++++------- 1 file changed, 41 insertions(+), 21 deletions(-) diff --git a/test/pdo_sqlsrv/pdo_stored_proc_fetch_datatypes.phpt b/test/pdo_sqlsrv/pdo_stored_proc_fetch_datatypes.phpt index 4afab3454..2936e9cae 100644 --- a/test/pdo_sqlsrv/pdo_stored_proc_fetch_datatypes.phpt +++ b/test/pdo_sqlsrv/pdo_stored_proc_fetch_datatypes.phpt @@ -24,9 +24,11 @@ function ProcFetch_BigInt($conn) $stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300); $stmt->execute(); - if (strncasecmp($outValue, "23456789", 8)) + $expected = "23456789"; + $outValue = trim($outValue); + if (strncasecmp($outValue, $expected, strlen($expected))) { - echo "Output value $outValue is unexpected!\n"; + echo "Output value $outValue is unexpected! Expected $expected\n"; } $stmt = null; @@ -49,9 +51,11 @@ function ProcFetch_Decimal($conn) $stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300); $stmt->execute(); - if (strncasecmp($outValue, "7", 1)) + $expected = "7"; + $outValue = trim($outValue); + if (strncasecmp($outValue, $expected, strlen($expected))) { - echo "Output value $outValue is unexpected!\n"; + echo "Output value $outValue is unexpected! Expected $expected\n"; } $stmt = null; @@ -74,9 +78,11 @@ function ProcFetch_Float($conn) $stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300); $stmt->execute(); - if (strncasecmp($outValue, "7.75", 4)) + $expected = "7.75"; + $outValue = trim($outValue); + if (strncasecmp($outValue, $expected, strlen($expected))) { - echo "Output value $outValue is unexpected!\n"; + echo "Output value $outValue is unexpected! Expected $expected\n"; } $stmt = null; @@ -99,9 +105,11 @@ function ProcFetch_Int($conn) $stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300); $stmt->execute(); - if (strncasecmp($outValue, "6912", 4)) + $expected = "6912"; + $outValue = trim($outValue); + if (strncasecmp($outValue, $expected, strlen($expected))) { - echo "Output value $outValue is unexpected!\n"; + echo "Output value $outValue is unexpected! Expected $expected\n"; } $stmt = null; @@ -124,9 +132,11 @@ function ProcFetch_Money($conn) $stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300); $stmt->execute(); - if (strncasecmp($outValue, "38.40", 5)) + $expected = "38.40"; + $outValue = trim($outValue); + if (strncasecmp($outValue, $expected, strlen($expected))) { - echo "Output value $outValue is unexpected!\n"; + echo "Output value $outValue is unexpected! Expected $expected\n"; } $stmt = null; @@ -149,9 +159,11 @@ function ProcFetch_Numeric($conn) $stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300); $stmt->execute(); - if (strncasecmp($outValue, "8", 1)) + $expected = "8"; + $outValue = trim($outValue); + if (strncasecmp($outValue, $expected, strlen($expected))) { - echo "Output value $outValue is unexpected!\n"; + echo "Output value $outValue is unexpected! Expected $expected\n"; } $stmt = null; @@ -174,9 +186,11 @@ function ProcFetch_Real($conn) $stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300); $stmt->execute(); - if (strncasecmp($outValue, "10", 2)) + $expected = "10"; + $outValue = trim($outValue); + if (strncasecmp($outValue, $expected, strlen($expected))) { - echo "Output value $outValue is unexpected!\n"; + echo "Output value $outValue is unexpected! Expected $expected\n"; } $stmt = null; @@ -199,9 +213,11 @@ function ProcFetch_SmallInt($conn) $stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300); $stmt->execute(); - if (strncasecmp($outValue, "90", 2)) + $expected = "90"; + $outValue = trim($outValue); + if (strncasecmp($outValue, $expected, strlen($expected))) { - echo "Output value $outValue is unexpected!\n"; + echo "Output value $outValue is unexpected! Expected $expected\n"; } $stmt = null; @@ -224,11 +240,13 @@ function ProcFetch_SmallMoney($conn) $stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300); $stmt->execute(); - if (strncasecmp($outValue, "21.70", 5)) + $expected = "21.70"; + $outValue = trim($outValue); + if (strncasecmp($outValue, $expected, strlen($expected))) { - echo "Output value $outValue is unexpected!\n"; + echo "Output value $outValue is unexpected! Expected $expected\n"; } - + $stmt = null; } @@ -249,9 +267,11 @@ function ProcFetch_TinyInt($conn) $stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300); $stmt->execute(); - if (strncasecmp($outValue, "23", 2)) + $expected = "23"; + $outValue = trim($outValue); + if (strncasecmp($outValue, $expected, strlen($expected))) { - echo "Output value $outValue is unexpected!\n"; + echo "Output value $outValue is unexpected! Expected $expected\n"; } $stmt = null;