fixed tests and added new ones

This commit is contained in:
yitam 2017-05-03 14:04:17 -07:00
parent 0c7560d112
commit 586b2b3e4e
48 changed files with 5392 additions and 3 deletions

View file

@ -0,0 +1,113 @@
--TEST--
PDO - Insert Nulls
--DESCRIPTION--
Test inserting nulls into nullable columns
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function InsertNullsTest($bindType)
{
include 'MsSetup.inc';
$outvar = null;
$failed = false;
Setup();
$conn = Connect();
DropTable($conn, $tableName);
CreateTable($conn, $tableName);
$stmt = $conn->query(<<<SQL
SELECT [TABLE_NAME],[COLUMN_NAME],[IS_NULLABLE] FROM [INFORMATION_SCHEMA].[COLUMNS] WHERE [TABLE_NAME] = '$tableName'
SQL
);
if ($stmt === false)
{
FatalError("Could not query for column information on table $tableName");
}
while ($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
Trace($row['COLUMN_NAME'] . ": " . $row['IS_NULLABLE'] . "\n");
$stmt2 = $conn->prepare("INSERT INTO [$tableName] ([" . $row['COLUMN_NAME'] . "]) VALUES (:p1)");
if (strpos($row['COLUMN_NAME'], "timestamp") !== false) continue;
if (($row['IS_NULLABLE'] == 'YES') && (strpos($row['COLUMN_NAME'], "binary") !== false))
{
if ($bindType == PDO::PARAM_LOB)
{
$stmt2->setAttribute(PDO::SQLSRV_ATTR_ENCODING, PDO::SQLSRV_ENCODING_BINARY);
$stmt2->bindValue(":p1", null, $bindType);
}
else if ($bindType == PDO::PARAM_STR)
{
$stmt2->bindParam(":p1", $outvar, $bindType, null, PDO::SQLSRV_ENCODING_BINARY);
}
}
else
{
$stmt2->bindParam(":p1", $outvar);
}
$stmt2->execute();
if ($stmt2->errorCode() !== '00000')
{
print_r($stmt2->errorInfo());
$failed = true;
}
}
DropTable($conn, $tableName);
return($failed);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
$failed = null;
$testName = "PDO - Insert Nulls";
StartTest($testName);
try
{
$failed |= InsertNullsTest(PDO::PARAM_LOB);
$failed |= InsertNullsTest(PDO::PARAM_STR);
}
catch (Exception $e)
{
echo $e->getMessage();
}
if ($failed)
FatalError("Possible Regression: Could not insert NULL");
EndTest($testName);
}
Repro();
?>
--EXPECT--
Test "PDO - Insert Nulls" completed successfully.

View file

@ -0,0 +1,76 @@
--TEST--
PDO - Large Column Name Test
--DESCRIPTION--
Verifies that long column names are supported (up to 128 chars).
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function LargeColumnNameTest($columnName, $expectfail)
{
include 'MsSetup.inc';
Setup();
$conn = Connect();
$tableName = "LargeColumnNameTest";
DropTable($conn, $tableName);
$conn->query("CREATE TABLE [$tableName] ([$columnName] int)");
$conn->query("INSERT INTO [$tableName] ([$columnName]) VALUES (5)");
$stmt = $conn->query("SELECT * from [$tableName]");
if ( null == $stmt )
{
if (!$expectfail)
FatalError("Possible regression: Unable to retrieve inserted value.");
}
DropTable($conn, $tableName);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
$testName = "PDO - Large Column Name Test";
StartTest($testName);
$columnName = "a";
try
{
for ($a = 1; $a <= 128; $a++)
{
LargeColumnNameTest($columnName, $a > 128);
$columnName .= "A";
}
}
catch (Exception $e)
{
echo $e->getMessage();
}
EndTest($testName);
}
Repro();
?>
--EXPECT--
Test "PDO - Large Column Name Test" completed successfully.

View file

@ -0,0 +1,76 @@
--TEST--
PDO - Large Unicode Column Name Test
--DESCRIPTION--
Verifies that long column names in Unicode are supported (up to 128 chars).
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function LargeColumnNameTest($columnName, $expectfail)
{
include 'MsSetup.inc';
Setup();
$conn = Connect();
$tableName = "LargeColumnNameTest";
DropTable($conn, $tableName);
$conn->query("CREATE TABLE [$tableName] ([$columnName] int)");
$conn->query("INSERT INTO [$tableName] ([$columnName]) VALUES (5)");
$stmt = $conn->query("SELECT * from [$tableName]");
if ( null == $stmt )
{
if (!$expectfail)
FatalError("Possible regression: Unable to retrieve inserted value.");
}
DropTable($conn, $tableName);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
$testName = "PDO - Large Column Name Test";
StartTest($testName);
$columnName = "是";
try
{
for ($a = 1; $a <= 128; $a++)
{
LargeColumnNameTest($columnName, $a > 128);
$columnName .= "是";
}
}
catch (Exception $e)
{
echo $e->getMessage();
}
EndTest($testName);
}
Repro();
?>
--EXPECT--
Test "PDO - Large Column Name Test" completed successfully.

View file

@ -0,0 +1,82 @@
--TEST--
PDO - Max Output Params Test
--DESCRIPTION--
Fetch data as VARCHAR(MAX)
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function MaxOutputParamsTest($expected, $length)
{
include 'MsSetup.inc';
$outstr = null;
$conn = Connect();
CreateProc(
$conn,
"EXEC_TEST",
"@OUT varchar(80) output",
"SET NOCOUNT ON; select @OUT = '$expected'; return (0)
");
$sql = "execute EXEC_TEST ?";
$stmt = $conn->prepare($sql);
if ($length)
{
$stmt->bindParam(1, $outstr, PDO::PARAM_STR, 10);
}
else
{
$stmt->bindParam(1, $outstr, PDO::PARAM_STR, 3);
}
$stmt->execute();
echo "Expected: $expected Received: $outstr\n";
if ($outstr !== $expected)
{
print_r($stmt->errorInfo());
return(-1);
}
return(0);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
$failed = null;
$testName = "PDO - Max Output Params Test";
StartTest($testName);
$failed |= MaxOutputParamsTest("abc", null);
$failed |= MaxOutputParamsTest("abc", -1);
if ($failed)
FatalError("Possible Regression: Value returned as VARCHAR(MAX) truncated");
EndTest($testName);
}
Repro();
?>
--EXPECT--
Expected: abc Received: abc
Expected: abc Received: abc
Test "PDO - Max Output Params Test" completed successfully.

View file

@ -6,7 +6,7 @@ when an URI-based construct is used.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php if ( !( strtoupper( substr( php_uname( 's' ),0,3 ) ) === 'WIN' ) ) die( "Skip, test on windows only." ); ?>
--FILE--
<?php
include 'MsCommon.inc';

View file

@ -6,7 +6,7 @@ when an URI-based construct is used.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php if ( !( strtoupper( substr( php_uname( 's' ),0,3 ) ) === 'WIN' ) ) die( "Skip, test on windows only." ); ?>
--FILE--
<?php
include 'MsCommon.inc';

View file

@ -0,0 +1,86 @@
--TEST--
PDO Fetch Test with PDO::FETCH_ASSOC
--DESCRIPTION--
Basic verification for "PDOStatement::fetchAll(PDO::FETCH_ASSOC)”.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function FetchAll($execMode, $fetchMode)
{
include 'MsSetup.inc';
$testName = "PDO Statement - Fetch All";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
$dataCols = "id, val";
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, val VARCHAR(10)", null);
InsertRowEx($conn1, $tableName, $dataCols, "1, 'A'", null);
InsertRowEx($conn1, $tableName, $dataCols, "2, 'B'", null);
InsertRowEx($conn1, $tableName, $dataCols, "3, 'C'", null);
// Query table and retrieve data
$stmt1 = ExecuteQueryEx($conn1, "SELECT * FROM [$tableName]", $execMode);
var_dump($stmt1->fetchAll($fetchMode));
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
FetchAll(false, PDO::FETCH_ASSOC);
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
array(3) {
[0]=>
array(2) {
["id"]=>
string(1) "1"
["val"]=>
string(1) "A"
}
[1]=>
array(2) {
["id"]=>
string(1) "2"
["val"]=>
string(1) "B"
}
[2]=>
array(2) {
["id"]=>
string(1) "3"
["val"]=>
string(1) "C"
}
}
Test "PDO Statement - Fetch All" completed successfully.

View file

@ -0,0 +1,86 @@
--TEST--
PDO Fetch Test with PDO::FETCH_NUM
--DESCRIPTION--
Basic verification for "PDOStatement::fetchAll(PDO::FETCH_NUM)”.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function FetchAll($execMode, $fetchMode)
{
include 'MsSetup.inc';
$testName = "PDO Statement - Fetch All";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
$dataCols = "id, val";
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, val VARCHAR(10)", null);
InsertRowEx($conn1, $tableName, $dataCols, "1, 'A'", null);
InsertRowEx($conn1, $tableName, $dataCols, "2, 'B'", null);
InsertRowEx($conn1, $tableName, $dataCols, "3, 'C'", null);
// Query table and retrieve data
$stmt1 = ExecuteQueryEx($conn1, "SELECT * FROM [$tableName]", $execMode);
var_dump($stmt1->fetchAll($fetchMode));
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
FetchAll(true, PDO::FETCH_NUM);
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
array(3) {
[0]=>
array(2) {
[0]=>
string(1) "1"
[1]=>
string(1) "A"
}
[1]=>
array(2) {
[0]=>
string(1) "2"
[1]=>
string(1) "B"
}
[2]=>
array(2) {
[0]=>
string(1) "3"
[1]=>
string(1) "C"
}
}
Test "PDO Statement - Fetch All" completed successfully.

View file

@ -0,0 +1,98 @@
--TEST--
PDO Fetch Test with PDO::FETCH_BOTH
--DESCRIPTION--
Basic verification for "PDOStatement::fetchAll(PDO::FETCH_BOTH)”.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function FetchAll($execMode, $fetchMode)
{
include 'MsSetup.inc';
$testName = "PDO Statement - Fetch All";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
$dataCols = "id, val";
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, val VARCHAR(10)", null);
InsertRowEx($conn1, $tableName, $dataCols, "1, 'A'", null);
InsertRowEx($conn1, $tableName, $dataCols, "2, 'B'", null);
InsertRowEx($conn1, $tableName, $dataCols, "3, 'C'", null);
// Query table and retrieve data
$stmt1 = ExecuteQueryEx($conn1, "SELECT * FROM [$tableName]", $execMode);
var_dump($stmt1->fetchAll($fetchMode));
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
FetchAll(false, PDO::FETCH_BOTH);
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
array(3) {
[0]=>
array(4) {
["id"]=>
string(1) "1"
[0]=>
string(1) "1"
["val"]=>
string(1) "A"
[1]=>
string(1) "A"
}
[1]=>
array(4) {
["id"]=>
string(1) "2"
[0]=>
string(1) "2"
["val"]=>
string(1) "B"
[1]=>
string(1) "B"
}
[2]=>
array(4) {
["id"]=>
string(1) "3"
[0]=>
string(1) "3"
["val"]=>
string(1) "C"
[1]=>
string(1) "C"
}
}
Test "PDO Statement - Fetch All" completed successfully.

View file

@ -0,0 +1,86 @@
--TEST--
PDO Fetch Test with PDO::FETCH_OBJ
--DESCRIPTION--
Basic verification for "PDOStatement::fetchAll(PDO::FETCH_OBJ)”.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function FetchAll($execMode, $fetchMode)
{
include 'MsSetup.inc';
$testName = "PDO Statement - Fetch All";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
$dataCols = "id, val";
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, val VARCHAR(10)", null);
InsertRowEx($conn1, $tableName, $dataCols, "1, 'A'", null);
InsertRowEx($conn1, $tableName, $dataCols, "2, 'B'", null);
InsertRowEx($conn1, $tableName, $dataCols, "3, 'C'", null);
// Query table and retrieve data
$stmt1 = ExecuteQueryEx($conn1, "SELECT * FROM [$tableName]", $execMode);
var_dump($stmt1->fetchAll($fetchMode));
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
FetchAll(false, PDO::FETCH_OBJ);
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECTF--
array(3) {
[0]=>
object(stdClass)#%d (2) {
["id"]=>
string(1) "1"
["val"]=>
string(1) "A"
}
[1]=>
object(stdClass)#%d (2) {
["id"]=>
string(1) "2"
["val"]=>
string(1) "B"
}
[2]=>
object(stdClass)#%d (2) {
["id"]=>
string(1) "3"
["val"]=>
string(1) "C"
}
}
Test "PDO Statement - Fetch All" completed successfully.

View file

@ -0,0 +1,114 @@
--TEST--
PDO Fetch Test with PDO::FETCH_GROUP
--DESCRIPTION--
Basic verification for "PDOStatement::fetchAll(PDO::FETCH_GROUP)”.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function FetchAll($fetchMode)
{
include 'MsSetup.inc';
$testName = "PDO Statement - Fetch All";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
$dataCols = "id, val";
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, val VARCHAR(10)", null);
InsertRowEx($conn1, $tableName, $dataCols, "1, 'A'", null);
InsertRowEx($conn1, $tableName, $dataCols, "2, 'A'", null);
InsertRowEx($conn1, $tableName, $dataCols, "3, 'C'", null);
// Query table and retrieve data
$stmt1 = PrepareQuery($conn1, "SELECT val, id FROM [$tableName]");
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_NUM|$fetchMode));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_ASSOC|$fetchMode));
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
FetchAll(PDO::FETCH_GROUP);
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
array(2) {
["A"]=>
array(2) {
[0]=>
array(1) {
[0]=>
string(1) "1"
}
[1]=>
array(1) {
[0]=>
string(1) "2"
}
}
["C"]=>
array(1) {
[0]=>
array(1) {
[0]=>
string(1) "3"
}
}
}
array(2) {
["A"]=>
array(2) {
[0]=>
array(1) {
["id"]=>
string(1) "1"
}
[1]=>
array(1) {
["id"]=>
string(1) "2"
}
}
["C"]=>
array(1) {
[0]=>
array(1) {
["id"]=>
string(1) "3"
}
}
}
Test "PDO Statement - Fetch All" completed successfully.

View file

@ -0,0 +1,120 @@
--TEST--
PDO Fetch Test with PDO::FETCH_UNIQUE
--DESCRIPTION--
Basic verification for "PDOStatement::fetchAll(PDO::FETCH_UNIQUE)”.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function FetchAll()
{
include 'MsSetup.inc';
$testName = "PDO Statement - Fetch All";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
$dataCols = "id, val";
CreateTableEx($conn1, $tableName, "id CHAR(1) NOT NULL PRIMARY KEY, val VARCHAR(10)", null);
InsertRowEx($conn1, $tableName, $dataCols, "'A', 'A'", null);
InsertRowEx($conn1, $tableName, $dataCols, "'B', 'A'", null);
InsertRowEx($conn1, $tableName, $dataCols, "'C', 'C'", null);
// Test FetchAll(PDO::FETCH_UNIQUE) without conflict
$stmt1 = PrepareQuery($conn1, "SELECT id, val FROM [$tableName]");
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_NUM|PDO::FETCH_UNIQUE));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_ASSOC|PDO::FETCH_UNIQUE));
unset($stmt1);
// Test FetchAll(PDO::FETCH_UNIQUE) with conflict
$stmt1 = ExecuteQuery($conn1, "SELECT val, id FROM [$tableName]");
var_dump($stmt1->fetchAll(PDO::FETCH_NUM|PDO::FETCH_UNIQUE));
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
FetchAll();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
array(3) {
["A"]=>
array(1) {
[0]=>
string(1) "A"
}
["B"]=>
array(1) {
[0]=>
string(1) "A"
}
["C"]=>
array(1) {
[0]=>
string(1) "C"
}
}
array(3) {
["A"]=>
array(1) {
["val"]=>
string(1) "A"
}
["B"]=>
array(1) {
["val"]=>
string(1) "A"
}
["C"]=>
array(1) {
["val"]=>
string(1) "C"
}
}
array(2) {
["A"]=>
array(1) {
[0]=>
string(1) "B"
}
["C"]=>
array(1) {
[0]=>
string(1) "C"
}
}
Test "PDO Statement - Fetch All" completed successfully.

View file

@ -0,0 +1,250 @@
--TEST--
PDO Fetch Test with PDO::FETCH_CLASSTYPE
--DESCRIPTION--
Basic verification for "PDOStatement::fetchAll(PDO::FETCH_CLASSTYPE)”.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function FetchAll()
{
include 'MsSetup.inc';
$testName = "PDO Statement - Fetch All";
StartTest($testName);
$conn1 = Connect();
// Prepare test tables
$dataCols1 = "id, name";
$table1 = $tableName."1";
CreateTableEx($conn1, $table1, "id int NOT NULL PRIMARY KEY, name VARCHAR(10) NOT NULL UNIQUE", null);
InsertRowEx($conn1, $table1, $dataCols1, "0, 'stdClass'", null);
InsertRowEx($conn1, $table1, $dataCols1, "1, 'Test1'", null);
InsertRowEx($conn1, $table1, $dataCols1, "2, 'Test2'", null);
$dataCols2 = "id, classtype, val";
$table2 = $tableName."2";
CreateTableEx($conn1, $table2, "id int NOT NULL PRIMARY KEY, classtype int, val VARCHAR(10)", null);
InsertRowEx($conn1, $table2, $dataCols2, "1, 0, 'A'", null);
InsertRowEx($conn1, $table2, $dataCols2, "2, 1, 'B'", null);
InsertRowEx($conn1, $table2, $dataCols2, "3, 2, 'C'", null);
InsertRowEx($conn1, $table2, $dataCols2, "4, 3, 'D'", null);
$dataCols3 = "id, classtype, val, grp";
$table3 = $tableName."3";
CreateTableEx($conn1, $table3, "id int NOT NULL PRIMARY KEY, classtype int, val VARCHAR(10), grp VARCHAR(10)", null);
InsertRowEx($conn1, $table3, $dataCols3, "1, 0, 'A', 'Group1'", null);
InsertRowEx($conn1, $table3, $dataCols3, "2, 1, 'B', 'Group1'", null);
InsertRowEx($conn1, $table3, $dataCols3, "3, 2, 'C', 'Group2'", null);
InsertRowEx($conn1, $table3, $dataCols3, "4, 3, 'D', 'Group2'", null);
// Test fetchAll(PDO::FETCH_CLASSTYPE)
$stmt1 = PrepareQuery($conn1, "SELECT $table1.name, $table2.id AS id, $table2.val AS val FROM $table2 LEFT JOIN $table1 ON $table2.classtype=$table1.id");
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_NUM));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_CLASS|PDO::FETCH_CLASSTYPE, 'Test3'));
unset($stmt1);
// Test fetchAll(PDO::FETCH_CLASSTYPE) with GROUP/UNIQUE
$stmt1 = PrepareQuery($conn1, "SELECT $table1.name, $table3.grp AS grp, $table3.id AS id, $table3.val AS val FROM $table3 LEFT JOIN $table1 ON $table3.classtype=$table1.id");
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_CLASS|PDO::FETCH_CLASSTYPE|PDO::FETCH_GROUP, 'Test3'));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_CLASS|PDO::FETCH_CLASSTYPE|PDO::FETCH_UNIQUE, 'Test3'));
// Cleanup
DropTable($conn1, $table1);
DropTable($conn1, $table2);
DropTable($conn1, $table3);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
class Test1
{
public function __construct()
{
echo __METHOD__ . "()\n";
}
}
class Test2
{
public function __construct()
{
echo __METHOD__ . "()\n";
}
}
class Test3
{
public function __construct()
{
echo __METHOD__ . "()\n";
}
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
FetchAll();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECTF--
array(4) {
[0]=>
array(3) {
[0]=>
string(8) "stdClass"
[1]=>
string(1) "1"
[2]=>
string(1) "A"
}
[1]=>
array(3) {
[0]=>
string(5) "Test1"
[1]=>
string(1) "2"
[2]=>
string(1) "B"
}
[2]=>
array(3) {
[0]=>
string(5) "Test2"
[1]=>
string(1) "3"
[2]=>
string(1) "C"
}
[3]=>
array(3) {
[0]=>
NULL
[1]=>
string(1) "4"
[2]=>
string(1) "D"
}
}
Test1::__construct()
Test2::__construct()
Test3::__construct()
array(4) {
[0]=>
object(stdClass)#%d (2) {
["id"]=>
string(1) "1"
["val"]=>
string(1) "A"
}
[1]=>
object(Test1)#%d (2) {
["id"]=>
string(1) "2"
["val"]=>
string(1) "B"
}
[2]=>
object(Test2)#%d (2) {
["id"]=>
string(1) "3"
["val"]=>
string(1) "C"
}
[3]=>
object(Test3)#%d (2) {
["id"]=>
string(1) "4"
["val"]=>
string(1) "D"
}
}
Test1::__construct()
Test2::__construct()
Test3::__construct()
array(2) {
["Group1"]=>
array(2) {
[0]=>
object(stdClass)#%d (2) {
["id"]=>
string(1) "1"
["val"]=>
string(1) "A"
}
[1]=>
object(Test1)#%d (2) {
["id"]=>
string(1) "2"
["val"]=>
string(1) "B"
}
}
["Group2"]=>
array(2) {
[0]=>
object(Test2)#%d (2) {
["id"]=>
string(1) "3"
["val"]=>
string(1) "C"
}
[1]=>
object(Test3)#%d (2) {
["id"]=>
string(1) "4"
["val"]=>
string(1) "D"
}
}
}
Test1::__construct()
Test2::__construct()
Test3::__construct()
array(2) {
["Group1"]=>
object(Test1)#%d (2) {
["id"]=>
string(1) "2"
["val"]=>
string(1) "B"
}
["Group2"]=>
object(Test3)#%d (2) {
["id"]=>
string(1) "4"
["val"]=>
string(1) "D"
}
}
Test "PDO Statement - Fetch All" completed successfully.

View file

@ -0,0 +1,138 @@
--TEST--
PDO Fetch Test with PDO::FETCH_COLUMN
--DESCRIPTION--
Verification for "PDOStatement::fetchAll(PDO::FETCH_COLUMN)".
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function Fetch()
{
include 'MsSetup.inc';
$testName = "PDO Statement - Fetch All";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
$dataCols = "id, val, val2";
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, val VARCHAR(10), val2 VARCHAR(10)", null);
InsertRowEx($conn1, $tableName, $dataCols, "1, 'A', 'A2'", null);
InsertRowEx($conn1, $tableName, $dataCols, "2, 'A', 'B2'", null);
// Testing with prepared query
$stmt1 = PrepareQuery($conn1, "SELECT id, val, val2 FROM [$tableName]");
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_COLUMN));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_COLUMN, 2));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_GROUP));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_UNIQUE));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_UNIQUE, 0));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_UNIQUE, 1));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_UNIQUE, 2));
unset($stmt1);
$stmt1 = PrepareQuery($conn1, "SELECT val, val2 FROM [$tableName]");
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_GROUP));
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
Fetch();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
array(2) {
[0]=>
string(1) "1"
[1]=>
string(1) "2"
}
array(2) {
[0]=>
string(2) "A2"
[1]=>
string(2) "B2"
}
array(2) {
[1]=>
array(1) {
[0]=>
string(1) "A"
}
[2]=>
array(1) {
[0]=>
string(1) "A"
}
}
array(2) {
[1]=>
string(1) "A"
[2]=>
string(1) "A"
}
array(2) {
[1]=>
string(1) "1"
[2]=>
string(1) "2"
}
array(2) {
[1]=>
string(1) "A"
[2]=>
string(1) "A"
}
array(2) {
[1]=>
string(2) "A2"
[2]=>
string(2) "B2"
}
array(1) {
["A"]=>
array(2) {
[0]=>
string(2) "A2"
[1]=>
string(2) "B2"
}
}
Test "PDO Statement - Fetch All" completed successfully.

View file

@ -0,0 +1,141 @@
--TEST--
PDO Fetch Test with PDO::FETCH_COLUMN for unicode column names
--DESCRIPTION--
Verification for "PDOStatement::fetchAll(PDO::FETCH_COLUMN)".
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function Fetch()
{
include 'MsSetup.inc';
$testName = "PDO Statement - Fetch All";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
$val = str_repeat("P银河系", 32);
$val2 = str_repeat("银河系мужирафиtest是", 8);
$dataCols = "id, $val, $val2";
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, $val VARCHAR(10), $val2 VARCHAR(10)", null);
InsertRowEx($conn1, $tableName, $dataCols, "1, 'A', 'A2'", null);
InsertRowEx($conn1, $tableName, $dataCols, "2, 'A', 'B2'", null);
// Testing with prepared query
$stmt1 = PrepareQuery($conn1, "SELECT id, $val, $val2 FROM [$tableName]");
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_COLUMN));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_COLUMN, 2));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_GROUP));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_UNIQUE));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_UNIQUE, 0));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_UNIQUE, 1));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_UNIQUE, 2));
unset($stmt1);
$stmt1 = PrepareQuery($conn1, "SELECT $val, $val2 FROM [$tableName]");
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_GROUP));
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
Fetch();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
array(2) {
[0]=>
string(1) "1"
[1]=>
string(1) "2"
}
array(2) {
[0]=>
string(2) "A2"
[1]=>
string(2) "B2"
}
array(2) {
[1]=>
array(1) {
[0]=>
string(1) "A"
}
[2]=>
array(1) {
[0]=>
string(1) "A"
}
}
array(2) {
[1]=>
string(1) "A"
[2]=>
string(1) "A"
}
array(2) {
[1]=>
string(1) "1"
[2]=>
string(1) "2"
}
array(2) {
[1]=>
string(1) "A"
[2]=>
string(1) "A"
}
array(2) {
[1]=>
string(2) "A2"
[2]=>
string(2) "B2"
}
array(1) {
["A"]=>
array(2) {
[0]=>
string(2) "A2"
[1]=>
string(2) "B2"
}
}
Test "PDO Statement - Fetch All" completed successfully.

View file

@ -0,0 +1,340 @@
--TEST--
PDO Fetch Test with PDO::FETCH_FUNC
--DESCRIPTION--
Basic verification for "PDOStatement::fetchAll(PDO::FETCH_FUNC)”.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function FetchAll()
{
include 'MsSetup.inc';
$testName = "PDO Statement - Fetch All";
StartTest($testName);
$conn1 = Connect();
// Prepare test tables
$dataCols = "id, val, grp";
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, val VARCHAR(10), grp VARCHAR(10)", null);
InsertRowEx($conn1, $tableName, $dataCols, "1, 'A', 'Group1'", null);
InsertRowEx($conn1, $tableName, $dataCols, "2, 'B', 'Group1'", null);
InsertRowEx($conn1, $tableName, $dataCols, "3, 'C', 'Group2'", null);
InsertRowEx($conn1, $tableName, $dataCols, "4, 'D', 'Group2'", null);
$f = new Test1(0, 0);
// Query table and retrieve data
$stmt1 = PrepareQuery($conn1, "SELECT grp, id FROM [$tableName]");
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_FUNC|PDO::FETCH_GROUP, 'test'));
unset($stmt1);
$stmt1 = PrepareQuery($conn1, "SELECT id, val FROM [$tableName]");
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_FUNC, 'test'));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_FUNC, array('Test1','factory')));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_FUNC, array($f, 'factory')));
unset($stmt1);
$stmt1 = $conn1->prepare("SELECT id, val FROM [$tableName]",
array(PDO::ATTR_STATEMENT_CLASS=>array('DerivedStatement',
array('Overloaded', $conn1))));
var_dump(get_class($stmt1));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_FUNC, array($stmt1, 'retrieve')));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_FUNC, array($stmt1, 'reTrieve')));
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_FUNC, array($stmt1, 'RETRIEVE')));
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
class DerivedStatement extends PDOStatement
{
private function __construct($name, $conn)
{
$this->name = $name;
echo __METHOD__ . "($name)\n";
}
function reTrieve($id, $val) {
echo __METHOD__ . "($id,$val)\n";
return array($id=>$val);
}
}
class Test1
{
public function __construct($id, $val)
{
echo __METHOD__ . "($id,$val)\n";
$this->id = $id;
$this->val = $val;
}
static public function factory($id, $val)
{
echo __METHOD__ . "($id,$val)\n";
return new self($id, $val);
}
}
function test($id,$val='N/A')
{
echo __METHOD__ . "($id,$val)\n";
return array($id=>$val);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
FetchAll();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECTF--
Test1::__construct(0,0)
test(1,N/A)
test(2,N/A)
test(3,N/A)
test(4,N/A)
array(2) {
["Group1"]=>
array(2) {
[0]=>
array(1) {
[1]=>
string(3) "N/A"
}
[1]=>
array(1) {
[2]=>
string(3) "N/A"
}
}
["Group2"]=>
array(2) {
[0]=>
array(1) {
[3]=>
string(3) "N/A"
}
[1]=>
array(1) {
[4]=>
string(3) "N/A"
}
}
}
test(1,A)
test(2,B)
test(3,C)
test(4,D)
array(4) {
[0]=>
array(1) {
[1]=>
string(1) "A"
}
[1]=>
array(1) {
[2]=>
string(1) "B"
}
[2]=>
array(1) {
[3]=>
string(1) "C"
}
[3]=>
array(1) {
[4]=>
string(1) "D"
}
}
Test1::factory(1,A)
Test1::__construct(1,A)
Test1::factory(2,B)
Test1::__construct(2,B)
Test1::factory(3,C)
Test1::__construct(3,C)
Test1::factory(4,D)
Test1::__construct(4,D)
array(4) {
[0]=>
object(Test1)#%d (2) {
["id"]=>
string(1) "1"
["val"]=>
string(1) "A"
}
[1]=>
object(Test1)#%d (2) {
["id"]=>
string(1) "2"
["val"]=>
string(1) "B"
}
[2]=>
object(Test1)#%d (2) {
["id"]=>
string(1) "3"
["val"]=>
string(1) "C"
}
[3]=>
object(Test1)#%d (2) {
["id"]=>
string(1) "4"
["val"]=>
string(1) "D"
}
}
Test1::factory(1,A)
Test1::__construct(1,A)
Test1::factory(2,B)
Test1::__construct(2,B)
Test1::factory(3,C)
Test1::__construct(3,C)
Test1::factory(4,D)
Test1::__construct(4,D)
array(4) {
[0]=>
object(Test1)#%d (2) {
["id"]=>
string(1) "1"
["val"]=>
string(1) "A"
}
[1]=>
object(Test1)#%d (2) {
["id"]=>
string(1) "2"
["val"]=>
string(1) "B"
}
[2]=>
object(Test1)#%d (2) {
["id"]=>
string(1) "3"
["val"]=>
string(1) "C"
}
[3]=>
object(Test1)#%d (2) {
["id"]=>
string(1) "4"
["val"]=>
string(1) "D"
}
}
DerivedStatement::__construct(Overloaded)
string(16) "DerivedStatement"
DerivedStatement::reTrieve(1,A)
DerivedStatement::reTrieve(2,B)
DerivedStatement::reTrieve(3,C)
DerivedStatement::reTrieve(4,D)
array(4) {
[0]=>
array(1) {
[1]=>
string(1) "A"
}
[1]=>
array(1) {
[2]=>
string(1) "B"
}
[2]=>
array(1) {
[3]=>
string(1) "C"
}
[3]=>
array(1) {
[4]=>
string(1) "D"
}
}
DerivedStatement::reTrieve(1,A)
DerivedStatement::reTrieve(2,B)
DerivedStatement::reTrieve(3,C)
DerivedStatement::reTrieve(4,D)
array(4) {
[0]=>
array(1) {
[1]=>
string(1) "A"
}
[1]=>
array(1) {
[2]=>
string(1) "B"
}
[2]=>
array(1) {
[3]=>
string(1) "C"
}
[3]=>
array(1) {
[4]=>
string(1) "D"
}
}
DerivedStatement::reTrieve(1,A)
DerivedStatement::reTrieve(2,B)
DerivedStatement::reTrieve(3,C)
DerivedStatement::reTrieve(4,D)
array(4) {
[0]=>
array(1) {
[1]=>
string(1) "A"
}
[1]=>
array(1) {
[2]=>
string(1) "B"
}
[2]=>
array(1) {
[3]=>
string(1) "C"
}
[3]=>
array(1) {
[4]=>
string(1) "D"
}
}
Test "PDO Statement - Fetch All" completed successfully.

View file

@ -0,0 +1,130 @@
--TEST--
PDO Fetch Object Test
--DESCRIPTION--
Basic verification for "PDOStatement::fetchObject”.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
class TestClass
{
private $set_calls = 0;
protected static $static_set_calls = 0;
// NOTE: PDO does not care about protected
protected $grp;
// NOTE: PDO does not care about private and calls __construct() after __set()
private function __construct($param1, $param2)
{
printf("TestClass::__construct(%s, %s): %d / %d\n", $param1, $param2,
self::$static_set_calls, $this->set_calls);
}
// NOTE: PDO will call __set() prior to calling __construct()
public function __set($prop, $value)
{
$this->inc();
printf("TestClass::__set(%s, -%s-) %d\n",
$prop, var_export($value, true), $this->set_calls, self::$static_set_calls);
$this->{$prop} = $value;
}
// NOTE: PDO can call regular methods prior to calling __construct()
public function inc()
{
$this->set_calls++;
self::$static_set_calls++;
}
}
function Fetch()
{
include 'MsSetup.inc';
$testName = "PDO Statement - Fetch Object";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
// Prepare test table
$dataCols = "id, label";
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, label CHAR(1)", null);
InsertRowEx($conn1, $tableName, $dataCols, "1, 'a'", null);
InsertRowEx($conn1, $tableName, $dataCols, "2, 'b'", null);
InsertRowEx($conn1, $tableName, $dataCols, "3, 'c'", null);
InsertRowEx($conn1, $tableName, $dataCols, "4, 'd'", null);
InsertRowEx($conn1, $tableName, $dataCols, "5, 'e'", null);
InsertRowEx($conn1, $tableName, $dataCols, "6, 'f'", null);
// Query test table and retrieve data
$tsql = "SELECT TOP(3) * FROM [$tableName] ORDER BY id ASC";
$stmt1 = PrepareQuery($conn1, $tsql);
$stmt1->execute();
$rowno = 0;
$rows[] = array();
while (is_object($rows[] = $stmt1->fetchObject('TestClass', array($rowno++, $rowno))))
{
printf("PDOStatement::fetchObject() was called for row $rowno\n");
}
var_dump($rows[$rowno - 1]);
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
Fetch();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECTF--
TestClass::__set(id, -'1'-) 1
TestClass::__set(label, -'a'-) 2
TestClass::__construct(0, 1): 2 / 2
PDOStatement::fetchObject() was called for row 1
TestClass::__set(id, -'2'-) 1
TestClass::__set(label, -'b'-) 2
TestClass::__construct(1, 2): 4 / 2
PDOStatement::fetchObject() was called for row 2
TestClass::__set(id, -'3'-) 1
TestClass::__set(label, -'c'-) 2
TestClass::__construct(2, 3): 6 / 2
PDOStatement::fetchObject() was called for row 3
object(TestClass)#%d (4) {
["set_calls":"TestClass":private]=>
int(2)
["grp":protected]=>
NULL
["id"]=>
string(1) "3"
["label"]=>
string(1) "c"
}
Test "PDO Statement - Fetch Object" completed successfully.

View file

@ -0,0 +1,123 @@
--TEST--
PDO Fetch LOB Test
--DESCRIPTION--
Verification for LOB handling.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function LobTest()
{
include 'MsSetup.inc';
$testName = "PDO Statement - Fetch LOB";
StartTest($testName);
$conn1 = Connect();
// Execute test
$data = str_repeat('A', 255);
FetchLob(1, $conn1, $tableName, "VARCHAR(512)", 1, $data);
FetchLob(2, $conn1, $tableName, "NVARCHAR(512)", 2, $data);
unset($data);
$data = str_repeat('B', 4000);
FetchLob(3, $conn1, $tableName, "VARCHAR(8000)", 3, $data);
FetchLob(4, $conn1, $tableName, "NVARCHAR(4000)", 4, $data);
unset($data);
$data = str_repeat('C', 100000);
FetchLob(5, $conn1, $tableName, "TEXT", 5, $data);
FetchLob(6, $conn1, $tableName, "NTEXT", 6, $data);
unset($data);
// Cleanup
DropTable($conn1, $tableName);
$conn1 = null;
EndTest($testName);
}
function FetchLob($offset, $conn, $table, $sqlType, $data1, $data2)
{
$id = NULL;
$label = NULL;
CreateTableEx($conn, $table, "id int NOT NULL PRIMARY KEY, label $sqlType", null);
InsertRowEx($conn, $table, "id, label", "$data1, '$data2'", null);
// Check data fetched with PDO::FETCH_BOUND
$stmt = ExecuteQuery($conn, "SELECT * FROM [$table]");
if (!$stmt->bindColumn(1, $id, PDO::PARAM_INT))
{
LogInfo($offset, "Cannot bind integer column");
}
if (!$stmt->bindColumn(2, $label, PDO::PARAM_LOB))
{
LogInfo($offset, "Cannot bind LOB column");
}
if (!$stmt->fetch(PDO::FETCH_BOUND))
{
LogInfo($offset, "Cannot fetch bound data");
}
if ($id != $data1)
{
LogInfo($offset, "ID data corruption: [$id] instead of [$data1]");
}
if ($label != $data2)
{
LogInfo($offset, "Label data corruption: [$label] instead of [$data2]");
}
unset($stmt);
unset($label);
// Check data fetched with PDO::FETCH_ASSOC
$stmt = ExecuteQuery($conn, "SELECT * FROM [$table]");
$refData = $stmt->fetch(PDO::FETCH_ASSOC);
if ($refData['id'] != $data1)
{
$id = $refData['id'];
LogInfo($offset, "ID data corruption: [$id] instead of [$data1]");
}
if ($refData['label'] != $data2)
{
$label = $refData['label'];
LogInfo($offset, "Label data corruption: [$label] instead of [$data2]");
}
unset($stmt);
unset($refData);
}
function LogInfo($offset, $msg)
{
printf("[%03d] %s\n", $offset, $msg);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
LobTest();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
Test "PDO Statement - Fetch LOB" completed successfully.

View file

@ -0,0 +1,163 @@
--TEST--
PDO Bind Column Test
--DESCRIPTION--
Verification for "PDOStatement::bindColumn".
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function Fetch()
{
include 'MsSetup.inc';
$testName = "PDO Statement - Bind Column";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
$dataCols = "idx, txt";
CreateTableEx($conn1, $tableName, "idx int NOT NULL PRIMARY KEY, txt VARCHAR(20)", null);
InsertRowEx($conn1, $tableName, $dataCols, "0, 'String0'", null);
InsertRowEx($conn1, $tableName, $dataCols, "1, 'String1'", null);
InsertRowEx($conn1, $tableName, $dataCols, "2, 'String2'", null);
InsertRowEx($conn1, $tableName, $dataCols, "3, 'String3'", null);
// Testing with prepared query
LogInfo(1, "Testing fetchColumn() ...");
$stmt1 = ExecuteQuery($conn1, "SELECT COUNT(idx) FROM [$tableName]");
var_dump($stmt1->fetchColumn());
unset($stmt1);
LogInfo(2, "Testing fetchAll() ...");
$stmt1 = PrepareQuery($conn1, "SELECT idx, txt FROM [$tableName] ORDER BY idx");
$stmt1->execute();
$data = $stmt1->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_UNIQUE);
var_dump($data);
LogInfo(3, "Testing bindColumn() ...");
$stmt1->bindColumn('idx', $idx);
$stmt1->bindColumn('txt', $txt);
$stmt1->execute();
while ($stmt1->fetch(PDO::FETCH_BOUND))
{
var_dump(array($idx=>$txt));
}
LogInfo(4, "Testing bindColumn() with data check ...");
$id = null;
$val = null;
$data = array();
$index = 0;
if (!$stmt1->bindColumn(1, $id, PDO::PARAM_INT))
{
LogError(5, "Cannot bind integer column", $stmt1);
}
if (!$stmt1->bindColumn(2, $val, PDO::PARAM_STR))
{
LogError(5, "Cannot bind string column", $stmt1);
}
$stmt1->execute();
while ($stmt1->fetch(PDO::FETCH_BOUND))
{
$data[] = array('id' => $id, 'val' => $val);
printf("id = %s (%s) / val = %s (%s)\n",
var_export($id, true), gettype($id),
var_export($val, true), gettype($val));
}
unset($stmt1);
$stmt1 = ExecuteQuery($conn1, "SELECT idx, txt FROM [$tableName] ORDER BY idx");
while ($row = $stmt1->fetch(PDO::FETCH_ASSOC))
{
if ($row['idx'] != $data[$index]['id'])
{
LogInfo(6, "Data corruption for integer column in row $index");
}
if ($row['txt'] != $data[$index]['val'])
{
LogInfo(6, "Data corruption for string column in row $index");
}
$index++;
}
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
function LogInfo($offset, $msg)
{
printf("[%03d] %s\n", $offset, $msg);
}
function LogError($offset, $msg, &$obj)
{
printf("[%03d] %s: %s\n", $offset, $msg, $obj->errorCode);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
Fetch();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
[001] Testing fetchColumn() ...
string(1) "4"
[002] Testing fetchAll() ...
array(4) {
[0]=>
string(7) "String0"
[1]=>
string(7) "String1"
[2]=>
string(7) "String2"
[3]=>
string(7) "String3"
}
[003] Testing bindColumn() ...
array(1) {
[0]=>
string(7) "String0"
}
array(1) {
[1]=>
string(7) "String1"
}
array(1) {
[2]=>
string(7) "String2"
}
array(1) {
[3]=>
string(7) "String3"
}
[004] Testing bindColumn() with data check ...
id = 0 (integer) / val = 'String0' (string)
id = 1 (integer) / val = 'String1' (string)
id = 2 (integer) / val = 'String2' (string)
id = 3 (integer) / val = 'String3' (string)
Test "PDO Statement - Bind Column" completed successfully.

View file

@ -0,0 +1,133 @@
--TEST--
PDO Bind Column Test
--DESCRIPTION--
Verification for "PDOStatement::bindColumn()".
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function Bind()
{
include 'MsSetup.inc';
$testName = "PDO Statement - Bind Column";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
$dataCols = "id, label";
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, label CHAR(1)", null);
InsertRowEx($conn1, $tableName, $dataCols, "1, 'a'", null);
InsertRowEx($conn1, $tableName, $dataCols, "2, 'b'", null);
InsertRowEx($conn1, $tableName, $dataCols, "3, 'c'", null);
InsertRowEx($conn1, $tableName, $dataCols, "4, 'd'", null);
InsertRowEx($conn1, $tableName, $dataCols, "5, 'e'", null);
InsertRowEx($conn1, $tableName, $dataCols, "6, 'f'", null);
$rowCount = 3;
$midRow = 4;
// Check bind column
$tsql1 = "SELECT TOP($rowCount) id, label FROM [$tableName] ORDER BY id ASC";
$data = BindColumn($conn1, $tsql1);
CheckBind($conn1, $tsql1, $data);
$tsql2 = "SELECT TOP($rowCount) id, label FROM (SELECT *, ROW_NUMBER() OVER(ORDER BY id ASC) as row FROM [$tableName]) [$tableName] WHERE row >= $midRow";
$data = BindColumn($conn1, $tsql2);
CheckBind($conn1, $tsql2, $data);
// Cleanup
DropTable($conn1, $tableName);
$conn1 = null;
EndTest($testName);
}
function BindColumn($conn, $tsql)
{
$id = null;
$label = null;
$data = array();
$stmt = PrepareQuery($conn, $tsql);
$stmt->execute();
if (!$stmt->bindColumn(1, $id, PDO::PARAM_INT))
{
LogInfo(1, "Cannot bind integer column");
}
if (!$stmt->bindColumn(2, $label, PDO::PARAM_STR))
{
LogInfo(1, "Cannot bind string column");
}
while ($stmt->fetch(PDO::FETCH_BOUND))
{
printf("id = %s (%s) / label = %s (%s)\n",
var_export($id, true), gettype($id),
var_export($label, true), gettype($label));
$data[] = array('id' => $id, 'label' => $label);
}
unset($stmt);
return ($data);
}
function CheckBind($conn, $tsql, $data)
{
$index = 0;
$stmt = ExecuteQuery($conn, $tsql);
while ($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
if ($row['id'] != $data[$index]['id'])
{
LogInfo(2, "Fetch bound and fetch assoc differ - column 'id', row $index");
}
if ($row['label'] != $data[$index]['label'])
{
LogInfo(2, "Fetch bound and fetch assoc differ - column 'label', row $index");
}
$index++;
}
unset($stmt);
}
function LogInfo($offset, $msg)
{
printf("[%03d] %s\n", $offset, $msg);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
Bind();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
id = 1 (integer) / label = 'a' (string)
id = 2 (integer) / label = 'b' (string)
id = 3 (integer) / label = 'c' (string)
id = 4 (integer) / label = 'd' (string)
id = 5 (integer) / label = 'e' (string)
id = 6 (integer) / label = 'f' (string)
Test "PDO Statement - Bind Column" completed successfully.

View file

@ -0,0 +1,85 @@
--TEST--
PDO Bind Param Test
--DESCRIPTION--
Verification for "PDOStatement::bindParam()".
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function Bind()
{
include 'MsSetup.inc';
$testName = "PDO Statement - Bind Param";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
$dataCols = "id, name";
CreateTableEx($conn1, $tableName, "id int, name VARCHAR(20)", null);
$conn1->exec( "CREATE CLUSTERED INDEX [idx_test_int] ON " . $tableName . "(id)" );
// Insert test data
$stmt1 = PrepareQuery($conn1, "INSERT INTO [$tableName] ($dataCols) VALUES(0, :name)");
$name = NULL;
$before_bind = $name;
$stmt1->bindParam(':name', $name);
// Check that bindParam does not modify parameter
if ($name !== $before_bind)
{
echo "bind: fail\n";
}
else
{
echo "bind: success\n";
}
var_dump($stmt1->execute());
unset($stmt1);
// Retrieve test data
$stmt1 = ExecuteQuery($conn1, "SELECT name FROM [$tableName] WHERE id = 0");
var_dump($stmt1->fetchColumn());
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
Bind();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
bind: success
bool(true)
NULL
Test "PDO Statement - Bind Param" completed successfully.

View file

@ -0,0 +1,142 @@
--TEST--
PDO Bind Param Test
--DESCRIPTION--
Verification for "PDOStatement::bindParam()".
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function Bind()
{
include 'MsSetup.inc';
$testName = "PDO Statement - Bind Param";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
$dataCols = "id, label";
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, label CHAR(1)", null);
InsertRowEx($conn1, $tableName, $dataCols, "1, 'a'", null);
InsertRowEx($conn1, $tableName, $dataCols, "2, 'b'", null);
InsertRowEx($conn1, $tableName, $dataCols, "3, 'c'", null);
InsertRowEx($conn1, $tableName, $dataCols, "4, 'd'", null);
InsertRowEx($conn1, $tableName, $dataCols, "5, 'e'", null);
InsertRowEx($conn1, $tableName, $dataCols, "6, 'f'", null);
$id = null;
$label = null;
// Bind param @ SELECT
$tsql1 = "SELECT TOP(2) id, label FROM [$tableName] WHERE id > ? ORDER BY id ASC";
$value1 = 0;
$stmt1 = PrepareQuery($conn1, $tsql1);
BindParam(1, $stmt1, $value1);
ExecStmt(1, $stmt1);
BindColumn(1, $stmt1, $id, $label);
FetchBound($stmt1, $id, $label);
ExecStmt(1, $stmt1);
FetchBound($stmt1, $id, $label);
unset($stmt1);
// Bind param @ INSERT
$tsql2 = "INSERT INTO [$tableName](id, label) VALUES (100, ?)";
$value2 = null;
$stmt1 = PrepareQuery($conn1, $tsql2);
BindParam(2, $stmt1, $value2);
ExecStmt(2, $stmt1);
unset($stmt1);
// Check binding
$tsql3 = "SELECT id, NULL AS _label FROM [$tableName] WHERE label IS NULL";
$stmt1 = ExecuteQuery($conn1, $tsql3);
BindColumn(3, $stmt1, $id, $label);
FetchBound($stmt1, $id, $label);
unset($stmt1);
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
function BindParam($offset, $stmt, &$value)
{
if (!$stmt->bindParam(1, $value))
{
LogInfo($offset,"Cannot bind parameter");
}
}
function BindColumn($offset, $stmt, &$param1, &$param2)
{
if (!$stmt->bindColumn(1, $param1, PDO::PARAM_INT))
{
LogInfo($offset, "Cannot bind integer column");
}
if (!$stmt->bindColumn(2, $param2, PDO::PARAM_STR))
{
LogInfo($offset, "Cannot bind string column");
}
}
function ExecStmt($offset, $stmt)
{
if (!$stmt->execute())
{
LogInfo($offset, "Cannot execute statement");
}
}
function FetchBound($stmt, &$param1, &$param2)
{
while ($stmt->fetch(PDO::FETCH_BOUND))
{
printf("id = %s (%s) / label = %s (%s)\n",
var_export($param1, true), gettype($param1),
var_export($param2, true), gettype($param2));
}
}
function LogInfo($offset, $msg)
{
printf("[%03d] %s\n", $offset, $msg);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
Bind();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
id = 1 (integer) / label = 'a' (string)
id = 2 (integer) / label = 'b' (string)
id = 1 (integer) / label = 'a' (string)
id = 2 (integer) / label = 'b' (string)
id = 100 (integer) / label = NULL (NULL)
Test "PDO Statement - Bind Param" completed successfully.

View file

@ -0,0 +1,84 @@
--TEST--
PDO Bind Value Test
--DESCRIPTION--
Verification for "PDOStatement::bindValue()".
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function Bind()
{
include 'MsSetup.inc';
$testName = "PDO Statement - Bind Value";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, val1 VARCHAR(10), val2 VARCHAR(10), val3 VARCHAR(10)", null);
$data = array("one", "two", "three");
// Insert test data
$stmt1 = PrepareQuery($conn1, "INSERT INTO [$tableName] VALUES(1, ?, ?, ?)");
foreach ($data as $i => $v)
{
$stmt1->bindValue($i+1, $v);
}
$stmt1->execute();
unset($stmt1);
// Retrieve test data
$stmt1 = PrepareQuery($conn1, "SELECT * FROM [$tableName]");
$stmt1->execute();
var_dump($stmt1->fetchAll(PDO::FETCH_ASSOC));
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
Bind();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
array(1) {
[0]=>
array(4) {
["id"]=>
string(1) "1"
["val1"]=>
string(3) "one"
["val2"]=>
string(3) "two"
["val3"]=>
string(5) "three"
}
}
Test "PDO Statement - Bind Value" completed successfully.

View file

@ -0,0 +1,203 @@
--TEST--
PDO Bind Value Test
--DESCRIPTION--
Verification for "PDOStatement::bindValue()".
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function Bind()
{
include 'MsSetup.inc';
$testName = "PDO Statement - Bind Value";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
$dataCols = "id, label";
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, label CHAR(1)", null);
InsertRowEx($conn1, $tableName, $dataCols, "1, 'a'", null);
InsertRowEx($conn1, $tableName, $dataCols, "2, 'b'", null);
InsertRowEx($conn1, $tableName, $dataCols, "3, 'c'", null);
InsertRowEx($conn1, $tableName, $dataCols, "4, 'd'", null);
InsertRowEx($conn1, $tableName, $dataCols, "5, 'e'", null);
InsertRowEx($conn1, $tableName, $dataCols, "6, 'f'", null);
$id = null;
$label = null;
// Check different value bind modes
$tsql1 = "SELECT TOP(2) id, label FROM [$tableName] WHERE id > ? ORDER BY id ASC";
$stmt1 = PrepareQuery($conn1, $tsql1);
printf("Binding value and not variable...\n");
BindValue(1, $stmt1, 0);
ExecStmt(1, $stmt1);
BindColumn(1, $stmt1, $id, $label);
FetchBound($stmt1, $id, $label);
printf("Binding variable...\n");
$var1 = 0;
BindVar(2, $stmt1, $var1);
ExecStmt(2, $stmt1);
BindColumn(2, $stmt1, $id, $label);
FetchBound($stmt1, $id, $label);
printf("Binding variable which references another variable...\n");
$var2 = 0;
$var_ref = &$var2;
BindVar(3, $stmt1, $var_ref);
ExecStmt(3, $stmt1);
BindColumn(3, $stmt1, $id, $label);
FetchBound($stmt1, $id, $label);
unset($stmt1);
$tsql2 = "SELECT TOP(2) id, label FROM [$tableName] WHERE id > ? AND id <= ? ORDER BY id ASC";
$stmt1 = PrepareQuery($conn1, $tsql2);
printf("Binding a variable and a value...\n");
$var3 = 0;
BindMixed(4, $stmt1, $var3, 2);
ExecStmt(4, $stmt1);
BindColumn(4, $stmt1, $id, $label);
FetchBound($stmt1, $id, $label);
printf("Binding a variable to two placeholders and changing the variable value in between the binds...\n");
$var4 = 0;
$var5 = 2;
BindPlaceholder(5, $stmt1, $var4, $var5);
ExecStmt(5, $stmt1);
BindColumn(5, $stmt1, $id, $label);
FetchBound($stmt1, $id, $label);
unset($stmt1);
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
function BindValue($offset, $stmt, $value)
{
if (!$stmt->bindValue(1, $value))
{
LogInfo($offset, "Cannot bind value");
}
}
function BindVar($offset, $stmt, &$var)
{
if (!$stmt->bindValue(1, $var))
{
LogInfo($offset, "Cannot bind variable");
}
}
function BindMixed($offset, $stmt, &$var, $value)
{
if (!$stmt->bindValue(1, $var))
{
LogInfo($offset, "Cannot bind variable");
}
if (!$stmt->bindValue(2, $value))
{
LogInfo($offset, "Cannot bind value");
}
}
function BindPlaceholder($offset, $stmt, &$var1, &$var2)
{
if (!$stmt->bindValue(1, $var1))
{
LogInfo($offset, "Cannot bind variable 1");
}
if (!$stmt->bindValue(2, $var2))
{
LogInfo($offset, "Cannot bind variable 2");
}
}
function BindColumn($offset, $stmt, &$param1, &$param2)
{
if (!$stmt->bindColumn(1, $param1, PDO::PARAM_INT))
{
LogInfo($offset, "Cannot bind integer column");
}
if (!$stmt->bindColumn(2, $param2, PDO::PARAM_STR))
{
LogInfo($offset, "Cannot bind string column");
}
}
function ExecStmt($offset, $stmt)
{
if (!$stmt->execute())
{
LogInfo($offset, "Cannot execute statement");
}
}
function FetchBound($stmt, &$param1, &$param2)
{
while ($stmt->fetch(PDO::FETCH_BOUND))
{
printf("id = %s (%s) / label = %s (%s)\n",
var_export($param1, true), gettype($param1),
var_export($param2, true), gettype($param2));
}
}
function LogInfo($offset, $msg)
{
printf("[%03d] %s\n", $offset, $msg);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
Bind();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
Binding value and not variable...
id = 1 (integer) / label = 'a' (string)
id = 2 (integer) / label = 'b' (string)
Binding variable...
id = 1 (integer) / label = 'a' (string)
id = 2 (integer) / label = 'b' (string)
Binding variable which references another variable...
id = 1 (integer) / label = 'a' (string)
id = 2 (integer) / label = 'b' (string)
Binding a variable and a value...
id = 1 (integer) / label = 'a' (string)
id = 2 (integer) / label = 'b' (string)
Binding a variable to two placeholders and changing the variable value in between the binds...
id = 1 (integer) / label = 'a' (string)
id = 2 (integer) / label = 'b' (string)
Test "PDO Statement - Bind Value" completed successfully.

View file

@ -0,0 +1,141 @@
--TEST--
PDO Bind Param Truncation Test
--DESCRIPTION--
Verification for "PDOStatement::bindParam()".
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function Bind()
{
include 'MsSetup.inc';
$testName = "PDO Statement - Bind Param Truncation";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
CreateTableEx($conn1, $tableName, "id INT IDENTITY NOT NULL, class INT, value CHAR(32)", null);
$conn1->exec( "CREATE CLUSTERED INDEX [idx_test_int] ON " . $tableName . "(id)" );
$tsql1 = "SET IDENTITY_INSERT [$tableName] ON";
$tsql2 = "INSERT INTO [$tableName] (id, class, value) VALUES(:id, :class, :value)";
$tsql3 = "SET IDENTITY_INSERT [$tableName] OFF";
$tsql4 = "SELECT id, value FROM [$tableName]";
$id = 0;
$class = 0;
$value = '';
// Prepare insert query
$stmt1 = PrepareQuery($conn1, "$tsql1; $tsql2; $tsql3;");
BindParam(1, $stmt1, ':id', $id);
BindParam(2, $stmt1, ':class', $class);
BindParam(3, $stmt1, ':value', $value);
// Insert test rows
$id = 1;
$class = 4;
$value = '2011';
ExecStmt(1, $stmt1);
$id = 2;
$class = 5;
$value = 'Sat, 20 Mar 10 21:29:13 -0600';
ExecStmt(2, $stmt1);
$id = 3;
$class = 6;
$value = 'Fri, 07 May 10 11:35:32 -0600';
ExecStmt(3, $stmt1);
unset($stmt1);
$stmt1 = null;
// Check data
$id = 0;
$value = '';
$stmt2 = ExecuteQuery($conn1, $tsql4);
BindColumn(1, $stmt2, $id, $value);
while ($stmt2->fetch(PDO::FETCH_BOUND))
{
printf("id = %s (%s) / value = %s (%s)\n",
var_export($id, true), gettype($id),
var_export($value, true), gettype($value));
}
unset($stmt2);
$stmt2 = null;
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
function BindParam($offset, $stmt, $param, &$value)
{
if (!$stmt->bindParam($param, $value))
{
LogInfo($offset,"Cannot bind parameter $param");
}
}
function BindColumn($offset, $stmt, &$param1, &$param2)
{
if (!$stmt->bindColumn(1, $param1, PDO::PARAM_INT))
{
LogInfo($offset, "Cannot bind integer column");
}
if (!$stmt->bindColumn(2, $param2, PDO::PARAM_STR))
{
LogInfo($offset, "Cannot bind string column");
}
}
function ExecStmt($offset, $stmt)
{
if (!$stmt->execute())
{
LogInfo($offset, "Cannot execute statement");
var_dump($stmt->errorInfo());
}
}
function LogInfo($offset, $msg)
{
printf("[%03d] %s\n", $offset, $msg);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
Bind();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
id = 1 (integer) / value = '2011 ' (string)
id = 2 (integer) / value = 'Sat, 20 Mar 10 21:29:13 -0600 ' (string)
id = 3 (integer) / value = 'Fri, 07 May 10 11:35:32 -0600 ' (string)
Test "PDO Statement - Bind Param Truncation" completed successfully.

View file

@ -0,0 +1,100 @@
--TEST--
PDO Transactions Test
--DESCRIPTION--
Basic verification for PDO Transactions.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function Transactions()
{
include 'MsSetup.inc';
$testName = "PDO - Transactions";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
$dataCols = "id, val";
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, val VARCHAR(10)", null);
InsertRowEx($conn1, $tableName, $dataCols, "1, 'A'", null);
InsertRowEx($conn1, $tableName, $dataCols, "2, 'B'", null);
InsertRowEx($conn1, $tableName, $dataCols, "3, 'C'", null);
// After INSERT ...
$count = countRows($conn1, $tableName);
echo "Rows after INSERT: $count.\n";
// Prepare DELETE query
$stmt1 = PrepareQuery($conn1, "DELETE FROM [$tableName]");
// Transaction -> Rollback
$conn1->beginTransaction();
$stmt1->execute();
$count = countRows($conn1, $tableName);
echo "Rows after DELETE: $count.\n";
$conn1->rollBack();
$count = countRows($conn1, $tableName);
echo "Rows after ROLLBACK: $count.\n";
// Transaction -> Commit
$conn1->beginTransaction();
$stmt1->execute();
$count = countRows($conn1, $tableName);
echo "Rows after DELETE: $count.\n";
$conn1->commit();
$count = countRows($conn1, $tableName);
echo "Rows after COMMIT: $count.\n";
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
function countRows($conn, $table)
{
$stmt = ExecuteQuery($conn, "SELECT COUNT(*) FROM [$table]");
$res = $stmt->fetchColumn();
unset($stmt);
return ($res);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
Transactions();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECTF--
Rows after INSERT: 3.
Rows after DELETE: 0.
Rows after ROLLBACK: 3.
Rows after DELETE: 0.
Rows after COMMIT: 0.
Test "PDO - Transactions" completed successfully.

View file

@ -0,0 +1,95 @@
--TEST--
PDO Transactions Test
--DESCRIPTION--
Basic verification for PDO Transactions.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function Transactions()
{
include 'MsSetup.inc';
$testName = "PDO - Transactions";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
$dataCols = "id, val";
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, val VARCHAR(10)", null);
InsertRowEx($conn1, $tableName, $dataCols, "1, 'A'", null);
InsertRowEx($conn1, $tableName, $dataCols, "2, 'B'", null);
InsertRowEx($conn1, $tableName, $dataCols, "3, 'C'", null);
// After initial INSERT ...
$count = countRows($conn1, $tableName);
echo "Rows after INSERT: $count.\n";
// Transaction -> Automatic rollback on disconnect
$conn1->beginTransaction();
InsertRowEx($conn1, $tableName, $dataCols, "4, 'X'", null);
InsertRowEx($conn1, $tableName, $dataCols, "5, 'Y'", null);
$conn1 = null; // disconnect without commit
$conn1 = Connect();
$count = countRows($conn1, $tableName);
echo "Rows after ROLLBACK: $count.\n";
// Transaction -> Commit
$conn1->beginTransaction();
InsertRowEx($conn1, $tableName, $dataCols, "4, 'D'", null);
InsertRowEx($conn1, $tableName, $dataCols, "5, 'E'", null);
InsertRowEx($conn1, $tableName, $dataCols, "6, 'F'", null);
$conn1->commit();
$count = countRows($conn1, $tableName);
echo "Rows after COMMIT: $count.\n";
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
function countRows($conn, $table)
{
$stmt = ExecuteQuery($conn, "SELECT COUNT(*) FROM [$table]");
$res = $stmt->fetchColumn();
unset($stmt);
return ($res);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
Transactions();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECTF--
Rows after INSERT: 3.
Rows after ROLLBACK: 3.
Rows after COMMIT: 6.
Test "PDO - Transactions" completed successfully.

View file

@ -0,0 +1,82 @@
--TEST--
Complex Insert Query Test
--DESCRIPTION--
Test the driver behavior with a complex insert query.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function ComplexInsert($count)
{
include 'MsSetup.inc';
$testName = "PDO - Complex Insert Query";
StartTest($testName);
Setup();
$conn1 = Connect();
DropTable($conn1, $tableName);
// $data = "a1='1234567890',a2='0987654321',a3='1234567890',a4='0987654321',a5='1234567890',a6='0987654321'";
$data = "a1='1', a2='2', a3='3', a4='4', a5='5', a6='6'";
$querySelect = "SELECT COUNT(*) FROM [$tableName]";
$queryInsert =
" SELECT $data INTO [$tableName]
DECLARE @i int
SET @i=1
WHILE (@i < $count)
BEGIN
INSERT [$tableName]
SELECT $data
SET @i = @i + 1
END
";
$stmt1 = ExecuteQuery($conn1, $queryInsert);
$stmt1->closeCursor();
$stmt1 = null;
$stmt2 = ExecuteQuery($conn1, $querySelect);
$row = $stmt2->fetch(PDO::FETCH_NUM);
printf("$count rows attempted; actual rows created = ".$row[0]."\n");
$stmt2 = null;
$conn1 = null;
EndTest($testName);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
ComplexInsert(1000);
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
1000 rows attempted; actual rows created = 1000
Test "PDO - Complex Insert Query" completed successfully.

View file

@ -0,0 +1,68 @@
--TEST--
PDO Get Parent Class Test
--DESCRIPTION--
Verification for "get_parent_class()" functionality.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function ExecTest()
{
include 'MsSetup.inc';
$testName = "PDO - Get Parent";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
CreateTableEx($conn1, $tableName, "id int", null);
$conn1->exec( "CREATE CLUSTERED INDEX [idx_test_int] ON " . $tableName . "(id)" );
InsertRowEx($conn1, $tableName, "id", "23", null);
// Retrieve data
$stmt1 = PrepareQuery($conn1, "SELECT id FROM [$tableName]");
$stmt1->execute();
$result = $stmt1->fetch(PDO::FETCH_LAZY);
// Retrieve class and parent
echo get_class($result), "\n";
var_dump(get_parent_class($result));
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
ExecTest();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
PDORow
bool(false)
Test "PDO - Get Parent" completed successfully.

View file

@ -0,0 +1,118 @@
--TEST--
PDO Statement Iterator Test
--DESCRIPTION--
Verification of PDOStatement with an iterator.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function ExecStmt()
{
include 'MsSetup.inc';
$testName = "PDO Statement - Iterator";
StartTest($testName);
$conn1 = Connect();
// Prepare test table
$dataCols = "id, val, grp";
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, val VARCHAR(10), grp VARCHAR(10)", null);
InsertRowEx($conn1, $tableName, $dataCols, "1, 'A', 'Group1'", null);
InsertRowEx($conn1, $tableName, $dataCols, "2, 'B', 'Group2'", null);
$tsql = "SELECT val, grp FROM [$tableName]";
// Testing with direct query
/*$stmt1 = $conn1->query($tsql, PDO::FETCH_CLASS, 'Test', array('WOW'));
$iter = new IteratorIterator($stmt1);
foreach ($iter as $data)
{
var_dump($data);
}
$iter->next(); // allowed
var_dump($iter->current()); // should return NULL
var_dump($iter->valid());*/ // should must return
unset($stmt1);
// Testing with prepared query
$stmt1 = $conn1->prepare($tsql, array(PDO::ATTR_STATEMENT_CLASS=>array('PDOStatementAggregate')));
foreach ($stmt1 as $data)
{
var_dump($data);
}
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
class Test
{
function __construct($name = 'N/A')
{
echo __METHOD__ . "($name)\n";
}
}
class PDOStatementAggregate extends PDOStatement implements IteratorAggregate
{
private function __construct()
{
echo __METHOD__ . "\n";
$this->setFetchMode(PDO::FETCH_NUM);
}
function getIterator()
{
echo __METHOD__ . "\n";
$this->execute();
return (new IteratorIterator($this, 'PDOStatement'));
}
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
ExecStmt();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECTF--
PDOStatementAggregate::__construct
PDOStatementAggregate::getIterator
array(2) {
[0]=>
string(1) "A"
[1]=>
string(6) "Group1"
}
array(2) {
[0]=>
string(1) "B"
[1]=>
string(6) "Group2"
}
Test "PDO Statement - Iterator" completed successfully.

View file

@ -0,0 +1,116 @@
--TEST--
PDO Recursive Iterator Test
--DESCRIPTION--
Verification of PDOStatement with a recursive iterator.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function ExecStmt()
{
include 'MsSetup.inc';
$testName = "PDO Statement - Recursive Iterator";
StartTest($testName);
$conn1 = Connect();
// Prepare test tables
$dataCols = "id, val, val2";
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, val VARCHAR(10), val2 VARCHAR(16)", null);
$data = array( array('10', 'Abc', 'zxy'),
array('20', 'Def', 'wvu'),
array('30', 'Ghi', 'tsr'));
// Insert using question mark placeholders
$stmt1 = PrepareQuery($conn1, "INSERT INTO [$tableName] VALUES(?, ?, ?)");
foreach ($data as $row)
{
$stmt1->execute($row);
}
unset($stmt1);
echo "===QUERY===\n";
$stmt1 = ExecuteQuery($conn1, "SELECT * FROM [$tableName]");
foreach(new RecursiveTreeIterator(new RecursiveArrayIterator($stmt1->fetchAll(PDO::FETCH_ASSOC)),
RecursiveTreeIterator::BYPASS_KEY) as $c=>$v)
{
echo "$v [$c]\n";
}
echo "===DONE===\n";
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
class Test
{
function __construct($name = 'N/A')
{
echo __METHOD__ . "($name)\n";
}
}
class PDOStatementAggregate extends PDOStatement implements IteratorAggregate
{
private function __construct()
{
echo __METHOD__ . "\n";
$this->setFetchMode(PDO::FETCH_NUM);
}
function getIterator()
{
echo __METHOD__ . "\n";
$this->execute();
return (new IteratorIterator($this, 'PDOStatement'));
}
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
ExecStmt();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
===QUERY===
|-Array [0]
| |-10 [id]
| |-Abc [val]
| \-zxy [val2]
|-Array [1]
| |-20 [id]
| |-Def [val]
| \-wvu [val2]
\-Array [2]
|-30 [id]
|-Ghi [val]
\-tsr [val2]
===DONE===
Test "PDO Statement - Recursive Iterator" completed successfully.

View file

@ -0,0 +1,133 @@
--TEST--
Extending PDO Test #1
--DESCRIPTION--
Verification of capabilities for extending PDO.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function Extend()
{
include 'MsSetup.inc';
$testName = "PDO - Extension";
StartTest($testName);
$conn1 = PDOConnect('ExPDO', $server, $uid, $pwd, true);
$conn1->test();
var_dump($conn1);
// Prepare test table
DropTable($conn1, $tableName);
$conn1->query("CREATE TABLE [$tableName] (id int NOT NULL PRIMARY KEY, val VARCHAR(10))");
$conn1->query("INSERT INTO [$tableName] VALUES(0, 'A')");
$conn1->query("INSERT INTO [$tableName] VALUES(1, 'B')");
// Retrieve test data via a direct query
$stmt1 = ExecuteQuery($conn1, "SELECT val, id FROM [$tableName]");
$result = $stmt1->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_UNIQUE);
var_dump($result);
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
class ExPDO extends PDO
{
public $test1 = 1;
function __destruct()
{
echo __METHOD__ . "()\n";
}
function test()
{
$this->test2 = 2;
var_dump($this->test1);
var_dump($this->test2);
$this->test2 = 22;
}
function query($sql)
{
echo __METHOD__ . "()\n";
$stmt = parent::prepare($sql, array(PDO::ATTR_STATEMENT_CLASS=>array('ExPDOStatement')));
$stmt->execute();
return ($stmt);
}
}
class ExPDOStatement extends PDOStatement
{
protected function __construct()
{
echo __METHOD__ . "()\n";
}
function __destruct()
{
echo __METHOD__ . "()\n";
}
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
Extend();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECTF--
int(1)
int(2)
object(ExPDO)#%d (2) {
["test1"]=>
int(1)
["test2"]=>
int(22)
}
ExPDO::query()
ExPDOStatement::__construct()
ExPDOStatement::__destruct()
ExPDO::query()
ExPDOStatement::__construct()
ExPDOStatement::__destruct()
ExPDO::query()
ExPDOStatement::__construct()
ExPDOStatement::__destruct()
ExPDO::query()
ExPDOStatement::__construct()
array(2) {
["A"]=>
string(1) "0"
["B"]=>
string(1) "1"
}
ExPDOStatement::__destruct()
ExPDO::__destruct()
Test "PDO - Extension" completed successfully.

View file

@ -0,0 +1,131 @@
--TEST--
Extending PDO Test #1
--DESCRIPTION--
Verification of capabilities for extending PDO.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function Extend()
{
include 'MsSetup.inc';
$testName = "PDO - Extension";
StartTest($testName);
// simply use $databaseName from MsSetup.inc to facilitate testing in Azure,
// which does not support switching databases
$conn2 = new ExPDO("sqlsrv:Server=$server;Database=$databaseName", $uid, $pwd);
DropTable($conn2, "tmp_table");
$conn2->exec("CREATE TABLE tmp_table (id INT)");
$conn2->exec("INSERT INTO tmp_table (id) VALUES (1), (2)");
$stmt1 = $conn2->query("SELECT * FROM tmp_table ORDER BY id ASC");
var_dump($stmt1->fetchAll(PDO::FETCH_ASSOC));
var_dump($stmt1->fetch());
$conn2->intercept_call();
// Cleanup
DropTable($conn2, "tmp_table");
$stmt1 = null;
$conn2 = null;
EndTest($testName);
}
class ExPDO extends PDO
{
public function __construct()
{
$this->protocol();
$args = func_get_args();
return (call_user_func_array(array($this, 'parent::__construct'), $args));
}
public function exec($args1)
{
$this->protocol();
$args = func_get_args();
return (call_user_func_array(array($this, 'parent::exec'), $args));
}
public function query()
{
$this->protocol();
$args = func_get_args();
return (call_user_func_array(array($this, 'parent::query'), $args));
}
public function __call($method, $args)
{
print "__call(".var_export($method, true).", ".var_export($args, true).")\n";
}
private function protocol()
{
$stack = debug_backtrace();
if (!isset($stack[1]))
{
return;
}
printf("%s(", $stack[1]['function']);
$args = '';
foreach ($stack[1]['args'] as $k => $v)
{
$args .= sprintf("%s, ", var_export($v, true));
}
if ($args != '')
{
printf("%s", substr($args, 0, -2));
}
printf(")\n");
}
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
Extend();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECTF--
__construct('%s', '%s', '%s')
exec('DROP TABLE %s')
exec('CREATE TABLE %s (id INT)')
exec('INSERT INTO %s (id) VALUES (1), (2)')
query('SELECT * FROM %s ORDER BY id ASC')
array(2) {
[0]=>
array(1) {
["id"]=>
string(1) "1"
}
[1]=>
array(1) {
["id"]=>
string(1) "2"
}
}
bool(false)
__call('intercept_call', array (
))
exec('DROP TABLE %s')
Test "PDO - Extension" completed successfully.

View file

@ -0,0 +1,145 @@
--TEST--
Extending PDO Test #2
--DESCRIPTION--
Verification of capabilities for extending PDO.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function Extend()
{
include 'MsSetup.inc';
$testName = "PDO - Extension";
StartTest($testName);
$data = array( array('10', 'Abc', 'zxy'),
array('20', 'Def', 'wvu'),
array('30', 'Ghi', 'tsr'));
$conn1 = PDOConnect('ExPDO', $server, $uid, $pwd, true);
var_dump(get_class($conn1));
// Prepare test table
DropTable($conn1, $tableName);
$conn1->exec("CREATE TABLE [$tableName] (id int NOT NULL PRIMARY KEY, val VARCHAR(10), val2 VARCHAR(16))");
$stmt1 = $conn1->prepare("INSERT INTO [$tableName] VALUES(?, ?, ?)");
var_dump(get_class($stmt1));
foreach ($data as $row)
{
$stmt1->execute($row);
}
unset($stmt1);
// Retrieve test data via a direct query
$stmt1 = $conn1->query("SELECT * FROM [$tableName]");
var_dump(get_class($stmt1));
var_dump(get_class($stmt1->dbh));
foreach($stmt1 as $obj)
{
var_dump($obj);
}
echo "===DONE===\n";
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
class ExPDO extends PDO
{
function __destruct()
{
echo __METHOD__ . "()\n";
}
function query($sql)
{
echo __METHOD__ . "()\n";
$stmt = $this->prepare($sql, array(PDO::ATTR_STATEMENT_CLASS=>array('ExPDOStatement', array($this))));
$stmt->setFetchMode(PDO::FETCH_ASSOC);
$stmt->execute();
return ($stmt);
}
}
class ExPDOStatement extends PDOStatement
{
public $dbh;
protected function __construct($dbh)
{
$this->dbh = $dbh;
echo __METHOD__ . "()\n";
}
function __destruct()
{
echo __METHOD__ . "()\n";
}
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
Extend();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
string(5) "ExPDO"
string(12) "PDOStatement"
ExPDO::query()
ExPDOStatement::__construct()
string(14) "ExPDOStatement"
string(5) "ExPDO"
array(3) {
["id"]=>
string(2) "10"
["val"]=>
string(3) "Abc"
["val2"]=>
string(3) "zxy"
}
array(3) {
["id"]=>
string(2) "20"
["val"]=>
string(3) "Def"
["val2"]=>
string(3) "wvu"
}
array(3) {
["id"]=>
string(2) "30"
["val"]=>
string(3) "Ghi"
["val2"]=>
string(3) "tsr"
}
===DONE===
ExPDOStatement::__destruct()
ExPDO::__destruct()
Test "PDO - Extension" completed successfully.

View file

@ -0,0 +1,159 @@
--TEST--
Extending PDO Test #3
--DESCRIPTION--
Verification of capabilities for extending PDO.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function Extend()
{
include 'MsSetup.inc';
$testName = "PDO - Extension";
StartTest($testName);
$data = array( array('10', 'Abc', 'zxy'),
array('20', 'Def', 'wvu'),
array('30', 'Ghi', 'tsr'));
$conn1 = PDOConnect('ExPDO', $server, $uid, $pwd, true);
var_dump(get_class($conn1));
// Prepare test table
DropTable($conn1, $tableName);
$conn1->exec("CREATE TABLE [$tableName] (id int NOT NULL PRIMARY KEY, val VARCHAR(10), val2 VARCHAR(16))");
$stmt1 = $conn1->prepare("INSERT INTO [$tableName] VALUES(?, ?, ?)");
var_dump(get_class($stmt1));
foreach ($data as $row)
{
$stmt1->execute($row);
}
unset($stmt1);
echo "===QUERY===\n";
// Retrieve test data via a direct query
$stmt1 = $conn1->query("SELECT * FROM [$tableName]");
var_dump(get_class($stmt1));
var_dump(get_class($stmt1->dbh));
echo "===FOREACH===\n";
foreach($stmt1 as $obj)
{
var_dump($obj);
}
echo "===DONE===\n";
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
class ExPDO extends PDO
{
function __destruct()
{
echo __METHOD__ . "()\n";
}
function query($sql)
{
echo __METHOD__ . "()\n";
$stmt = $this->prepare($sql, array(PDO::ATTR_STATEMENT_CLASS=>array('ExPDOStatement', array($this))));
$stmt->setFetchMode(PDO::FETCH_ASSOC);
$stmt->execute();
return ($stmt);
}
}
class ExPDOStatement extends PDOStatement
{
public $dbh;
protected function __construct($dbh)
{
$this->dbh = $dbh;
echo __METHOD__ . "()\n";
}
function __destruct()
{
echo __METHOD__ . "()\n";
}
function execute($params = array())
{
echo __METHOD__ . "()\n";
parent::execute();
}
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
Extend();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
string(5) "ExPDO"
string(12) "PDOStatement"
===QUERY===
ExPDO::query()
ExPDOStatement::__construct()
ExPDOStatement::execute()
string(14) "ExPDOStatement"
string(5) "ExPDO"
===FOREACH===
array(3) {
["id"]=>
string(2) "10"
["val"]=>
string(3) "Abc"
["val2"]=>
string(3) "zxy"
}
array(3) {
["id"]=>
string(2) "20"
["val"]=>
string(3) "Def"
["val2"]=>
string(3) "wvu"
}
array(3) {
["id"]=>
string(2) "30"
["val"]=>
string(3) "Ghi"
["val2"]=>
string(3) "tsr"
}
===DONE===
ExPDOStatement::__destruct()
ExPDO::__destruct()
Test "PDO - Extension" completed successfully.

View file

@ -0,0 +1,174 @@
--TEST--
Extending PDO Test #4
--DESCRIPTION--
Verification of capabilities for extending PDO.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function Extend()
{
include 'MsSetup.inc';
$testName = "PDO - Extension";
StartTest($testName);
$data = array( array('10', 'Abc', 'zxy'),
array('20', 'Def', 'wvu'),
array('30', 'Ghi', 'tsr'));
$conn1 = PDOConnect('ExPDO', $server, $uid, $pwd, true);
var_dump(get_class($conn1));
// Prepare test table
DropTable($conn1, $tableName);
$conn1->exec("CREATE TABLE [$tableName] (id int NOT NULL PRIMARY KEY, val VARCHAR(10), val2 VARCHAR(16))");
$stmt1 = $conn1->prepare("INSERT INTO [$tableName] VALUES(?, ?, ?)");
var_dump(get_class($stmt1));
foreach ($data as $row)
{
$stmt1->execute($row);
}
unset($stmt1);
echo "===QUERY===\n";
// Retrieve test data via a direct query
var_dump($conn1->getAttribute(PDO::ATTR_STATEMENT_CLASS));
$conn1->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('ExPDOStatement', array($conn1)));
var_dump($conn1->getAttribute(PDO::ATTR_STATEMENT_CLASS));
$stmt1 = $conn1->query("SELECT * FROM [$tableName]");
var_dump(get_class($stmt1));
var_dump(get_class($stmt1->dbh));
echo "===FOREACH===\n";
foreach($stmt1 as $obj)
{
var_dump($obj);
}
echo "===DONE===\n";
// Cleanup
DropTable($conn1, $tableName);
$stmt1 = null;
$conn1 = null;
EndTest($testName);
}
class ExPDO extends PDO
{
function __destruct()
{
echo __METHOD__ . "()\n";
}
function query($sql)
{
echo __METHOD__ . "()\n";
$stmt = parent::query($sql);
return ($stmt);
}
}
class ExPDOStatement extends PDOStatement
{
public $dbh;
protected function __construct($dbh)
{
$this->dbh = $dbh;
$this->setFetchMode(PDO::FETCH_ASSOC);
echo __METHOD__ . "()\n";
}
function __destruct()
{
echo __METHOD__ . "()\n";
}
function execute($params = array())
{
echo __METHOD__ . "()\n";
parent::execute();
}
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
Extend();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECTF--
string(5) "ExPDO"
string(12) "PDOStatement"
===QUERY===
array(1) {
[0]=>
string(12) "PDOStatement"
}
array(2) {
[0]=>
string(14) "ExPDOStatement"
[1]=>
array(1) {
[0]=>
object(ExPDO)#%d (0) {
}
}
}
ExPDO::query()
ExPDOStatement::__construct()
string(14) "ExPDOStatement"
string(5) "ExPDO"
===FOREACH===
array(3) {
["id"]=>
string(2) "10"
["val"]=>
string(3) "Abc"
["val2"]=>
string(3) "zxy"
}
array(3) {
["id"]=>
string(2) "20"
["val"]=>
string(3) "Def"
["val2"]=>
string(3) "wvu"
}
array(3) {
["id"]=>
string(2) "30"
["val"]=>
string(3) "Ghi"
["val2"]=>
string(3) "tsr"
}
===DONE===
ExPDOStatement::__destruct()
Test "PDO - Extension" completed successfully.
ExPDO::__destruct()

View file

@ -0,0 +1,64 @@
--TEST--
PDO - Quote Null Terminator
--DESCRIPTION--
Verifies the functionality of PDO::Quote, ensuring that the returned string
length does not include the null-terminator.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
function QuoteTest()
{
include 'MsSetup.inc';
$testName = "PDO - Quote Null Terminator";
StartTest($testName);
Setup();
$testString = "This is a test string";
$expectedString = "'This is a test string'ASDF";
$conn = Connect();
$returnString = $conn->Quote($testString) . "ASDF";
if ($returnString !== $expectedString)
{
echo "Test String: $testString\nExpected String: $expectedString\nQuoted String: $returnString\n";
FatalError("Possible Regression: Quoted string may have null-terminator");
}
EndTest($testName);
}
//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{
try
{
QuoteTest();
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
Repro();
?>
--EXPECT--
Test "PDO - Quote Null Terminator" completed successfully.

View file

@ -20,7 +20,7 @@ UTF-8 connection strings
?>
--EXPECTREGEX--
Fatal error: Uncaught PDOException: SQLSTATE\[(08001|HYT00)\]: .*\[Microsoft\]\[ODBC Driver 1[0-9] for SQL Server\](Named Pipes Provider: Could not open a connection to SQL Server \[2\]\. |Login timeout expired) in .+(\/|\\)pdo_utf8_conn\.php:[0-9]+
Fatal error: Uncaught PDOException: SQLSTATE\[(28000|08001|HYT00)\]: .*\[Microsoft\]\[ODBC Driver 1[0-9] for SQL Server\](\[SQL Server\])?(Named Pipes Provider: Could not open a connection to SQL Server \[2\]\. |Login timeout expired|Login failed for user 'sa'\.) in .+(\/|\\)pdo_utf8_conn\.php:[0-9]+
Stack trace:
#0 .+(\/|\\)pdo_utf8_conn\.php\([0-9]+\): PDO->__construct\('sqlsrv:Server=l\.\.\.', 'sa', 'Sunshine4u'\)
#1 {main}

View file

@ -0,0 +1,210 @@
--TEST--
PDOStatement::BindParam for predefined constants and buffered query.
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
//*************************************************************************************
// Test binding with different predefined constants and using buffered query to update and
// select data.
//*************************************************************************************
require_once 'MsCommon.inc';
function insert($db)
{
$query = "DECLARE @string VARCHAR(MAX) = '0000000000'";
$query .= "DECLARE @string1 VARCHAR(MAX) = '00'";
$query .= "DECLARE @bin VARBINARY(MAX)";
$query .= "DECLARE @bin1 VARBINARY(2)";
$query .= "SET @bin = CAST(@string AS VARBINARY(MAX))";
$query .= "SET @bin1 = CAST(@string1 AS VARBINARY(2))";
$query .= "INSERT INTO PDO_AllTypes (";
$query .= "BigIntCol,BitCol,IntCol,";
$query .= "SmallIntCol,TinyIntCol,";
$query .= "DecimalCol,NumCol,MoneyCol,";
$query .= "SmallMoneyCol,FloatCol,RealCol,";
$query .= "CharCol,VarcharCol,TextCol,";
$query .= "NCharCol,NVarcharCol,ImageCol,";
$query .= "BinaryCol,VarbinaryCol,SmallDTCol,";
$query .= "DateTimeCol,DTOffsetCol,";
$query .= "TimeCol,Guidcol,VarbinaryMaxCol,";
$query .= "VarcharMaxCol,XmlCol,NTextCol,";
$query .= "NVarCharMaxCol) VALUES (0,'0',0,1,1,111,1,";
$query .= "111.1110,111.1110,111.111,111.111,";
$query .= "'STRINGCOL2','STRINGCOL2',";
$query .= "'1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.',";
$query .= "'STRINGCOL2','STRINGCOL2','00',";
$query .= "CONVERT(BINARY(2),@bin),CONVERT(VARBINARY(2),@bin1),'2000-11-11 11:11:00',";
$query .= "'2000-11-11 11:11:11.110',";
$query .= "'2000-11-11 11:11:11.1110000 +00:00','11:11:11.1110000',";
$query .= "'AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA',CONVERT(VARBINARY(MAX),@bin1) ,";
$query .= "'1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.',";
$query .= "'<xml> 1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.</xml>',";
$query .= "'1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.',";
$query .= "'1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.')";
$numRows = $db->exec($query);
echo "Insert complete!\n";
}
function bindParam_LOB($db)
{
// Binding LOB with buffered queries activated.
$noteID = fopen('php://memory', 'a');
$data = '0';
$query = "UPDATE PDO_AllTypes SET [VarbinaryCol]=:Name WHERE [BitCol]=:value";
$stmt = $db->prepare($query,array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED));
fwrite($noteID, '00');
rewind($noteID);
$stmt->bindParam(':Name',$noteID,PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY);
$stmt->bindParam(':value',$data);
$result = $stmt->execute();
$select = "SELECT * FROM PDO_AllTypes WHERE [BitCol]=:value";
$stmt = $db->prepare($select,array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->bindParam(':value',$data);
$stmt->execute();
$result = $stmt->fetchColumn(26); // Retrieve VarbinaryCol
print("$result\n");
}
function bindParam_STR($db)
{
// Binding STR with buffered queries activated.
$noteID = fopen('php://memory', 'a');
$data = 'STRINGCOL2';
$query = "UPDATE PDO_AllTypes SET [BitCol]=:Name WHERE [CharCol]=:value";
$stmt = $db->prepare($query,array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED));
fwrite($noteID, '1');
rewind($noteID);
$stmt->bindParam(':Name',$noteID,PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_BINARY);
$stmt->bindParam(':value',$data);
$stmt->execute();
$select = "SELECT * FROM PDO_AllTypes WHERE [CharCol]=:value";
$stmt = $db->prepare($select,array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->bindParam(':value',$data);
$stmt->execute();
$result = $stmt->fetchColumn(2); // Retrieve BitCol
$result = str_replace("\0","",$result);
print("$result\n");
}
function bindParam_NULL($db)
{
// Binding NULL with buffered queries activated.
$noteID = fopen('php://memory', 'a');
$data = 'STRINGCOL2';
$query = "UPDATE PDO_AllTypes SET [BitCol]=:Name WHERE [VarcharCol]=:value";
$stmt = $db->prepare($query,array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED));
fwrite($noteID, null);
rewind($noteID);
$stmt->bindParam(':Name',$noteID,PDO::PARAM_NULL);
$stmt->bindParam(':value',$data);
$stmt->execute();
$data = '0';
$select = "SELECT * FROM PDO_AllTypes WHERE [BitCol]=:value";
$stmt = $db->prepare($select,array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->bindParam(':value',$data);
$stmt->execute();
$result = $stmt->fetchColumn(2); // Retrieve BitCol
$result = str_replace("\0","",$result);
print("$result\n");
}
function bindParam_INT($db)
{
// Binding INT with buffered queries activated.
$noteID = fopen('php://memory', 'a');
$data = 0;
$query = "UPDATE PDO_ALLTypes SET [IntCol]=:Name WHERE [IntCol]=:value";
$stmt = $db->prepare($query,array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED));
fwrite($noteID, '1');
rewind($noteID);
$stmt->bindParam(':Name',$noteID,PDO::PARAM_INT);
$stmt->bindParam(':value',$data);
$stmt->execute();
$select = "SELECT * FROM PDO_AllTypes WHERE [BigIntCol]=:value";
$stmt = $db->prepare($select,array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->bindParam(':value',$data,PDO::PARAM_INT);
$stmt->execute();
$result = $stmt->fetchColumn(11); // Retrieve IntCol
$result = str_replace("\0","",$result);
print("$result\n");
}
function bindParam_BOOL($db)
{
// Binding BOOL with buffered queries activated.
$noteID = fopen('php://memory', 'a');
$data = '0';
$query = "UPDATE PDO_AllTypes SET [BitCol]=:Name WHERE [BigIntCol]=:value";
$stmt = $db->prepare($query,array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED));
fwrite($noteID, '1');
rewind($noteID);
$stmt->bindParam(':Name',$noteID,PDO::PARAM_BOOL);
$stmt->bindParam(':value',$data);
$stmt->execute();
$query = "SELECT * FROM PDO_AllTypes WHERE [BigIntCol]=:value";
$stmt = $db->prepare($query,array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->bindParam(':value',$data,PDO::PARAM_BOOL);
$stmt->execute();
$result = $stmt->fetchColumn(2); // Retrieve BitCol
$result = str_replace("\0","",$result);
print("$result\n");
}
function delete($db)
{
$data = "STRINGCOL2";
$query = "DELETE FROM PDO_AllTypes WHERE [CharCol]=:value";
$stmt = $db->prepare($query,array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED));
$stmt->bindParam(':value',$data);
$stmt->execute();
}
try {
$db = connect();
insert($db);
bindParam_LOB($db);
bindParam_STR($db);
bindParam_NULL($db);
bindParam_INT($db);
bindParam_BOOL($db);
delete($db);
echo "Test Completed";
}
catch( PDOException $e ) {
var_dump( $e );
exit;
}
?>
--EXPECT--
Insert complete!
00
1
0
1
1
Test Completed

View file

@ -0,0 +1,61 @@
--TEST--
Test the bindColumn method using either by bind by column number or bind by column name
--SKIPIF--
<?php require "skipif.inc"; ?>
--FILE--
<?php
require_once "MsCommon.inc";
function bindColumn_byName($db)
{
global $table1;
$stmt = $db->prepare("SELECT IntCol, CharCol, DateTimeCol FROM " . $table1);
$stmt->execute();
$stmt->bindColumn('IntCol', $intCol);
$stmt->bindColumn('CharCol', $charCol);
$stmt->bindColumn('DateTimeCol', $dateTimeCol);
while($row = $stmt->fetch(PDO::FETCH_BOUND))
{
echo $intCol . " : " . $charCol . " : " . $dateTimeCol . "\n";
}
}
function bindColumn_byNumber($db)
{
global $table1;
$stmt = $db->prepare("SELECT IntCol, CharCol, DateTimeCol FROM " . $table1);
$stmt->execute();
$stmt->bindColumn(1, $intCol);
$stmt->bindColumn(2, $charCol);
$stmt->bindColumn(3, $dateTimeCol);
while($row = $stmt->fetch(PDO::FETCH_BOUND))
{
echo $intCol . " : " . $charCol . " : " . $dateTimeCol . "\n";
}
}
try
{
$db = connect();
echo "Bind Column by name :\n";
bindColumn_byName($db);
echo "Bind Column by number :\n";
bindColumn_byNumber($db);
}
catch (PDOException $e)
{
var_dump($e);
}
?>
--EXPECT--
Bind Column by name :
1 : STRINGCOL1 : 2000-11-11 11:11:11.110
2 : STRINGCOL2 : 2000-11-11 11:11:11.223
Bind Column by number :
1 : STRINGCOL1 : 2000-11-11 11:11:11.110
2 : STRINGCOL2 : 2000-11-11 11:11:11.223

View file

@ -0,0 +1,163 @@
--TEST--
PDOStatement::BindParam for NULL types and for value types.
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
//*************************************************************************************
// WHEN LENGTH IS SPECIFIED THAN WE CONSIDER THE TYPE TO BE OUTPUT TYPE.
// THIS IS NOT ALLOWED. SINCE STREAM TYPES CANNOT BE OUTPUT TYPES
//$stmt->bindParam(1, $param, PDO::PARAM_LOB, 10, PDO::SQLSRV_ENCODING_BINARY);
// THIS IS ERROR DUE TO > 8000
//$stmt->bindParam(1, $param, PDO::PARAM_STR, 9000, PDO::SQLSRV_ENCODING_BINARY);
// THIS RESULTS IN INVALID LENGTH ERROR.
//$stmt->bindParam(1, $param, PDO::PARAM_STR, -1, PDO::SQLSRV_ENCODING_BINARY);
// THIS DOES NOT WORK FOR ALL CASES SINCE PDO CALLS BINDPARAM DURING SQLEXECUTE.
//$stmt->setAttribute(PDO::SQLSRV_ATTR_ENCODING, PDO::SQLSRV_ENCODING_BINARY );
//*************************************************************************************
require_once 'MsCommon.inc';
function bind_params_with_null($db)
{
global $table2;
$sql = " INSERT INTO " .$table2 . "
([BigIntCol]
,[BinaryCol]
,[BitCol]
,[CharCol]
,[DateCol]
,[DateTimeCol]
,[DateTime2Col]
,[DTOffsetCol]
,[DecimalCol]
,[FloatCol]
,[ImageCol]
,[IntCol]
,[MoneyCol]
,[NCharCol]
,[NTextCol]
,[NumCol]
,[NVarCharCol]
,[NVarCharMaxCol]
,[RealCol]
,[SmallDTCol]
,[SmallIntCol]
,[SmallMoneyCol]
,[TextCol]
,[TimeCol]
,[TinyIntCol]
,[Guidcol]
,[VarbinaryCol]
,[VarbinaryMaxCol]
,[VarcharCol]
,[VarcharMaxCol]
,[XmlCol])
VALUES (?,?,?,?,?,?,?,?,?,? /*10*/,?,?,?,?,?,?,?,?,?,? /*20*/, ?,?,?,?,?,?,?,?,?,?, ? /*31*/)";
$stmt = $db->prepare($sql);
$param = null;
$stmt->bindParam(1, $param);
$stmt->bindParam(2, $param, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY );
$stmt->bindParam(3, $param );
$stmt->bindParam(4, $param );
$stmt->bindParam(5, $param );
$stmt->bindParam(6, $param );
$stmt->bindParam(7, $param );
$stmt->bindParam(8, $param );
$stmt->bindParam(9, $param );
$stmt->bindParam(10, $param );
$stmt->bindParam(11, $param );
$stmt->bindParam(12, $param );
$stmt->bindParam(13, $param );
$stmt->bindParam(14, $param );
$stmt->bindParam(15, $param );
$stmt->bindParam(16, $param );
$stmt->bindParam(17, $param );
$stmt->bindParam(18, $param );
$stmt->bindParam(19, $param );
$stmt->bindParam(20, $param );
$stmt->bindParam(21, $param );
$stmt->bindParam(22, $param );
$stmt->bindParam(23, $param );
$stmt->bindParam(24, $param );
$stmt->bindParam(25, $param );
$stmt->bindParam(26, $param );
$stmt->bindParam(27, $param, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_BINARY ); //PDO::PARAM_STR OR PDO::PARAM_LOB DOES NOT MATTER
$stmt->bindParam(28, $param, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_BINARY );
$stmt->bindParam(29, $param );
$stmt->bindParam(30, $param );
$stmt->bindParam(31, $param );
$stmt->execute();
}
function bind_params_int($db)
{
global $table2;
$stmt = $db->prepare("SELECT * FROM " . $table2 . " WHERE BigIntCol = :bigIntCol ");
$int = 1;
$stmt->bindParam(":bigIntCol", $int, PDO::PARAM_INT);
$stmt->execute();
}
function bind_params_str($db)
{
global $table2;
$stmt = $db->prepare("SELECT * FROM " . $table2 . " WHERE CharCol = :charCol ");
$char = "STRINGCOL1";
$stmt->bindParam(":charCol", $char, PDO::PARAM_STR);
$stmt->execute();
}
function bind_params_bool($db)
{
global $table2;
$stmt = $db->prepare("SELECT * FROM " . $table2 . " WHERE BitCol = :bool ");
$bool = 0;
$stmt->bindParam(":bool" , $bool, PDO::PARAM_BOOL);
$stmt->execute();
}
function bind_params_lob($db)
{
global $table2;
$stmt = $db->prepare("SELECT * FROM " . $table2 . " WHERE BinaryCol = :lob ");
$lob = 0;
$stmt->bindParam(":lob" , $lob, PDO::PARAM_LOB);
$stmt->execute();
}
try {
$db = connect();
create_and_insert_table2( $db );
bind_params_with_null($db);
bind_params_int($db);
bind_params_str($db);
bind_params_bool($db);
bind_params_lob($db);
echo "Test Succeeded";
}
catch( PDOException $e ) {
var_dump( $e );
exit;
}
?>
--EXPECT--
Test Succeeded

View file

@ -0,0 +1,27 @@
--TEST--
Test bindValue method.
--SKIPIF--
<?php require "skipif.inc"; ?>
--FILE--
<?php
require_once 'MsCommon.inc';
try{
$db = connect();
global $table2;
$bigint = 1;
$string = "STRINGCOL1";
$stmt = $db->prepare("SELECT IntCol FROM " . $table2 . " WHERE BigIntCol = :bigint AND CharCol = :string");
$stmt->bindValue(':bigint', $bigint, PDO::PARAM_INT);
$stmt->bindValue(':string', $string, PDO::PARAM_STR);
$stmt->execute();
echo "Test Complete!\n";
}
catch (PDOException $e)
{
var_dump($e);
}
?>
--EXPECT--
Test Complete!

View file

@ -0,0 +1,28 @@
--TEST--
Test PDOStatement::closeCursor method.
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once 'MsCommon.inc';
try{
$db = connect();
global $table2;
$stmt = $db->prepare("SELECT * FROM " . $table2);
$stmt->execute();
$result = $stmt->fetch();
$stmt->closeCursor();
echo "Test complete!";
}
catch ( PDOException $e)
{
var_dump($e);
}
?>
--EXPECT--
Test complete!

View file

@ -0,0 +1,24 @@
--TEST--
Test PDOStatement::columnCount if the number of the columns in a result set.
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once 'MsCommon.inc';
try
{
$db = connect();
$sql = "SELECT * FROM PDO_AllTypes";
$stmt = $db->prepare($sql);
$stmt->execute();
print_r("Existing table contains: " . $stmt->columnCount());
}
catch(PDOException $e)
{
var_dump($e);
}
?>
--EXPECT--
Existing table contains: 31

View file

@ -0,0 +1,39 @@
--TEST--
Test debugDumpParams method.
--SKIPIF--
<?php require "skipif.inc"; ?>
--FILE--
<?php
require_once 'MsCommon.inc';
try{
$db = connect();
global $table2;
$bigint = 1;
$string = "STRINGCOL1";
$stmt = $db->prepare("SELECT IntCol FROM " . $table2 . " WHERE BigIntCol = :bigint AND CharCol = :string");
$stmt->bindValue(':bigint', $bigint, PDO::PARAM_INT);
$stmt->bindValue(':string', $string, PDO::PARAM_STR);
$stmt->execute();
$stmt->debugDumpParams();
}
catch (PDOException $e)
{
var_dump($e);
}
?>
--EXPECT--
SQL: [79] SELECT IntCol FROM PDO_AllTypes WHERE BigIntCol = :bigint AND CharCol = :string
Params: 2
Key: Name: [7] :bigint
paramno=0
name=[7] ":bigint"
is_param=1
param_type=1
Key: Name: [7] :string
paramno=1
name=[7] ":string"
is_param=1
param_type=2

View file

@ -0,0 +1,40 @@
--TEST--
Test PDOStatement::errorInfo and PDOStatement::errorCode methods.
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once 'MsCommon.inc';
try
{
$db = connect();
$stmt = $db->prepare("SELECT * FROM PDO_Types_1");
$stmt->execute();
$arr = $stmt->errorInfo();
print_r("Error Info :\n");
var_dump($arr);
$arr = $stmt->errorCode();
print_r("Error Code : " . $arr . "\n");
$db = null;
}
catch (PDOException $e)
{
var_dump($e);
}
?>
--EXPECT--
Error Info :
array(3) {
[0]=>
string(5) "00000"
[1]=>
NULL
[2]=>
NULL
}
Error Code : 00000

View file

@ -0,0 +1,53 @@
--TEST--
Test PDOStatement::execute method.
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once 'MsCommon.inc';
try
{
$db = connect();
$stmt = $db->prepare("SELECT * FROM PDO_Types_1");
$stmt->execute();
$rows = $stmt->fetch(PDO::FETCH_ASSOC);
var_dump($rows);
// Test update table value
$stmt = $db->prepare("UPDATE PDO_Types_1 SET IntCol=1");
$rows = $stmt->execute();
var_dump($rows);
// Test insert value to table
$stmt1 = $db->prepare("INSERT INTO PDO_Types_1 (IntCol,CharCol,NCharCol,DateTimeCol,VarcharCol,NVarCharCol,FloatCol,XmlCol) VALUES (2,'STRINGCOL1','STRINGCOL1','2000-11-11 11:11:11.110','STRINGCOL1','STRINGCOL1',111.111,'<xml> 1 This is a really large string used to test certain large data types like xml data type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.</xml>')");
$rows = $stmt1->execute();
var_dump($rows);
$db = null;
}
catch(PDOException $e)
{
var_dump($e);
}
?>
--EXPECT--
array(8) {
["IntCol"]=>
string(1) "1"
["CharCol"]=>
string(10) "STRINGCOL1"
["NCharCol"]=>
string(10) "STRINGCOL1"
["DateTimeCol"]=>
string(23) "2000-11-11 11:11:11.110"
["VarcharCol"]=>
string(10) "STRINGCOL1"
["NVarCharCol"]=>
string(10) "STRINGCOL1"
["FloatCol"]=>
string(7) "111.111"
["XmlCol"]=>
string(431) "<xml> 1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.</xml>"
}
bool(true)
bool(true)

View file

@ -0,0 +1,349 @@
--TEST--
reading different encodings in strings and streams.
--SKIPIF--
<?php if ( !( strtoupper( substr( php_uname( 's' ),0,3 ) ) === 'WIN' ) ) die( "Skip, test on windows only." ); ?>
--FILE--
<?php
function setup_test( $conn, $field_type )
{
prepare_params( $params, $field_type );
$tableName = "[dbo.TestTable" . $field_type . "]";
put_image_into_table($conn, $params);
return $params;
}
function start_test()
{
require( 'MsCommon.inc' );
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
$conn = Connect();
if( !$conn ) {
FatalError( "Failed to Connect." );
}
$params = setup_test( $conn, "varbinary(max)" );
echo "retrieving binary encoded varbinary(max)\n";
$stmt = sqlsrv_query($conn, $params['selectQuery']);
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$result = sqlsrv_fetch($stmt);
if( $result === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$db_stream = sqlsrv_get_field($stmt, 0, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY));
if( $db_stream === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$file_stream = fopen($params['testImageURL'], "rb");
while (($file_line = fread( $file_stream, 80 )) &&
($db_line = fread( $db_stream, 80 ))) {
if( $file_line != $db_line )
die( "Binary not identical" );
}
sqlsrv_free_stmt( $stmt );
fclose( $file_stream );
echo "retrieving char encoded varbinary(max)\n";
$stmt = sqlsrv_query( $conn, $params['selectQuery'] );
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$result = sqlsrv_fetch( $stmt );
if( $result === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$db_stream = sqlsrv_get_field( $stmt, 0, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_CHAR) );
if( $db_stream === false ) {
die( print_r( sqlsrv_errors(), true ));
}
while ($db_line = fread( $db_stream, 80 )) {
echo "$db_line\n";
}
sqlsrv_free_stmt( $stmt );
$params = setup_test( $conn, "varchar(max)" );
$stmt = sqlsrv_query($conn, $params['selectQuery']);
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$result = sqlsrv_fetch($stmt);
if( $result === false ) {
die( print_r( sqlsrv_errors(), true ));
}
echo "retrieving binary encoded varchar(max)\n";
$db_stream = sqlsrv_get_field($stmt, 0, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY));
if( $db_stream === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$file_stream = fopen($params['testImageURL'], "rb");
while (($file_line = fread( $file_stream, 80 )) &&
($db_line = fread( $db_stream, 80 ))) {
if( $file_line != $db_line )
die( "Binary not identical" );
}
sqlsrv_free_stmt( $stmt );
echo "retrieving char encoded varchar(max)\n";
$stmt = sqlsrv_query( $conn, $params['selectQuery'] );
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$result = sqlsrv_fetch( $stmt );
if( $result === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$db_stream = sqlsrv_get_field( $stmt, 0, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_CHAR) );
if( $db_stream === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$file_stream = fopen($params['testImageURL'], "rb");
while (($file_line = fread( $file_stream, 80 )) &&
($db_line = fread( $db_stream, 80 ))) {
if( $file_line != $db_line )
{
// continue testing even if the data not identical
echo( "Characters not identical!!\n" );
break;
}
}
sqlsrv_free_stmt( $stmt );
$params = setup_test( $conn, "nvarchar(max)" );
$stmt = sqlsrv_query($conn, $params['selectQuery']);
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$result = sqlsrv_fetch($stmt);
if( $result === false ) {
die( print_r( sqlsrv_errors(), true ));
}
echo "retrieving binary encoded nvarchar(max)\n";
$db_stream = sqlsrv_get_field($stmt, 0, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY));
if( $db_stream === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$file_stream = fopen($params['testImageURL'], "rb");
while (($file_line = fread( $file_stream, 80 )) &&
($db_line = fread( $db_stream, 80 ))) {
if( $file_line != $db_line )
die( "Binary not identical" );
}
sqlsrv_free_stmt( $stmt );
echo "retrieving char encoded nvarchar(max)\n";
$stmt = sqlsrv_query( $conn, $params['selectQuery'] );
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$result = sqlsrv_fetch( $stmt );
if( $result === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$db_stream = sqlsrv_get_field( $stmt, 0, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_CHAR) );
if( $db_stream === false ) {
die( print_r( sqlsrv_errors(), true ));
}
while ($db_line = fread( $db_stream, 80 )) {
echo "$db_line\n";
}
sqlsrv_free_stmt( $stmt );
sqlsrv_close( $conn );
echo "Test successful.\n";
}
function put_image_into_table($conn, $params)
{
drop_test_table($conn, $params);
create_test_table($conn, $params);
$data = fopen($params['testImageURL'], "rb");
if( !$data ) {
die("Couldn't open image for reading.");
}
$stmt = sqlsrv_query($conn, $params['insertQuery'], array( array($data, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY))));
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
do {
$read = sqlsrv_send_stream_data($stmt);
if ($read === false) die(print_r(sqlsrv_errors(), true));
} while ($read);
fclose($data);
sqlsrv_free_stmt($stmt);
}
function prepare_params( &$arr, $field_type )
{
$uname = php_uname();
$phpgif = "\\php.gif";
if (IsWindows())
{
$phpgif = '\\php.gif';
}
else // other than Windows
{
$phpgif = '/php.gif';
}
$arr['tableName'] = $tblName = "[encoding_test_" . $field_type . "]";
$arr['columnName'] = $colName = "php_gif";
$arr['fieldType'] = $field_type;
$arr['dropQuery'] = "IF OBJECT_ID(N'$tblName', N'U') IS NOT NULL DROP TABLE $tblName";
$arr['createQuery'] = "CREATE TABLE $tblName ($colName $field_type)";
$arr['insertQuery'] = "INSERT INTO $tblName ($colName) VALUES (?)";
$arr['selectQuery'] = "SELECT TOP 1 $colName FROM $tblName";
$arr['testImageURL'] = dirname( $_SERVER['PHP_SELF'] ) . $phpgif; // use this when no http access
$arr['MIMEType'] = "image/gif";
}
function drop_test_table( $conn, $params )
{
run_query( $conn, $params['dropQuery'] );
}
function create_test_table( $conn, $params )
{
run_query( $conn, $params['createQuery'] );
}
function run_query($conn, $query)
{
$qStmt = sqlsrv_query( $conn, $query );
if( !$qStmt ) {
die( print_r(sqlsrv_errors(), true) );
}
sqlsrv_free_stmt( $qStmt );
}
start_test();
?>
--EXPECT--
retrieving binary encoded varbinary(max)
retrieving char encoded varbinary(max)
47494638396178004300E66A007F82B839374728252ACCCDE2A1A4CBD3D5E7B2B4D44342588386B9
8283B35252729092C2C2C4DEAAACD04C4B635B5C83DDDEEC3B383C6E71A56A6D9D61638D7579B17B
7EB5E5E6F0999CC68C8DC1B9BAD96B6B924E4E6B7174A97A7AA3888BBD7274A37473988E90C15A5B
7EE2E3EF7B7DADA4A5D06D70A27276AC9596C8BBBDD97478AE8588BB9295C3D8D9EA9292C4646692
6B6E9FA5A8CE9496C52E2B2F535168B3B4D76C6A8C5C5B768A8DBF666896686A9A9C9FC8312E39AE
B0D39C9CCD5556789EA1CA9699C58182AF6769973F3D50BCBEDA5E60899899C88C8EBF898ABA5758
7CB6B7D7D5D7E8221E206C6F9ECED0E4BFC0DC777BB47678A75F5E7D9999CC6E6F987377AE221E1F
FFFFFF908E8F595657C7C6C7EEEEF5D5D4D5F6F6FA828081ACAAAB747273F1F0F19E9C9DE3E2E34B
4849B9B8B96764658989B600FF0047465FDFE0ED9B9CCC696B9C6F73A78C8CBAB8B9D9B8BAD79A9B
CCA7AACFDBDCEB9A9CC9666484686789A7A8D26E70A08B8BB9C6C7E0C7C9E1696C9C9798CB21F904
0100006A002C00000000780043000007FF806A82838485868788898A8B8C8D8E8F90919293949596
97966D3F6D73989E9FA03F7979363E1A714C1A1A4C063E3E0D3204413C18422D0B4922391F193922
2F29A0C2A10D1A0C7D4D055050037D7C0C51512A72ACAF74B1B342332DBA1F080016161557282516
0919C1C3EB8C26717C2E6C6C1010752EC903D432B3221FFE2C0011080440B0E03782E1A4AC40F146
C2093F3B9E4C1992849D4535416C0C6043E282471224F23510B2408AC9932853AA5C79725C070913
76E88041E108052B43445CC4148409148E1E2FB83042A705CBA34893A2BCF226068C23471E8C5872
C483CE9D907E687401812304230458281D4B36E995133A1E2C01A240C1882933FFB02E32A1A14013
17750A184852B6AF5FA41D602C51C08183033C09E41ACA1365009402037CE4F8BB720186CB98317C
A09CF40D05050ED6AC51E041B19A3C46F8F419C06406E7951FB270994D9B4B97D74ADD2C5973E080
83103BDD4561C0A00102DC2B3170C1C2BCB999DBC89376D85DA4C89AD2C37EF8906344050F0BD157
AA20D3BCB99802E1955E79702040000E70409930C0440E0100E9571610539E391915F929F58602EE
F570072673D0E18301321C17A04A5D98D11F165C10F0A05231ACD1430F07EC51C90F3234D0404917
A6044016136291C5662526F540001B0227491B04ECE3608B272937A1195FE0A8941F45D040031591
D8110401338087D4FF079935D9248B47A910C684625CD024892C31E9E496F88D858203340850C323
4860100494477DF045166CB6E9E69B59745140035DA2540018139201679B170C60E1490BEC29289B
5D0CD0805240082080038DCC200406622945C07229566A06185C7C01204A5D6C51698A346CA14519
5D9068C0949F4EB805185E747128522308E004A38A6C23C48D498D97EAA75B7801419727EEFA2918
636020C500780AAB6A1903243582134EE090480A22B480665210F0A76C8A61406012065E6C9B221A
B75DE0A9B8E5D1E045B348AD012D7685FCE1CB64657D2121BAFD7901A094F8E6DB008AFD36474319
7F1E158013022C60483FF492155BC0E56DD1E39D1033A7C5FF05E1568C8518D01DD581AC63129202
021FD439D6A43BC239C619DA4EE805019D4EC8C59B637081468A5A64816AC4709671C6B913968125
4B0A409B0621DEE03A96AEFD89E12D4A0B34D00579136AC100C0FDAD8812060D7C1141D559685135
BB801AF045B2FD8561805234CC3AC81F0020A06459D9E6B9A989597CDD74161997C7E34A1000DD5C
CE823377C6DA2A7D3006CE771FB504B40AAB218205269365AFCC05A714B8AA3A53F9744A31F77746
1634046DEC4AA197A745E32C7500ED0D82B090505F0F4F38C6B5276DDE1F1A59A0DDDC7F2A051B74
1913D290C551A90FCE3A4B45B8AD4638739385727F11F4C8D2E5FD118EB94AE0169FC519AA5E7014
FFD6E501AF14074EF420480594315D1E1A9FA7547BDAE43777BB4AFCF6B745D863B38401F1DB530A
05A025881550A66ED95B9E490C00BEA0F5AD39D5D38FEF9803862C140E0B87630903A8D69FFB0990
8029B802FBFC82BDF2548825C9634E043AB7BBF89D2485580803E94CB71200786D42E422CB009D20
081418B02FC2EB20EE8E45A9ECF5AE6ACB0B6279BC00C0741D4F3F1C2C4F1814B8921D0AA2032818
21597444BD27A2E40305F042E9FA4383317CE182274C49F726F4BDF0710F02629C50F52A77142BAA
61215A5C5A1499432E15F8510510E8C218B43046D10DA07ECCF1204AF2C733B165AF0B7F046417CA
E04899517125E853DFF33A7085BEEC47FF555A086528C570AF1489E10B0478A00ABD68A70962A182
17149528B540CA6189AF2CCDA3D507DED081BE44486368F8C2024E8543179AC45C139261210376CA
A149E77582488104DEF043A528B15FCD3C962BADB612446281891A038330FBF2382744EE7912E8E5
58D6D82F1A9C619C5240667FB8F0AAADA992396D0C5804CE700167B2CD798278C10924D049A53052
5C6620C3180650A71976D09FC4D41FFFF065061932808E49299A138E4688219CE00D63A198FE6639
4B3270610C854253A0481A4A569E44055C60E9E82E28069686D2A42865C010A5033243A4E0042750
275260C8850BD0831E05F82301FC6912401EF5A89903D4009E4A8F432E93395EFF30EA5193EA4702
EC742C074BD82192108313A00029D74C24537D24850534B13C59C02872DCE50478192201652D6872
EEB942B6B2A4010D8C58C7F2534E6929A2047965C941F9684CBF4A8101956C0E18D013A072D26A11
8835AB04ABC600C7AA447752BC2465347A594694600231E8401EA540D47A7AD6247973D9E9A2D381
0340ABB48D48006A25A0C5B462610C6BF5D10216C746B9FA85083D80966123A184274C40B352F8DF
16A64B5DDEBDD69ED4A52E1806FB1A05C84A00329AC40B40E08718F0160005A02A3D10775D29A057
BD10702D65887030274480A39648801B50FB86D5B6D7AF27B0AD7241F18229F801B5AAFDAF5F51C0
015939A108F80585FF12F4E08603F757C1253AC11A1CDC83F0B28305143EB004CE8AE1F01CE1008A
12400F60A718168060076E70430CA85962CAF881030108930002C062D30822092520C20E603C011A
D738291320500F842426BBFA78102948801E74400421BB21A8FEC5F01B8E80E30D2DB9087878C193
17F10229EBE0CC67DEC147497CDD1D1C4101ED81D1860E70030F8DF9112F40C0148800833EFB9908
7EF8A850F33301223C0034D5718FA27110023BDF99122218C29E2940E94A53FA087DAE70A0DFC069
4E4BE0D39F062A50897069B688A63707A84E110270001C6C20318F16460A3E50021058012A507980
AE773D9525AC05086C690B610A6398D09CBA37455000156E38300431C75A31295002023CE0810D6C
202DBE0676B0DB426CC370800A23188115AC5082663FFBDC8B10411A10701574BBFBDDF08E77BC03
01003B30
retrieving binary encoded varchar(max)
retrieving char encoded varchar(max)
retrieving binary encoded nvarchar(max)
retrieving char encoded nvarchar(max)
???xC???????????????????????????????????????????????????????????????????????????
????????????????????????????????????????????<3F>???????????????????????????????????
?????ś˙???????????????????????????????????xC?????????????????????????????????
????????????????????????????????,???????????????????????????????????????????????
????????????I???????????????????e???????????????????????????????????????????????
???????????D????????????????????????????????-?@??????????????A??????????????????
???????????T?<3F>?????????????????%?z??????????????????????????????????????????????
?????????????Z??Ű??????????????????????????????a????????????????????????????????
???????? ????????????????????????????????????u?????????????????????????????????
?g???????????????????????? ??????????????????Ś??????¨?????Ë???????????ź?????????
????????????????????????????????????????????????????????????????????????????????
????????????????????????????????U???????????????????????????????????????????????
???????????Ô?????????????????????????G??????????????????????????????????????????
???????????????????????????????????????????????????????????????????????????????
??????????a?????????????????????????????????????L???????????????<???????????????
??????????p??????R????????????P????????????????????????????ľ?
Test successful.