Merge pull request #320 from yitam/addNewTests

Uploaded some more tests
This commit is contained in:
v-kaywon 2017-03-09 11:55:11 -08:00 committed by GitHub
commit 5ccbda81e1
11 changed files with 1373 additions and 0 deletions

View file

@ -0,0 +1,74 @@
--TEST--
testing the quote method with different inputs and then test with a empty query
--SKIPIF--
--FILE--
<?php
include 'pdo_tools.inc';
function Quote()
{
require("autonomous_setup.php");
$conn = new PDO( "sqlsrv:server=$serverName", $username, $password);
$output1 = $conn->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("<XmlTestData><Letters>The quick brown fox jumps over the lazy dog</Letters><Digits>0123456789</Digits></XmlTestData>");
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) "'<XmlTestData><Letters>The quick brown fox jumps over the lazy dog</Letters><Digits>0123456789</Digits></XmlTestData>'"
Done
...Test 'pdo_connection_quote' completed successfully.

View file

@ -0,0 +1,108 @@
--TEST--
fetch multiple result sets with MARS on and then off
--SKIPIF--
--FILE--
<?php
include 'pdo_tools.inc';
function NestedQuery_Mars($on)
{
require("autonomous_setup.php");
$database = "tempdb";
$tableName = GetTempTableName();
$conn = new PDO( "sqlsrv:server=$serverName;Database=$database;MultipleActiveResultSets=$on", $username, $password);
$conn->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.

View file

@ -0,0 +1,92 @@
--TEST--
test query time out at the connection level and statement level
--SKIPIF--
--FILE--
<?php
include 'pdo_tools.inc';
function QueryTimeout($connLevel)
{
require("autonomous_setup.php");
$database = "tempdb";
$tableName = GetTempTableName();
$conn = new PDO( "sqlsrv:server=$serverName;Database=$database", $username, $password);
$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.

View file

@ -0,0 +1,181 @@
--TEST--
test rowCount() with different querying method and test nextRowset() with different fetch
--SKIPIF--
--FILE--
<?php
include 'pdo_tools.inc';
function RowCount_Query($exec)
{
require("autonomous_setup.php");
$database = "tempdb";
$tableName = GetTempTableName();
$conn = new PDO( "sqlsrv:server=$serverName;Database=$database", $username, $password);
$stmt = $conn->exec("CREATE TABLE $tableName ([c1_int] int, [c2_real] real)");
$numRows = 5;
for ($i = 1; $i <= $numRows; $i++)
{
InsertData($conn, $tableName, $i);
}
FetchRowsets($conn, $tableName, $numRows);
for ($i = 1; $i <= $numRows; $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 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)
{
$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.

View file

@ -0,0 +1,320 @@
--TEST--
call stored procedures with inputs of ten different datatypes to get outputs of various types
--SKIPIF--
--FILE--
<?php
include 'pdo_tools.inc';
function ProcFetch_BigInt($conn)
{
$procName = GetTempProcName();
$stmt = $conn->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();
$expected = "23456789";
$outValue = trim($outValue);
if (strncasecmp($outValue, $expected, strlen($expected)))
{
echo "Output value $outValue is unexpected! Expected $expected\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();
$expected = "7";
$outValue = trim($outValue);
if (strncasecmp($outValue, $expected, strlen($expected)))
{
echo "Output value $outValue is unexpected! Expected $expected\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();
$expected = "7.75";
$outValue = trim($outValue);
if (strncasecmp($outValue, $expected, strlen($expected)))
{
echo "Output value $outValue is unexpected! Expected $expected\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();
$expected = "6912";
$outValue = trim($outValue);
if (strncasecmp($outValue, $expected, strlen($expected)))
{
echo "Output value $outValue is unexpected! Expected $expected\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();
$expected = "38.40";
$outValue = trim($outValue);
if (strncasecmp($outValue, $expected, strlen($expected)))
{
echo "Output value $outValue is unexpected! Expected $expected\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();
$expected = "8";
$outValue = trim($outValue);
if (strncasecmp($outValue, $expected, strlen($expected)))
{
echo "Output value $outValue is unexpected! Expected $expected\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();
$expected = "10";
$outValue = trim($outValue);
if (strncasecmp($outValue, $expected, strlen($expected)))
{
echo "Output value $outValue is unexpected! Expected $expected\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();
$expected = "90";
$outValue = trim($outValue);
if (strncasecmp($outValue, $expected, strlen($expected)))
{
echo "Output value $outValue is unexpected! Expected $expected\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();
$expected = "21.70";
$outValue = trim($outValue);
if (strncasecmp($outValue, $expected, strlen($expected)))
{
echo "Output value $outValue is unexpected! Expected $expected\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();
$expected = "23";
$outValue = trim($outValue);
if (strncasecmp($outValue, $expected, strlen($expected)))
{
echo "Output value $outValue is unexpected! Expected $expected\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.

View file

@ -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--
<?php
include 'pdo_tools.inc';
function StoredProc_Xml($conn)
{
$inValue1 = pack('H*', '3C586D6C54657374446174613E4A65207072C3A966C3A87265206C27C3A974C3A93C2F586D6C54657374446174613E');
$procName = GetTempProcName();
$stmt = $conn->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) "<XmlTestData>Je préfère l'été</XmlTestData>"
bool(true)
bool(true)
Done
...Test 'pdo_utf8_stored_proc_unicode_chars' completed successfully.

View file

@ -0,0 +1,120 @@
--TEST--
Test fetching datatime fields as strings
--FILE--
<?php
include 'tools.inc';
function FetchDateTime_AsString($conn)
{
$tableName = GetTempTableName();
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_timestamp] timestamp, [c3_datetime] datetime, [c4_smalldatetime] smalldatetime)");
sqlsrv_free_stmt($stmt);
$numRows = 0;
$query = GetQuery($tableName, ++$numRows);
$stmt = sqlsrv_query($conn, $query);
sqlsrv_free_stmt($stmt);
$query = GetQuery($tableName, ++$numRows);
$stmt = sqlsrv_query($conn, $query);
sqlsrv_free_stmt($stmt);
$query = GetQuery($tableName, ++$numRows);
$stmt = sqlsrv_query($conn, $query);
sqlsrv_free_stmt($stmt);
$query = GetQuery($tableName, ++$numRows);
$stmt = sqlsrv_query($conn, $query);
sqlsrv_free_stmt($stmt);
$query = "SELECT [c3_datetime], [c4_smalldatetime] FROM $tableName ORDER BY c2_timestamp";
$stmt1 = sqlsrv_query($conn, $query);
$stmt2 = sqlsrv_query($conn, $query);
FetchData($stmt1, $stmt2, $numRows);
sqlsrv_free_stmt($stmt1);
sqlsrv_free_stmt($stmt2);
}
function FetchData($stmt1, $stmt2, $numRows)
{
$rowFetched = 0;
do {
$obj = sqlsrv_fetch_object($stmt1);
$row = sqlsrv_fetch_array($stmt2, SQLSRV_FETCH_ASSOC);
$value1 = $obj->c3_datetime;
$value2 = $row['c3_datetime'];
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);
}
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);
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.

View file

@ -0,0 +1,141 @@
--TEST--
Test calling sqlsrv_get_field twice in a row. Intentionally trigger various error messages.
--FILE--
<?php
include 'tools.inc';
function FetchFieldTwice($conn)
{
$tableName = GetTempTableName();
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_float] float, [c3_real] real, [c4_datetime] datetime)");
sqlsrv_free_stmt($stmt);
$query = "INSERT INTO $tableName ([c1_int], [c2_float], [c3_real], [c4_datetime]) VALUES ((968580013), (1.09), (3.438), ('1756-04-16 23:27:09.131'))";
$stmt = sqlsrv_query($conn, $query);
sqlsrv_execute($stmt);
PrintError(); // errors expected here
sqlsrv_free_stmt($stmt);
$query = "SELECT * FROM $tableName";
$stmt = sqlsrv_prepare($conn, $query);
$result = sqlsrv_fetch($stmt);
if ($result !== false)
{
echo "Fetch should have failed!\n";
}
PrintError(); // errors expected here
if (! sqlsrv_execute($stmt))
{
FatalError("Errors in executing statement.\n");
}
$numFields = sqlsrv_num_fields($stmt);
$metadata = sqlsrv_field_metadata($stmt);
while ($result = sqlsrv_fetch($stmt))
{
for ($i = -1; $i <= $numFields; $i++)
{
FetchField($stmt, $i, $metadata, false);
FetchField($stmt, $i, $metadata, true);
}
}
sqlsrv_free_stmt($stmt);
}
function FetchField($stmt, $idx, $metadata, $errorExpected)
{
if ($idx < 0 || $idx >= 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.

View file

@ -0,0 +1,65 @@
--TEST--
Test insert various numeric data types and fetch them back as strings
--FILE--
<?php
include 'tools.inc';
function ParamQuery($conn, $type, $sqlsrvType, $inValue)
{
$tableName = GetTempTableName();
$stmt = sqlsrv_query($conn, "CREATE TABLE [$tableName] ([col1] int, [col2] $type)");
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query($conn, "INSERT INTO [$tableName] VALUES (?, ?)", array(1, array($inValue, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_FLOAT, $sqlsrvType)));
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query($conn, "SELECT * FROM $tableName");
sqlsrv_fetch($stmt);
$value = sqlsrv_get_field($stmt, 1, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
CompareNumericData($value, $inValue);
sqlsrv_free_stmt($stmt);
}
function Repro()
{
StartTest("sqlsrv_param_query_data_types");
try
{
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
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"); }
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.

View file

@ -0,0 +1,77 @@
--TEST--
Test sending queries (query or prepare) with a timeout specified. Errors are expected.
--FILE--
<?php
include 'tools.inc';
function QueryTimeout($conn, $exec)
{
$tableName = GetTempTableName();
$stmt = sqlsrv_query($conn, "CREATE TABLE [$tableName] ([c1_int] int, [c2_tinyint] tinyint, [c3_smallint] smallint, [c4_bigint] bigint, [c5_bit] bit, [c6_float] float, [c7_real] real, [c8_decimal] decimal(28,4), [c9_numeric] numeric(32,4), [c10_money] money, [c11_smallmoney] smallmoney, [c12_char] char(512), [c13_varchar] varchar(512), [c14_varchar_max] varchar(max), [c15_uniqueidentifier] uniqueidentifier, [c16_datetime] datetime, [c17_smalldatetime] smalldatetime, [c18_timestamp] timestamp)");
sqlsrv_free_stmt($stmt);
if ($exec)
{
$stmt = sqlsrv_query($conn, "WAITFOR DELAY '00:00:03'; SELECT * FROM $tableName", array(), array('QueryTimeout' => 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);
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.

View file

@ -0,0 +1,90 @@
--TEST--
Test sending queries (query or prepare) with a timeout specified using transactions. Errors are expected.
--FILE--
<?php
include 'tools.inc';
function QueryTimeout($conn1, $conn2, $commit)
{
$tableName = GetTempTableName('testQueryTimeout');
$stmt = sqlsrv_query($conn1, "CREATE TABLE $tableName ([c1_int] int, [c2_tinyint] tinyint, [c3_smallint] smallint, [c4_bigint] bigint, [c5_bit] bit, [c6_float] float, [c7_real] real, [c8_decimal] decimal(28,4), [c9_numeric] numeric(32,4), [c10_money] money, [c11_smallmoney] smallmoney)");
sqlsrv_free_stmt($stmt);
sqlsrv_begin_transaction($conn1);
$query = "INSERT INTO $tableName VALUES ((-2147483648), (127), (null), (9223372036854775807), (0), (1), (0), (null), (0.8654), (922337203685477.5807), (-214748.3648))";
$stmt = sqlsrv_query($conn1, $query);
$numRows = sqlsrv_rows_affected($stmt);
if ($numRows !== 1)
echo "Number of rows affected unexpected!\n";
$query = "INSERT INTO $tableName VALUES ((2147483647), (154), (-5459), (1), (0), (-1.79E+308), (1), (0.4430), (0), (0.2511), (0.7570))";
$stmt = sqlsrv_query($conn1, $query);
$numRows = sqlsrv_rows_affected($stmt);
if ($numRows !== 1)
echo "Number of rows affected unexpected!\n";
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query($conn2, "SELECT * FROM $tableName", array(), array('QueryTimeout' => 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);
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.