Skip to content

Commit

Permalink
Merge pull request #320 from yitam/addNewTests
Browse files Browse the repository at this point in the history
Uploaded some more tests
  • Loading branch information
yukiwongky authored Mar 9, 2017
2 parents 867ca5c + a10fe30 commit 5ccbda8
Show file tree
Hide file tree
Showing 11 changed files with 1,373 additions and 0 deletions.
74 changes: 74 additions & 0 deletions test/pdo_sqlsrv/pdo_connection_quote.phpt
Original file line number Diff line number Diff line change
@@ -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.
108 changes: 108 additions & 0 deletions test/pdo_sqlsrv/pdo_nested_query_mars.phpt
Original file line number Diff line number Diff line change
@@ -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.
92 changes: 92 additions & 0 deletions test/pdo_sqlsrv/pdo_query_timeout.phpt
Original file line number Diff line number Diff line change
@@ -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.
Loading

0 comments on commit 5ccbda8

Please sign in to comment.