additional pdo tests and new test data
This commit is contained in:
parent
bb364f989d
commit
0c7560d112
File diff suppressed because one or more lines are too long
60
test/pdo_sqlsrv/PDO11_Drivers.phpt
Normal file
60
test/pdo_sqlsrv/PDO11_Drivers.phpt
Normal file
|
@ -0,0 +1,60 @@
|
|||
--TEST--
|
||||
PDO Drivers Info Test
|
||||
--DESCRIPTION--
|
||||
Verifies the functionality of "PDO:getAvailableDrivers()”.
|
||||
--ENV--
|
||||
PHPT_EXEC=true
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
include 'MsCommon.inc';
|
||||
|
||||
function DriversInfo()
|
||||
{
|
||||
include 'MsSetup.inc';
|
||||
|
||||
$testName = "PDO - Drivers";
|
||||
StartTest($testName);
|
||||
|
||||
$drivers = PDO::getAvailableDrivers();
|
||||
if (in_array("sqlsrv", $drivers))
|
||||
{
|
||||
$count = count($drivers);
|
||||
for ($i = 0; $i < $count; $i++)
|
||||
{
|
||||
Trace("Driver #".($i + 1).": ".$drivers[$i]."\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("$PhpDriver is missing.\n");
|
||||
}
|
||||
|
||||
EndTest($testName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Repro
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
function Repro()
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
DriversInfo();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
echo $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
Repro();
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
Test "PDO - Drivers" completed successfully.
|
61
test/pdo_sqlsrv/PDO12_Info.phpt
Normal file
61
test/pdo_sqlsrv/PDO12_Info.phpt
Normal file
|
@ -0,0 +1,61 @@
|
|||
--TEST--
|
||||
PDO PHP Info Test
|
||||
--DESCRIPTION--
|
||||
Verifies the functionality of PDO with phpinfo().
|
||||
--ENV--
|
||||
PHPT_EXEC=true
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
include 'MsCommon.inc';
|
||||
|
||||
function DriversInfo()
|
||||
{
|
||||
include 'MsSetup.inc';
|
||||
|
||||
$testName = "PDO - phpinfo";
|
||||
StartTest($testName);
|
||||
|
||||
ob_start();
|
||||
phpinfo();
|
||||
$info = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
// Check phpinfo() data
|
||||
if (stristr($info, "PDO support => enabled") === false)
|
||||
{
|
||||
printf("PDO is not enabled\n");
|
||||
}
|
||||
else if (stristr($info, "pdo_sqlsrv support => enabled") === false)
|
||||
{
|
||||
printf("Cannot find PDO driver line in phpinfo() output\n");
|
||||
}
|
||||
|
||||
EndTest($testName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Repro
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
function Repro()
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
DriversInfo();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
echo $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
Repro();
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
Test "PDO - phpinfo" completed successfully.
|
62
test/pdo_sqlsrv/PDO21_Connection.phpt
Normal file
62
test/pdo_sqlsrv/PDO21_Connection.phpt
Normal file
|
@ -0,0 +1,62 @@
|
|||
--TEST--
|
||||
PDO Connection Test
|
||||
--DESCRIPTION--
|
||||
Checks whether the driver can successfully establish a database connection.
|
||||
Verifies as well that invalid connection attempts fail as expected.
|
||||
--ENV--
|
||||
PHPT_EXEC=true
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
include 'MsCommon.inc';
|
||||
|
||||
function ConnectionTest()
|
||||
{
|
||||
include 'MsSetup.inc';
|
||||
|
||||
$testName = "PDO Connection";
|
||||
StartTest($testName);
|
||||
|
||||
// Invalid connection attempt => errors are expected
|
||||
Trace("Invalid connection attempt (to a non-existing server) ....\n");
|
||||
$conn1 = PDOConnect('PDO', "InvalidServerName", $uid, $pwd, false);
|
||||
if ($conn1)
|
||||
{
|
||||
printf("Invalid connection attempt should have failed.\n");
|
||||
}
|
||||
$conn1 = null;
|
||||
|
||||
|
||||
// Valid connection attempt => no errors are expected
|
||||
Trace("\nValid connection attempt (to $server) ....\n");
|
||||
$conn2 = Connect();
|
||||
$conn2 = null;
|
||||
|
||||
EndTest($testName);
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Repro
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
function Repro()
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
ConnectionTest();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
echo $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
Repro();
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
Test "PDO Connection" completed successfully.
|
||||
|
149
test/pdo_sqlsrv/PDO22_ConnPool1.phpt
Normal file
149
test/pdo_sqlsrv/PDO22_ConnPool1.phpt
Normal file
|
@ -0,0 +1,149 @@
|
|||
--TEST--
|
||||
PDO Connection Pooling Test
|
||||
--DESCRIPTION--
|
||||
Checks whether the driver can successfully establish a database connection
|
||||
when an URI-based construct is used.
|
||||
--ENV--
|
||||
PHPT_EXEC=true
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
include 'MsCommon.inc';
|
||||
|
||||
function ConnectionTest()
|
||||
{
|
||||
include 'MsSetup.inc';
|
||||
|
||||
$testName = "PDO Connection Pooling";
|
||||
StartTest($testName);
|
||||
|
||||
$optionsDefault = null;
|
||||
$optionsPool = null;
|
||||
$optionsNotPool = null;
|
||||
|
||||
if ($dsnMode)
|
||||
{
|
||||
$optionsDefault = "APP=Microsoft PHP;";
|
||||
$optionsPool = "APP=Microsoft PHP;ConnectionPooling=1;";
|
||||
$optionsNotPool = "APP=Microsoft PHP;ConnectionPooling=0;";
|
||||
}
|
||||
else
|
||||
{
|
||||
$optionsDefault = array('APP'=>'Microsoft PHP');
|
||||
$optionsPool = array('APP'=>'Microsoft PHP', 'ConnectionPooling'=>1);
|
||||
$optionsNotPool = array('APP'=>'Microsoft PHP', 'ConnectionPooling'=>0);
|
||||
}
|
||||
|
||||
// Create pool
|
||||
$conn1 = DoConnect($optionsPool);
|
||||
$conn2 = DoConnect($optionsPool);
|
||||
$conn3 = DoConnect($optionsPool);
|
||||
|
||||
$connId1 = ConnectionID($conn1);
|
||||
$connId2 = ConnectionID($conn2);
|
||||
$connId3 = ConnectionID($conn3);
|
||||
|
||||
$conn1 = null;
|
||||
$conn2 = null;
|
||||
$conn3 = null;
|
||||
|
||||
$conn4 = DoConnect($optionsDefault);
|
||||
if (!IsPoolConnection($conn4, $connId1, $connId2, $connId3))
|
||||
{
|
||||
echo "Default connection was expected to be a pool connection..\n";
|
||||
}
|
||||
$conn4 = null;
|
||||
|
||||
|
||||
$conn5 = DoConnect($optionsPool);
|
||||
if (!IsPoolConnection($conn5, $connId1, $connId2, $connId3))
|
||||
{
|
||||
echo "A pool connection was expected...\n";
|
||||
}
|
||||
$conn5 = null;
|
||||
|
||||
$conn6 = DoConnect($optionsNotPool);
|
||||
if (IsPoolConnection($conn6, $connId1, $connId2, $connId3))
|
||||
{
|
||||
echo "A pool connection was not expected...\n";
|
||||
}
|
||||
$conn6 = null;
|
||||
|
||||
EndTest($testName);
|
||||
}
|
||||
|
||||
function DoConnect($options)
|
||||
{
|
||||
include 'MsSetup.inc';
|
||||
|
||||
$conn = null;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
if ($dsnMode)
|
||||
{
|
||||
$conn = new PDO("sqlsrv:Server=$server;$options", $uid, $pwd);
|
||||
}
|
||||
else
|
||||
{
|
||||
$conn = new PDO("sqlsrv:Server=$server", $uid, $pwd, $options);
|
||||
}
|
||||
$conn->setAttribute(PDO::SQLSRV_ATTR_ENCODING, PDO::SQLSRV_ENCODING_SYSTEM);
|
||||
}
|
||||
catch (PDOException $e)
|
||||
{
|
||||
$conn = null;
|
||||
TraceEx("\nFailed to connect to $server: ".$e->getMessage(), true);
|
||||
}
|
||||
|
||||
return ($conn);
|
||||
}
|
||||
|
||||
function ConnectionID($conn)
|
||||
{
|
||||
$tsql = "SELECT @@SPID FROM master.dbo.sysprocesses WHERE (program_name='Microsoft PHP')";
|
||||
|
||||
$stmt = ExecuteQuery($conn, $tsql);
|
||||
$connID = $stmt->fetchColumn(0);
|
||||
$stmt->closeCursor();
|
||||
$stmt = null;
|
||||
|
||||
return ($connID);
|
||||
}
|
||||
|
||||
function IsPoolConnection($conn, $Id1, $Id2, $Id3)
|
||||
{
|
||||
$connID = ConnectionID($conn);
|
||||
if (($connID == $Id1) || ($connID == $Id2) || ($connID == $Id3))
|
||||
{
|
||||
return (true);
|
||||
}
|
||||
return (false);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Repro
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
function Repro()
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
ConnectionTest();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
echo $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
Repro();
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Test "PDO Connection Pooling" completed successfully.
|
||||
|
142
test/pdo_sqlsrv/PDO23_ConnPool2.phpt
Normal file
142
test/pdo_sqlsrv/PDO23_ConnPool2.phpt
Normal file
|
@ -0,0 +1,142 @@
|
|||
--TEST--
|
||||
PDO Connection Pooling Test
|
||||
--DESCRIPTION--
|
||||
Checks whether the driver can successfully establish a database connection
|
||||
when an URI-based construct is used.
|
||||
--ENV--
|
||||
PHPT_EXEC=true
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
include 'MsCommon.inc';
|
||||
|
||||
function ConnectionTest($noPasses)
|
||||
{
|
||||
include 'MsSetup.inc';
|
||||
|
||||
$testName = "PDO Connection Pooling";
|
||||
StartTest($testName);
|
||||
|
||||
|
||||
$optionsPool = null;
|
||||
$optionsNotPool = null;
|
||||
|
||||
if ($dsnMode)
|
||||
{
|
||||
$optionsPool = "APP=Microsoft PHP;ConnectionPooling=1;";
|
||||
$optionsNotPool = "APP=Microsoft PHP;ConnectionPooling=0;";
|
||||
}
|
||||
else
|
||||
{
|
||||
$optionsPool = array('APP'=>'Microsoft PHP', 'ConnectionPooling'=>1);
|
||||
$optionsNotPool = array('APP'=>'Microsoft PHP', 'ConnectionPooling'=>0);
|
||||
}
|
||||
|
||||
// Establish a pool connection
|
||||
$conn1 = DoConnect($optionsPool);
|
||||
$conn1ID = ConnectionID($conn1);
|
||||
$conn1 = null;
|
||||
|
||||
// Verifies that non-pool connections have a different id
|
||||
for ($i = 0; $i < $noPasses; $i++)
|
||||
{
|
||||
$conn2 = DoConnect($optionsNotPool);
|
||||
$conn2ID = ConnectionID($conn2);
|
||||
$conn2 = null;
|
||||
if ($conn1ID == $conn2ID)
|
||||
{
|
||||
echo "A different connection id was expected: $conn1ID => $conn2ID\n";
|
||||
break;
|
||||
}
|
||||
$conn2 = null;
|
||||
}
|
||||
|
||||
|
||||
// Verifies that pool connections have the same id
|
||||
for ($i = 0; $i < $noPasses; $i++)
|
||||
{
|
||||
$conn2 = DoConnect($optionsPool);
|
||||
$conn2ID = ConnectionID($conn2);
|
||||
$conn2 = null;
|
||||
if ($conn1ID != $conn2ID)
|
||||
{
|
||||
echo "The same connection id was expected: $conn1ID => $conn2ID\n";
|
||||
break;
|
||||
}
|
||||
$conn2 = null;
|
||||
}
|
||||
EndTest($testName);
|
||||
}
|
||||
|
||||
|
||||
function DoConnect($options)
|
||||
{
|
||||
include 'MsSetup.inc';
|
||||
|
||||
$conn = null;
|
||||
|
||||
try
|
||||
{
|
||||
if ($dsnMode)
|
||||
{
|
||||
$conn = new PDO("sqlsrv:Server=$server;$options", $uid, $pwd);
|
||||
}
|
||||
else
|
||||
{
|
||||
$conn = new PDO("sqlsrv:Server=$server", $uid, $pwd, $options);
|
||||
}
|
||||
$conn->setAttribute(PDO::SQLSRV_ATTR_ENCODING, PDO::SQLSRV_ENCODING_SYSTEM);
|
||||
}
|
||||
catch (PDOException $e)
|
||||
{
|
||||
$conn = null;
|
||||
TraceEx("\nFailed to connect to $server: ".$e->getMessage(), true);
|
||||
}
|
||||
|
||||
return ($conn);
|
||||
}
|
||||
|
||||
function ConnectionID($conn)
|
||||
{
|
||||
$query = "SELECT @@SPID FROM master.dbo.sysprocesses WHERE (program_name='Microsoft PHP')";
|
||||
$connID = null;
|
||||
|
||||
$stmt = $conn->query($query);
|
||||
$row = $stmt->fetch();
|
||||
if ($row)
|
||||
{
|
||||
$connID = $row[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Failed to retrieve connection id\n";
|
||||
}
|
||||
$stmt = null;
|
||||
return ($connID);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Repro
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
function Repro()
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
ConnectionTest(5);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
echo $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
Repro();
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
Test "PDO Connection Pooling" completed successfully.
|
||||
|
80
test/pdo_sqlsrv/PDO24_ErrorCode.phpt
Normal file
80
test/pdo_sqlsrv/PDO24_ErrorCode.phpt
Normal file
|
@ -0,0 +1,80 @@
|
|||
--TEST--
|
||||
PDO Test for PDO::errorCode()
|
||||
--DESCRIPTION--
|
||||
Verification of PDO::errorCode()
|
||||
--ENV--
|
||||
PHPT_EXEC=true
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
include 'MsCommon.inc';
|
||||
|
||||
function CheckErrorCode()
|
||||
{
|
||||
include 'MsSetup.inc';
|
||||
|
||||
$testName = "PDO Connection - Error Code";
|
||||
|
||||
StartTest($testName);
|
||||
|
||||
$conn1 = Connect();
|
||||
CheckError(1, $conn1, '00000');
|
||||
|
||||
// Prepare test table
|
||||
$table1 = $tableName."1";
|
||||
$table2 = $tableName."2";
|
||||
CreateTableEx($conn1, $table1, "id int NOT NULL PRIMARY KEY, label VARCHAR(10)", null);
|
||||
|
||||
// Check errors when executing SELECT queries
|
||||
$stmt1 = $conn1->prepare("SELECT id, label FROM [$table1]");
|
||||
CheckError(2, $conn1);
|
||||
CheckError(3, $stmt1);
|
||||
$stmt1->execute();
|
||||
$stmt2 = &$stmt1;
|
||||
CheckError(4, $stmt1);
|
||||
$stmt1->closeCursor();
|
||||
|
||||
DropTable($conn1, $table1);
|
||||
CheckError(5, $conn1);
|
||||
|
||||
// Cleanup
|
||||
$stmt1 = null;
|
||||
$conn1 = null;
|
||||
|
||||
EndTest($testName);
|
||||
|
||||
}
|
||||
|
||||
function CheckError($offset, &$obj, $expected = '00000')
|
||||
{
|
||||
$code = $obj->errorCode();
|
||||
if (($code != $expected) && (($expected != '00000') || ($code !='')))
|
||||
{
|
||||
printf("[%03d] Expecting error code '%s' got code '%s'\n",
|
||||
$offset, $expected, $code);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Repro
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
function Repro()
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
CheckErrorCode();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
echo $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
Repro();
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
Test "PDO Connection - Error Code" completed successfully.
|
116
test/pdo_sqlsrv/PDO25_ErrorInfo.phpt
Normal file
116
test/pdo_sqlsrv/PDO25_ErrorInfo.phpt
Normal file
|
@ -0,0 +1,116 @@
|
|||
--TEST--
|
||||
PDO Test for PDO::errorInfo()
|
||||
--DESCRIPTION--
|
||||
Verification of PDO::errorInfo()
|
||||
--ENV--
|
||||
PHPT_EXEC=true
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
include 'MsCommon.inc';
|
||||
|
||||
function CheckErrorInfo()
|
||||
{
|
||||
include 'MsSetup.inc';
|
||||
|
||||
$testName = "PDO Connection - Error Info";
|
||||
StartTest($testName);
|
||||
|
||||
$conn1 = Connect();
|
||||
CheckError(1, $conn1, '00000');
|
||||
|
||||
// Prepare test table
|
||||
$table1 = $tableName."1";
|
||||
$table2 = $tableName."2";
|
||||
CreateTableEx($conn1, $table1, "id int NOT NULL PRIMARY KEY, label VARCHAR(10)", null);
|
||||
|
||||
// Check errors when executing SELECT queries
|
||||
$stmt1 = $conn1->prepare("SELECT id, label FROM [$table1]");
|
||||
CheckError(2, $conn1);
|
||||
CheckError(3, $stmt1);
|
||||
$stmt1->execute();
|
||||
$stmt2 = &$stmt1;
|
||||
CheckError(4, $stmt1);
|
||||
$stmt1->closeCursor();
|
||||
|
||||
|
||||
//DropTable($conn1, $table1);
|
||||
@$stmt1->execute();
|
||||
CheckError(5, $conn1);
|
||||
//CheckError(6, $stmt1, '42S02');
|
||||
//CheckError(7, $stmt2, '42S02');
|
||||
$stmt1->closeCursor();
|
||||
|
||||
DropTable($conn1, $table2);
|
||||
$conn2 = &$conn1;
|
||||
//@$conn1->query("SELECT id, label FROM [$table2]");
|
||||
//CheckError(8, $conn1, '42S02');
|
||||
//CheckError(9, $conn2, '42S02');
|
||||
|
||||
|
||||
CreateTableEx($conn1, $table1, "id int NOT NULL PRIMARY KEY, label VARCHAR(10)", null);
|
||||
$stmt1 = $conn1->query("SELECT id, label FROM [$table1]");
|
||||
CheckError(10, $conn1);
|
||||
CheckError(11, $stmt1);
|
||||
$stmt1->closeCursor();
|
||||
|
||||
// @$conn1->query("SELECT id, label FROM [$table2]");
|
||||
// CheckError(12, $conn1, '42S02');
|
||||
// CheckError(13, $conn2, '42S02');
|
||||
CheckError(14, $stmt1);
|
||||
|
||||
// Cleanup
|
||||
DropTable($conn1, $table1);
|
||||
$stmt1 = null;
|
||||
$conn1 = null;
|
||||
|
||||
EndTest($testName);
|
||||
}
|
||||
|
||||
|
||||
function CheckError($offset, &$obj, $expected = '00000')
|
||||
{
|
||||
$info = $obj->errorInfo();
|
||||
$code = $info[0];
|
||||
|
||||
if (($code != $expected) && (($expected != '00000') || ($code != '')))
|
||||
{
|
||||
printf("[%03d] Expecting error code '%s' got code '%s'\n",
|
||||
$offset, $expected, $code);
|
||||
}
|
||||
if ($expected != '00000')
|
||||
{
|
||||
if (!isset($info[1]) || ($info[1] == ''))
|
||||
{
|
||||
printf("[%03d] Driver-specific error code not set\n", $offset);
|
||||
}
|
||||
if (!isset($info[2]) || ($info[2] == ''))
|
||||
{
|
||||
printf("[%03d] Driver-specific error message.not set\n", $offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Repro
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
function Repro()
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
CheckErrorInfo();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
echo $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
Repro();
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
Test "PDO Connection - Error Info" completed successfully.
|
77
test/pdo_sqlsrv/PDO26_ConnAttr.phpt
Normal file
77
test/pdo_sqlsrv/PDO26_ConnAttr.phpt
Normal file
|
@ -0,0 +1,77 @@
|
|||
--TEST--
|
||||
PDO Info Test
|
||||
--DESCRIPTION--
|
||||
Verifies the functionality of "getAttribute”.
|
||||
--ENV--
|
||||
PHPT_EXEC=true
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
include 'MsCommon.inc';
|
||||
|
||||
function AttrTest()
|
||||
{
|
||||
include 'MsSetup.inc';
|
||||
|
||||
$testName = "PDO Connection - Attribute Info";
|
||||
StartTest($testName);
|
||||
|
||||
$conn1 = Connect();
|
||||
ShowInfo($conn1);
|
||||
$conn1 = null;
|
||||
|
||||
EndTest($testName);
|
||||
}
|
||||
|
||||
function ShowInfo($conn)
|
||||
{
|
||||
$attributes = array("AUTOCOMMIT", // Not supported
|
||||
"CASE", // 0
|
||||
"CLIENT_VERSION", // array
|
||||
"CONNECTION_STATUS", // Not supported
|
||||
"DRIVER_NAME", // sqlsrv
|
||||
"ERRMODE", // 0
|
||||
"ORACLE_NULLS", // 0
|
||||
"PERSISTENT", // false
|
||||
"PREFETCH", // Not supported
|
||||
"SERVER_INFO", // array
|
||||
"SERVER_VERSION", // string
|
||||
"STATEMENT_CLASS", // array
|
||||
"STRINGIFY_FETCHES", // false
|
||||
"TIMEOUT"); // Not supported
|
||||
|
||||
foreach ($attributes as $val)
|
||||
{
|
||||
$att = "PDO::ATTR_$val";
|
||||
$attKey = constant($att);
|
||||
$attVal = $conn->getAttribute($attKey);
|
||||
|
||||
Trace("$att ($attKey): [$attVal]\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Repro
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
function Repro()
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
AttrTest();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
echo $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
Repro();
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
SQLSTATE[IM001]: Driver does not support this function: driver does not support that attribute
|
77
test/pdo_sqlsrv/PDO27_ReadOnlyAttr.phpt
Normal file
77
test/pdo_sqlsrv/PDO27_ReadOnlyAttr.phpt
Normal file
|
@ -0,0 +1,77 @@
|
|||
--TEST--
|
||||
PDO Test for read-only attributes
|
||||
--DESCRIPTION--
|
||||
Verification of read-only attributes
|
||||
--ENV--
|
||||
PHPT_EXEC=true
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
include 'MsCommon.inc';
|
||||
|
||||
function ReadOnly()
|
||||
{
|
||||
include 'MsSetup.inc';
|
||||
|
||||
$testName = "PDO Connection - Attribute";
|
||||
StartTest($testName);
|
||||
|
||||
$conn1 = Connect();
|
||||
$conn1->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
|
||||
|
||||
CheckAttribute($conn1, "PDO::ATTR_CLIENT_VERSION");
|
||||
CheckAttribute($conn1, "PDO::ATTR_DRIVER_NAME");
|
||||
CheckAttribute($conn1, "PDO::ATTR_SERVER_INFO");
|
||||
CheckAttribute($conn1, "PDO::ATTR_SERVER_VERSION");
|
||||
|
||||
// Cleanup
|
||||
$conn1 = null;
|
||||
|
||||
EndTest($testName);
|
||||
}
|
||||
|
||||
|
||||
function CheckAttribute($conn, $attName)
|
||||
{
|
||||
$att = constant($attName);
|
||||
|
||||
// Attribute value is a non-empty string
|
||||
$value1 = $conn->getAttribute($att);
|
||||
|
||||
// Attribute is read-only
|
||||
if ($conn->setAttribute($att, $value1) !== false)
|
||||
{
|
||||
printf("Attribute $attName must be read-only\n");
|
||||
}
|
||||
|
||||
// Attribute value should not change
|
||||
$value2 = $conn->getAttribute($att);
|
||||
if ($value2 !== $value1)
|
||||
{
|
||||
printf("Value of attribute $attName should not change from '%s' to '%s'\n", $value1, $value2);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Repro
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
function Repro()
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
ReadOnly();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
echo $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
Repro();
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
Test "PDO Connection - Attribute" completed successfully.
|
149
test/pdo_sqlsrv/PDO28_CaseAttr.phpt
Normal file
149
test/pdo_sqlsrv/PDO28_CaseAttr.phpt
Normal file
|
@ -0,0 +1,149 @@
|
|||
--TEST--
|
||||
PDO Test for PDO::ATTR_CASE
|
||||
--DESCRIPTION--
|
||||
Verification of fetch behavior when using PDO::ATTR_CASE.
|
||||
--ENV--
|
||||
PHPT_EXEC=true
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
include 'MsCommon.inc';
|
||||
|
||||
function ExecStmt()
|
||||
{
|
||||
include 'MsSetup.inc';
|
||||
|
||||
$testName = "PDO Connection - Case Attribute";
|
||||
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);
|
||||
|
||||
// Retrieve data as array with no change on columns case
|
||||
$conn1->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL);
|
||||
$stmt1 = PrepareQuery($conn1, "SELECT * FROM [$tableName]");
|
||||
$stmt1->execute();
|
||||
var_dump($stmt1->fetchAll(PDO::FETCH_ASSOC));
|
||||
$stmt1->closeCursor();
|
||||
|
||||
// Retrieve data as array with lower case columns
|
||||
$conn1->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
|
||||
$stmt1 = PrepareQuery($conn1, "SELECT * FROM [$tableName]");
|
||||
$stmt1->execute();
|
||||
var_dump($stmt1->fetchAll(PDO::FETCH_ASSOC));
|
||||
$stmt1->closeCursor();
|
||||
|
||||
// Retrieve data as array with upper case columns
|
||||
$conn1->setAttribute(PDO::ATTR_CASE, PDO::CASE_UPPER);
|
||||
$stmt1 = PrepareQuery($conn1, "SELECT * FROM [$tableName]");
|
||||
$stmt1->execute();
|
||||
var_dump($stmt1->fetchAll(PDO::FETCH_ASSOC));
|
||||
$stmt1->closeCursor();
|
||||
|
||||
// Cleanup
|
||||
DropTable($conn1, $tableName);
|
||||
$stmt1 = null;
|
||||
$conn1 = null;
|
||||
|
||||
EndTest($testName);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Repro
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
function Repro()
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
ExecStmt();
|
||||
}
|
||||
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"
|
||||
}
|
||||
}
|
||||
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"
|
||||
}
|
||||
}
|
||||
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 Connection - Case Attribute" completed successfully.
|
98
test/pdo_sqlsrv/PDO29_ConnInterface.phpt
Normal file
98
test/pdo_sqlsrv/PDO29_ConnInterface.phpt
Normal file
|
@ -0,0 +1,98 @@
|
|||
--TEST--
|
||||
PDO Interface Test
|
||||
--DESCRIPTION--
|
||||
Verifies the compliance of the PDO API Interface.
|
||||
--ENV--
|
||||
PHPT_EXEC=true
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
include 'MsCommon.inc';
|
||||
|
||||
function ConnInfo()
|
||||
{
|
||||
include 'MsSetup.inc';
|
||||
|
||||
$testName = "PDO - Interface";
|
||||
StartTest($testName);
|
||||
|
||||
$conn1 = Connect();
|
||||
|
||||
CheckInterface($conn1);
|
||||
$conn1 = null;
|
||||
|
||||
EndTest($testName);
|
||||
}
|
||||
|
||||
function CheckInterface($conn)
|
||||
{
|
||||
$expected = array(
|
||||
'getAvailableDrivers' => true,
|
||||
'__construct' => true,
|
||||
'errorCode' => true,
|
||||
'errorInfo' => true,
|
||||
'getAttribute' => true,
|
||||
'setAttribute' => true,
|
||||
'beginTransaction' => true,
|
||||
'commit' => true,
|
||||
'rollBack' => true,
|
||||
'exec' => true,
|
||||
'query' => true,
|
||||
'prepare' => true,
|
||||
'lastInsertId' => true,
|
||||
'quote' => true,
|
||||
'__wakeup' => true,
|
||||
'__sleep' => true,
|
||||
'inTransaction' => true,
|
||||
);
|
||||
$classname = get_class($conn);
|
||||
$methods = get_class_methods($classname);
|
||||
foreach ($methods as $k => $method)
|
||||
{
|
||||
if (isset($expected[$method]))
|
||||
{
|
||||
unset($expected[$method]);
|
||||
unset($methods[$k]);
|
||||
}
|
||||
if ($method == $classname)
|
||||
{
|
||||
unset($expected['__construct']);
|
||||
unset($methods[$k]);
|
||||
}
|
||||
}
|
||||
if (!empty($expected))
|
||||
{
|
||||
printf("Dumping missing class methods\n");
|
||||
var_dump($expected);
|
||||
}
|
||||
if (!empty($methods))
|
||||
{
|
||||
printf("Found more methods than expected, dumping list\n");
|
||||
var_dump($methods);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Repro
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
function Repro()
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
ConnInfo();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
echo $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
Repro();
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
Test "PDO - Interface" completed successfully.
|
93
test/pdo_sqlsrv/PDO30_Exec.phpt
Normal file
93
test/pdo_sqlsrv/PDO30_Exec.phpt
Normal file
|
@ -0,0 +1,93 @@
|
|||
--TEST--
|
||||
PDO Exec Test
|
||||
--DESCRIPTION--
|
||||
Basic verification for PDO::exec().
|
||||
--ENV--
|
||||
PHPT_EXEC=true
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
include 'MsCommon.inc';
|
||||
|
||||
function ExecStmt()
|
||||
{
|
||||
include 'MsSetup.inc';
|
||||
|
||||
$testName = "PDO Connection - Exec";
|
||||
StartTest($testName);
|
||||
|
||||
$conn1 = Connect();
|
||||
|
||||
$dbName1 = $databaseName."1";
|
||||
$dbName2 = $databaseName."2";
|
||||
CreateDB($conn1, $dbName1);
|
||||
DoExec(1, $conn1, "ALTER DATABASE [$dbName1] MODIFY NAME = [$dbName2]", 0);
|
||||
DoExec(2, $conn1, "DROP DATABASE [$dbName2]", 0);
|
||||
|
||||
CreateTableEx($conn1, $tableName, "id INT, val CHAR(10)", null);
|
||||
DoExec(3, $conn1, "CREATE INDEX [$tableIndex] ON [$tableName](id)", 0);
|
||||
DoExec(4, $conn1, "DROP INDEX [$tableIndex] ON [$tableName]", 0);
|
||||
DoExec(5, $conn1, "ALTER TABLE [$tableName] DROP COLUMN id", 0);
|
||||
DoExec(6, $conn1, "ALTER TABLE [$tableName] ADD id INT", 0);
|
||||
DoExec(7, $conn1, "INSERT INTO [$tableName] (id, val) VALUES (1, 'ABC')", 1);
|
||||
|
||||
// Cleanup
|
||||
DropTable($conn1, $tableName);
|
||||
DropDB($conn1, $dbName1);
|
||||
$stmt1 = null;
|
||||
$conn1 = null;
|
||||
|
||||
EndTest($testName);
|
||||
}
|
||||
|
||||
|
||||
function DoExec($offset, &$conn, $tsql, $expected)
|
||||
{
|
||||
$ret = false;
|
||||
try
|
||||
{
|
||||
$actual = @$conn->exec($tsql);
|
||||
if ($actual === $expected)
|
||||
{
|
||||
$ret = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("[%03d] Expecting '%s' (%s) instead of '%s' (%s) when executing '%s', [%s] %s\n",
|
||||
$offset, $expected, gettype($expected), $actual, gettype($actual),
|
||||
$tsql, $conn->errorCode(), implode(' ', $conn->errorInfo()));
|
||||
}
|
||||
}
|
||||
catch (PDOException $e)
|
||||
{
|
||||
printf("[%03d] Execution of '%s' has failed, [%s] %s\n",
|
||||
$offset, $tsql, $conn->errorCode(), implode(' ', $conn->errorInfo()));
|
||||
}
|
||||
return ($ret);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Repro
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
function Repro()
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
ExecStmt();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
echo $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
Repro();
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
Test "PDO Connection - Exec" completed successfully.
|
132
test/pdo_sqlsrv/PDO31_Statement.phpt
Normal file
132
test/pdo_sqlsrv/PDO31_Statement.phpt
Normal file
|
@ -0,0 +1,132 @@
|
|||
--TEST--
|
||||
PDO Basic Statement Test
|
||||
--DESCRIPTION--
|
||||
Basic verification for PDOStatement.
|
||||
--ENV--
|
||||
PHPT_EXEC=true
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
include 'MsCommon.inc';
|
||||
|
||||
function ExecStmt()
|
||||
{
|
||||
include 'MsSetup.inc';
|
||||
|
||||
$testName = "PDO Statement";
|
||||
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 prepared query
|
||||
$stmt1 = ExecuteQueryEx($conn1, $tsql, false);
|
||||
$stmt1->setFetchMode(PDO::FETCH_NUM);
|
||||
foreach ($stmt1 as $data)
|
||||
{
|
||||
var_dump($data);
|
||||
}
|
||||
unset($stmt1);
|
||||
|
||||
// Testing direct query
|
||||
$stmt1 = $conn1->query($tsql, PDO::FETCH_CLASS, 'Test');
|
||||
foreach ($stmt1 as $data)
|
||||
{
|
||||
var_dump($data);
|
||||
}
|
||||
unset($stmt1);
|
||||
|
||||
$stmt1 = $conn1->query($tsql, PDO::FETCH_CLASS, 'Test', array('WOW'));
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Repro
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
function Repro()
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
ExecStmt();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
echo $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
Repro();
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(1) "A"
|
||||
[1]=>
|
||||
string(6) "Group1"
|
||||
}
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(1) "B"
|
||||
[1]=>
|
||||
string(6) "Group2"
|
||||
}
|
||||
Test::__construct(N/A)
|
||||
object(Test)#%d (2) {
|
||||
["val"]=>
|
||||
string(1) "A"
|
||||
["grp"]=>
|
||||
string(6) "Group1"
|
||||
}
|
||||
Test::__construct(N/A)
|
||||
object(Test)#%d (2) {
|
||||
["val"]=>
|
||||
string(1) "B"
|
||||
["grp"]=>
|
||||
string(6) "Group2"
|
||||
}
|
||||
Test::__construct(WOW)
|
||||
object(Test)#%d (2) {
|
||||
["val"]=>
|
||||
string(1) "A"
|
||||
["grp"]=>
|
||||
string(6) "Group1"
|
||||
}
|
||||
Test::__construct(WOW)
|
||||
object(Test)#%d (2) {
|
||||
["val"]=>
|
||||
string(1) "B"
|
||||
["grp"]=>
|
||||
string(6) "Group2"
|
||||
}
|
||||
Test "PDO Statement" completed successfully.
|
100
test/pdo_sqlsrv/PDO32_StmtInterface.phpt
Normal file
100
test/pdo_sqlsrv/PDO32_StmtInterface.phpt
Normal file
|
@ -0,0 +1,100 @@
|
|||
--TEST--
|
||||
PDOStatement Interface Test
|
||||
--DESCRIPTION--
|
||||
Verifies the compliance of the PDOStatement API Interface.
|
||||
--ENV--
|
||||
PHPT_EXEC=true
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
include 'MsCommon.inc';
|
||||
|
||||
function StmtInfo()
|
||||
{
|
||||
include 'MsSetup.inc';
|
||||
|
||||
$testName = "PDOStatement - Interface";
|
||||
StartTest($testName);
|
||||
|
||||
$conn1 = Connect();
|
||||
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, val VARCHAR(10)", null);
|
||||
$stmt1 = ExecuteQuery($conn1, "SELECT * FROM [$tableName]");
|
||||
|
||||
CheckInterface($stmt1);
|
||||
$stmt1 = null;
|
||||
$conn1 = null;
|
||||
|
||||
EndTest($testName);
|
||||
}
|
||||
|
||||
function CheckInterface($stmt)
|
||||
{
|
||||
$expected = array(
|
||||
'errorCode' => true,
|
||||
'errorInfo' => true,
|
||||
'getAttribute' => true,
|
||||
'setAttribute' => true,
|
||||
'debugDumpParams' => true,
|
||||
'bindColumn' => true,
|
||||
'bindParam' => true,
|
||||
'bindValue' => true,
|
||||
'closeCursor' => true,
|
||||
'columnCount' => true,
|
||||
'execute' => true,
|
||||
'setFetchMode' => true,
|
||||
'fetch' => true,
|
||||
'fetchAll' => true,
|
||||
'fetchColumn' => true,
|
||||
'fetchObject' => true,
|
||||
'getColumnMeta' => true,
|
||||
'nextRowset' => true,
|
||||
'rowCount' => true,
|
||||
'__wakeup' => true,
|
||||
'__sleep' => true,
|
||||
);
|
||||
$classname = get_class($stmt);
|
||||
$methods = get_class_methods($classname);
|
||||
foreach ($methods as $k => $method)
|
||||
{
|
||||
if (isset($expected[$method]))
|
||||
{
|
||||
unset($expected[$method]);
|
||||
unset($methods[$k]);
|
||||
}
|
||||
}
|
||||
if (!empty($expected))
|
||||
{
|
||||
printf("Dumping missing class methods\n");
|
||||
var_dump($expected);
|
||||
}
|
||||
if (!empty($methods))
|
||||
{
|
||||
printf("Found more methods than expected, dumping list\n");
|
||||
var_dump($methods);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Repro
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
function Repro()
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
StmtInfo();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
echo $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
Repro();
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
Test "PDOStatement - Interface" completed successfully.
|
105
test/pdo_sqlsrv/PDO33_Execute.phpt
Normal file
105
test/pdo_sqlsrv/PDO33_Execute.phpt
Normal file
|
@ -0,0 +1,105 @@
|
|||
--TEST--
|
||||
PDO Statement Execution Test
|
||||
--DESCRIPTION--
|
||||
Basic verification for "PDOStatement::execute()".
|
||||
--ENV--
|
||||
PHPT_EXEC=true
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
include 'MsCommon.inc';
|
||||
|
||||
function ExecStmt()
|
||||
{
|
||||
include 'MsSetup.inc';
|
||||
|
||||
$testName = "PDO Statement - Execute";
|
||||
StartTest($testName);
|
||||
|
||||
$conn1 = Connect();
|
||||
|
||||
// Prepare test table
|
||||
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'),
|
||||
array('40', 'Jkl', 'qpo'),
|
||||
array('50', 'Mno', 'nml'),
|
||||
array('60', 'Pqr', 'kji'));
|
||||
|
||||
// Insert using question mark placeholders
|
||||
$stmt1 = PrepareQuery($conn1, "INSERT INTO [$tableName] VALUES(?, ?, ?)");
|
||||
foreach ($data as $row)
|
||||
{
|
||||
$stmt1->execute($row);
|
||||
}
|
||||
unset($stmt1);
|
||||
|
||||
// Count inserted rows
|
||||
$stmt2 = PrepareQuery($conn1, "SELECT COUNT(id) FROM [$tableName]");
|
||||
$stmt2->execute();
|
||||
$num = $stmt2->fetchColumn();
|
||||
echo 'There are ' . $num . " rows in the table.\n";
|
||||
$stmt2->closeCursor();
|
||||
|
||||
// Insert using named parameters
|
||||
$stmt1 = PrepareQuery($conn1, "INSERT INTO [$tableName] VALUES(:first, :second, :third)");
|
||||
foreach ($data as $row)
|
||||
{
|
||||
$stmt1->execute(array(':first'=>($row[0] + 5), ':second'=>$row[1], ':third'=>$row[2]));
|
||||
}
|
||||
unset($stmt1);
|
||||
|
||||
$stmt2->execute();
|
||||
$num = $stmt2->fetchColumn();
|
||||
unset($stmt2);
|
||||
echo 'There are ' . $num . " rows in the table.\n";
|
||||
|
||||
// Fetch
|
||||
$stmt1 = PrepareQuery($conn1, "SELECT TOP(1) :param FROM [$tableName] ORDER BY id ASC");
|
||||
$stmt1->execute(array(':param' => 'ID'));
|
||||
var_dump($stmt1->fetchAll(PDO::FETCH_ASSOC));
|
||||
$stmt1->closeCursor();
|
||||
|
||||
// Cleanup
|
||||
DropTable($conn1, $tableName);
|
||||
$stmt1 = null;
|
||||
$stmt2 = null;
|
||||
$conn1 = null;
|
||||
|
||||
EndTest($testName);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Repro
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
function Repro()
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
ExecStmt();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
echo $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
Repro();
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
There are 6 rows in the table.
|
||||
There are 12 rows in the table.
|
||||
array(1) {
|
||||
[0]=>
|
||||
array(1) {
|
||||
[""]=>
|
||||
string(2) "ID"
|
||||
}
|
||||
}
|
||||
Test "PDO Statement - Execute" completed successfully.
|
75
test/pdo_sqlsrv/PDO34_ColumnCount.phpt
Normal file
75
test/pdo_sqlsrv/PDO34_ColumnCount.phpt
Normal file
|
@ -0,0 +1,75 @@
|
|||
--TEST--
|
||||
PDO Columns Count Test
|
||||
--DESCRIPTION--
|
||||
Basic verification for "PDOStatement::columnCount()".
|
||||
--ENV--
|
||||
PHPT_EXEC=true
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
include 'MsCommon.inc';
|
||||
|
||||
function ExecStmt()
|
||||
{
|
||||
include 'MsSetup.inc';
|
||||
|
||||
$testName = "PDO Statement - Column Count";
|
||||
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(16)", null);
|
||||
InsertRowEx($conn1, $tableName, $dataCols, "1, 'A', 'A'", null);
|
||||
InsertRowEx($conn1, $tableName, $dataCols, "2, 'B', 'B'", null);
|
||||
InsertRowEx($conn1, $tableName, $dataCols, "3, 'C', 'C'", null);
|
||||
|
||||
$tsql1 = "SELECT id, val FROM [$tableName]";
|
||||
$tsql2 = "SELECT id, val, val2 FROM [$tableName]";
|
||||
$tsql3 = "SELECT COUNT(*) FROM [$tableName]";
|
||||
|
||||
// Testing with direct query
|
||||
foreach (array($tsql1, $tsql2, $tsql3) as $tsql)
|
||||
{
|
||||
$stmt1 = ExecuteQuery($conn1, $tsql);
|
||||
$res = $stmt1->columnCount();
|
||||
echo "Counted $res columns.\n";
|
||||
unset($stmt1);
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
DropTable($conn1, $tableName);
|
||||
$stmt1 = null;
|
||||
$conn1 = null;
|
||||
|
||||
EndTest($testName);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Repro
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
function Repro()
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
ExecStmt();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
echo $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
Repro();
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Counted 2 columns.
|
||||
Counted 3 columns.
|
||||
Counted 1 columns.
|
||||
Test "PDO Statement - Column Count" completed successfully.
|
157
test/pdo_sqlsrv/PDO35_ColumnMeta.phpt
Normal file
157
test/pdo_sqlsrv/PDO35_ColumnMeta.phpt
Normal file
|
@ -0,0 +1,157 @@
|
|||
--TEST--
|
||||
PDO Column Metadata Test
|
||||
--DESCRIPTION--
|
||||
Verification for "PDOStatenent::getColumnMetadata".
|
||||
--ENV--
|
||||
PHPT_EXEC=true
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
include 'MsCommon.inc';
|
||||
|
||||
function Fetch()
|
||||
{
|
||||
include 'MsSetup.inc';
|
||||
|
||||
$testName = "PDO Statement - Column Metadata";
|
||||
StartTest($testName);
|
||||
|
||||
$conn1 = Connect();
|
||||
|
||||
// Prepare test table
|
||||
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'),
|
||||
array('40', 'Jkl', 'qpo'),
|
||||
array('50', 'Mno', 'nml'),
|
||||
array('60', 'Pqr', 'kji'));
|
||||
|
||||
// Insert using question mark placeholders
|
||||
$stmt1 = PrepareQuery($conn1, "INSERT INTO [$tableName] VALUES(?, ?, ?)");
|
||||
foreach ($data as $row)
|
||||
{
|
||||
$stmt1->execute($row);
|
||||
}
|
||||
unset($stmt1);
|
||||
|
||||
// Retrieve column metadata via a SELECT query
|
||||
$stmt1 = ExecuteQuery($conn1, "SELECT id, val, val2 FROM [$tableName]");
|
||||
$md = $stmt1->getColumnMeta(0);
|
||||
var_dump($md);
|
||||
$md = $stmt1->getColumnMeta(1);
|
||||
var_dump($md);
|
||||
$md = $stmt1->getColumnMeta(2);
|
||||
var_dump($md);
|
||||
unset($stmt1);
|
||||
|
||||
// Retrieve column metadata as returned by a COUNT query
|
||||
$stmt1 = ExecuteQuery($conn1, "SELECT COUNT(*) FROM [$tableName]");
|
||||
$md = $stmt1->getColumnMeta(0);
|
||||
var_dump($md);
|
||||
|
||||
|
||||
// Cleanup
|
||||
DropTable($conn1, $tableName);
|
||||
$stmt1 = null;
|
||||
$conn1 = null;
|
||||
|
||||
EndTest($testName);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Repro
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
function Repro()
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
Fetch();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
echo $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
Repro();
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
array(8) {
|
||||
["flags"]=>
|
||||
int(0)
|
||||
["sqlsrv:decl_type"]=>
|
||||
string(3) "int"
|
||||
["native_type"]=>
|
||||
string(6) "string"
|
||||
["table"]=>
|
||||
string(0) ""
|
||||
["pdo_type"]=>
|
||||
int(2)
|
||||
["name"]=>
|
||||
string(2) "id"
|
||||
["len"]=>
|
||||
int(10)
|
||||
["precision"]=>
|
||||
int(0)
|
||||
}
|
||||
array(8) {
|
||||
["flags"]=>
|
||||
int(0)
|
||||
["sqlsrv:decl_type"]=>
|
||||
string(7) "varchar"
|
||||
["native_type"]=>
|
||||
string(6) "string"
|
||||
["table"]=>
|
||||
string(0) ""
|
||||
["pdo_type"]=>
|
||||
int(2)
|
||||
["name"]=>
|
||||
string(3) "val"
|
||||
["len"]=>
|
||||
int(10)
|
||||
["precision"]=>
|
||||
int(0)
|
||||
}
|
||||
array(8) {
|
||||
["flags"]=>
|
||||
int(0)
|
||||
["sqlsrv:decl_type"]=>
|
||||
string(7) "varchar"
|
||||
["native_type"]=>
|
||||
string(6) "string"
|
||||
["table"]=>
|
||||
string(0) ""
|
||||
["pdo_type"]=>
|
||||
int(2)
|
||||
["name"]=>
|
||||
string(4) "val2"
|
||||
["len"]=>
|
||||
int(16)
|
||||
["precision"]=>
|
||||
int(0)
|
||||
}
|
||||
array(8) {
|
||||
["flags"]=>
|
||||
int(0)
|
||||
["sqlsrv:decl_type"]=>
|
||||
string(3) "int"
|
||||
["native_type"]=>
|
||||
string(6) "string"
|
||||
["table"]=>
|
||||
string(0) ""
|
||||
["pdo_type"]=>
|
||||
int(2)
|
||||
["name"]=>
|
||||
string(0) ""
|
||||
["len"]=>
|
||||
int(10)
|
||||
["precision"]=>
|
||||
int(0)
|
||||
}
|
||||
Test "PDO Statement - Column Metadata" completed successfully.
|
85
test/pdo_sqlsrv/PDO36_RowCount.phpt
Normal file
85
test/pdo_sqlsrv/PDO36_RowCount.phpt
Normal file
|
@ -0,0 +1,85 @@
|
|||
--TEST--
|
||||
PDO Row Count Test
|
||||
--DESCRIPTION--
|
||||
Verification for "PDOStatement::rowCount()".
|
||||
--ENV--
|
||||
PHPT_EXEC=true
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
include 'MsCommon.inc';
|
||||
|
||||
function RowCountTest()
|
||||
{
|
||||
include 'MsSetup.inc';
|
||||
|
||||
$testName = "PDO Statement - Row Count";
|
||||
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);
|
||||
|
||||
// Check row count
|
||||
$tsql1 = "SELECT id FROM [$tableName] WHERE 1 = 0";
|
||||
//CheckRowCount($conn1, $tsql1, 0);
|
||||
|
||||
$tsql2 = "SELECT id FROM [$tableName] WHERE id = 1";
|
||||
CheckRowCount($conn1, $tsql2, -1);
|
||||
|
||||
$tsql3 = "INSERT INTO [$tableName] ($dataCols) VALUES (7, 'g')";
|
||||
CheckRowCount($conn1, $tsql3, 1);
|
||||
|
||||
$tsql3 = "DELETE FROM [$tableName]";
|
||||
CheckRowCount($conn1, $tsql3, 7);
|
||||
|
||||
// Cleanup
|
||||
DropTable($conn1, $tableName);
|
||||
$conn1 = null;
|
||||
|
||||
EndTest($testName);
|
||||
}
|
||||
|
||||
function CheckRowCount($conn, $tsql, $rows)
|
||||
{
|
||||
$stmt = ExecuteQuery($conn, $tsql);
|
||||
$count = $stmt->rowCount();
|
||||
if ($count !== $rows)
|
||||
{
|
||||
printf("Unexpected row count: $count instead of $rows\n");
|
||||
}
|
||||
unset($stmt);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Repro
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
function Repro()
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
RowCountTest();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
echo $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
Repro();
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
Test "PDO Statement - Row Count" completed successfully.
|
133
test/pdo_sqlsrv/PDO37_FetchMode.phpt
Normal file
133
test/pdo_sqlsrv/PDO37_FetchMode.phpt
Normal file
|
@ -0,0 +1,133 @@
|
|||
--TEST--
|
||||
PDO Fetch Mode Test
|
||||
--DESCRIPTION--
|
||||
Basic verification for "PDOStatement::setFetchMode()”.
|
||||
--ENV--
|
||||
PHPT_EXEC=true
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
include 'MsCommon.inc';
|
||||
|
||||
function FetchMode()
|
||||
{
|
||||
include 'MsSetup.inc';
|
||||
|
||||
$testName = "PDO Statement - Set Fetch Mode";
|
||||
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);
|
||||
|
||||
// Execute test
|
||||
$tsql = "SELECT val, grp FROM [$tableName]";
|
||||
|
||||
$stmt1 = $conn1->query($tsql, PDO::FETCH_NUM);
|
||||
var_dump($stmt1->fetchAll());
|
||||
unset($stmt1);
|
||||
|
||||
$stmt1 = $conn1->query($tsql, PDO::FETCH_CLASS, 'Test');
|
||||
var_dump($stmt1->fetchAll());
|
||||
unset($stmt1);
|
||||
|
||||
$stmt1 = $conn1->query($tsql, PDO::FETCH_NUM);
|
||||
$stmt1->setFetchMode(PDO::FETCH_CLASS, 'Test', array('Changed'));
|
||||
var_dump($stmt1->fetchAll());
|
||||
|
||||
// Cleanup
|
||||
DropTable($conn1, $tableName);
|
||||
$stmt1 = null;
|
||||
$conn1 = null;
|
||||
|
||||
EndTest($testName);
|
||||
}
|
||||
|
||||
class Test
|
||||
{
|
||||
function __construct($name = 'N/A')
|
||||
{
|
||||
echo __METHOD__ . "($name)\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Repro
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
function Repro()
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
FetchMode();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
echo $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
Repro();
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
array(2) {
|
||||
[0]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(1) "A"
|
||||
[1]=>
|
||||
string(6) "Group1"
|
||||
}
|
||||
[1]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
string(1) "B"
|
||||
[1]=>
|
||||
string(6) "Group2"
|
||||
}
|
||||
}
|
||||
Test::__construct(N/A)
|
||||
Test::__construct(N/A)
|
||||
array(2) {
|
||||
[0]=>
|
||||
object(Test)#%d (2) {
|
||||
["val"]=>
|
||||
string(1) "A"
|
||||
["grp"]=>
|
||||
string(6) "Group1"
|
||||
}
|
||||
[1]=>
|
||||
object(Test)#%d (2) {
|
||||
["val"]=>
|
||||
string(1) "B"
|
||||
["grp"]=>
|
||||
string(6) "Group2"
|
||||
}
|
||||
}
|
||||
Test::__construct(Changed)
|
||||
Test::__construct(Changed)
|
||||
array(2) {
|
||||
[0]=>
|
||||
object(Test)#%d (2) {
|
||||
["val"]=>
|
||||
string(1) "A"
|
||||
["grp"]=>
|
||||
string(6) "Group1"
|
||||
}
|
||||
[1]=>
|
||||
object(Test)#%d (2) {
|
||||
["val"]=>
|
||||
string(1) "B"
|
||||
["grp"]=>
|
||||
string(6) "Group2"
|
||||
}
|
||||
}
|
||||
Test "PDO Statement - Set Fetch Mode" completed successfully.
|
273
test/pdo_sqlsrv/PDO38_FetchBound.phpt
Normal file
273
test/pdo_sqlsrv/PDO38_FetchBound.phpt
Normal file
|
@ -0,0 +1,273 @@
|
|||
--TEST--
|
||||
PDO Fetch Bound Test
|
||||
--DESCRIPTION--
|
||||
Verification for "PDOStatenent::fetch(PDO::FETCH_BOUND)".
|
||||
--ENV--
|
||||
PHPT_EXEC=true
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
include 'MsCommon.inc';
|
||||
|
||||
function Fetch()
|
||||
{
|
||||
include 'MsSetup.inc';
|
||||
|
||||
$testName = "PDO Statement - Fetch Bound";
|
||||
StartTest($testName);
|
||||
|
||||
$conn1 = Connect();
|
||||
|
||||
// Prepare test table
|
||||
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'),
|
||||
array('40', 'Jkl', 'qpo'),
|
||||
array('50', 'Mno', 'nml'),
|
||||
array('60', 'Pqr', 'kji'));
|
||||
|
||||
// Insert using question mark placeholders
|
||||
$stmt1 = PrepareQuery($conn1, "INSERT INTO [$tableName] VALUES(?, ?, ?)");
|
||||
foreach ($data as $row)
|
||||
{
|
||||
$stmt1->execute($row);
|
||||
}
|
||||
unset($stmt1);
|
||||
|
||||
// Count inserted rows
|
||||
$stmt2 = PrepareQuery($conn1, "SELECT COUNT(id) FROM [$tableName]");
|
||||
$stmt2->execute();
|
||||
$num = $stmt2->fetchColumn();
|
||||
echo 'There are ' . $num . " rows in the table.\n";
|
||||
$stmt2->closeCursor();
|
||||
|
||||
// Insert using named parameters
|
||||
$stmt1 = PrepareQuery($conn1, "INSERT INTO [$tableName] VALUES(:first, :second, :third)");
|
||||
foreach ($data as $row)
|
||||
{
|
||||
$stmt1->execute(array(':first'=>($row[0] + 5), ':second'=>$row[1], ':third'=>$row[2]));
|
||||
}
|
||||
unset($stmt1);
|
||||
|
||||
$stmt2->execute();
|
||||
$num = $stmt2->fetchColumn();
|
||||
echo 'There are ' . $num . " rows in the table.\n";
|
||||
|
||||
$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);
|
||||
|
||||
// Testing with prepared query
|
||||
$stmt1 = PrepareQuery($conn1, "SELECT COUNT(idx) FROM [$tableName]");
|
||||
|
||||
$stmt1->execute();
|
||||
var_dump($stmt1->fetchColumn());
|
||||
unset($stmt1);
|
||||
|
||||
$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);
|
||||
|
||||
echo "===WHILE===\n";
|
||||
|
||||
$stmt1->bindColumn('idx', $idx);
|
||||
$stmt1->bindColumn('txt', $txt);
|
||||
$stmt1->execute();
|
||||
while ($stmt1->fetch(PDO::FETCH_BOUND))
|
||||
{
|
||||
var_dump(array($idx=>$txt));
|
||||
}
|
||||
|
||||
echo "===ALONE===\n";
|
||||
|
||||
$stmt2 = PrepareQuery($conn1, "SELECT txt FROM [$tableName] WHERE idx=:inp");
|
||||
$stmt2->bindParam(':inp', $idx); // by foreign name
|
||||
|
||||
$stmt3 = PrepareQuery($conn1, "SELECT idx FROM [$tableName] WHERE txt=:txt");
|
||||
$stmt3->bindParam(':txt', $txt); // using same name
|
||||
|
||||
foreach($data as $idx => $txt)
|
||||
{
|
||||
var_dump(array($idx=>$txt));
|
||||
|
||||
var_dump($stmt2->execute());
|
||||
if ($idx == 0)
|
||||
{ // bindColumn()s after execute() has been called at least once
|
||||
$stmt2->bindColumn('txt', $col1);
|
||||
}
|
||||
var_dump($stmt2->fetch(PDO::FETCH_BOUND));
|
||||
$stmt2->closeCursor();
|
||||
|
||||
var_dump($stmt3->execute());
|
||||
if ($idx == 0)
|
||||
{ // bindColumn()s after execute() has been called at least once
|
||||
$stmt3->bindColumn('idx', $col2);
|
||||
}
|
||||
var_dump($stmt3->fetch(PDO::FETCH_BOUND));
|
||||
$stmt3->closeCursor();
|
||||
|
||||
var_dump(array($col2=>$col1));
|
||||
}
|
||||
|
||||
echo "===REBIND/SAME===\n";
|
||||
|
||||
$stmt3->bindColumn('idx', $col1);
|
||||
foreach($data as $idx => $txt)
|
||||
{
|
||||
var_dump(array($idx=>$txt));
|
||||
var_dump($stmt2->execute());
|
||||
var_dump($stmt2->fetch(PDO::FETCH_BOUND));
|
||||
$stmt2->closeCursor();
|
||||
|
||||
var_dump($col1);
|
||||
var_dump($stmt3->execute());
|
||||
var_dump($stmt3->fetch(PDO::FETCH_BOUND));
|
||||
$stmt3->closeCursor();
|
||||
var_dump($col1);
|
||||
}
|
||||
|
||||
echo "===REBIND/CONFLICT===\n";
|
||||
|
||||
$stmt1->bindColumn('idx', $col1);
|
||||
$stmt1->bindColumn('txt', $col1);
|
||||
$stmt1->execute();
|
||||
while($stmt1->fetch(PDO::FETCH_BOUND))
|
||||
{
|
||||
var_dump($col1);
|
||||
}
|
||||
|
||||
|
||||
// Cleanup
|
||||
DropTable($conn1, $tableName);
|
||||
$stmt1 = null;
|
||||
$stmt2 = null;
|
||||
$stmt3 = null;
|
||||
$conn1 = null;
|
||||
|
||||
EndTest($testName);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Repro
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
function Repro()
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
Fetch();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
echo $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
Repro();
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
There are 6 rows in the table.
|
||||
There are 12 rows in the table.
|
||||
string(1) "3"
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(7) "String0"
|
||||
[1]=>
|
||||
string(7) "String1"
|
||||
[2]=>
|
||||
string(7) "String2"
|
||||
}
|
||||
===WHILE===
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(7) "String0"
|
||||
}
|
||||
array(1) {
|
||||
[1]=>
|
||||
string(7) "String1"
|
||||
}
|
||||
array(1) {
|
||||
[2]=>
|
||||
string(7) "String2"
|
||||
}
|
||||
===ALONE===
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(7) "String0"
|
||||
}
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(7) "String0"
|
||||
}
|
||||
array(1) {
|
||||
[1]=>
|
||||
string(7) "String1"
|
||||
}
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
array(1) {
|
||||
[1]=>
|
||||
string(7) "String1"
|
||||
}
|
||||
array(1) {
|
||||
[2]=>
|
||||
string(7) "String2"
|
||||
}
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
array(1) {
|
||||
[2]=>
|
||||
string(7) "String2"
|
||||
}
|
||||
===REBIND/SAME===
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(7) "String0"
|
||||
}
|
||||
bool(true)
|
||||
bool(true)
|
||||
string(7) "String0"
|
||||
bool(true)
|
||||
bool(true)
|
||||
string(1) "0"
|
||||
array(1) {
|
||||
[1]=>
|
||||
string(7) "String1"
|
||||
}
|
||||
bool(true)
|
||||
bool(true)
|
||||
string(7) "String1"
|
||||
bool(true)
|
||||
bool(true)
|
||||
string(1) "1"
|
||||
array(1) {
|
||||
[2]=>
|
||||
string(7) "String2"
|
||||
}
|
||||
bool(true)
|
||||
bool(true)
|
||||
string(7) "String2"
|
||||
bool(true)
|
||||
bool(true)
|
||||
string(1) "2"
|
||||
===REBIND/CONFLICT===
|
||||
string(7) "String0"
|
||||
string(7) "String1"
|
||||
string(7) "String2"
|
||||
Test "PDO Statement - Fetch Bound" completed successfully.
|
155
test/pdo_sqlsrv/PDO39_FetchInto.phpt
Normal file
155
test/pdo_sqlsrv/PDO39_FetchInto.phpt
Normal file
|
@ -0,0 +1,155 @@
|
|||
--TEST--
|
||||
PDO Fetch Test with FETCH_INTO mode
|
||||
--DESCRIPTION--
|
||||
Verification of fetch behavior with "PDO::FETCH_INTO" mode.
|
||||
--ENV--
|
||||
PHPT_EXEC=true
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
include 'MsCommon.inc';
|
||||
|
||||
function Fetch()
|
||||
{
|
||||
include 'MsSetup.inc';
|
||||
|
||||
$testName = "PDO Statement - Fetch Into";
|
||||
StartTest($testName);
|
||||
|
||||
$conn1 = Connect();
|
||||
|
||||
// Prepare test table
|
||||
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'),
|
||||
array('40', 'Jkl', 'qpo'),
|
||||
array('50', 'Mno', 'nml'),
|
||||
array('60', 'Pqr', 'kji'));
|
||||
|
||||
// Insert data using question mark placeholders
|
||||
$stmt1 = PrepareQuery($conn1, "INSERT INTO [$tableName] VALUES(?, ?, ?)");
|
||||
foreach ($data as $row)
|
||||
{
|
||||
$stmt1->execute($row);
|
||||
}
|
||||
unset($stmt1);
|
||||
|
||||
// Retrive data
|
||||
$stmt1 = PrepareQuery($conn1, "SELECT * FROM [$tableName]");
|
||||
|
||||
echo "===SUCCESS===\n";
|
||||
$stmt1->setFetchMode(PDO::FETCH_INTO, new Test);
|
||||
$stmt1->execute();
|
||||
foreach($stmt1 as $obj)
|
||||
{
|
||||
var_dump($obj);
|
||||
}
|
||||
|
||||
echo "===FAIL===\n";
|
||||
$stmt1->setFetchMode(PDO::FETCH_INTO, new Fail);
|
||||
$stmt1->execute();
|
||||
foreach($stmt1 as $obj)
|
||||
{
|
||||
var_dump($obj);
|
||||
}
|
||||
|
||||
|
||||
// Cleanup
|
||||
DropTable($conn1, $tableName);
|
||||
$stmt1 = null;
|
||||
$conn1 = null;
|
||||
|
||||
EndTest($testName);
|
||||
}
|
||||
|
||||
class Test
|
||||
{
|
||||
public $id, $val, $val2;
|
||||
}
|
||||
|
||||
class Fail
|
||||
{
|
||||
protected $id;
|
||||
public $val, $val2;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Repro
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
function Repro()
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
Fetch();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
echo $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
Repro();
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
===SUCCESS===
|
||||
object(Test)#%d (3) {
|
||||
["id"]=>
|
||||
string(2) "10"
|
||||
["val"]=>
|
||||
string(3) "Abc"
|
||||
["val2"]=>
|
||||
string(3) "zxy"
|
||||
}
|
||||
object(Test)#%d (3) {
|
||||
["id"]=>
|
||||
string(2) "20"
|
||||
["val"]=>
|
||||
string(3) "Def"
|
||||
["val2"]=>
|
||||
string(3) "wvu"
|
||||
}
|
||||
object(Test)#%d (3) {
|
||||
["id"]=>
|
||||
string(2) "30"
|
||||
["val"]=>
|
||||
string(3) "Ghi"
|
||||
["val2"]=>
|
||||
string(3) "tsr"
|
||||
}
|
||||
object(Test)#%d (3) {
|
||||
["id"]=>
|
||||
string(2) "40"
|
||||
["val"]=>
|
||||
string(3) "Jkl"
|
||||
["val2"]=>
|
||||
string(3) "qpo"
|
||||
}
|
||||
object(Test)#%d (3) {
|
||||
["id"]=>
|
||||
string(2) "50"
|
||||
["val"]=>
|
||||
string(3) "Mno"
|
||||
["val2"]=>
|
||||
string(3) "nml"
|
||||
}
|
||||
object(Test)#%d (3) {
|
||||
["id"]=>
|
||||
string(2) "60"
|
||||
["val"]=>
|
||||
string(3) "Pqr"
|
||||
["val2"]=>
|
||||
string(3) "kji"
|
||||
}
|
||||
===FAIL===
|
||||
|
||||
Fatal error: Uncaught Error: Cannot access protected property Fail::$id in %sPDO39_FetchInto.php:%x
|
||||
Stack trace:
|
||||
#0 %sPDO39_FetchInto.php(%x): Fetch()
|
||||
#1 %sPDO39_FetchInto.php(%x): Repro()
|
||||
#2 {main}
|
||||
thrown in %sPDO39_FetchInto.php on line %x
|
67
test/pdo_sqlsrv/PDO40_FetchLazy.phpt
Normal file
67
test/pdo_sqlsrv/PDO40_FetchLazy.phpt
Normal file
|
@ -0,0 +1,67 @@
|
|||
--TEST--
|
||||
PDO Query Test with PDO::FETCH_LAZY
|
||||
--DESCRIPTION--
|
||||
Verification for "PDO::query() with PDO::FETCH_LAZY mode".
|
||||
--ENV--
|
||||
PHPT_EXEC=true
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
include 'MsCommon.inc';
|
||||
|
||||
function Fetch()
|
||||
{
|
||||
include 'MsSetup.inc';
|
||||
|
||||
$testName = "PDO Statement - Fetch Lazy";
|
||||
StartTest($testName);
|
||||
|
||||
$conn1 = Connect();
|
||||
|
||||
// Prepare test table
|
||||
$dataCols = "id, name";
|
||||
CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, name VARCHAR(20)", null);
|
||||
InsertRowEx($conn1, $tableName, $dataCols, "1, 'test1'", null);
|
||||
InsertRowEx($conn1, $tableName, $dataCols, "2, 'test2'", null);
|
||||
|
||||
// Testing with direct query
|
||||
$stmt1 = $conn1->query("SELECT * FROM [$tableName]", PDO::FETCH_LAZY);
|
||||
foreach ($stmt1 as $v)
|
||||
{
|
||||
echo "lazy: " . $v->id.$v->name."\n";
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
DropTable($conn1, $tableName);
|
||||
$stmt1 = null;
|
||||
$conn1 = null;
|
||||
|
||||
EndTest($testName);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Repro
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
function Repro()
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
Fetch();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
echo $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
Repro();
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
lazy: 1test1
|
||||
lazy: 2test2
|
||||
Test "PDO Statement - Fetch Lazy" completed successfully.
|
|
@ -9,9 +9,9 @@ require_once 'MsCommon.inc';
|
|||
|
||||
|
||||
function testException(){
|
||||
$db = connect();
|
||||
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$sql = "SELECT * FROM temp_table";
|
||||
$db = connect();
|
||||
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$sql = "SELECT * FROM temp_table";
|
||||
try{
|
||||
$q = $db->query($sql);
|
||||
} catch ( Exception $e ){
|
||||
|
@ -20,16 +20,16 @@ function testException(){
|
|||
}
|
||||
|
||||
function testWarning(){
|
||||
$db = connect();
|
||||
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
|
||||
$sql = "SELECT * FROM temp_table";
|
||||
$db = connect();
|
||||
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
|
||||
$sql = "SELECT * FROM temp_table";
|
||||
$q = $db->query($sql);
|
||||
}
|
||||
|
||||
function testSilent(){
|
||||
$db = connect();
|
||||
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
|
||||
$sql = "SELECT * FROM temp_table";
|
||||
$db = connect();
|
||||
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
|
||||
$sql = "SELECT * FROM temp_table";
|
||||
$q = $db->query($sql);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,8 +5,6 @@ Test the PDO::getAvailableDrivers() method.
|
|||
--FILE--
|
||||
<?php
|
||||
|
||||
require_once 'MsCommon.inc';
|
||||
|
||||
try
|
||||
{
|
||||
// Do not print anything, as the result will be different for each computer
|
||||
|
|
50
test/pdo_sqlsrv/pdo_insertDataType.phpt
Normal file
50
test/pdo_sqlsrv/pdo_insertDataType.phpt
Normal file
|
@ -0,0 +1,50 @@
|
|||
--TEST--
|
||||
Test the different type of data for retrieving
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require_once 'MsCommon.inc';
|
||||
|
||||
try
|
||||
{
|
||||
$db = connect();
|
||||
|
||||
|
||||
$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 (1,'0',1,1,1,111,1,";
|
||||
$query .= "111.1110,111.1110,111.111,111.111,";
|
||||
$query .= "'STRINGCOL1','STRINGCOL1',";
|
||||
$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 .= "'STRINGCOL1','STRINGCOL1','00',";
|
||||
$query .= "CONVERT(BINARY(2),'0000000000',2),CONVERT(VARBINARY(2),CAST('00' AS VARCHAR(2)),2),'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),CAST('00' AS VARCHAR(MAX)),2) ,";
|
||||
$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!";
|
||||
}
|
||||
catch(PDOException $e)
|
||||
{
|
||||
var_dump($e);
|
||||
}
|
||||
?>
|
||||
|
||||
--EXPECT--
|
||||
Insert complete!
|
68
test/pdo_sqlsrv/pdo_passwords.phpt
Normal file
68
test/pdo_sqlsrv/pdo_passwords.phpt
Normal file
|
@ -0,0 +1,68 @@
|
|||
--TEST--
|
||||
Test password with non alphanumeric characters
|
||||
--DESCRIPTION--
|
||||
The first three cases should have no problem connecting. Only the last case fails because the
|
||||
right curly brace should be escaped with another right brace.
|
||||
In Azure we can't set DEFAULT_DATABASE for a login user. For this test to psss must connect
|
||||
to the test database defined in MsSetup.inc
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require 'MsSetup.inc';
|
||||
|
||||
try{
|
||||
// Test 1
|
||||
$conn = new PDO( "sqlsrv:Server=$server;Database=$databaseName;ConnectionPooling=false;" , "test_password", "! ;4triou");
|
||||
if(!$conn)
|
||||
{
|
||||
echo "Test 1: Should have connected.";
|
||||
}
|
||||
}
|
||||
catch(PDOException $e){
|
||||
print_r($e->getMessage() . "\n");
|
||||
|
||||
}
|
||||
try{
|
||||
// Test 2
|
||||
$conn = new PDO( "sqlsrv:Server=$server;Database=$databaseName;ConnectionPooling=false;" , "test_password2", "!}} ;4triou");
|
||||
if(!$conn)
|
||||
{
|
||||
echo "Test 2: Should have connected.";
|
||||
}
|
||||
}
|
||||
catch(PDOException $e){
|
||||
print_r($e->getMessage() . "\n");
|
||||
|
||||
}
|
||||
try{
|
||||
// Test 3
|
||||
$conn = new PDO( "sqlsrv:Server=$server;Database=$databaseName;ConnectionPooling=false;" , "test_password3", "! ;4triou}}");
|
||||
if(!$conn)
|
||||
{
|
||||
echo "Test 3: Should have connected.";
|
||||
}
|
||||
}
|
||||
catch(PDOException $e){
|
||||
print_r($e->getMessage() . "\n");
|
||||
|
||||
}
|
||||
// Test invalid password.
|
||||
try
|
||||
{
|
||||
// Test 4
|
||||
$conn = new PDO( "sqlsrv:Server=$server;Database=$databaseName;ConnectionPooling=false;" , "test_password3", "! ;4triou}");
|
||||
}
|
||||
catch( PDOException $e ) {
|
||||
print_r( $e->getMessage() );
|
||||
exit;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
--EXPECTREGEX--
|
||||
SQLSTATE\[IMSSP\]: An unescaped right brace \(}\) was found in either the user name or password\. All right braces must be escaped with another right brace \(}}\)\.
|
||||
|
||||
|
||||
|
149
test/pdo_sqlsrv/pdo_prepare.phpt
Normal file
149
test/pdo_sqlsrv/pdo_prepare.phpt
Normal file
|
@ -0,0 +1,149 @@
|
|||
--TEST--
|
||||
Test the PDO::prepare() method.
|
||||
--ENV--
|
||||
PHPT_EXEC=true
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require 'MsSetup.inc';
|
||||
require_once 'MsCommon.inc';
|
||||
|
||||
try
|
||||
{
|
||||
$db = connect();
|
||||
$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
|
||||
|
||||
// Test_1 : Test with no parameters
|
||||
echo "Test_1 : Test with no parameters :\n";
|
||||
$stmt = $db->prepare('select * from ' . $table1);
|
||||
if(!$stmt->execute())
|
||||
{
|
||||
die("Test_1 failed.");
|
||||
}
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
var_dump($result);
|
||||
|
||||
// Test_2 : Test with indexed parameters
|
||||
echo "Test_2 : Test with indexed parameters :\n";
|
||||
$stmt = $db->prepare('select IntCol, CharCol from ' . $table1 . ' where IntCol = ? and CharCol = ?');
|
||||
if(!$stmt->execute(array(1, 'STRINGCOL1')))
|
||||
{
|
||||
die("Test_2 failed.");
|
||||
}
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
var_dump($result);
|
||||
|
||||
// Test_3 : Test with named parameters
|
||||
echo "Test_3 : Test with named parameters :\n";
|
||||
$IntColVal = 2;
|
||||
$CharColVal = 'STRINGCOL2';
|
||||
$stmt = $db->prepare('select IntCol, CharCol from ' . $table1 . ' where IntCol = :IntColVal and CharCol = :CharColVal');
|
||||
if(!$stmt->execute(array(':IntColVal' => $IntColVal, ':CharColVal' => $CharColVal)))
|
||||
{
|
||||
die("Test_3 failed.");
|
||||
}
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
var_dump($result);
|
||||
|
||||
// Test_4: Test single prepare, multiple execution with indexed parameters
|
||||
echo "Test_4 : Test single prepare, multiple execution with indexed parameters :\n";
|
||||
$IntColVal = 1;
|
||||
$stmt = $db->prepare('select IntCol from ' . $table1 . ' where IntCol = ?');
|
||||
$stmt->bindParam(1, $IntColVal);
|
||||
if(!$stmt->execute())
|
||||
{
|
||||
die("Test_4 failed.");
|
||||
}
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
var_dump($result);
|
||||
|
||||
// Execute the stmt again
|
||||
$IntColVal = 2;
|
||||
if(!$stmt->execute())
|
||||
{
|
||||
die("Test_4 failed.");
|
||||
}
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
var_dump($result);
|
||||
|
||||
// Test_5: Test single prepare, multiple execution with named parameters
|
||||
echo "Test_5 : Test single prepare, multiple execution with named parameters :\n";
|
||||
$IntColVal = 1;
|
||||
$stmt = $db->prepare('select IntCol from ' . $table1 . ' where IntCol = :IntColVal');
|
||||
$stmt->bindParam(':IntColVal', $IntColVal);
|
||||
if(!$stmt->execute())
|
||||
{
|
||||
die("Test_5 failed.");
|
||||
}
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
var_dump($result);
|
||||
|
||||
// Execute the stmt again
|
||||
$IntColVal = 2;
|
||||
if(!$stmt->execute())
|
||||
{
|
||||
die("Test_5 failed.");
|
||||
}
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
var_dump($result);
|
||||
}
|
||||
catch(PDOException $err)
|
||||
{
|
||||
var_dump($err);
|
||||
exit();
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
Test_1 : Test with no parameters :
|
||||
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>"
|
||||
}
|
||||
Test_2 : Test with indexed parameters :
|
||||
array(2) {
|
||||
["IntCol"]=>
|
||||
string(1) "1"
|
||||
["CharCol"]=>
|
||||
string(10) "STRINGCOL1"
|
||||
}
|
||||
Test_3 : Test with named parameters :
|
||||
array(2) {
|
||||
["IntCol"]=>
|
||||
string(1) "2"
|
||||
["CharCol"]=>
|
||||
string(10) "STRINGCOL2"
|
||||
}
|
||||
Test_4 : Test single prepare, multiple execution with indexed parameters :
|
||||
array(1) {
|
||||
["IntCol"]=>
|
||||
string(1) "1"
|
||||
}
|
||||
array(1) {
|
||||
["IntCol"]=>
|
||||
string(1) "2"
|
||||
}
|
||||
Test_5 : Test single prepare, multiple execution with named parameters :
|
||||
array(1) {
|
||||
["IntCol"]=>
|
||||
string(1) "1"
|
||||
}
|
||||
array(1) {
|
||||
["IntCol"]=>
|
||||
string(1) "2"
|
||||
}
|
80
test/pdo_sqlsrv/pdo_prepare_attribute.phpt
Normal file
80
test/pdo_sqlsrv/pdo_prepare_attribute.phpt
Normal file
|
@ -0,0 +1,80 @@
|
|||
--TEST--
|
||||
Test PDO::prepare() with PDO::ATTR_EMULATE_PREPARES.
|
||||
--ENV--
|
||||
PHPT_EXEC=true
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require_once 'MsCommon.inc';
|
||||
|
||||
$db = connect();
|
||||
|
||||
$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
|
||||
|
||||
// retrieve correct results
|
||||
$s = $db->prepare( "SELECT '' + TITLE FROM cd_info GROUP BY '' + TITLE" );
|
||||
|
||||
$s->execute();
|
||||
|
||||
$titles = array();
|
||||
|
||||
while( $r = $s->fetch()) {
|
||||
|
||||
$titles[] = $r[0];
|
||||
}
|
||||
|
||||
$exception_thrown = false;
|
||||
|
||||
try {
|
||||
|
||||
$s = $db->prepare( 'SELECT :prefix + TITLE FROM cd_info GROUP BY :prefix + TITLE' );
|
||||
|
||||
$s->bindValue( ':prefix', "" );
|
||||
|
||||
$s->execute();
|
||||
|
||||
while( $r = $s->fetch()) {
|
||||
|
||||
print_r( $r );
|
||||
}
|
||||
|
||||
}
|
||||
catch ( PDOException $e ) {
|
||||
|
||||
$exception_thrown = true;
|
||||
}
|
||||
|
||||
if( !$exception_thrown ) {
|
||||
|
||||
die( "Exception not thrown\nTest failed\n" );
|
||||
}
|
||||
|
||||
$s = $db->prepare( "SELECT :prefix + TITLE FROM cd_info GROUP BY :prefix + TITLE",
|
||||
array( PDO::ATTR_EMULATE_PREPARES => true ));
|
||||
|
||||
$s->bindValue( ':prefix', "" );
|
||||
|
||||
$s->execute();
|
||||
|
||||
$param_titles = array();
|
||||
|
||||
while( $r = $s->fetch()) {
|
||||
|
||||
$param_titles[] = $r[0];
|
||||
}
|
||||
|
||||
if ( $titles === $param_titles ) {
|
||||
echo "Test succeeded\n";
|
||||
}
|
||||
else {
|
||||
|
||||
echo "Test failed\n";
|
||||
print_r( $titles );
|
||||
print_r( $param_titles );
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
Test succeeded
|
140
test/pdo_sqlsrv/pdo_query.phpt
Normal file
140
test/pdo_sqlsrv/pdo_query.phpt
Normal file
|
@ -0,0 +1,140 @@
|
|||
--TEST--
|
||||
Test the PDO::query() method.
|
||||
--ENV--
|
||||
PHPT_EXEC=true
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require_once 'MsCommon.inc';
|
||||
|
||||
|
||||
function query_default( $conn )
|
||||
{
|
||||
global $table1;
|
||||
$stmt = $conn->query( "Select * from " . $table1 );
|
||||
$result = $stmt->fetch();
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
function query_column( $conn )
|
||||
{
|
||||
global $table1;
|
||||
$stmt = $conn->query( "Select * from " . $table1, PDO::FETCH_COLUMN, 2 );
|
||||
$result = $stmt->fetch();
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
function query_class( $conn )
|
||||
{
|
||||
global $table1;
|
||||
global $table1_class;
|
||||
$stmt = $conn->query( "Select * from " . $table1, PDO::FETCH_CLASS, $table1_class );
|
||||
$result = $stmt->fetch();
|
||||
$result->dumpAll();
|
||||
}
|
||||
|
||||
function query_into( $conn )
|
||||
{
|
||||
global $table1;
|
||||
global $table1_class;
|
||||
$obj = new $table1_class;
|
||||
$stmt = $conn->query( "Select * from " . $table1, PDO::FETCH_INTO, $obj );
|
||||
$result = $stmt->fetch();
|
||||
$result->dumpAll();
|
||||
}
|
||||
|
||||
function query_empty_table( $conn )
|
||||
{
|
||||
CreateTableEx($conn, 'emptyTable', "c1 INT, c2 INT");
|
||||
$stmt = $conn->query( "Select * from emptyTable");
|
||||
$result = $stmt->fetch();
|
||||
var_dump($result);
|
||||
DropTable($conn, 'emptyTable');
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$db = connect();
|
||||
echo "TEST_1 : query with default fetch style :\n";
|
||||
query_default($db);
|
||||
|
||||
echo "TEST_2 : query with FETCH_COLUMN :\n";
|
||||
query_column($db);
|
||||
|
||||
echo "TEST_3 : query with FETCH_CLASS :\n";
|
||||
query_class($db);
|
||||
|
||||
echo "TEST_4 : query with FETCH_INTO :\n";
|
||||
query_into($db);
|
||||
|
||||
echo "TEST_5 : query an empty table :\n";
|
||||
query_empty_table($db);
|
||||
}
|
||||
|
||||
catch( PDOException $e ) {
|
||||
var_dump( $e );
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
TEST_1 : query with default fetch style :
|
||||
array(16) {
|
||||
["IntCol"]=>
|
||||
string(1) "1"
|
||||
[0]=>
|
||||
string(1) "1"
|
||||
["CharCol"]=>
|
||||
string(10) "STRINGCOL1"
|
||||
[1]=>
|
||||
string(10) "STRINGCOL1"
|
||||
["NCharCol"]=>
|
||||
string(10) "STRINGCOL1"
|
||||
[2]=>
|
||||
string(10) "STRINGCOL1"
|
||||
["DateTimeCol"]=>
|
||||
string(23) "2000-11-11 11:11:11.110"
|
||||
[3]=>
|
||||
string(23) "2000-11-11 11:11:11.110"
|
||||
["VarcharCol"]=>
|
||||
string(10) "STRINGCOL1"
|
||||
[4]=>
|
||||
string(10) "STRINGCOL1"
|
||||
["NVarCharCol"]=>
|
||||
string(10) "STRINGCOL1"
|
||||
[5]=>
|
||||
string(10) "STRINGCOL1"
|
||||
["FloatCol"]=>
|
||||
string(7) "111.111"
|
||||
[6]=>
|
||||
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>"
|
||||
[7]=>
|
||||
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>"
|
||||
}
|
||||
TEST_2 : query with FETCH_COLUMN :
|
||||
string(10) "STRINGCOL1"
|
||||
TEST_3 : query with FETCH_CLASS :
|
||||
string(1) "1"
|
||||
string(10) "STRINGCOL1"
|
||||
string(10) "STRINGCOL1"
|
||||
string(23) "2000-11-11 11:11:11.110"
|
||||
string(10) "STRINGCOL1"
|
||||
string(10) "STRINGCOL1"
|
||||
string(7) "111.111"
|
||||
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>"
|
||||
TEST_4 : query with FETCH_INTO :
|
||||
string(1) "1"
|
||||
string(10) "STRINGCOL1"
|
||||
string(10) "STRINGCOL1"
|
||||
string(23) "2000-11-11 11:11:11.110"
|
||||
string(10) "STRINGCOL1"
|
||||
string(10) "STRINGCOL1"
|
||||
string(7) "111.111"
|
||||
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>"
|
||||
TEST_5 : query an empty table :
|
||||
bool(false)
|
32
test/pdo_sqlsrv/pdo_quote.phpt
Normal file
32
test/pdo_sqlsrv/pdo_quote.phpt
Normal file
|
@ -0,0 +1,32 @@
|
|||
--TEST--
|
||||
Test the PDO::quote() method.
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require_once 'MsCommon.inc';
|
||||
|
||||
try
|
||||
{
|
||||
$conn = connect(array(PDO::SQLSRV_ATTR_ENCODING => 3, PDO::ATTR_CASE => 2));
|
||||
|
||||
$unquoted = "ABC'DE";
|
||||
$quoted1 = $conn->quote($unquoted);
|
||||
$quoted2 = $conn->quote($quoted1);
|
||||
|
||||
var_dump($unquoted);
|
||||
var_dump($quoted1);
|
||||
var_dump($quoted2);
|
||||
}
|
||||
|
||||
catch( PDOException $e ) {
|
||||
var_dump( $e );
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
--EXPECT--
|
||||
string(6) "ABC'DE"
|
||||
string(9) "'ABC''DE'"
|
||||
string(15) "'''ABC''''DE'''"
|
494
test/pdo_sqlsrv/pdo_testDataType.phpt
Normal file
494
test/pdo_sqlsrv/pdo_testDataType.phpt
Normal file
|
@ -0,0 +1,494 @@
|
|||
--TEST--
|
||||
Test the different type of data for retrieving
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require_once 'MsCommon.inc';
|
||||
|
||||
|
||||
function testBigInt()
|
||||
{
|
||||
$db = connect();
|
||||
// Retrieve data type
|
||||
$stmt = $db->query("SELECT BigIntCol FROM PDO_AllTypes");
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
function testBit()
|
||||
{
|
||||
$db = connect();
|
||||
// Retrieve data type
|
||||
$stmt = $db->query("SELECT BitCol FROM PDO_AllTypes");
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
function testInt()
|
||||
{
|
||||
$db = connect();
|
||||
// Retrieve data type
|
||||
$stmt = $db->query("SELECT IntCol FROM PDO_AllTypes");
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
function testSmallInt()
|
||||
{
|
||||
$db = connect();
|
||||
// Retrieve data type
|
||||
$stmt = $db->query("SELECT SmallIntCol FROM PDO_AllTypes");
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
function testTinyInt()
|
||||
{
|
||||
$db = connect();
|
||||
// Retrieve data type
|
||||
$stmt = $db->query("SELECT TinyIntCol FROM PDO_AllTypes");
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
function testDecimal()
|
||||
{
|
||||
$db = connect();
|
||||
// Retrieve data type
|
||||
$stmt = $db->query("SELECT DecimalCol FROM PDO_AllTypes");
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
function testNumeric()
|
||||
{
|
||||
$db = connect();
|
||||
// Retrieve data type
|
||||
$stmt = $db->query("SELECT NumCol FROM PDO_AllTypes");
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
function testMoney()
|
||||
{
|
||||
$db = connect();
|
||||
// Retrieve data type
|
||||
$stmt = $db->query("SELECT MoneyCol FROM PDO_AllTypes");
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
function testSmallMoney()
|
||||
{
|
||||
$db = connect();
|
||||
// Retrieve data type
|
||||
$stmt = $db->query("SELECT SmallMoneyCol FROM PDO_AllTypes");
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
function testFloat()
|
||||
{
|
||||
$db = connect();
|
||||
$stmt = $db->query("SELECT FloatCol FROM PDO_AllTypes");
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
function testReal()
|
||||
{
|
||||
$db = connect();
|
||||
$stmt = $db->query("SELECT RealCol FROM PDO_AllTypes");
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
function testChar()
|
||||
{
|
||||
$db = connect();
|
||||
$stmt = $db->query("SELECT CharCol FROM PDO_AllTypes");
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
function testVarchar()
|
||||
{
|
||||
$db = connect();
|
||||
$stmt = $db->query("SELECT VarcharCol FROM PDO_AllTypes");
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
function testText()
|
||||
{
|
||||
$db = connect();
|
||||
$stmt = $db->query("SELECT TextCol FROM PDO_AllTypes");
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
function testNText()
|
||||
{
|
||||
$db = connect();
|
||||
$stmt = $db->query("SELECT NTextCol FROM PDO_AllTypes");
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
function testNChar()
|
||||
{
|
||||
$db = connect();
|
||||
$stmt = $db->query("SELECT NCharCol FROM PDO_AllTypes");
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
function testNVarchar()
|
||||
{
|
||||
$db = connect();
|
||||
$stmt = $db->query("SELECT NVarcharCol FROM PDO_AllTypes");
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
function testImage()
|
||||
{
|
||||
$db = connect();
|
||||
$stmt = $db->query("SELECT ImageCol FROM PDO_AllTypes");
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
function testBinary()
|
||||
{
|
||||
$db = connect();
|
||||
$stmt = $db->query("SELECT BinaryCol FROM PDO_AllTypes");
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
function testVarbinary()
|
||||
{
|
||||
$db = connect();
|
||||
$stmt = $db->query("SELECT VarbinaryCol FROM PDO_AllTypes");
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
function testDateTime2()
|
||||
{
|
||||
$db = connect();
|
||||
$stmt = $db->query("SELECT DateTime2Col FROM PDO_AllTypes");
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
function testDatetimeoffset()
|
||||
{
|
||||
$db = connect();
|
||||
$stmt = $db->query("SELECT DTOffsetCol FROM PDO_AllTypes");
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
function testsmalldatetime()
|
||||
{
|
||||
$db = connect();
|
||||
$stmt = $db->query("SELECT SmallDTCol FROM PDO_AllTypes");
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
function testDateTime()
|
||||
{
|
||||
$db = connect();
|
||||
$stmt = $db->query("SELECT DateTimeCol FROM PDO_AllTypes");
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
function testDate()
|
||||
{
|
||||
$db = connect();
|
||||
$stmt = $db->query("SELECT DateCol FROM PDO_AllTypes");
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
function testNVarcharMax()
|
||||
{
|
||||
$db = connect();
|
||||
$stmt = $db->query("SELECT NVarCharMaxCol FROM PDO_AllTypes");
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
function testTime()
|
||||
{
|
||||
$db = connect();
|
||||
$stmt = $db->query("SELECT TimeCol FROM PDO_AllTypes");
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
function testUniqueidentifier()
|
||||
{
|
||||
$db = connect();
|
||||
$stmt = $db->query("SELECT Guidcol FROM PDO_AllTypes");
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
function testVarbinaryMax()
|
||||
{
|
||||
$db = connect();
|
||||
$stmt = $db->query("SELECT VarbinaryMaxCol FROM PDO_AllTypes");
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
function testVarcharMax()
|
||||
{
|
||||
$db = connect();
|
||||
$stmt = $db->query("SELECT VarcharMaxCol FROM PDO_AllTypes");
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
function testXml()
|
||||
{
|
||||
$db = connect();
|
||||
$stmt = $db->query("SELECT XmlCol FROM PDO_AllTypes");
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
//$db = connect();
|
||||
//$sql = "INSERT INTO PDO_AllTypes(BigIntCol,BitCol,IntCol,) VALUES(" . GetSampleData(4) . ",1,)";
|
||||
//$numRows = $db->exec($sql);
|
||||
|
||||
echo "Test_1 : bigint data type :\n";
|
||||
testBigInt();
|
||||
echo "Test_2 : bit data type :\n";
|
||||
testBit();
|
||||
echo "Test_3 : int data type :\n";
|
||||
testInt();
|
||||
echo "Test_4 : smallint data type:\n";
|
||||
testSmallInt();
|
||||
echo "Test_5 : tinyint data type:\n";
|
||||
testTinyInt();
|
||||
echo "Test_6 : decimal data type:\n";
|
||||
testDecimal();
|
||||
echo "Test_7 : numeric data type:\n";
|
||||
testNumeric();
|
||||
echo "Test_8 : money data type:\n";
|
||||
testMoney();
|
||||
echo "Test_9 : smallmoney data type:\n";
|
||||
testSmallMoney();
|
||||
echo "Test_10 : float data type:\n";
|
||||
testFloat();
|
||||
echo "Test_11 : real data type:\n";
|
||||
testReal();
|
||||
echo "Test_12 : char data type:\n";
|
||||
testChar();
|
||||
echo "Test_13 : varchar data type:\n";
|
||||
testVarchar();
|
||||
echo "Test_14 : text data type:\n";
|
||||
testText();
|
||||
echo "Test_15 : nchar data type:\n";
|
||||
testNChar();
|
||||
echo "Test_16 : nvarchar data type:\n";
|
||||
testNVarchar();
|
||||
echo "Test_17 : image data type:\n";
|
||||
testImage();
|
||||
echo "Test_18 : binary data type:\n";
|
||||
testBinary();
|
||||
echo "Test_19 : varbinary data type:\n";
|
||||
testVarbinary();
|
||||
echo "Test_20 : smalldatetime data type:\n";
|
||||
testsmalldatetime();
|
||||
echo "Test_21 : datetime data type:\n";
|
||||
testDateTime();
|
||||
echo "Test_22 : datetime2 data type:\n";
|
||||
testsmalldatetime();
|
||||
echo "Test_23 : datetimeoffset data type:\n";
|
||||
testDatetimeoffset();
|
||||
echo "Test_24 : time data type:\n";
|
||||
testTime();
|
||||
echo "Test_25 : Uniqueidentifier data type:\n";
|
||||
testUniqueidentifier();
|
||||
echo "Test_26 : VarbinaryMax data type:\n";
|
||||
testVarbinaryMax();
|
||||
echo "Test_27 : VarcharMax data type:\n";
|
||||
testVarcharMax();
|
||||
echo "Test_28 : xml data type:\n";
|
||||
testXml();
|
||||
echo "Test_29 : ntext data type:\n";
|
||||
testNText();
|
||||
echo "Test_30 : nvarcharmax data type:\n";
|
||||
testNVarcharMax();
|
||||
|
||||
}
|
||||
catch (PDOException $e)
|
||||
{
|
||||
var_dump($e);
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
--EXPECT--
|
||||
Test_1 : bigint data type :
|
||||
array(1) {
|
||||
["BigIntCol"]=>
|
||||
string(1) "1"
|
||||
}
|
||||
Test_2 : bit data type :
|
||||
array(1) {
|
||||
["BitCol"]=>
|
||||
string(1) "0"
|
||||
}
|
||||
Test_3 : int data type :
|
||||
array(1) {
|
||||
["IntCol"]=>
|
||||
string(1) "1"
|
||||
}
|
||||
Test_4 : smallint data type:
|
||||
array(1) {
|
||||
["SmallIntCol"]=>
|
||||
string(1) "1"
|
||||
}
|
||||
Test_5 : tinyint data type:
|
||||
array(1) {
|
||||
["TinyIntCol"]=>
|
||||
string(1) "1"
|
||||
}
|
||||
Test_6 : decimal data type:
|
||||
array(1) {
|
||||
["DecimalCol"]=>
|
||||
string(3) "111"
|
||||
}
|
||||
Test_7 : numeric data type:
|
||||
array(1) {
|
||||
["NumCol"]=>
|
||||
string(1) "1"
|
||||
}
|
||||
Test_8 : money data type:
|
||||
array(1) {
|
||||
["MoneyCol"]=>
|
||||
string(8) "111.1110"
|
||||
}
|
||||
Test_9 : smallmoney data type:
|
||||
array(1) {
|
||||
["SmallMoneyCol"]=>
|
||||
string(8) "111.1110"
|
||||
}
|
||||
Test_10 : float data type:
|
||||
array(1) {
|
||||
["FloatCol"]=>
|
||||
string(7) "111.111"
|
||||
}
|
||||
Test_11 : real data type:
|
||||
array(1) {
|
||||
["RealCol"]=>
|
||||
string(7) "111.111"
|
||||
}
|
||||
Test_12 : char data type:
|
||||
array(1) {
|
||||
["CharCol"]=>
|
||||
string(10) "STRINGCOL1"
|
||||
}
|
||||
Test_13 : varchar data type:
|
||||
array(1) {
|
||||
["VarcharCol"]=>
|
||||
string(10) "STRINGCOL1"
|
||||
}
|
||||
Test_14 : text data type:
|
||||
array(1) {
|
||||
["TextCol"]=>
|
||||
string(420) " 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."
|
||||
}
|
||||
Test_15 : nchar data type:
|
||||
array(1) {
|
||||
["NCharCol"]=>
|
||||
string(10) "STRINGCOL1"
|
||||
}
|
||||
Test_16 : nvarchar data type:
|
||||
array(1) {
|
||||
["NVarcharCol"]=>
|
||||
string(10) "STRINGCOL1"
|
||||
}
|
||||
Test_17 : image data type:
|
||||
array(1) {
|
||||
["ImageCol"]=>
|
||||
string(1) " |