replaced autonomous_setup.php by MsCommon.inc

This commit is contained in:
yitam 2017-05-01 17:01:30 -07:00
parent ce6337709b
commit a5ee59bfa6
75 changed files with 3389 additions and 816 deletions

1103
test/sqlsrv/MsCommon.inc Normal file
View file

@ -0,0 +1,1103 @@
<?php
/*
Microsoft SQL Server Driver for PHP - Unit Test Framework
Copyright (c) Microsoft Corporation. All rights reserved.
Description:
Common functions (shared by all tests).
*/
$useUTF8data = false;
function IsWindows()
{
// This method returns TRUE when running in a Windows platform
// The possible values are WIN32, WINNT and Windows
return (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN');
}
function UseUTF8Data()
{
global $useUTF8data;
return $useUTF8data;
}
function SetUTF8Data($val)
{
global $useUTF8data;
$useUTF8data = $val;
}
function TestMode()
{
$testMode = getenv('PHPT_EXEC');
return ($testMode ? true : false);
}
function TraceMode()
{
include 'MsSetup.inc';
return ((!TestMode() && $traceEnabled) ? true : false);
}
function Trace($msg)
{
if (TraceMode())
{
echo $msg;
}
}
function TraceData($sqlType, $data)
{
if (TraceMode())
{
$msg = strtoupper(" $sqlType:");
echo "$msg\t";
if (strlen($msg) <= 7)
{
echo "\t";
}
if (strlen($msg) <= 15)
{
echo "\t";
}
echo "$data\n"
;
}
}
function IsMarsSupported()
{
include 'MsSetup.inc';
return ($marsMode ? true : false);
}
function IsDaasMode()
{
include 'MsSetup.inc';
return ($daasMode ? true : false);
}
function StartTest($testName)
{
include 'MsSetup.inc';
if (TraceMode())
{
echo "$PhpDriver: starting \"$testName\" test...\n\n";
}
if (!extension_loaded("sqlsrv"))
{
die("$PhpDriver cannot be loaded.");
}
// Set timezone
$tz = ini_get('date.timezone');
if (strcmp($tz, "") == 0)
{
date_default_timezone_set('America/Los_Angeles');
$tz = date_default_timezone_get();
}
Trace("Timezone: $tz.\n");
}
function EndTest($testName)
{
include 'MsSetup.inc';
if (TraceMode())
{
echo "\n$PhpDriver: ";
}
echo "Test \"$testName\" completed successfully.\n";
}
function Setup()
{
set_time_limit(0);
sqlsrv_configure('LogSubsystems', SQLSRV_LOG_SYSTEM_OFF);
sqlsrv_configure('WarningsReturnAsErrors', 1);
}
function Configure($param, $expected)
{
sqlsrv_configure($param, $expected);
$actual = sqlsrv_get_config($param);
if ($actual == $expected)
{
Trace("Set configuration parameter $param = $actual.\n");
}
else
{
die("Failed to set configuration parameter $param = $expected.");
}
}
function ConnectUTF8()
{
return Connect(array( 'CharacterSet'=>'UTF-8' ));
}
function Connect($options = array())
{
include 'MsSetup.inc';
if (sizeof($options) > 0)
{
$connectionOptions = array_merge($connectionOptions, $options);
}
Trace("Attempting connection to $server...");
$conn = sqlsrv_connect($server, $connectionOptions);
if ($conn === false)
{
FatalError("Failed to connect to $server.");
}
Trace(" successfully connected.\n\n");
return ($conn);
}
function ConnectSpecial($options = array())
{
require 'MsSetup.inc';
if (!isset($options['UID']) && !isset($options['uid'])) {
$options['UID'] = $uid;
}
if (!isset($options['pwd']) && !isset($options['PWD'])) {
$options['pwd'] = $pwd;
}
if (!isset($options['Database'])) {
$options['Database'] = $database;
}
return sqlsrv_connect($server, $options);
}
function GetTempTableName($table = '', $temporary = true)
{
// A temporary table name with the '#' prefix will be automatically
// dropped once the connection is closed. Otherwise, the caller
// should take care of dropping the temp table afterwards.
$timestamp = round(microtime(true)*1000);
$prefix = '';
if ($temporary)
$prefix = '#';
if (strlen($table) == 0)
$table = 'php_test_table';
return $prefix . $table . '_' . $timestamp;
}
function GetTempProcName($proc = '', $temporary = true)
{
// A temporary stored procedure name with the '#' prefix will be
// automatically dropped once the connection is closed. Otherwise,
// the caller should take care of dropping the temp procedure afterwards.
$timestamp = round(microtime(true)*1000);
$prefix = '';
if ($temporary)
$prefix = '#';
if (strlen($proc) == 0)
$proc = 'php_test_proc';
return $prefix . $proc . '_' . $timestamp;
}
function ExecuteQuery($conn, $query)
{
$stmt = sqlsrv_query($conn, $query);
if ($stmt === false)
{
FatalError("Query execution failed: $query");
}
return ($stmt);
}
function PrepareQuery($conn, $query)
{
$stmt = sqlsrv_prepare($conn, $query);
if ($stmt === false)
{
FatalError("Query preparation failed: $query");
}
return ($stmt);
}
function ExecuteQueryEx($conn, $query, $modeDirect)
{
if ($modeDirect)
{ // direct execution
$stmt = sqlsrv_query($conn, $query);
}
else
{
$stmt = PrepareQuery($conn, $query);
sqlsrv_execute($stmt);
}
return ($stmt);
}
function GetSqlType($k)
{
switch ($k)
{
case 1: return ("int");
case 2: return ("tinyint");
case 3: return ("smallint");
case 4: return ("bigint");
case 5: return ("bit");
case 6: return ("float");
case 7: return ("real");
case 8: return ("decimal(28,4)");
case 9: return ("numeric(32,4)");
case 10: return ("money");
case 11: return ("smallmoney");
case 12: return ("char(512)");
case 13: return ("varchar(512)");
case 14: return ("varchar(max)");
case 15: return ("nchar(512)");
case 16: return ("nvarchar(512)");
case 17: return ("nvarchar(max)");
case 18: return ("text");
case 19: return ("ntext");
case 20: return ("binary(512)");
case 21: return ("varbinary(512)");
case 22: return ("varbinary(max)");
case 23: return ("image");
case 24: return ("uniqueidentifier");
case 25: return ("datetime");
case 26: return ("smalldatetime");
case 27: return ("timestamp");
case 28: return ("xml");
default: break;
}
return ("udt");
}
function GetDriverType($k, $dataSize)
{
switch ($k)
{
case 1: return (SQLSRV_SQLTYPE_INT);
case 2: return (SQLSRV_SQLTYPE_TINYINT);
case 3: return (SQLSRV_SQLTYPE_SMALLINT);
case 4: return (SQLSRV_SQLTYPE_BIGINT);
case 5: return (SQLSRV_SQLTYPE_BIT);
case 6: return (SQLSRV_SQLTYPE_FLOAT);
case 7: return (SQLSRV_SQLTYPE_REAL);
case 8: return (SQLSRV_SQLTYPE_DECIMAL(28, 4));
case 9: return (SQLSRV_SQLTYPE_NUMERIC(32, 4));
case 10: return (SQLSRV_SQLTYPE_MONEY);
case 11: return (SQLSRV_SQLTYPE_SMALLMONEY);
case 12: return (SQLSRV_SQLTYPE_CHAR($dataSize));
case 13: return (SQLSRV_SQLTYPE_VARCHAR($dataSize));
case 14: return (SQLSRV_SQLTYPE_VARCHAR('max'));
case 15: return (SQLSRV_SQLTYPE_NCHAR($dataSize));
case 16: return (SQLSRV_SQLTYPE_NVARCHAR($dataSize));
case 17: return (SQLSRV_SQLTYPE_NVARCHAR('max'));
case 18: return (SQLSRV_SQLTYPE_TEXT);
case 19: return (SQLSRV_SQLTYPE_NTEXT);
case 20: return (SQLSRV_SQLTYPE_BINARY($dataSize));
case 21: return (SQLSRV_SQLTYPE_VARBINARY($dataSize));
case 22: return (SQLSRV_SQLTYPE_VARBINARY('max'));
case 23: return (SQLSRV_SQLTYPE_IMAGE);
case 24: return (SQLSRV_SQLTYPE_UNIQUEIDENTIFIER);
case 25: return (SQLSRV_SQLTYPE_DATETIME);
case 26: return (SQLSRV_SQLTYPE_SMALLDATETIME);
case 27: return (SQLSRV_SQLTYPE_TIMESTAMP);
case 28: return (SQLSRV_SQLTYPE_XML);
default: break;
}
return (SQLSRV_SQLTYPE_UDT);
}
function IsXml($k)
{
switch ($k)
{
case 28: return (true); // xml
default: break;
}
return (false);
}
function IsStreamable($k)
{
switch ($k)
{
case 12: return (true); // nchar(512)
case 13: return (true); // varchar(512)
case 14: return (true); // varchar(max)
case 15: return (true); // nchar(512)
case 16: return (true); // nvarchar(512)
case 17: return (true); // nvarchar(max)
case 18: return (true); // text
case 19: return (true); // ntext
case 20: return (true); // binary
case 21: return (true); // varbinary(512)
case 22: return (true); // varbinary(max)
case 23: return (true); // image
case 28: return (true); // xml
default: break;
}
return (false);
}
function IsNumeric($k)
{
switch ($k)
{
case 1: return (true); // int
case 2: return (true); // tinyint
case 3: return (true); // smallint
case 4: return (true); // bigint
case 5: return (true); // bit
case 6: return (true); // float
case 7: return (true); // real
case 8: return (true); // decimal(28,4)
case 9: return (true); // numeric(32,4)
case 10: return (true); // money
case 11: return (true); // smallmoney
default: break;
}
return (false);
}
function IsChar($k)
{
switch ($k)
{
case 12: return (true); // nchar(512)
case 13: return (true); // varchar(512)
case 14: return (true); // varchar(max)
case 15: return (true); // nchar(512)
case 16: return (true); // nvarchar(512)
case 17: return (true); // nvarchar(max)
case 18: return (true); // text
case 19: return (true); // ntext
case 28: return (true); // xml
default: break;
}
return (false);
}
function IsBinary($k)
{
switch ($k)
{
case 20: return (true); // binary
case 21: return (true); // varbinary(512)
case 22: return (true); // varbinary(max)
case 23: return (true); // image
default: break;
}
return (false);
}
function IsDateTime($k)
{
switch ($k)
{
case 25: return (true); // datetime
case 26: return (true); // smalldatetime
case 27: return (true); // timestamp
default: break;
}
return (false);
}
function IsUnicode($k)
{
switch ($k)
{
case 15: return (true); // nchar(512)
case 16: return (true); // nvarchar(512)
case 17: return (true); // nvarchar(max)
case 19: return (true); // ntext
default: break;
}
return (false);
}
function IsUpdatable($k)
{
switch ($k)
{
case 27: return (false); // timestamp
default: break;
}
return (true);
}
function IsLiteral($k)
{
switch ($k)
{
case 12: return (true); // nchar(512)
case 13: return (true); // varchar(512)
case 14: return (true); // varchar(max)
case 15: return (true); // nchar(512)
case 16: return (true); // nvarchar(512)
case 17: return (true); // nvarchar(max)
case 18: return (true); // text
case 19: return (true); // ntext
case 24: return (true); // uniqueidentifier
case 25: return (true); // datetime
case 26: return (true); // smalldatetime
case 28: return (true); // xml
default: break;
}
return (false);
}
function GetMetadata($k, $info)
{
if (strcasecmp($info, 'Name') == 0)
{
return (getColName($k));
}
if (strcasecmp($info, 'Size') == 0)
{
return (getColSize($k));
}
if (strcasecmp($info, 'Precision') == 0)
{
return (getColPrecision($k));
}
if (strcasecmp($info, 'Scale') == 0)
{
return (getColScale($k));
}
if (strcasecmp($info, 'Nullable') == 0)
{
return (getColNullable($k));
}
return ("");
}
function GetColName($k)
{
switch ($k)
{
case 1: return ("c1_int");
case 2: return ("c2_tinyint");
case 3: return ("c3_smallint");
case 4: return ("c4_bigint");
case 5: return ("c5_bit");
case 6: return ("c6_float");
case 7: return ("c7_real");
case 8: return ("c8_decimal");
case 9: return ("c9_numeric");
case 10: return ("c10_money");
case 11: return ("c11_smallmoney");
case 12: return ("c12_char");
case 13: return ("c13_varchar");
case 14: return ("c14_varchar_max");
case 15: return ("c15_nchar");
case 16: return ("c16_nvarchar");
case 17: return ("c17_nvarchar_max");
case 18: return ("c18_text");
case 19: return ("c19_ntext");
case 20: return ("c20_binary");
case 21: return ("c21_varbinary");
case 22: return ("c22_varbinary_max");
case 23: return ("c23_image");
case 24: return ("c24_uniqueidentifier");
case 25: return ("c25_datetime");
case 26: return ("c26_smalldatetime");
case 27: return ("c27_timestamp");
case 28: return ("c28_xml");
default: break;
}
return ("");
}
function GetColSize($k)
{
switch ($k)
{
case 12: return ("512");
case 13: return ("512");
case 14: return ("0");
case 15: return ("512");
case 16: return ("512");
case 17: return ("0");
case 18: return ("2147483647");
case 19: return ("1073741823");
case 20: return ("512");
case 21: return ("512");
case 22: return ("0)");
case 23: return ("2147483647");
case 24: return ("36");
//case 25: return ("23");
//case 26: return ("16");
case 27: return ("8");
case 28: return ("0");
default: break;
}
return ("");
}
function GetColPrecision($k)
{
switch ($k)
{
case 1: return ("10");
case 2: return ("3");
case 3: return ("5");
case 4: return ("19");
case 5: return ("1");
case 6: return ("53");
case 7: return ("24");
case 8: return ("28");
case 9: return ("32");
case 10: return ("19");
case 11: return ("10");
case 25: return ("23");
case 26: return ("16");
default: break;
}
return ("");
}
function GetColScale($k)
{
switch ($k)
{
case 8: return ("4");
case 9: return ("4");
case 10: return ("4");
case 11: return ("4");
case 25: return ("3");
case 26: return ("0");
default: break;
}
return ("");
}
function GetColNullable($k)
{
return (IsUpdatable($k) ? "1" : "0");
}
function GetSampleData($k)
{
switch ($k)
{
case 1: // int
return ("123456789");
case 2: // tinyint
return ("234");
case 3: // smallint
return ("5678");
case 4: // bigint
return ("123456789987654321");
case 5: // bit
return ("1");
case 6: // float
return ("123.456");
case 7: // real
return ("789.012");
case 8: // decimal
return ("12.34");
case 9: // numeric
return ("567.89");
case 10:// money
return ("321.54");
case 11:// smallmoney
return ("67.89");
case 12:// char
case 15:// nchar
return ("The quick brown fox jumps over the lazy dog");
case 13:// varchar
case 16:// nvarchar
return ("The quick brown fox jumps over the lazy dog 9876543210");
case 14:// varchar(max)
case 17:// nvarchar(max)
return ("The quick brown fox jumps over the lazy dog 0123456789");
case 18:// text
case 19:// ntext
return ("0123456789 The quick brown fox jumps over the lazy dog");
case 20:// binary
return ("0123456789");
case 21:// varbinary
return ("01234567899876543210");
case 22:// varbinary(max)
return ("98765432100123456789");
case 23:// image
return ("01234567899876543210");
case 24:// uniqueidentifier
return ("12345678-9012-3456-7890-123456789012");
case 25:// datetime
case 26:// smalldatetime
return (date("Y-m-d"));
case 27:// timestamp
return (null);
case 28:// xml
return ("<XmlTestData><Letters1>The quick brown fox jumps over the lazy dog</Letters1><Digits1>0123456789</Digits1></XmlTestData>");
default:
break;
}
return (null);
}
function CreateTable($conn, $tableName)
{
Trace("Creating table $tableName ...");
$dataType = "[c1_int] int, [c2_tinyint] tinyint, [c3_smallint] smallint, [c4_bigint] bigint, [c5_bit] bit, [c6_float] float, [c7_real] real, [c8_decimal] decimal(28,4), [c9_numeric] numeric(32,4), [c10_money] money, [c11_smallmoney] smallmoney, [c12_char] char(512), [c13_varchar] varchar(512), [c14_varchar_max] varchar(max), [c15_nchar] nchar(512), [c16_nvarchar] nvarchar(512), [c17_nvarchar_max] nvarchar(max), [c18_text] text, [c19_ntext] ntext, [c20_binary] binary(512), [c21_varbinary] varbinary(512), [c22_varbinary_max] varbinary(max), [c23_image] image, [c24_uniqueidentifier] uniqueidentifier, [c25_datetime] datetime, [c26_smalldatetime] smalldatetime, [c27_timestamp] timestamp, [c28_xml] xml";
CreateTableEx($conn, $tableName, $dataType);
Trace(" completed successfully.\n");
}
function CreateTableEx($conn, $tableName, $dataType)
{
$sql = "CREATE TABLE [$tableName] ($dataType)";
DropTable($conn,$tableName);
$stmt = sqlsrv_query($conn, $sql);
if ($stmt === false)
{
FatalError("Failed to create test table: ".$sql);
}
sqlsrv_free_stmt($stmt);
}
function CreateTableIndex($conn, $tableName, $colIndex)
{
include 'MsSetup.inc';
CreateTableIndexEx($conn, $tableName, $tableIndex, $colIndex);
}
function CreateTableIndexEx($conn, $tableName, $tableIndex, $colIndex)
{
Trace("Creating table index for $tableName ...");
$sqlIndex = "CREATE CLUSTERED INDEX [$tableIndex] ON [$tableName]($colIndex)";
$stmt = sqlsrv_query($conn, $sqlIndex);
if ($stmt === false)
{
FatalError("Failed to create clustered index for test table: ".$sqlIndex);
}
sqlsrv_free_stmt($stmt);
Trace(" completed successfully.\n");
}
function CreateUniqueIndex($conn, $tableName, $colIndex)
{
include 'MsSetup.inc';
CreateUniqueIndexEx($conn, $tableName, $tableIndex, $colIndex);
}
function CreateUniqueIndexEx($conn, $tableName, $tableIndex, $colIndex)
{
Trace("Creating unique table index for $tableName ...");
$sqlIndex = "CREATE UNIQUE INDEX [$tableIndex] ON [$tableName]($colIndex)";
$stmt = sqlsrv_query($conn, $sqlIndex);
if ($stmt === false)
{
FatalError("Failed to create unique index for test table: ".$sqlIndex);
}
sqlsrv_free_stmt($stmt);
Trace(" completed successfully.\n");
}
function DropTable($conn, $tableName)
{
$stmt = sqlsrv_query($conn, "DROP TABLE [$tableName]");
if ($stmt === false)
{
}
else
{
sqlsrv_free_stmt($stmt);
}
}
function SelectFromTable($conn, $tableName)
{
return (SelectFromTableEx($conn, $tableName, null));
}
function SelectFromTableEx($conn, $tableName, $cond)
{
if (($cond != null) && (strlen($cond) > 0))
{
return (SelectQuery($conn, "SELECT * FROM [$tableName] WHERE $cond"));
}
else
{
return (SelectQuery($conn, "SELECT * FROM [$tableName]"));
}
}
function SelectQuery($conn, $query)
{
return (SelectQueryEx($conn, $query, null));
}
function SelectQueryEx($conn, $query, $options)
{
if ($options != null)
{
$stmt = sqlsrv_query($conn, $query, null, $options);
}
else
{
$stmt = sqlsrv_query($conn, $query);
}
if ($stmt === false)
{
FatalError("Failed to query test table");
}
$numFields = sqlsrv_num_fields($stmt);
if ($numFields <= 0)
{
die("Unexpected number of fields: ".$numFields);
}
return ($stmt);
}
function RowCount($stmt)
{
$rowCount = 0;
while (sqlsrv_fetch($stmt))
{
$rowCount++;
}
return ($rowCount);
}
function NumRows($conn, $tableName)
{
$stmt = SelectFromTable($conn, $tableName);
$rowCount = RowCount($stmt);
sqlsrv_free_stmt($stmt);
return ($rowCount);
}
function InsertQueryData($tableName, $index)
{
if (UseUTF8data())
{
include_once 'MsData_UTF8.inc';
return (InsertQueryExUTF8($tableName, $index));
}
else
{
include_once 'MsData.inc';
return (InsertQueryEx($tableName, $index));
}
}
function InsertQuery($tableName)
{
return (InsertQueryData($tableName, rand(1, 20)));
}
function InsertRows($conn, $tableName, $rowCount)
{
Trace("Inserting $rowCount rows into $tableName ...");
$count = 0;
for($i = 0; $i < $rowCount; $i++)
{
if (InsertRow($conn, $tableName))
{
$count++;
}
}
Trace(" completed successfully.\n");
if ($count != $rowCount)
{
die("$count rows inserted instead of $rowCount\n");
}
return ($count);
}
function InsertRowsByRange($conn, $tableName, $minIndex, $maxIndex)
{
$rowCount = $maxIndex - $minIndex + 1;
if ($rowCount > 0)
{
Trace("Inserting $rowCount rows into $tableName ...");
for($i = $minIndex; $i <= $maxIndex; $i++)
{
InsertRowByIndex($conn, $tableName, $i);
}
Trace(" completed successfully.\n");
}
}
function InsertRow($conn, $tableName)
{
$query = InsertQuery($tableName);
$stmt = sqlsrv_query($conn, $query);
return (InsertCheck($stmt));
}
function InsertRowEx($conn, $tableName, $dataCols, $dataValues, $dataOptions)
{
$stmt = sqlsrv_query($conn, "INSERT INTO [$tableName] ($dataCols) VALUES ($dataValues)", $dataOptions);
return (InsertCheck($stmt));
}
function InsertRowByIndex($conn, $tableName, $index)
{
$query = InsertQueryData($tableName, $index);
$stmt = sqlsrv_query($conn, $query);
return (InsertCheck($stmt));
}
function InsertStream($conn, $tableName, $dataCols, $dataValues, $dataOptions, $atExec)
{
if ($atExec)
{
$stmt = sqlsrv_query($conn, "INSERT INTO [$tableName] ($dataCols) VALUES ($dataValues)", $dataOptions, array('SendStreamParamsAtExec' => 1));
}
else
{
$stmt = sqlsrv_query($conn, "INSERT INTO [$tableName] ($dataCols) VALUES ($dataValues)", $dataOptions);
if ($stmt)
{
while (sqlsrv_send_stream_data($stmt))
{
}
}
}
return (InsertCheck($stmt));
}
function InsertCheck($stmt)
{
if ($stmt === false)
{
FatalError("Failed to insert row into test table");
}
$numRows = sqlsrv_rows_affected($stmt);
sqlsrv_free_stmt($stmt);
if ($numRows != 1)
{
die("Unexpected row count at insert: ".$numRows);
}
return (true);
}
function GetInsertData($rowIndex, $colIndex, $skip)
{
$query = InsertQueryData("TestTable", $rowIndex);
$data = strstr($query, "((");
$pos = 1;
if ($data === false)
{
die("Failed to retrieve data on row $rowIndex");
}
$data = substr($data, 2);
while ($pos < ($colIndex - $skip))
{
$data = strstr($data, ", (");
$pos++;
if ($data === false)
{
die("Failed to retrieve data on row $rowIndex, column $pos");
}
$data = substr($data, 3);
}
// Is it's XML type, we can't use the closing bracket as the next delimiter
// because a bracket can be part of the xml data, unless the data is null
$pos = strpos($data, ")");
if ($pos === false)
{
die("Failed to isolate data on row $rowIndex, column $pos");
}
$tmp = substr($data, 0, $pos); // don't replace $data in case it's xml data
if (strcasecmp($tmp, "null") == 0 || strlen($tmp) == 0) // data can actually be blank for null
{
$tmp = "";
}
else if (IsXml($colIndex))
{
$str = ">')"; // use the XML closing angle bracket as the delimiter
$pos = strpos($data, $str);
$tmp = substr($data, 0, $pos + 2);
}
$data = $tmp; // update $data
if (IsUnicode($colIndex))
{ // N'data'
$data = substr($data, 2, strlen($data) - 3);
}
else if (IsLiteral($colIndex))
{ // 'data'
$data = substr($data, 1, strlen($data) - 2);
}
else if (IsBinary($colIndex))
{ // 0xdata
$data = substr($data, 2);
}
return (trim($data));
}
function CreateProc($conn, $procName, $procArgs, $procCode)
{
DropProc($conn,$procName);
$stmt = sqlsrv_query($conn, "CREATE PROC [$procName] ($procArgs) AS BEGIN $procCode END");
if ($stmt === false)
{
FatalError("Failed to create test procedure");
}
sqlsrv_free_stmt($stmt);
}
function DropProc($conn, $procName)
{
$stmt = sqlsrv_query($conn, "DROP PROC [$procName]");
if ($stmt === false)
{
}
else
{
sqlsrv_free_stmt($stmt);
}
}
function CallProc($conn, $procName, $procArgs, $procValues)
{
$stmt = CallProcEx($conn, $procName, "", $procArgs, $procValues);
sqlsrv_free_stmt($stmt);
}
function CallProcEx($conn, $procName, $procPrefix, $procArgs, $procValues)
{
$stmt = sqlsrv_query($conn, "{ $procPrefix CALL [$procName] ($procArgs)}", $procValues);
if ($stmt === false)
{
FatalError("Failed to call test procedure");
}
return ($stmt);
}
function CreateFunc($conn, $funcName, $funcArgs, $retType, $funcCode)
{
DropFunc($conn,$funcName);
$stmt = sqlsrv_query($conn, "CREATE FUNCTION [$funcName] ($funcArgs) RETURNS $retType AS BEGIN $funcCode END");
if ($stmt === false)
{
FatalError("Failed to create test function");
}
sqlsrv_free_stmt($stmt);
}
function DropFunc($conn, $funcName)
{
$stmt = sqlsrv_query($conn, "DROP FUNCTION [$funcName]");
if ($stmt === false)
{
}
else
{
sqlsrv_free_stmt($stmt);
}
}
function CallFunc($conn, $funcName, $funcArgs, $funcValues)
{
$stmt = sqlsrv_query($conn, "{ ? = CALL [$funcName]($funcArgs)}", $funcValues);
if ($stmt === false)
{
FatalError("Failed to call test function");
}
sqlsrv_free_stmt($stmt);
}
function FatalError($errorMsg)
{
SetUTF8Data(false);
handle_errors();
die($errorMsg."\n");
}
function PrintErrors($message = "")
{
if (strlen($message) > 0)
{
echo $message . "\n";
}
$errors = sqlsrv_errors(SQLSRV_ERR_ERRORS);
if(count($errors) == 0)
{
$errors = sqlsrv_errors(SQLSRV_ERR_ALL);
}
$count = count($errors);
for($i = 0; $i < $count; $i++)
{
echo $errors[$i]['message'] . "\n";
}
}
function handle_errors()
{
$errors = sqlsrv_errors(SQLSRV_ERR_ERRORS);
$count = count($errors);
if($count == 0)
{
$errors = sqlsrv_errors(SQLSRV_ERR_ALL);
$count = count($errors);
}
if($count > 0)
{
for($i = 0; $i < $count; $i++)
{
echo ($errors[$i]['message']."\n");
}
}
}
?>

101
test/sqlsrv/MsData.inc Normal file

File diff suppressed because one or more lines are too long

101
test/sqlsrv/MsData_UTF8.inc Normal file

File diff suppressed because one or more lines are too long

40
test/sqlsrv/MsSetup.inc Normal file
View file

@ -0,0 +1,40 @@
<?php
/*
Microsoft SQL Server Driver for PHP - Unit Test Framework
Copyright (c) Microsoft Corporation. All rights reserved.
Description:
Global variables defining the execution context
*/
$PhpDriver = "Microsoft SQL Server Driver for PHP";
$server = 'SQL-2K12-SP3-1.galaxy.ad';
$database = 'test_win123';
$userName = 'sa';
$userPassword = 'Moonshine4me';
$tableName = "php_test_table";
$tableIndex = "php_test_table_index";
$procName = "php_test_proc";
$fileName = "php_test_file.dat";
$connectionOptions = array("Database"=>$database, "UID"=>$userName, "PWD"=>$userPassword, "TraceOn"=>false);
$daasMode = false;
$marsMode = true;
$traceEnabled = false;
if (isset($_ENV['MSSQL_SERVER']) || isset($_ENV['MSSQL_USER']) || isset($_ENV['MSSQL_PASSWORD'])) {
$server = $_ENV['MSSQL_SERVER'];
$uid = $_ENV['MSSQL_USER'];
$pwd = $_ENV['MSSQL_PASSWORD'];
$databaseName = $_ENV['MSSQL_DATABASE_NAME'];
$DriverName = $_ENV['MSSQL_DRIVER_NAME'];
} else {
$uid = $userName;
$pwd = $userPassword;
$databaseName = $database;
$DriverName = "ODBC Driver 11 for SQL Server";
}
?>

View file

@ -1,16 +0,0 @@
<?php
// Set SQL server + user + password
$serverName = getenv('MSSQL_SERVERNAME') ?: "localhost";
$username = getenv('MSSQL_USERNAME') ?: "sa";
$password = getenv('MSSQL_PASSWORD') ?: "<YourStrong!Passw0rd>";
// Generate unique DB name, example: php_20160817_1471475608267
$dbName = "php_" . date("Ymd") . "_" . round(microtime(true)*1000);
// Generic table name example: php_20160817_1471475608267.dbo.php_firefly
$tableName = $dbName.".dbo.php_firefly";
// Connection options
$connectionInfo = array("UID"=>"$username", "PWD"=>"$password");
?>

View file

@ -1,17 +1,19 @@
--TEST--
Test the connection resiliency keywords
--DESCRIPTION--
Test the connection resiliency keywords ConnectRetryCount and ConnectRetryInterval and their ranges of acceptable values
--SKIPIF--
<?php if ( !( strtoupper( substr( php_uname( 's' ),0,3 ) ) === 'WIN' ) ) die( "Skip, not running on windows." ); ?>
--FILE--
<?php
require_once( "autonomous_setup.php" );
require_once( "MsSetup.inc" );
function TryToConnect( $serverName, $username, $password, $retryCount, $retryInterval, $number )
function TryToConnect( $server, $userName, $userPassword, $retryCount, $retryInterval, $number )
{
$connectionInfo = array( "UID"=>$username, "PWD"=>$password,
$connectionInfo = array( "UID"=>$userName, "PWD"=>$userPassword,
"ConnectRetryCount"=>$retryCount, "ConnectRetryInterval"=>$retryInterval );
$conn = sqlsrv_connect( $serverName, $connectionInfo );
$conn = sqlsrv_connect( $server, $connectionInfo );
if( $conn === false )
{
echo "Could not connect on $number attempt.\n";
@ -24,17 +26,17 @@ function TryToConnect( $serverName, $username, $password, $retryCount, $retryInt
}
}
TryToConnect( $serverName, $username, $password, 10, 30, 'first');
TryToConnect( $serverName, $username, $password, 0, 30, 'second');
TryToConnect( $serverName, $username, $password, 256, 30, 'third');
TryToConnect( $serverName, $username, $password, 5, 70, 'fourth');
TryToConnect( $serverName, $username, $password, -1, 30, 'fifth');
TryToConnect( $serverName, $username, $password, 'thisisnotaninteger', 30, 'sixth');
TryToConnect( $serverName, $username, $password, 5, 3.14159, 'seventh');
TryToConnect( $server, $userName, $userPassword, 10, 30, 'first');
TryToConnect( $server, $userName, $userPassword, 0, 30, 'second');
TryToConnect( $server, $userName, $userPassword, 256, 30, 'third');
TryToConnect( $server, $userName, $userPassword, 5, 70, 'fourth');
TryToConnect( $server, $userName, $userPassword, -1, 30, 'fifth');
TryToConnect( $server, $userName, $userPassword, 'thisisnotaninteger', 30, 'sixth');
TryToConnect( $server, $userName, $userPassword, 5, 3.14159, 'seventh');
$connectionInfo = array( "UID"=>$username, "PWD"=>$password, "ConnectRetryCount" );
$connectionInfo = array( "UID"=>$userName, "PWD"=>$userPassword, "ConnectRetryCount" );
$conn = sqlsrv_connect( $serverName, $connectionInfo );
$conn = sqlsrv_connect( $server, $connectionInfo );
if( $conn === false )
{
echo "Could not connect on eighth attempt.\n";
@ -46,9 +48,9 @@ else
sqlsrv_close( $conn );
}
$connectionInfo = array( "UID"=>$username, "PWD"=>$password, "ConnectRetryInterval" );
$connectionInfo = array( "UID"=>$userName, "PWD"=>$userPassword, "ConnectRetryInterval" );
$conn = sqlsrv_connect( $serverName, $connectionInfo );
$conn = sqlsrv_connect( $server, $connectionInfo );
if( $conn === false )
{
echo "Could not connect on ninth attempt.\n";

BIN
test/sqlsrv/php.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

7
test/sqlsrv/skipif.inc Normal file
View file

@ -0,0 +1,7 @@
<?php
if (!extension_loaded("sqlsrv")) {
die("skip extension not loaded");
}
?>

View file

@ -0,0 +1,12 @@
<?php
if (!extension_loaded("sqlsrv")) {
die("skip extension not loaded");
}
include 'MsCommon.inc';
if ( IsDaasMode() ) {
die("skip test in Azure");
}
?>

View file

@ -9,20 +9,12 @@ With unixODBC 2.3.4 + pooling the statement executes without error.
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsCommon.inc");
$connectionInfo = array("UID"=>"$username", "PWD"=>"$password");
$conn = sqlsrv_connect($serverName, $connectionInfo);
$conn = Connect();
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$conn = null;
$conn = sqlsrv_connect($serverName, $connectionInfo);
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$bindtable = "#BindStringTest";
$sproc = "#uspPerson";
@ -41,21 +33,21 @@ if( $stmt === false ) {
$stmt = sqlsrv_query( $conn, "INSERT INTO $bindtable (PersonID, Name) VALUES (11, N'JSmith')" );
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
}
$tsql_createSP = "CREATE PROCEDURE $sproc
@id int, @return nvarchar(50) OUTPUT
AS
BEGIN
SET NOCOUNT ON;
SET @return = (SELECT Name FROM $bindtable WHERE PersonID = @id)
END";
AS
BEGIN
SET NOCOUNT ON;
SET @return = (SELECT Name FROM $bindtable WHERE PersonID = @id)
END";
$stmt = sqlsrv_query( $conn, $tsql_createSP);
if( $stmt === false )
{
echo "Error in executing statement 2.\n";
die( print_r( sqlsrv_errors(), true));
echo "Error in executing statement 2.\n";
die( print_r( sqlsrv_errors(), true));
}
$tsql_callSP = "{call $sproc( ? , ?)}";
@ -68,15 +60,15 @@ echo "---------Encoding char-----------\n";
$id = 10;
$return = "";
$params = array(
array($id, SQLSRV_PARAM_IN),
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
SQLSRV_SQLTYPE_NVARCHAR(32)
));
if( $stmt = sqlsrv_query($conn, $tsql_callSP, $params) === false)
{
print_r( sqlsrv_errors(), true);
print_r( sqlsrv_errors(), true);
}
$expectedLength = 6;
@ -89,15 +81,15 @@ echo "---------Encoding binary---------\n";
$id = 10;
$return = "";
$params = array(
array($id, SQLSRV_PARAM_IN),
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY),
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY),
SQLSRV_SQLTYPE_NVARCHAR(32)
));
if( $stmt = sqlsrv_query($conn, $tsql_callSP, $params) == false)
{
print_r( sqlsrv_errors(), true);
}
{
print_r( sqlsrv_errors(), true);
}
$expectedLength = 12;
$expectedValue = "M\0i\0l\0l\0e\0r\0";
@ -112,15 +104,15 @@ echo "---------Encoding char-----------\n";
$id = 10;
$return = "";
$params = array(
array($id, SQLSRV_PARAM_IN),
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
SQLSRV_SQLTYPE_NVARCHAR(50)
));
if( $stmt = sqlsrv_query($conn, $tsql_callSP, $params) === false)
{
print_r( sqlsrv_errors(), true);
print_r( sqlsrv_errors(), true);
}
$expectedLength = 6;
@ -134,15 +126,15 @@ echo "---------Encoding binary---------\n";
$id = 10;
$return = "";
$params = array(
array($id, SQLSRV_PARAM_IN),
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY),
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY),
SQLSRV_SQLTYPE_NVARCHAR(50)
));
if( $stmt = sqlsrv_query($conn, $tsql_callSP, $params) == false)
{
print_r( sqlsrv_errors(), true);
}
{
print_r( sqlsrv_errors(), true);
}
$expectedLength = 12;
$expectedValue = "M\0i\0l\0l\0e\0r\0";
@ -159,16 +151,16 @@ $return = "";
$params = array(
array($id, SQLSRV_PARAM_IN),
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
SQLSRV_SQLTYPE_NVARCHAR(1)
));
// with unixODBC 2.3.4 connection pooling the statement may not fail.
if( $stmt = sqlsrv_query($conn, $tsql_callSP, $params) === false)
{
echo "Statement should fail\n";
echo "Statement should fail\n";
}
$expectedLength = 1;
@ -181,15 +173,15 @@ echo "---------Encoding binary---------\n";
$id = 10;
$return = "";
$params = array(
array($id, SQLSRV_PARAM_IN),
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY),
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY),
SQLSRV_SQLTYPE_NVARCHAR(1)
));
if( $stmt = sqlsrv_query($conn, $tsql_callSP, $params) == false)
{
echo "Statement should fail\n";
}
{
echo "Statement should fail\n";
}
$expectedLength = 2;
$expectedValue = "M\0";
@ -204,15 +196,15 @@ echo "---------Encoding char-----------\n";
$id = 10;
$return = "";
$params = array(
array($id, SQLSRV_PARAM_IN),
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
SQLSRV_SQLTYPE_NCHAR(32)
));
if( $stmt = sqlsrv_query($conn, $tsql_callSP, $params) === false)
{
print_r( sqlsrv_errors(), true);
print_r( sqlsrv_errors(), true);
}
$expectedLength = 32;
@ -225,15 +217,15 @@ echo "---------Encoding binary---------\n";
$id = 10;
$return = "";
$params = array(
array($id, SQLSRV_PARAM_IN),
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY),
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY),
SQLSRV_SQLTYPE_NCHAR(32)
));
if( $stmt = sqlsrv_query($conn, $tsql_callSP, $params) == false)
{
print_r( sqlsrv_errors(), true);
}
{
print_r( sqlsrv_errors(), true);
}
$expectedLength = 64;
$expectedValue = "M\0i\0l\0l\0e\0r\0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0";
@ -248,15 +240,15 @@ echo "---------Encoding char-----------\n";
$id = 10;
$return = "";
$params = array(
array($id, SQLSRV_PARAM_IN),
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
SQLSRV_SQLTYPE_NCHAR(0)
));
if( $stmt = sqlsrv_query($conn, $tsql_callSP, $params) === false)
{
echo "Statement should fail\n";
echo "Statement should fail\n";
}
$expectedLength = 0;
@ -269,16 +261,16 @@ echo "---------Encoding binary---------\n";
$id = 10;
$return = "";
$params = array(
array($id, SQLSRV_PARAM_IN),
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY),
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY),
SQLSRV_SQLTYPE_NCHAR(0)
));
if( $stmt = sqlsrv_query($conn, $tsql_callSP, $params) == false)
{
echo "Statement should fail\n";
}
{
echo "Statement should fail\n";
}
$expectedLength = 0;
$expectedValue = "";
$actualLength = strlen($return);
@ -292,15 +284,15 @@ echo "---------Encoding char-----------\n";
$id = 10;
$return = "";
$params = array(
array($id, SQLSRV_PARAM_IN),
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
SQLSRV_SQLTYPE_NCHAR(50)
));
if( $stmt = sqlsrv_query($conn, $tsql_callSP, $params) === false)
{
print_r( sqlsrv_errors(), true);
print_r( sqlsrv_errors(), true);
}
$expectedLength = 50;
@ -313,15 +305,15 @@ echo "---------Encoding binary---------\n";
$id = 10;
$return = "";
$params = array(
array($id, SQLSRV_PARAM_IN),
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY),
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY),
SQLSRV_SQLTYPE_NCHAR(50)
));
if( $stmt = sqlsrv_query($conn, $tsql_callSP, $params) == false)
{
print_r( sqlsrv_errors(), true);
}
{
print_r( sqlsrv_errors(), true);
}
$expectedLength = 100;
$expectedValue = "M\0i\0l\0l\0e\0r\0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0";
@ -337,15 +329,15 @@ echo "---------Encoding char-----------\n";
$id = 10;
$return = "";
$params = array(
array($id, SQLSRV_PARAM_IN),
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
SQLSRV_SQLTYPE_NCHAR(1)
));
if( $stmt = sqlsrv_query($conn, $tsql_callSP, $params) === false)
{
print_r( sqlsrv_errors(), true);
print_r( sqlsrv_errors(), true);
}
$expectedLength = 1;
@ -358,15 +350,15 @@ echo "---------Encoding binary---------\n";
$id = 10;
$return = "";
$params = array(
array($id, SQLSRV_PARAM_IN),
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY),
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY),
SQLSRV_SQLTYPE_NCHAR(1)
));
if( $stmt = sqlsrv_query($conn, $tsql_callSP, $params) == false)
{
print_r( sqlsrv_errors(), true);
}
{
print_r( sqlsrv_errors(), true);
}
$expectedLength = 2;
$expectedValue = "M\0";

View file

@ -3,10 +3,10 @@ Test sqlsrv_client_info
--SKIPIF--
--FILE--
<?php
require_once("autonomous_setup.php");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
require_once("MsCommon.inc");
$conn = Connect();
if( !$conn ) {
die( print_r( sqlsrv_errors(), true));
die( print_r( sqlsrv_errors(), true));
}
$client_info = sqlsrv_client_info( $conn );

View file

@ -2,19 +2,15 @@
Free statement twice
--FILE--
<?php
include 'tools.inc';
include 'MsCommon.inc';
function CloseTwice()
{
require_once("autonomous_setup.php");
{
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
sqlsrv_get_config('WarningsReturnAsErrors');
// Connect
$connectionInfo = array("UID"=>"$username", "PWD"=>"$password");
$conn = sqlsrv_connect($serverName, $connectionInfo);
$conn = Connect();
if( !$conn ) { FatalError("Could not connect.\n"); }
$tableName = GetTempTableName();
@ -53,9 +49,7 @@ Repro();
?>
--EXPECTREGEX--

...Starting 'sqlsrv_close_twice' test...
Warning: sqlsrv_free_stmt\(\): supplied resource is not a valid ss_sqlsrv_stmt resource in .+sqlsrv_close_twice.php on line [0-9]+
Done
...Test 'sqlsrv_close_twice' completed successfully.
Test "sqlsrv_close_twice" completed successfully.

View file

@ -2,19 +2,15 @@
Test a complex query with IDENTITY_INSERT
--FILE--
<?php
include 'tools.inc';
include 'MsCommon.inc';
function ComplexQuery()
{
require_once("autonomous_setup.php");
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
sqlsrv_get_config('WarningsReturnAsErrors');
// Connect
$connectionInfo = array("UID"=>$username, "PWD"=>$password, "CharacterSet"=>"UTF-8");
$conn = sqlsrv_connect($serverName, $connectionInfo);
$conn = Connect(array("CharacterSet"=>"UTF-8"));
if( !$conn ) { FatalError("Could not connect.\n"); }
$tableName = GetTempTableName();
@ -75,6 +71,8 @@ function ComplexQuery()
function Repro()
{
StartTest("sqlsrv_statement_complex_query");
echo "\nTest begins...\n";
try
{
ComplexQuery();
@ -90,14 +88,14 @@ function Repro()
Repro();
?>
--EXPECTF--
--EXPECTREGEX--

...Starting 'sqlsrv_statement_complex_query' test...
[Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Cannot insert explicit value for identity column in table '%s' when IDENTITY_INSERT is set to OFF.
Test begins...
\[Microsoft\]\[ODBC Driver 13 for SQL Server\]\[SQL Server\]Cannot insert explicit value for identity column in table '.+' when IDENTITY_INSERT is set to OFF.
544
23000
Number of rows inserted: 2
Number of rows fetched: 2
Done
...Test 'sqlsrv_statement_complex_query' completed successfully.
Test "sqlsrv_statement_complex_query" completed successfully.

View file

@ -2,19 +2,17 @@
Test insert various data types and fetch as strings
--FILE--
<?php
include 'MsCommon.inc';
include 'tools.inc';
function ExplicitFetch()
{
include 'autonomous_setup.php';
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
sqlsrv_get_config('WarningsReturnAsErrors');
// Connect
$connectionInfo = array("UID"=>$username, "PWD"=>$password, "CharacterSet"=>"UTF-8");
$conn = sqlsrv_connect($serverName, $connectionInfo);
$connectionInfo = array("CharacterSet"=>"UTF-8");
$conn = Connect($connectionInfo);
if( !$conn ) { FatalError("Could not connect.\n"); }
$tableName = GetTempTableName();
@ -73,6 +71,7 @@ function GetInputData($index)
function Repro()
{
StartTest("sqlsrv_data_types_explict_fetch");
echo "\nTest begins...\n";
try
{
ExplicitFetch();
@ -90,11 +89,11 @@ Repro();
?>
--EXPECT--

...Starting 'sqlsrv_data_types_explict_fetch' test...
Test begins...
Comparing data in row 1
Comparing data in row 2
Comparing data in row 3
Comparing data in row 4
Done
...Test 'sqlsrv_data_types_explict_fetch' completed successfully.
Test "sqlsrv_data_types_explict_fetch" completed successfully.

View file

@ -2,19 +2,17 @@
Test insert various data types and fetch as strings
--FILE--
<?php
include 'MsCommon.inc';
include 'tools.inc';
function FetchAsStream_Binary()
{
include 'autonomous_setup.php';
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
sqlsrv_get_config('WarningsReturnAsErrors');
// Connect
$connectionInfo = array("Database" => "tempdb", "UID"=>$username, "PWD"=>$password, "CharacterSet"=>"UTF-8");
$conn = sqlsrv_connect($serverName, $connectionInfo);
$connectionInfo = array("CharacterSet"=>"UTF-8");
$conn = Connect($connectionInfo);
if( !$conn ) { FatalError("Could not connect.\n"); }
$tableName = GetTempTableName();
@ -86,6 +84,7 @@ function GetQuery($tableName, $index)
function Repro()
{
StartTest("sqlsrv_data_types_fetch_binary_stream");
echo "\nTest begins...\n";
try
{
FetchAsStream_Binary();
@ -103,9 +102,9 @@ Repro();
?>
--EXPECT--

...Starting 'sqlsrv_data_types_fetch_binary_stream' test...
Test begins...
Comparing data in row 1
Comparing data in row 2
Done
...Test 'sqlsrv_data_types_fetch_binary_stream' completed successfully.
Test "sqlsrv_data_types_fetch_binary_stream" completed successfully.

View file

@ -2,19 +2,15 @@
Free statement twice
--FILE--
<?php
include 'tools.inc';
include 'MsCommon.inc';
function ExecuteTwice()
{
require_once("autonomous_setup.php");
{
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
sqlsrv_get_config('WarningsReturnAsErrors');
// Connect
$connectionInfo = array("UID"=>$username, "PWD"=>$password);
$conn = sqlsrv_connect($serverName, $connectionInfo);
$conn = Connect();
if( !$conn ) { FatalError("Could not connect.\n"); }
$tableName = GetTempTableName();
@ -46,6 +42,7 @@ function ExecuteTwice()
function Repro()
{
StartTest("sqlsrv_statement_execute_twice");
echo "\nTest begins...\n";
try
{
ExecuteTwice();
@ -63,10 +60,10 @@ Repro();
?>
--EXPECT--

...Starting 'sqlsrv_statement_execute_twice' test...
Test begins...
A statement must be prepared with sqlsrv_prepare before calling sqlsrv_execute.
-23
IMSSP
Done
...Test 'sqlsrv_statement_execute_twice' completed successfully.
Test "sqlsrv_statement_execute_twice" completed successfully.

View file

@ -2,7 +2,7 @@
Test transactions commit, rollback and aborting in between
--FILE--
<?php
include 'tools.inc';
include 'MsCommon.inc';
function ComplexTransaction($conn, $conn2)
{
@ -105,15 +105,13 @@ function RunTest()
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
require_once("autonomous_setup.php");
$database = "tempdb";
echo "\nTest begins...\n";
// Connect
$connectionInfo = array('Database'=>$database, 'UID'=>$username, 'PWD'=>$password);
$conn = sqlsrv_connect($serverName, $connectionInfo);
$conn = Connect();
if( !$conn ) { FatalError("Could not connect.\n"); }
$conn2 = sqlsrv_connect($serverName, $connectionInfo);
$conn2 = Connect();
if( !$conn2 ) { FatalError("Could not connect.\n"); }
ComplexTransaction($conn, $conn2);
@ -133,7 +131,7 @@ RunTest();
?>
--EXPECT--

...Starting 'sqlsrv_fetch_complex_transactions' test...
Test begins...
Number of rows fetched: 10
Committed deleting 3 rows
Number of rows fetched: 7
@ -147,4 +145,4 @@ Deletion aborted
Number of rows fetched: 4
Done
...Test 'sqlsrv_fetch_complex_transactions' completed successfully.
Test "sqlsrv_fetch_complex_transactions" completed successfully.

View file

@ -2,7 +2,7 @@
Test with static cursor and select different rows in some random order
--FILE--
<?php
include 'tools.inc';
include 'MsCommon.inc';
function FetchRow_Query($conn)
{
@ -135,12 +135,10 @@ function RunTest()
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
require_once("autonomous_setup.php");
$database = "tempdb";
echo "\nTest begins...\n";
// Connect
$connectionInfo = array('Database'=>$database, 'UID'=>$username, 'PWD'=>$password);
$conn = sqlsrv_connect($serverName, $connectionInfo);
$conn = Connect();
if( !$conn ) { FatalError("Could not connect.\n"); }
FetchRow_Query($conn);
@ -160,7 +158,7 @@ RunTest();
?>
--EXPECT--

...Starting 'sqlsrv_fetch_cursor_static_scroll' test...
Test begins...
1, Row 1
2, Row 2
3, Row 3
@ -203,4 +201,4 @@ last row: 10, Row 10
row 1 from the current row:
Done
...Test 'sqlsrv_fetch_cursor_static_scroll' completed successfully.
Test "sqlsrv_fetch_cursor_static_scroll" completed successfully.

View file

@ -2,7 +2,7 @@
Test various cursor types and whether they reflect changes in the database
--FILE--
<?php
include 'tools.inc';
include 'MsCommon.inc';
function Fetch_WithCursor($conn, $cursorType)
{
@ -113,12 +113,10 @@ function RunTest()
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
require_once("autonomous_setup.php");
$database = "tempdb";
echo "\nTest begins...\n";
// Connect
$connectionInfo = array('Database'=>$database, 'UID'=>$username, 'PWD'=>$password);
$conn = sqlsrv_connect($serverName, $connectionInfo);
$conn = Connect();
if( !$conn ) { FatalError("Could not connect.\n"); }
echo "\nUsing SQLSRV_CURSOR_FORWARD...\n";
@ -145,7 +143,7 @@ RunTest();
?>
--EXPECT--

...Starting 'sqlsrv_fetch_cursor_types' test...
Test begins...
Using SQLSRV_CURSOR_FORWARD...
Error occurred in sqlsrv_num_rows, which is expected
@ -191,4 +189,4 @@ int(4)
string(10) "Row 4 "
Done
...Test 'sqlsrv_fetch_cursor_types' completed successfully.
Test "sqlsrv_fetch_cursor_types" completed successfully.

View file

@ -2,7 +2,7 @@
Test fetching datatime fields as strings
--FILE--
<?php
include 'tools.inc';
include 'MsCommon.inc';
function FetchDateTime_AsString($conn)
{
@ -89,12 +89,10 @@ function Repro()
{
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
require_once("autonomous_setup.php");
echo "\nTest begins...\n";
// Connect
$connectionInfo = array("UID"=>$username, "PWD"=>$password, 'ReturnDatesAsStrings'=>true);
$conn = sqlsrv_connect($serverName, $connectionInfo);
$conn = Connect(array('ReturnDatesAsStrings'=>true));
if( !$conn ) { FatalError("Could not connect.\n"); }
FetchDateTime_AsString($conn);
@ -114,7 +112,7 @@ Repro();
?>
--EXPECT--

...Starting 'sqlsrv_fetch_datetime_as_strings' test...
Test begins...
Done
...Test 'sqlsrv_fetch_datetime_as_strings' completed successfully.
Test "sqlsrv_fetch_datetime_as_strings" completed successfully.

View file

@ -2,7 +2,7 @@
Test calling sqlsrv_get_field twice in a row. Intentionally trigger various error messages.
--FILE--
<?php
include 'tools.inc';
include 'MsCommon.inc';
function FetchFieldTwice($conn)
{
@ -38,26 +38,24 @@ function FetchFieldTwice($conn)
{
for ($i = -1; $i <= $numFields; $i++)
{
FetchField($stmt, $i, $metadata, false);
FetchField($stmt, $i, $metadata, true);
FetchField($stmt, $i, $numFields, false);
FetchField($stmt, $i, $numFields, true);
}
}
sqlsrv_free_stmt($stmt);
}
function FetchField($stmt, $idx, $metadata, $errorExpected)
function FetchField($stmt, $idx, $numFields, $errorExpected)
{
if ($idx < 0 || $idx >= count($metadata))
if ($idx < 0 || $idx >= $numFields)
{
$value1 = sqlsrv_get_field($stmt, $idx);
PrintError(true); // errors expected because the idx is out of bound
PrintError(true); // errors expected because $idx is out of bound
}
else
{
$colType = $metadata[$idx]['Type'];
if (IsDateTime($colType))
if ($idx == 3)
{
$value1 = sqlsrv_get_field($stmt, $idx, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
}
@ -93,11 +91,10 @@ function Repro()
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
require_once("autonomous_setup.php");
echo "\nTest begins...\n";
// Connect
$connectionInfo = array("UID"=>$username, "PWD"=>$password);
$conn = sqlsrv_connect($serverName, $connectionInfo);
$conn = Connect();
if( !$conn ) { FatalError("Could not connect.\n"); }
FetchFieldTwice($conn);
@ -117,7 +114,7 @@ Repro();
?>
--EXPECT--

...Starting 'sqlsrv_fetch_field_twice_data_types' test...
Test begins...
string(79) "A statement must be prepared with sqlsrv_prepare before calling sqlsrv_execute."
string(63) "The statement must be executed before results can be retrieved."
string(52) "An invalid parameter was passed to sqlsrv_get_field."
@ -138,4 +135,4 @@ string(52) "An invalid parameter was passed to sqlsrv_get_field."
string(52) "An invalid parameter was passed to sqlsrv_get_field."
Done
...Test 'sqlsrv_fetch_field_twice_data_types' completed successfully.
Test "sqlsrv_fetch_field_twice_data_types" completed successfully.

View file

@ -2,7 +2,7 @@
Populate a test table with many fields and fetch them back using wrong data types
--FILE--
<?php
include 'tools.inc';
include 'MsCommon.inc';
function PopulateTestTable($conn, $tableName)
{
@ -42,13 +42,11 @@ function RunTest()
{
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
echo "\nTest begins...\n";
require_once("autonomous_setup.php");
$database = "tempdb";
// Connect
$connectionInfo = array("UID"=>$username, "PWD"=>$password, 'CharacterSet'=>'UTF-8');
$conn = sqlsrv_connect($serverName, $connectionInfo);
$conn = Connect(array('CharacterSet'=>'UTF-8'));
if( !$conn ) { FatalError("Could not connect.\n"); }
$tableName = GetTempTableName();
@ -76,7 +74,7 @@ RunTest();
?>
--EXPECT--

...Starting 'sqlsrv_fetch_invalid_types' test...
Test begins...
Fetch all as integers...
Failed in field 8
Failed in field 9
@ -134,4 +132,4 @@ Failed in field 26
Failed in field 27
Done
...Test 'sqlsrv_fetch_invalid_types' completed successfully.
Test "sqlsrv_fetch_invalid_types" completed successfully.

View file

@ -2,19 +2,15 @@
Fetch missing row
--FILE--
<?php
include 'tools.inc';
include 'MsCommon.inc';
function MissingRow_Fetch()
{
include 'autonomous_setup.php';
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
sqlsrv_get_config('WarningsReturnAsErrors');
// Connect
$connectionInfo = array("UID"=>$username, "PWD"=>$password);
$conn = sqlsrv_connect($serverName, $connectionInfo);
$conn = Connect();
if( !$conn ) { FatalError("Could not connect.\n"); }
$tableName = GetTempTableName();
@ -42,6 +38,7 @@ function MissingRow_Fetch()
function Repro()
{
StartTest("sqlsrv_fetch_missing_row");
echo "\nTest begins...\n";
try
{
MissingRow_Fetch();
@ -59,10 +56,10 @@ Repro();
?>
--EXPECT--

...Starting 'sqlsrv_fetch_missing_row' test...
Test begins...
There are no more rows in the active result set. Since this result set is not scrollable, no more data may be retrieved.
-22
IMSSP
Done
...Test 'sqlsrv_fetch_missing_row' completed successfully.
Test "sqlsrv_fetch_missing_row" completed successfully.

View file

@ -2,7 +2,7 @@
Test insert various data types and fetch as strings
--FILE--
<?php
include 'tools.inc';
include 'MsCommon.inc';
class TestClass2
{
@ -21,16 +21,14 @@ class TestClass3
}
function FetchObject_ClassArgs()
{
include 'autonomous_setup.php';
{
include 'tools.inc';
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
sqlsrv_get_config('WarningsReturnAsErrors');
// Connect
$connectionInfo = array("Database" => "tempdb", "UID"=>$username, "PWD"=>$password, "CharacterSet"=>"UTF-8");
$conn = sqlsrv_connect($serverName, $connectionInfo);
$conn = Connect(array("CharacterSet"=>"UTF-8"));
if( !$conn ) { FatalError("Could not connect.\n"); }
$tableName = GetTempTableName();
@ -106,9 +104,10 @@ function GetQuery($tableName, $index)
return $query;
}
function Repro()
function RunTest()
{
StartTest("sqlsrv_fetch_object_class");
echo "\nTest begins...\n";
try
{
FetchObject_ClassArgs();
@ -121,12 +120,12 @@ function Repro()
EndTest("sqlsrv_fetch_object_class");
}
Repro();
RunTest();
?>
--EXPECT--

...Starting 'sqlsrv_fetch_object_class' test...
Test begins...
Constructor called with 3 arguments
Comparing data in row 1
Constructor called with 3 arguments
@ -137,4 +136,4 @@ Constructor called with 2 arguments
Comparing data in row 2
Done
...Test 'sqlsrv_fetch_object_class' completed successfully.
Test "sqlsrv_fetch_object_class" completed successfully.

View file

@ -2,7 +2,7 @@
Test various Katmai types, like geography, geometry, hierarchy, sparse, etc. and fetch them back as strings
--FILE--
<?php
include 'tools.inc';
include 'MsCommon.inc';
function Katmai_Basic_Types($conn)
{
@ -122,17 +122,14 @@ function Katmai_SparseNumeric($conn)
function RunTest()
{
StartTest("sqlsrv_katmai_special_types");
echo "\nTest begins...\n";
try
{
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
require_once("autonomous_setup.php");
$database = "tempdb";
// Connect
$connectionInfo = array("UID"=>$username, "PWD"=>$password);
$conn = sqlsrv_connect($serverName, $connectionInfo);
$conn = Connect();
if( !$conn ) { FatalError("Could not connect.\n"); }
Katmai_Basic_Types($conn);
@ -154,7 +151,7 @@ RunTest();
?>
--EXPECT--

...Starting 'sqlsrv_katmai_special_types' test...
Test begins...
Showing results of Katmai basic fields
string(44) "E6100000010C3333333333134A406666666666661A40"
@ -176,4 +173,4 @@ string(6) "1.0000"
string(6) "1.0000"
Done
...Test 'sqlsrv_katmai_special_types' completed successfully.
Test "sqlsrv_katmai_special_types" completed successfully.

View file

@ -2,19 +2,15 @@
Test insertion with floats
--FILE--
<?php
include 'tools.inc';
include 'MsCommon.inc';
function ExecData($withParams)
{
include 'autonomous_setup.php';
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
sqlsrv_get_config('WarningsReturnAsErrors');
// Connect
$connectionInfo = array("UID"=>$username, "PWD"=>$password);
$conn = sqlsrv_connect($serverName, $connectionInfo);
$conn = Connect();
if( !$conn ) { FatalError("Could not connect.\n"); }
$tableName = GetTempTableName();
@ -67,6 +63,9 @@ function ExecData($withParams)
$idx = 0;
$stmt = sqlsrv_query($conn, "SELECT * FROM $tableName");
$epsilon = 0.00001;
while ($result = sqlsrv_fetch($stmt))
{
for ($i = 0; $i < 2; $i++)
@ -75,7 +74,7 @@ function ExecData($withParams)
$expected = $values[$idx++];
$diff = abs(($value - $expected) / $expected);
if ($diff > _EPSILON)
if ($diff > $epsilon)
{
echo "Value $value is unexpected\n";
}
@ -88,6 +87,8 @@ function ExecData($withParams)
function Repro()
{
StartTest("sqlsrv_statement_exec_param_floats");
echo "\nTest begins...\n";
try
{
ExecData(true);
@ -106,7 +107,7 @@ Repro();
?>
--EXPECT--

...Starting 'sqlsrv_statement_exec_param_floats' test...
Test begins...
Done
...Test 'sqlsrv_statement_exec_param_floats' completed successfully.
Test "sqlsrv_statement_exec_param_floats" completed successfully.

View file

@ -2,19 +2,15 @@
Test insertion with floats
--FILE--
<?php
include 'tools.inc';
include 'MsCommon.inc';
function ExecData($withParams)
{
include 'autonomous_setup.php';
{
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
sqlsrv_get_config('WarningsReturnAsErrors');
// Connect
$connectionInfo = array("UID"=>$username, "PWD"=>$password);
$conn = sqlsrv_connect($serverName, $connectionInfo);
$conn = Connect();
if( !$conn ) { FatalError("Could not connect.\n"); }
$tableName = GetTempTableName();
@ -130,6 +126,7 @@ function DeleteRows($conn, $numRows, $tableName)
function Repro()
{
StartTest("sqlsrv_statement_exec_param_ints");
echo "\nTest begins...\n";
try
{
ExecData(true);
@ -148,7 +145,7 @@ Repro();
?>
--EXPECT--

...Starting 'sqlsrv_statement_exec_param_ints' test...
Test begins...
Number of Actual Rows: 5
Number of Affected Rows: 3
Number of Actual Rows: 2
@ -159,4 +156,4 @@ Number of Actual Rows: 2
Number of Affected Rows: 2
Done
...Test 'sqlsrv_statement_exec_param_ints' completed successfully.
Test "sqlsrv_statement_exec_param_ints" completed successfully.

View file

@ -2,7 +2,7 @@
Test insert various numeric data types and fetch them back as strings
--FILE--
<?php
include 'tools.inc';
include 'MsCommon.inc';
function ExecData_Value($conn, $numRows, $phpType = SQLSRV_PHPTYPE_NULL)
{
@ -93,17 +93,14 @@ function FetchData($stmt, $numRows)
function Repro()
{
StartTest("sqlsrv_param_query_array_inputs");
echo "\nTest begins...\n";
try
{
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
require_once("autonomous_setup.php");
$database = "tempdb";
// Connect
$connectionInfo = array("UID"=>$username, "PWD"=>$password);
$conn = sqlsrv_connect($serverName, $connectionInfo);
$conn = Connect();
if( !$conn ) { FatalError("Could not connect.\n"); }
$numRows = 5;
@ -128,7 +125,7 @@ Repro();
?>
--EXPECT--

...Starting 'sqlsrv_param_query_array_inputs' test...
Test begins...
Insert integers without PHP type
1, 2
11, 12
@ -155,4 +152,4 @@ Insert floats without direction
41.0, 42.0
Done
...Test 'sqlsrv_param_query_array_inputs' completed successfully.
Test "sqlsrv_param_query_array_inputs" completed successfully.

View file

@ -2,6 +2,7 @@
Test insert various numeric data types and fetch them back as strings
--FILE--
<?php
include 'MsCommon.inc';
include 'tools.inc';
function ParamQuery($conn, $type, $sqlsrvType, $inValue)
@ -17,6 +18,7 @@ function ParamQuery($conn, $type, $sqlsrvType, $inValue)
$stmt = sqlsrv_query($conn, "SELECT * FROM $tableName");
sqlsrv_fetch($stmt);
$value = sqlsrv_get_field($stmt, 1, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
CompareNumericData($value, $inValue);
sqlsrv_free_stmt($stmt);
@ -25,17 +27,14 @@ function ParamQuery($conn, $type, $sqlsrvType, $inValue)
function Repro()
{
StartTest("sqlsrv_param_query_data_types");
echo "\nTest begins...\n";
try
{
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
require_once("autonomous_setup.php");
$database = "tempdb";
// Connect
$connectionInfo = array("UID"=>$username, "PWD"=>$password);
$conn = sqlsrv_connect($serverName, $connectionInfo);
$conn = Connect();
if( !$conn ) { FatalError("Could not connect.\n"); }
ParamQuery($conn, "float", SQLSRV_SQLTYPE_FLOAT, 12.345);
@ -59,7 +58,7 @@ Repro();
?>
--EXPECT--

...Starting 'sqlsrv_param_query_data_types' test...
Test begins...
Done
...Test 'sqlsrv_param_query_data_types' completed successfully.
Test "sqlsrv_param_query_data_types" completed successfully.

View file

@ -2,7 +2,7 @@
Insert with query params but with wrong parameters or types
--FILE--
<?php
include 'tools.inc';
include 'MsCommon.inc';
function ParamQueryError_PhpType_Mismatch($conn)
{
@ -35,13 +35,12 @@ function ParamQueryError_Dir_Invalid($conn)
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_varchar_max] varchar(max))");
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(1, array("Test Data", 32, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_VARCHAR('max'))));
print handle_errors() . "\n";
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(1, array("Test Data", 32, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_VARCHAR('max'))));
PrintErrors();
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(1, array("Test Data", 'SQLSRV_PARAM_INTERNAL', SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_VARCHAR('max'))));
print handle_errors() . "\n";
PrintErrors();
}
function ParamQueryError_PhpType_Encoding($conn)
@ -52,7 +51,8 @@ function ParamQueryError_PhpType_Encoding($conn)
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(1, array("Test Data", SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING('SQLSRV_ENC_UNKNOWN'), null)));
print handle_errors() . "\n";
PrintErrors();
}
function ParamQueryError_PhpType_Invalid($conn)
@ -63,10 +63,10 @@ function ParamQueryError_PhpType_Invalid($conn)
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(1, array("Test Data", SQLSRV_PARAM_IN, 'SQLSRV_PHPTYPE_UNKNOWN', SQLSRV_SQLTYPE_VARCHAR('max'))));
print handle_errors() . "\n";
PrintErrors();
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(1, array("Test Data", SQLSRV_PARAM_IN, 6, SQLSRV_SQLTYPE_VARCHAR('max'))));
print handle_errors() . "\n";
PrintErrors();
}
//--------------------------------------------------------------------
@ -76,17 +76,15 @@ function ParamQueryError_PhpType_Invalid($conn)
function RunTest()
{
StartTest("sqlsrv_param_query_errors");
echo "\nTest begins...\n";
try
{
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
require_once("autonomous_setup.php");
$database = "tempdb";
// Connect
$connectionInfo = array('Database'=>$database, 'UID'=>$username, 'PWD'=>$password, 'CharacterSet'=>'UTF-8');
$conn = sqlsrv_connect($serverName, $connectionInfo);
$conn = Connect();
if( !$conn ) { FatalError("Could not connect.\n"); }
ParamQueryError_PhpType_Mismatch($conn);
@ -109,7 +107,7 @@ RunTest();
?>
--EXPECT--

...Starting 'sqlsrv_param_query_errors' test...
Test begins...
An invalid direction for parameter 2 was specified. SQLSRV_PARAM_IN, SQLSRV_PARAM_OUT, and SQLSRV_PARAM_INOUT are valid values.
An invalid direction for parameter 2 was specified. SQLSRV_PARAM_IN, SQLSRV_PARAM_OUT, and SQLSRV_PARAM_INOUT are valid values.
An invalid PHP type for parameter 2 was specified.
@ -117,4 +115,4 @@ An invalid PHP type for parameter 2 was specified.
An invalid PHP type for parameter 2 was specified.
Done
...Test 'sqlsrv_param_query_errors' completed successfully.
Test "sqlsrv_param_query_errors" completed successfully.

View file

@ -2,7 +2,7 @@
Insert with query params but with various invalid inputs or boundaries
--FILE--
<?php
include 'tools.inc';
include 'MsCommon.inc';
function ParamQueryError_MinMaxScale($conn)
{
@ -12,10 +12,10 @@ function ParamQueryError_MinMaxScale($conn)
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_decimal) VALUES (?, ?)", array(1, array(0.0, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_DECIMAL(28, 34))));
print handle_errors() . "\n";
PrintErrors();
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c3_numeric) VALUES (?, ?)", array(1, array(0.0, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_NUMERIC(32, -1))));
print handle_errors() . "\n";
PrintErrors();
}
function ParamQueryError_MinMaxSize($conn)
@ -26,10 +26,10 @@ function ParamQueryError_MinMaxSize($conn)
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(1, array("Test Data", SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_VARCHAR(0))));
print handle_errors() . "\n";
PrintErrors();
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(1, array("Test Data", SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_VARCHAR(9000))));
print handle_errors() . "\n";
PrintErrors();
}
function ParamQueryError_MinMaxPrecision($conn)
@ -40,10 +40,10 @@ function ParamQueryError_MinMaxPrecision($conn)
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c3_numeric) VALUES (?, ?)", array(1, array(0.0, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_NUMERIC(40, 0))));
print handle_errors() . "\n";
PrintErrors();
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_decimal) VALUES (?, ?)", array(1, array(0.0, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_DECIMAL(-1, 0))));
print handle_errors() . "\n";
PrintErrors();
}
//--------------------------------------------------------------------
@ -53,17 +53,14 @@ function ParamQueryError_MinMaxPrecision($conn)
function RunTest()
{
StartTest("sqlsrv_param_query_invalid_inputs");
echo "\nTest begins...\n";
try
{
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
require_once("autonomous_setup.php");
$database = "tempdb";
// Connect
$connectionInfo = array('Database'=>$database, 'UID'=>$username, 'PWD'=>$password, 'CharacterSet'=>'UTF-8');
$conn = sqlsrv_connect($serverName, $connectionInfo);
$conn = Connect();
if( !$conn ) { FatalError("Could not connect.\n"); }
ParamQueryError_MinMaxScale($conn);
@ -85,7 +82,7 @@ RunTest();
?>
--EXPECT--

...Starting 'sqlsrv_param_query_invalid_inputs' test...
Test begins...
An invalid size or precision for parameter 2 was specified.
An invalid size or precision for parameter 2 was specified.
An invalid size or precision for parameter 2 was specified.
@ -94,4 +91,4 @@ An invalid size or precision for parameter 2 was specified.
An invalid size or precision for parameter 2 was specified.
Done
...Test 'sqlsrv_param_query_invalid_inputs' completed successfully.
Test "sqlsrv_param_query_invalid_inputs" completed successfully.

View file

@ -2,19 +2,15 @@
Call sqlsrv_cancel and then sqlsrv_fetch
--FILE--
<?php
include 'tools.inc';
include 'MsCommon.inc';
function Cancel()
{
require_once("autonomous_setup.php");
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
sqlsrv_get_config('WarningsReturnAsErrors');
// Connect
$connectionInfo = array("UID"=>$username, "PWD"=>$password, "CharacterSet"=>"UTF-8");
$conn = sqlsrv_connect($serverName, $connectionInfo);
$conn = Connect(array("CharacterSet"=>"UTF-8"));
if( !$conn ) { FatalError("Could not connect.\n"); }
$tableName = GetTempTableName();
@ -79,6 +75,7 @@ function GetQuery($tableName, $index)
function Repro()
{
StartTest("sqlsrv_statement_cancel");
echo "\nTest begins...\n";
try
{
Cancel();
@ -96,10 +93,10 @@ Repro();
?>
--EXPECTREGEX--

...Starting 'sqlsrv_statement_cancel' test...
Test begins...
\[Microsoft\](\[ODBC Driver 13 for SQL Server\]|\[ODBC Driver Manager\])([ ]{0,1}Function sequence error)
0
(HY010)
Done
...Test 'sqlsrv_statement_cancel' completed successfully.
Test "sqlsrv_statement_cancel" completed successfully.

View file

@ -2,7 +2,7 @@
Test sending queries (query or prepare) with a timeout specified. Errors are expected.
--FILE--
<?php
include 'tools.inc';
include 'MsCommon.inc';
function QueryTimeout($conn, $exec)
{
@ -33,17 +33,14 @@ function QueryTimeout($conn, $exec)
function Repro()
{
StartTest("sqlsrv_statement_query_timeout");
echo "\nTest begins...\n";
try
{
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
require_once("autonomous_setup.php");
$database = "tempdb";
// Connect
$connectionInfo = array("UID"=>$username, "PWD"=>$password);
$conn = sqlsrv_connect($serverName, $connectionInfo);
$conn = Connect();
if( !$conn ) { FatalError("Could not connect.\n"); }
QueryTimeout($conn, true);
@ -65,7 +62,7 @@ Repro();
?>
--EXPECT--

...Starting 'sqlsrv_statement_query_timeout' test...
Test begins...
[Microsoft][ODBC Driver 13 for SQL Server]Query timeout expired
0
HYT00
@ -74,4 +71,4 @@ HYT00
HYT00
Done
...Test 'sqlsrv_statement_query_timeout' completed successfully.
Test "sqlsrv_statement_query_timeout" completed successfully.

View file

@ -2,7 +2,7 @@
Test sending queries (query or prepare) with a timeout specified using transactions. Errors are expected.
--FILE--
<?php
include 'tools.inc';
include 'MsCommon.inc';
function QueryTimeout($conn1, $conn2, $commit)
{
@ -44,19 +44,17 @@ function QueryTimeout($conn1, $conn2, $commit)
function Repro()
{
StartTest("sqlsrv_statement_query_timeout_transaction");
echo "\nTest begins...\n";
try
{
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
require_once("autonomous_setup.php");
// Connect
$connectionInfo = array("UID"=>$username, "PWD"=>$password, 'ConnectionPooling'=>0);
$conn1 = sqlsrv_connect($serverName, $connectionInfo);
$conn1 = Connect(array('ConnectionPooling'=>0));
if( !$conn1 ) { FatalError("Could not connect.\n"); }
$conn2 = sqlsrv_connect($serverName, $connectionInfo);
$conn2 = Connect(array('ConnectionPooling'=>0));
if( !$conn2 ) { FatalError("Could not connect.\n"); }
QueryTimeout($conn1, $conn2, true);
@ -78,7 +76,7 @@ Repro();
?>
--EXPECT--

...Starting 'sqlsrv_statement_query_timeout_transaction' test...
Test begins...
[Microsoft][ODBC Driver 13 for SQL Server]Query timeout expired
0
HYT00
@ -87,4 +85,4 @@ HYT00
HYT00
Done
...Test 'sqlsrv_statement_query_timeout_transaction' completed successfully.
Test "sqlsrv_statement_query_timeout_transaction" completed successfully.

View file

@ -2,19 +2,15 @@
Test stored procedure that returns a varchar
--FILE--
<?php
include 'tools.inc';
include 'MsCommon.inc';
function StoredProc_varchar()
{
include 'autonomous_setup.php';
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
sqlsrv_get_config('WarningsReturnAsErrors');
// Connect
$connectionInfo = array("UID"=>$username, "PWD"=>$password);
$conn = sqlsrv_connect($serverName, $connectionInfo);
$conn = Connect();
if( !$conn ) { FatalError("Could not connect.\n"); }
$procName = GetTempProcName();
@ -50,6 +46,7 @@ function StoredProc_varchar()
function Repro()
{
StartTest("sqlsrv_stored_proc_varchar");
echo "\nTest begins...\n";
try
{
StoredProc_varchar();
@ -67,7 +64,7 @@ Repro();
?>
--EXPECT--

...Starting 'sqlsrv_stored_proc_varchar' test...
Test begins...
Microsoft SQL Server Driver for PHP
Microsoft SQL Server Driver for PHP
Microsoft SQL Server Driver for PHP
@ -75,4 +72,4 @@ Microsoft SQL Server Driver for PHP
Microsoft SQL Server Driver for PHP
Done
...Test 'sqlsrv_stored_proc_varchar' completed successfully.
Test "sqlsrv_stored_proc_varchar" completed successfully.

View file

@ -2,7 +2,7 @@
Populate different test tables with character fields using empty stream data as inputs
--FILE--
<?php
include 'tools.inc';
include 'MsCommon.inc';
function EmptyStream_Char2Stream($conn, $fileName)
{
@ -67,17 +67,14 @@ function FetchData($conn, $tableName, $fld)
function RunTest()
{
StartTest("sqlsrv_streams_empty_char");
echo "\nTest begins...\n";
try
{
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
require_once("autonomous_setup.php");
$database = "tempdb";
// Connect
$connectionInfo = array('Database'=>$database, 'UID'=>$username, 'PWD'=>$password, 'CharacterSet'=>'UTF-8');
$conn = sqlsrv_connect($serverName, $connectionInfo);
$conn = Connect();
if( !$conn ) { FatalError("Could not connect.\n"); }
// create an empty file
@ -104,7 +101,7 @@ RunTest();
?>
--EXPECT--

...Starting 'sqlsrv_streams_empty_char' test...
Test begins...
bool(false)
bool(false)
bool(false)
@ -115,4 +112,4 @@ bool(false)
bool(false)
Done
...Test 'sqlsrv_streams_empty_char' completed successfully.
Test "sqlsrv_streams_empty_char" completed successfully.

View file

@ -2,7 +2,7 @@
Populate different binary fields using null stream data as inputs.
--FILE--
<?php
include 'tools.inc';
include 'MsCommon.inc';
function NullStream_Bin2String($conn, $tableName)
{
@ -45,17 +45,14 @@ function FetchData($conn, $tableName, $value)
function RunTest()
{
StartTest("sqlsrv_streams_null_binary");
echo "\nTest begins...\n";
try
{
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
require_once("autonomous_setup.php");
$database = "tempdb";
// Connect
$connectionInfo = array('Database'=>$database, 'UID'=>$username, 'PWD'=>$password);
$conn = sqlsrv_connect($serverName, $connectionInfo);
$conn = Connect();
if( !$conn ) { FatalError("Could not connect.\n"); }
// create a test table
@ -81,7 +78,7 @@ RunTest();
?>
--EXPECT--

...Starting 'sqlsrv_streams_null_binary' test...
Test begins...
NULL
NULL
NULL
@ -90,4 +87,4 @@ NULL
NULL
Done
...Test 'sqlsrv_streams_null_binary' completed successfully.
Test "sqlsrv_streams_null_binary" completed successfully.

View file

@ -2,7 +2,7 @@
Populate different unicode character fields using null stream data as inputs
--FILE--
<?php
include 'tools.inc';
include 'MsCommon.inc';
function NullStream_Char2Stream($conn)
{
@ -39,17 +39,14 @@ function FetchData($conn, $tableName)
function RunTest()
{
StartTest("sqlsrv_streams_null_nchar");
echo "\nTest begins...\n";
try
{
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
require_once("autonomous_setup.php");
$database = "tempdb";
// Connect
$connectionInfo = array('Database'=>$database, 'UID'=>$username, 'PWD'=>$password, 'CharacterSet'=>'UTF-8');
$conn = sqlsrv_connect($serverName, $connectionInfo);
$conn = Connect();
if( !$conn ) { FatalError("Could not connect.\n"); }
NullStream_Char2Stream($conn);
@ -69,11 +66,11 @@ RunTest();
?>
--EXPECT--

...Starting 'sqlsrv_streams_null_nchar' test...
Test begins...
NULL
NULL
NULL
NULL
Done
...Test 'sqlsrv_streams_null_nchar' completed successfully.
Test "sqlsrv_streams_null_nchar" completed successfully.

View file

@ -0,0 +1,56 @@
<?php
// globals
$table1 = "SS_AllTypes";
function create_table1($conn )
{
global $table1;
$create_query =
"IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'".$table1."') AND type in (N'U')) DROP TABLE " . $table1 .
" CREATE TABLE " .$table1 . " (
[BigIntCol] [bigint] NULL,
[BinaryCol] [binary](5) NULL,
[BitCol] [bit] NULL,
[CharCol] [char](10) NULL,
[DateCol] [date] NULL,
[DateTimeCol] [datetime] NULL,
[DateTime2Col] [datetime2](7) NULL,
[DTOffsetCol] [datetimeoffset](7) NULL,
[DecimalCol] [decimal](18, 0) NULL,
[FloatCol] [float] NULL,
[ImageCol] [image] NULL,
[IntCol] [int] NULL,
[MoneyCol] [money] NULL,
[NCharCol] [nchar](10) NULL,
[NTextCol] [ntext] NULL,
[NumCol] [numeric](18, 0) NULL,
[NVarCharCol] [nvarchar](50) NULL,
[NVarCharMaxCol] [nvarchar](max) NULL,
[RealCol] [real] NULL,
[SmallDTCol] [smalldatetime] NULL,
[SmallIntCol] [smallint] NULL,
[SmallMoneyCol] [smallmoney] NULL,
[TextCol] [text] NULL,
[TimeCol] [time](7) NULL,
[TinyIntCol] [tinyint] NULL,
[Guidcol] [uniqueidentifier] NULL,
[VarbinaryCol] [varbinary](50) NULL,
[VarbinaryMaxCol] [varbinary](max) NULL,
[VarcharCol] [varchar](50) NULL,
[VarcharMaxCol] [varchar](max) NULL,
[XmlCol] [xml] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
";
$stmt = sqlsrv_query($conn, $create_query );
if( $stmt == false ) {
print_r( sqlsrv_errors() );
die("Statement creation failed");
}
}
?>

View file

@ -4,14 +4,13 @@ Connect to the default database with credentials
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsCommon.inc");
$connectionInfo = array( "UID"=>"$username", "PWD"=>"$password" );
$conn = sqlsrv_connect( $serverName, $connectionInfo );
$conn = Connect();
if( !$conn ) {
echo "Connection could not be established.\n";
die( print_r( sqlsrv_errors(), true));
echo "Connection could not be established.\n";
die( print_r( sqlsrv_errors(), true));
}
sqlsrv_close($conn);
print "Done";

View file

@ -4,14 +4,11 @@ Connect with options
--FILE--
<?php
require_once("autonomous_setup.php");
$connectionInfo = array("Database"=>"master", "UID"=>"$username", "PWD"=>"$password");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
require_once("MsCommon.inc");
$conn = Connect();
if( !$conn ) {
echo "Connection could not be established.\n";
die( print_r( sqlsrv_errors(), true));
FatalError("Connection could not be established.\n");
}
sqlsrv_close($conn);
print "Done";

View file

@ -4,27 +4,30 @@ Temporary table
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsCommon.inc");
// Connect
$conn = sqlsrv_connect($serverName, $connectionInfo);
// Connect
$conn = Connect();
if( !$conn ) {
FatalError("Connection could not be established.\n");
}
// Create temporary table and insert data
$sql = "CREATE TABLE #T (col VARCHAR(32));
INSERT INTO #T VALUES ('PHP7 SQLSRV')";
// Create temporary table and insert data
$sql = "CREATE TABLE #T (col VARCHAR(32));
INSERT INTO #T VALUES ('PHP7 SQLSRV')";
$stmt = sqlsrv_query($conn, $sql);
// Get the data
$sql = "SELECT * FROM #T";
$stmt = sqlsrv_query($conn, $sql);
sqlsrv_fetch($stmt);
var_dump(sqlsrv_get_field($stmt, 0));
// Get the data
$sql = "SELECT * FROM #T";
$stmt = sqlsrv_query($conn, $sql);
sqlsrv_fetch($stmt);
var_dump(sqlsrv_get_field($stmt, 0));
// Free statement and close connection
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
// Free statement and close connection
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
print "Done"
print "Done"
?>
--EXPECT--

View file

@ -4,14 +4,15 @@ sqlsrv_fetch_array() using a scrollable cursor
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsCommon.inc");
// Connect
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( !$conn ) { die( print_r( sqlsrv_errors(), true)); }
$conn = Connect();
if( !$conn ) {
FatalError("Connection could not be established.\n");
}
// Create database
sqlsrv_query($conn,"CREATE DATABASE ". $dbName) ?: die();
$tableName = GetTempTableName();
// Create table
$query = "CREATE TABLE $tableName (ID VARCHAR(10))";
@ -23,7 +24,7 @@ $stmt = sqlsrv_query($conn, $query) ?: die( print_r( sqlsrv_errors(), true) );
// Fetch data
$query = "SELECT ID FROM $tableName";
$stmt = sqlsrv_query($conn, $query, [], array("Scrollable"=>"buffered"))
?: die( print_r(sqlsrv_errors(), true));
?: die( print_r(sqlsrv_errors(), true));
// Fetch first row
$row = sqlsrv_fetch_array($stmt,SQLSRV_FETCH_ASSOC,SQLSRV_SCROLL_NEXT);
@ -37,9 +38,6 @@ echo $row['ID']."\n";
$row = sqlsrv_fetch_array($stmt,SQLSRV_FETCH_ASSOC,SQLSRV_SCROLL_LAST);
echo $row['ID']."\n";
// DROP database
$stmt = sqlsrv_query($conn,"DROP DATABASE ". $dbName);
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
print "Done"

View file

@ -4,11 +4,13 @@ sqlsrv_get_field() using SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_CHAR)
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsCommon.inc");
// Connect
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( !$conn ) { die( print_r( sqlsrv_errors(), true)); }
$conn = Connect(array("CharacterSet"=>"UTF-8"));
if( !$conn ) {
FatalError("Connection could not be established.\n");
}
// Create table
$query = "CREATE TABLE #TA1 (ID NVARCHAR(10))";
@ -23,13 +25,13 @@ $query = "SELECT * FROM #TA1";
$stmt = sqlsrv_query( $conn, $query ) ?: die( print_r( sqlsrv_errors(), true) );
while(sqlsrv_fetch($stmt)) {
$field = sqlsrv_get_field($stmt, 0, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_CHAR));
var_dump($field);
while(!feof($field))
{
echo fread($field, 100)."\n";
}
$field = sqlsrv_get_field($stmt, 0, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_CHAR));
var_dump(get_resource_type($field));
while(!feof($field))
{
echo fread($field, 100)."\n";
}
}
// Close connection
@ -39,10 +41,10 @@ print "Done"
?>
--EXPECT--
resource(9) of type (stream)
string(6) "stream"
1998.1
resource(10) of type (stream)
string(6) "stream"
-2004.2436
resource(11) of type (stream)
string(6) "stream"
4.2 EUR
Done

View file

@ -4,14 +4,15 @@ sqlsrv_get_field() using SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY)
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsCommon.inc");
// Connect
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( !$conn ) { die( print_r( sqlsrv_errors(), true)); }
$conn = Connect();
if( !$conn ) {
FatalError("Connection could not be established.\n");
}
// Create database
sqlsrv_query($conn,"CREATE DATABASE ". $dbName) ?: die();
$tableName = GetTempTableName();
// Create table
$query = "CREATE TABLE ".$tableName." (ID VARCHAR(10))";
@ -25,18 +26,15 @@ $query = "SELECT * FROM ".$tableName;
$stmt = sqlsrv_query( $conn, $query ) ?: die( print_r( sqlsrv_errors(), true) );
while(sqlsrv_fetch($stmt)) {
$field = sqlsrv_get_field($stmt,0,SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY));
var_dump($field);
while(!feof($field))
{
echo fread($field, 100)."\n";
}
$field = sqlsrv_get_field($stmt,0,SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY));
var_dump(get_resource_type($field));
while(!feof($field))
{
echo fread($field, 100)."\n";
}
}
// DROP database
$stmt = sqlsrv_query($conn,"DROP DATABASE ". $dbName);
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
@ -44,10 +42,10 @@ print "Done"
?>
--EXPECT--
resource(10) of type (stream)
string(6) "stream"
1998.1
resource(11) of type (stream)
string(6) "stream"
-2004.2436
resource(12) of type (stream)
string(6) "stream"
4.2EUR
Done

View file

@ -4,14 +4,15 @@ Data type precedence: conversion NVARCHAR(n)
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsCommon.inc");
// Connect
$connectionInfo = array("UID"=>$username, "PWD"=>$password, "CharacterSet"=>"UTF-8");
$conn = sqlsrv_connect($serverName, $connectionInfo) ?: die();
$conn = Connect(array("CharacterSet"=>"UTF-8"));
if( !$conn ) {
FatalError("Connection could not be established.\n");
}
// Create database
sqlsrv_query($conn,"CREATE DATABASE ". $dbName) ?: die();
$tableName = GetTempTableName();
// Create table. Column names: passport
$sql = "CREATE TABLE $tableName (c1 NVARCHAR(8))";
@ -31,12 +32,9 @@ $sql = "SELECT * FROM $tableName";
$stmt = sqlsrv_query($conn, $sql);
while($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_NUMERIC)) {
var_dump($row[0]);
var_dump($row[0]);
}
// DROP database
sqlsrv_query($conn,"DROP DATABASE ". $dbName);
// Free statement and connection resources
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);

View file

@ -4,13 +4,15 @@ Data type precedence: conversion VARCHAR(n)
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsCommon.inc");
// Connect
$conn = sqlsrv_connect($serverName, $connectionInfo) ?: die();
$conn = Connect();
if( !$conn ) {
FatalError("Connection could not be established.\n");
}
// Create database
sqlsrv_query($conn,"CREATE DATABASE ". $dbName) ?: die();
$tableName = GetTempTableName();
// Create table. Column names: passport
$sql = "CREATE TABLE $tableName (c1 VARCHAR(30))";
@ -26,13 +28,10 @@ $sql = "SELECT * FROM $tableName";
$stmt = sqlsrv_query($conn, $sql);
for($i=0; $i<3; $i++)
{
$row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_NUMERIC);
var_dump($row[0]);
$row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_NUMERIC);
var_dump($row[0]);
}
// DROP database
sqlsrv_query($conn,"DROP DATABASE ". $dbName);
// Free statement and connection resources
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);

View file

@ -4,43 +4,41 @@ sqlsrv_field_metadata() VARCHAR(n), NVARCHAR(n), INT
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsCommon.inc");
// Connect
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( !$conn ) { die( print_r( sqlsrv_errors(), true)); }
$conn = Connect();
if( !$conn ) {
FatalError("Connection could not be established.\n");
}
// Create database
sqlsrv_query($conn,"CREATE DATABASE ". $dbName) ?: die();
$tableName = GetTempTableName();
// Create table
$stmt = sqlsrv_query($conn, "create table ".$tableName." (FirstName VARCHAR(10), LastName NVARCHAR(20), Age INT)");
$stmt = sqlsrv_query($conn, "create table $tableName (FirstName VARCHAR(10), LastName NVARCHAR(20), Age INT)");
if( $stmt === false ) { die( print_r( sqlsrv_errors(), true )); }
sqlsrv_free_stmt( $stmt);
// Insert data
$sql = "INSERT INTO ".$tableName." VALUES ('John', 'Doe', 30)";
$sql = "INSERT INTO $tableName VALUES ('John', 'Doe', 30)";
$stmt = sqlsrv_query( $conn, $sql);
sqlsrv_free_stmt( $stmt);
// Insert data
$sql = "INSERT INTO ".$tableName." VALUES ('Nhoj', N'Eoduard', -3),('Vi Lo', N'N/A', 1987)";
$sql = "INSERT INTO $tableName VALUES ('Nhoj', N'Eoduard', -3),('Vi Lo', N'N/A', 1987)";
$stmt = sqlsrv_query($conn, $sql);
sqlsrv_free_stmt($stmt);
// Prepare the statement
$query = "SELECT FirstName, LastName, Age FROM ".$tableName;
$query = "SELECT FirstName, LastName, Age FROM $tableName";
$stmt = sqlsrv_prepare($conn, $query);
// Get field metadata
foreach( sqlsrv_field_metadata( $stmt) as $fieldMetadata)
$res[] = $fieldMetadata;
$res[] = $fieldMetadata;
var_dump($res);
// DROP database
$stmt = sqlsrv_query($conn,"DROP DATABASE ". $dbName);
sqlsrv_free_stmt( $stmt);
sqlsrv_close($conn);
print "Done";

View file

@ -4,14 +4,15 @@ Field metadata unicode
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsCommon.inc");
// Connect
$connectionInfo = array("UID"=>"$username", "PWD"=>"$password", "CharacterSet"=>"UTF-8");
$conn = sqlsrv_connect($serverName, $connectionInfo) ?: die();
$conn = Connect(array("CharacterSet"=>"UTF-8"));
if( !$conn ) {
FatalError("Connection could not be established.\n");
}
// Create database
sqlsrv_query($conn,"CREATE DATABASE ". $dbName) ?: die();
$tableName = GetTempTableName();
// Create table. Column names: passport
$sql = "CREATE TABLE $tableName (पासपोर्ट CHAR(2), پاسپورٹ VARCHAR(2), Διαβατήριο VARCHAR(MAX))";
@ -24,12 +25,9 @@ $stmt = sqlsrv_prepare($conn, $sql);
// Get and display field metadata
foreach(sqlsrv_field_metadata($stmt) as $meta)
{
print_r($meta);
print_r($meta);
}
// DROP database
sqlsrv_query($conn,"DROP DATABASE ". $dbName);
// Free statement and connection resources
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);

View file

@ -4,29 +4,30 @@ Transaction operations: commit successful transactions
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsCommon.inc");
function PrintContent($conn)
{
global $tableName;
$query = "SELECT * FROM $tableName";
$stmt = sqlsrv_query($conn, $query);
// Fetch first row
$row = sqlsrv_fetch_array($stmt,SQLSRV_FETCH_ASSOC);
print_r($row);
global $tableName;
$query = "SELECT * FROM $tableName";
$stmt = sqlsrv_query($conn, $query);
// Fetch first row
$row = sqlsrv_fetch_array($stmt,SQLSRV_FETCH_ASSOC);
print_r($row);
}
// Connect
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( !$conn ) { die( print_r( sqlsrv_errors(), true)); }
$conn = Connect();
if( !$conn ) {
PrintErrors("Connection could not be established.\n");
}
// Create database
sqlsrv_query($conn,"CREATE DATABASE ". $dbName) ?: die();
$tableName = GetTempTableName();
// Create table
$sql = "CREATE TABLE $tableName (
GroupId VARCHAR(10) primary key, Accepted INT,
Tentative INT NOT NULL CHECK (Tentative >= 0))";
GroupId VARCHAR(10) primary key, Accepted INT,
Tentative INT NOT NULL CHECK (Tentative >= 0))";
$stmt = sqlsrv_query($conn, $sql);
@ -53,20 +54,17 @@ $stmt2 = sqlsrv_query($conn, $sql, $params);
// Commit the transactions
if ($stmt1 && $stmt2)
{
sqlsrv_commit($conn);
sqlsrv_commit($conn);
}
else
{
echo "\nERROR: $stmt1 and $stmt2 should be valid\n";
sqlsrv_rollback($conn);
echo "\nTransactions were rolled back.\n";
echo "\nERROR: $stmt1 and $stmt2 should be valid\n";
sqlsrv_rollback($conn);
echo "\nTransactions were rolled back.\n";
}
PrintContent($conn);
// DROP database
$stmt = sqlsrv_query($conn,"DROP DATABASE ". $dbName);
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
print "Done"

View file

@ -8,14 +8,15 @@ would then fail.
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsCommon.inc");
// Connect
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( !$conn ) { die( print_r( sqlsrv_errors(), true)); }
$conn = Connect();
if( !$conn ) {
FatalError("Connection could not be established.\n");
}
// Create database
sqlsrv_query($conn,"CREATE DATABASE ". $dbName) ?: die();
$tableName = GetTempTableName();
// Create table
$query = "CREATE TABLE $tableName (ID VARCHAR(10))";
@ -27,7 +28,7 @@ $stmt = sqlsrv_query($conn, $query) ?: die( print_r( sqlsrv_errors(), true) );
// Fetch data using forward only cursor
$query = "SELECT ID FROM $tableName";
$stmt = sqlsrv_query($conn, $query)
?: die( print_r(sqlsrv_errors(), true));
?: die( print_r(sqlsrv_errors(), true));
// repeated calls should return true and fetch should work.
echo "Has Rows?" . (sqlsrv_has_rows($stmt) ? " Yes!" : " NO!") . "\n";
@ -36,15 +37,15 @@ echo "Has Rows?" . (sqlsrv_has_rows($stmt) ? " Yes!" : " NO!") . "\n";
echo "Has Rows?" . (sqlsrv_has_rows($stmt) ? " Yes!" : " NO!") . "\n";
if (sqlsrv_has_rows($stmt)) {
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_NUMERIC))
{
echo $row[0]."\n";
}
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_NUMERIC))
{
echo $row[0]."\n";
}
}
// Fetch data using a scrollable cursor
$stmt = sqlsrv_query($conn, $query, [], array("Scrollable"=>"buffered"))
?: die( print_r(sqlsrv_errors(), true));
?: die( print_r(sqlsrv_errors(), true));
echo "Has Rows?" . (sqlsrv_has_rows($stmt) ? " Yes!" : " NO!") . "\n";
echo "Has Rows?" . (sqlsrv_has_rows($stmt) ? " Yes!" : " NO!") . "\n";
@ -52,15 +53,15 @@ echo "Has Rows?" . (sqlsrv_has_rows($stmt) ? " Yes!" : " NO!") . "\n";
echo "Has Rows?" . (sqlsrv_has_rows($stmt) ? " Yes!" : " NO!") . "\n";
if (sqlsrv_has_rows($stmt)) {
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_NUMERIC))
{
echo $row[0]."\n";
}
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_NUMERIC))
{
echo $row[0]."\n";
}
}
$query = "SELECT ID FROM $tableName where ID='nomatch'";
$stmt = sqlsrv_query($conn, $query)
?: die( print_r(sqlsrv_errors(), true));
?: die( print_r(sqlsrv_errors(), true));
// repeated calls should return false if there are no rows.
echo "Has Rows?" . (sqlsrv_has_rows($stmt) ? " Yes!" : " NO!") . "\n";
@ -68,16 +69,13 @@ echo "Has Rows?" . (sqlsrv_has_rows($stmt) ? " Yes!" : " NO!") . "\n";
// Fetch data using a scrollable cursor
$stmt = sqlsrv_query($conn, $query, [], array("Scrollable"=>"buffered"))
?: die( print_r(sqlsrv_errors(), true));
?: die( print_r(sqlsrv_errors(), true));
// repeated calls should return false if there are no rows.
echo "Has Rows?" . (sqlsrv_has_rows($stmt) ? " Yes!" : " NO!") . "\n";
echo "Has Rows?" . (sqlsrv_has_rows($stmt) ? " Yes!" : " NO!") . "\n";
// DROP database
$stmt = sqlsrv_query($conn,"DROP DATABASE ". $dbName);
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
print "Done"

View file

@ -4,29 +4,29 @@ Transaction operations: rolled-back transactions
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsCommon.inc");
function PrintContent($conn)
function PrintContent($conn, $tableName)
{
global $tableName;
$query = "SELECT * FROM $tableName";
$stmt = sqlsrv_query($conn, $query);
// Fetch the first row
$row = sqlsrv_fetch_array($stmt,SQLSRV_FETCH_ASSOC);
print_r($row);
$query = "SELECT * FROM $tableName";
$stmt = sqlsrv_query($conn, $query);
// Fetch the first row
$row = sqlsrv_fetch_array($stmt,SQLSRV_FETCH_ASSOC);
print_r($row);
}
// Connect
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( !$conn ) { die( print_r( sqlsrv_errors(), true)); }
$conn = Connect();
if( !$conn ) {
FatalError("Connection could not be established.\n");
}
// Create database
sqlsrv_query($conn,"CREATE DATABASE ". $dbName) ?: die();
$tableName = GetTempTableName();
// Create table
$sql = "CREATE TABLE $tableName (
GroupId VARCHAR(10) primary key, Accepted INT,
Tentative INT NOT NULL CHECK (Tentative >= 0))";
GroupId VARCHAR(10) primary key, Accepted INT,
Tentative INT NOT NULL CHECK (Tentative >= 0))";
$stmt = sqlsrv_query($conn, $sql);
@ -54,17 +54,14 @@ $stmt2 = sqlsrv_query($conn, $sql, $params);
// Commit the transactions
if ($stmt1 && $stmt2)
{
echo "\nERROR: $stmt2 should be bool(false)\n";
echo "\nERROR: $stmt2 should be bool(false)\n";
}
else
{
sqlsrv_rollback($conn);
sqlsrv_rollback($conn);
}
PrintContent($conn);
// DROP database
$stmt = sqlsrv_query($conn,"DROP DATABASE ". $dbName);
PrintContent($conn, $tableName);
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);

View file

@ -4,12 +4,13 @@ Streaming nvarchar(max) unicode (Russian) with CharacterSet=utf-8
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsCommon.inc");
// Connect
$connectionInfo = array("UID"=>$username, "PWD"=>$password, "CharacterSet"=>"utf-8");
$conn = sqlsrv_connect($serverName, $connectionInfo);
if( !$conn ) { die( print_r( sqlsrv_errors(), true)); }
$conn = Connect(array("CharacterSet"=>"utf-8"));
if( !$conn ) {
FatalError("Connection could not be established.\n");
}
// Create table
$sql = "CREATE TABLE #Table (c1 NVARCHAR(max))";

View file

@ -4,11 +4,13 @@ Streaming nvarchar(max) with sqlsrv_fetch_array()
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsCommon.inc");
// Connect
$conn = sqlsrv_connect($serverName, $connectionInfo);
if( !$conn ) { die( print_r( sqlsrv_errors(), true)); }
$conn = Connect(array("CharacterSet"=>"utf-8"));
if( !$conn ) {
FatalError("Connection could not be established.\n");
}
// Create table
$sql = "CREATE TABLE #Table (c1 NVARCHAR(max))";

View file

@ -4,12 +4,13 @@ Streaming nvarchar(max) with sqlsrv_fetch_array() and CharacterSet=utf-8
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsCommon.inc");
// Connect
$connectionInfo = array("UID"=>$username, "PWD"=>$password, "CharacterSet"=>"utf-8");
$conn = sqlsrv_connect($serverName, $connectionInfo);
if( !$conn ) { die( print_r( sqlsrv_errors(), true)); }
$conn = Connect(array("CharacterSet"=>"utf-8"));
if( !$conn ) {
FatalError("Connection could not be established.\n");
}
// Create table
$sql = "CREATE TABLE #Table (c1 NVARCHAR(max))";

View file

@ -4,13 +4,15 @@ Error checking for failed conversion: VARCHAR value 'null' to data type INT
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsCommon.inc");
// Connect
$conn = sqlsrv_connect($serverName, $connectionInfo) ?: die();
$conn = Connect();
if( !$conn ) {
FatalError("Connection could not be established.\n");
}
// Create database
sqlsrv_query($conn,"CREATE DATABASE ". $dbName) ?: die();
$tableName = GetTempTableName();
// Create table
$sql = "CREATE TABLE $tableName (ID INT)";
@ -24,9 +26,6 @@ $stmt = sqlsrv_query($conn, $sql);
$err = sqlsrv_errors();
print_r($err[0]);
// DROP database
sqlsrv_query($conn,"DROP DATABASE ". $dbName);
// Free statement and connection resources
sqlsrv_close($conn);

View file

@ -4,14 +4,15 @@ Error checking for failed explicit data type conversions NCHAR(2)
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsCommon.inc");
// Connect
$connectionInfo = array("UID"=>$username, "PWD"=>$password, "CharacterSet"=>"UTF-8");
$conn = sqlsrv_connect($serverName, $connectionInfo) ?: die();
$conn = Connect(array("CharacterSet"=>"utf-8"));
if( !$conn ) {
PrintErrors("Connection could not be established.\n");
}
// Create database
sqlsrv_query($conn,"CREATE DATABASE ". $dbName) ?: die();
$tableName = GetTempTableName();
// Create table. Column names: passport
$sql = "CREATE TABLE $tableName (c1 NCHAR(2))";
@ -25,9 +26,6 @@ $stmt = sqlsrv_query($conn, $sql);
$err = sqlsrv_errors();
print_r($err[0]);
// DROP database
sqlsrv_query($conn,"DROP DATABASE ". $dbName);
// Free statement and connection resources
sqlsrv_close($conn);

View file

@ -4,11 +4,13 @@ Enable multiple active result sets (MARS)
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsCommon.inc");
// Connect
$connectionInfo = array("UID"=>$username, "PWD"=>$password, 'MultipleActiveResultSets' => true);
$conn = sqlsrv_connect($serverName, $connectionInfo) ?: die();
$conn = Connect(array('MultipleActiveResultSets' => true));
if( !$conn ) {
FatalError("Connection could not be established.\n");
}
// Query
$stmt1 = sqlsrv_query( $conn, "SELECT 'ONE'" ) ?: die(print_r( sqlsrv_errors(), true ));

View file

@ -4,11 +4,13 @@ Error checking for multiple active result sets (MARS) disabled
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsCommon.inc");
// Connect
$connectionInfo = array("UID"=>$username, "PWD"=>$password, 'MultipleActiveResultSets' => false);
$conn = sqlsrv_connect($serverName, $connectionInfo) ?: die();
$conn = Connect(array('MultipleActiveResultSets' => false));
if( !$conn ) {
FatalError("Connection could not be established.\n");
}
// Query
$stmt1 = sqlsrv_query( $conn, "SELECT 'ONE'" ) ?: die(print_r( sqlsrv_errors(), true ));

View file

@ -10,10 +10,10 @@ function print_errors()
function test()
{
require_once("autonomous_setup.php");
require_once("MsCommon.inc");
// Connect
$conn = sqlsrv_connect($serverName, $connectionInfo);
$conn = Connect();
if( !$conn ) { print_errors(); }
$sql = "EXEC dbo.sp_executesql

View file

@ -1,22 +1,22 @@
--TEST--
Create/drop database
--SKIPIF--
<?php require('skipif_azure.inc'); ?>
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsCommon.inc");
$connectionInfo = array( "UID"=>"$username", "PWD"=>"$password");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
// Check if connected
if( !$conn ) { die( print_r( sqlsrv_errors(), true)); }
$conn = Connect(array("Database"=>'master'));
if( !$conn ) {
FatalError("Connection could not be established.\n");
}
// Set database name
$dbUniqueName = "php_uniqueDB01";
// DROP database if exists
$stmt = sqlsrv_query($conn,"IF EXISTS(SELECT name FROM sys.databases WHERE name = '"
.$dbUniqueName."') DROP DATABASE ".$dbUniqueName);
.$dbUniqueName."') DROP DATABASE ".$dbUniqueName);
if($stmt === false){ die( print_r( sqlsrv_errors(), true )); }
sqlsrv_free_stmt($stmt);

View file

@ -1,17 +1,14 @@
--TEST--
Create database that already exists
--SKIPIF--
<?php require('skipif_azure.inc'); ?>
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsCommon.inc");
$connectionInfo = array( "UID"=>"$username", "PWD"=>"$password");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
// Check if connected
$conn = Connect(array("Database"=>'master'));
if( !$conn ) {
echo "Connection could not be established.\n";
die( print_r( sqlsrv_errors(), true));
FatalError("Connection could not be established.\n");
}
// Set database name
@ -19,7 +16,7 @@ $dbUniqueName = "uniqueDB01";
// DROP database if exists
$stmt = sqlsrv_query($conn,"IF EXISTS(SELECT name FROM sys.databases WHERE name = '"
.$dbUniqueName."') DROP DATABASE ".$dbUniqueName);
.$dbUniqueName."') DROP DATABASE ".$dbUniqueName);
sqlsrv_free_stmt($stmt);
@ -29,7 +26,7 @@ $stmt = sqlsrv_query($conn,"CREATE DATABASE ". $dbUniqueName);
if( $stmt === false)
{
printf("%-20s%10s\n","CREATE DATABASE","FAILED");
die( print_r( sqlsrv_errors(), true ));
die( print_r( sqlsrv_errors(), true ));
}
@ -38,18 +35,17 @@ $stmt = sqlsrv_query($conn,"CREATE DATABASE ". $dbUniqueName);
var_dump($stmt);
if( $stmt === false)
{
$res = array_values(sqlsrv_errors());
var_dump($res[0]['SQLSTATE']);
var_dump($res[0][1]);
// var_dump($res[0][2]);
$res = array_values(sqlsrv_errors());
var_dump($res[0]['SQLSTATE']);
var_dump($res[0][1]);
}
else {
printf("%-20s\n","ERROR: CREATE database MUST return bool(false)");
printf("%-20s\n","ERROR: CREATE database MUST return bool(false)");
}
// DROP database
sqlsrv_query($conn,"IF EXISTS(SELECT name FROM sys.databases WHERE name = '"
.$dbUniqueName."') DROP DATABASE ".$dbUniqueName);
.$dbUniqueName."') DROP DATABASE ".$dbUniqueName);
sqlsrv_close($conn);
print "Done";

View file

@ -3,15 +3,11 @@ Create database that already exists
--SKIPIF--
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsCommon.inc");
$connectionInfo = array( "UID"=>"$username", "PWD"=>"$password");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
// Check if connected
$conn = Connect(array("Database"=>'master'));
if( !$conn ) {
echo "Connection could not be established.\n";
die( print_r( sqlsrv_errors(), true));
FatalError("Connection could not be established.\n");
}
// Set database name
@ -19,7 +15,7 @@ $dbUniqueName = "uniqueDB01";
// DROP database if exists
$stmt = sqlsrv_query($conn,"IF EXISTS(SELECT name FROM sys.databases WHERE name = '"
.$dbUniqueName."') DROP DATABASE ".$dbUniqueName);
.$dbUniqueName."') DROP DATABASE ".$dbUniqueName);
sqlsrv_free_stmt($stmt);
@ -29,7 +25,7 @@ $stmt = sqlsrv_query($conn,"CREATE DATABASE ". $dbUniqueName);
if( $stmt === false)
{
printf("%-20s%10s\n","CREATE DATABASE","FAILED");
die( print_r( sqlsrv_errors(), true ));
die( print_r( sqlsrv_errors(), true ));
}
@ -38,18 +34,18 @@ $stmt = sqlsrv_query($conn,"CREATE DATABASE ". $dbUniqueName);
var_dump($stmt);
if( $stmt === false)
{
$res = array_values(sqlsrv_errors());
var_dump($res[0]['SQLSTATE']);
var_dump($res[0][1]);
// var_dump($res[0][2]);
$res = array_values(sqlsrv_errors());
var_dump($res[0]['SQLSTATE']);
var_dump($res[0][1]);
// var_dump($res[0][2]);
}
else {
printf("%-20s\n","ERROR: CREATE database MUST return bool(false)");
printf("%-20s\n","ERROR: CREATE database MUST return bool(false)");
}
// DROP database
sqlsrv_query($conn,"IF EXISTS(SELECT name FROM sys.databases WHERE name = '"
.$dbUniqueName."') DROP DATABASE ".$dbUniqueName);
.$dbUniqueName."') DROP DATABASE ".$dbUniqueName);
sqlsrv_close($conn);
print "Done";

View file

@ -3,15 +3,11 @@ Create database that already exists
--SKIPIF--
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsCommon.inc");
$connectionInfo = array( "UID"=>"$username", "PWD"=>"$password");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
// Check if connected
$conn = Connect(array("Database"=>'master'));
if( !$conn ) {
echo "Connection could not be established.\n";
die( print_r( sqlsrv_errors(), true));
FatalError("Connection could not be established.\n");
}
// Set database name
@ -19,7 +15,7 @@ $dbUniqueName = "uniqueDB01";
// DROP database if exists
$stmt = sqlsrv_query($conn,"IF EXISTS(SELECT name FROM sys.databases WHERE name = '"
.$dbUniqueName."') DROP DATABASE ".$dbUniqueName);
.$dbUniqueName."') DROP DATABASE ".$dbUniqueName);
sqlsrv_free_stmt($stmt);
@ -29,7 +25,7 @@ $stmt = sqlsrv_query($conn,"CREATE DATABASE ". $dbUniqueName);
if( $stmt === false)
{
printf("%-20s%10s\n","CREATE DATABASE","FAILED");
die( print_r( sqlsrv_errors(), true ));
die( print_r( sqlsrv_errors(), true ));
}
@ -38,17 +34,17 @@ $stmt = sqlsrv_query($conn,"CREATE DATABASE ". $dbUniqueName);
var_dump($stmt);
if( $stmt === false)
{
$res = array_values(sqlsrv_errors());
var_dump($res[0]['SQLSTATE']);
var_dump($res[0][1]);
$res = array_values(sqlsrv_errors());
var_dump($res[0]['SQLSTATE']);
var_dump($res[0][1]);
}
else {
printf("%-20s\n","ERROR: CREATE database MUST return bool(false)");
printf("%-20s\n","ERROR: CREATE database MUST return bool(false)");
}
// DROP database
sqlsrv_query($conn,"IF EXISTS(SELECT name FROM sys.databases WHERE name = '"
.$dbUniqueName."') DROP DATABASE ".$dbUniqueName);
.$dbUniqueName."') DROP DATABASE ".$dbUniqueName);
sqlsrv_close($conn);
print "Done";

View file

@ -1,17 +1,14 @@
--TEST--
Drop missing database
--SKIPIF--
<?php require('skipif_azure.inc'); ?>
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsCommon.inc");
$connectionInfo = array( "UID"=>"$username", "PWD"=>"$password");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
// Check if connected
$conn = Connect(array("Database"=>'master'));
if( !$conn ) {
echo "Connection could not be established.\n";
die( print_r( sqlsrv_errors(), true));
FatalError("Connection could not be established.\n");
}
// Set database name
@ -19,7 +16,7 @@ $dbUniqueName = "uniqueDB01";
// DROP database if exists
$stmt = sqlsrv_query($conn,"IF EXISTS(SELECT name FROM sys.databases WHERE name = '"
.$dbUniqueName."') DROP DATABASE ".$dbUniqueName);
.$dbUniqueName."') DROP DATABASE ".$dbUniqueName);
sqlsrv_free_stmt($stmt);
// DROP missing database
@ -27,8 +24,8 @@ $stmt = sqlsrv_query($conn,"DROP DATABASE ". $dbUniqueName);
var_dump($stmt);
if( $stmt === false )
{
$res = array_values(sqlsrv_errors());
var_dump($res[0]['code']);
$res = array_values(sqlsrv_errors());
var_dump($res[0]['code']);
}
else {
printf("%-20s\n","ERROR: DROP missing database MUST return bool(false)");

View file

@ -1,25 +1,21 @@
--TEST--
Drop missing database unicode
--SKIPIF--
<?php require('skipif_azure.inc'); ?>
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsCommon.inc");
$connectionInfo = array( "UID"=>"$username", "PWD"=>"$password", "CharacterSet" => 'UTF-8');
$conn = sqlsrv_connect( $serverName, $connectionInfo);
// Check if connected
if( !$conn ) {
echo "Connection could not be established.\n";
die( print_r( sqlsrv_errors(), true));
}
$connectionInfo = array("CharacterSet"=>"UTF-8");
$conn = Connect($connectionInfo);
if( !$conn ) { PrintErrors("Could not connect.\n"); }
// Set database name
$dbUniqueName = "uniqueDB01_银河系";
// DROP database if exists
$stmt = sqlsrv_query($conn,"IF EXISTS(SELECT name FROM sys.databases WHERE name = '"
.$dbUniqueName."') DROP DATABASE ".$dbUniqueName);
.$dbUniqueName."') DROP DATABASE ".$dbUniqueName);
sqlsrv_free_stmt($stmt);
// DROP missing database
@ -27,10 +23,10 @@ $stmt = sqlsrv_query($conn,"DROP DATABASE ". $dbUniqueName);
var_dump($stmt);
if( $stmt === false )
{
$res = array_values(sqlsrv_errors());
var_dump($res[0]['SQLSTATE']);
var_dump($res[0][1]);
var_dump($res[0][2]);
$res = array_values(sqlsrv_errors());
var_dump($res[0]['SQLSTATE']);
var_dump($res[0][1]);
var_dump($res[0][2]);
}
else {

View file

@ -4,47 +4,40 @@ sqlsrv_fetch() with SQLSRV_SCROLL_ABSOLUTE using out of range offset
--FILE--
<?php
function print_errors($message = "")
{
if (strlen($message) > 0)
{
echo $message . "\n";
}
die( print_r( sqlsrv_errors(), true));
}
function test()
{
require_once("autonomous_setup.php");
require_once("MsCommon.inc");
// Connect
$conn = sqlsrv_connect($serverName, $connectionInfo);
if( !$conn ) { print_errors(); }
$conn = Connect();
if( !$conn ) {
PrintErrors("Connection could not be established.\n");
}
// Prepare the statement
$sql = "select name from sys.databases";
$sql = "select * from cd_info";
$stmt = sqlsrv_prepare( $conn, $sql, array(), array("Scrollable"=>SQLSRV_CURSOR_CLIENT_BUFFERED) );
if( $stmt === false ) { print_errors(); }
if( $stmt === false ) { PrintErrors(); }
sqlsrv_execute($stmt);
// Get row count
$row_count = sqlsrv_num_rows( $stmt );
if ($row_count == 0) { print_errors("There should be at least one row!\n"); }
if ($row_count == 0) { PrintErrors("There should be at least one row!\n"); }
sqlsrv_execute($stmt);
$row = sqlsrv_fetch($stmt, SQLSRV_SCROLL_FIRST);
$field = sqlsrv_get_field($stmt, 0);
if (! $field) { print_errors(); }
if (! $field) { PrintErrors(); }
$row = sqlsrv_fetch($stmt, SQLSRV_SCROLL_LAST);
$field = sqlsrv_get_field($stmt, 0);
if (! $field) { print_errors(); }
if (! $field) { PrintErrors(); }
// this should return false
$row = sqlsrv_fetch($stmt, SQLSRV_SCROLL_ABSOLUTE, $row_count);
if ($row) { print_errors("This should return false!"); }
if ($row) { PrintErrors("This should return false!"); }
$field = sqlsrv_get_field($stmt, 0);
if ($field !== false) { print_errors("This should have resulted in error!"); }
if ($field !== false) { PrintErrors("This should have resulted in error!"); }
sqlsrv_free_stmt( $stmt);
sqlsrv_close($conn);

View file

@ -4,22 +4,21 @@ sqlsrv_has_rows() using a forward and scrollable cursor
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsCommon.inc");
function fetchData($conn, $table, $size)
{
$ret = sqlsrv_configure('ClientBufferMaxKBSize', $size);
var_dump($ret);
$stmt = sqlsrv_prepare($conn, "SELECT * FROM ".$table, array(), array("Scrollable"=>"buffered"));
$attr = sqlsrv_get_config('ClientBufferMaxKBSize');
$stmt = sqlsrv_prepare($conn, "SELECT * FROM $table", array(), array("Scrollable"=>"buffered"));
$attr = sqlsrv_get_config('ClientBufferMaxKBSize');
echo("ClientBufferMaxKBSize is $attr\n");
sqlsrv_execute($stmt);
$rows = sqlsrv_has_rows($stmt);
sqlsrv_execute($stmt);
$rows = sqlsrv_has_rows($stmt);
var_dump($rows);
sqlsrv_execute($stmt);
sqlsrv_execute($stmt);
$numRowsFetched = 0;
while ($row = sqlsrv_fetch_array($stmt))
{
@ -29,32 +28,35 @@ function fetchData($conn, $table, $size)
}
// Connect
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( !$conn ) { die( print_r( sqlsrv_errors(), true)); }
$conn = Connect();
if( !$conn ) {
PrintErrors("Connection could not be established.\n");
}
$tableName1 = GetTempTableName('php_test_table_1');
$tableName2 = GetTempTableName('php_test_table_2');
// Create database
sqlsrv_query($conn,"CREATE DATABASE ". $dbName) ?: die();
// Create table
$stmt = sqlsrv_query($conn, "CREATE TABLE ".$dbName.".[dbo].[php_test_table_1] ([c1_int] int, [c2_varchar_max] varchar(max))");
$stmt = sqlsrv_query($conn, "CREATE TABLE ".$dbName.".[dbo].[php_test_table_2] ([c1_int] int, [c2_varchar_1036] varchar(1036))");
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName1 ([c1_int] int, [c2_varchar_max] varchar(max))");
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName2 ([c1_int] int, [c2_varchar_1036] varchar(1036))");
// insert > 1KB into c2_varchar_max & c2_varchar_1036 (1036 characters).
$stmt = sqlsrv_query($conn, "INSERT INTO ".$dbName.".[dbo].[php_test_table_1] (c1_int, c2_varchar_max) VALUES (1, 'This is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a test')");
$stmt = sqlsrv_query($conn, "INSERT INTO ".$dbName.".[dbo].[php_test_table_2] (c1_int, c2_varchar_1036) VALUES (1, 'This is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a test')");
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName1 (c1_int, c2_varchar_max) VALUES (1, 'This is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a test')");
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName2 (c1_int, c2_varchar_1036) VALUES (1, 'This is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a testThis is a test')");
// set client buffer size to 0KB returns false
$ret = sqlsrv_configure('ClientBufferMaxKBSize', 0);
var_dump($ret);
// set client buffer size to 1KB
$size = 1;
fetchData($conn, $dbName.".[dbo].[php_test_table_1]", $size); // this should return 0 rows.
fetchData($conn, $dbName.".[dbo].[php_test_table_2]", $size); // this should return 0 rows.
// set client buffer size to 2KB
$size = 2;
fetchData($conn, $dbName.".[dbo].[php_test_table_1]", $size); // this should return 1 row.
fetchData($conn, $dbName.".[dbo].[php_test_table_2]", $size); // this should return 1 row.
// DROP database
$stmt = sqlsrv_query($conn,"DROP DATABASE ". $dbName);
// set client buffer size to 1KB
$size = 1;
fetchData($conn, $tableName1, $size); // this should return 0 rows.
fetchData($conn, $tableName2, $size); // this should return 0 rows.
// set client buffer size to 2KB
$size = 2;
fetchData($conn, $tableName1, $size); // this should return 1 row.
fetchData($conn, $tableName2, $size); // this should return 1 row.
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
print "Done"

View file

@ -6,12 +6,11 @@ Test numeric conversion (number to string, string to number) functionality for b
--FILE--
<?php
require_once("autonomous_setup.php");
require_once("MsCommon.inc");
$connectionInfo = array("UID"=>"$username", "PWD"=>"$password", "CharacterSet" => "UTF-8");
$conn = sqlsrv_connect($serverName, $connectionInfo);
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true ));
$conn = Connect(array("CharacterSet"=>"utf-8"));
if( !$conn ) {
PrintErrors("Connection could not be established.\n");
}
$sample = 1234567890.1234;
@ -42,15 +41,12 @@ if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$query = 'SELECT TOP 2 * FROM #TESTTABLE';
$stmt = sqlsrv_query( $conn, $query, array(), array("Scrollable"=>SQLSRV_CURSOR_CLIENT_BUFFERED));
if(!$stmt)
{
echo "Statement could not be prepared.\n";
die( print_r( sqlsrv_errors(),true));
echo "Statement could not be prepared.\n";
die( print_r( sqlsrv_errors(),true));
}
sqlsrv_execute( $stmt );
@ -59,9 +55,6 @@ var_dump($array);
$array = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_NUMERIC );
var_dump($array);
$numFields = sqlsrv_num_fields( $stmt );
$meta = sqlsrv_field_metadata( $stmt );
$rowcount = sqlsrv_num_rows( $stmt);

View file

@ -6,21 +6,20 @@ GitHub issue #231 - String truncation when binding varchar(max)
sqlsrv_configure( 'WarningsReturnAsErrors', 1 );
require_once("autonomous_setup.php");
require_once("MsCommon.inc");
// Connect
$connectionInfo = array( "UID"=>$username, "PWD"=>$password);
$conn = sqlsrv_connect($serverName, $connectionInfo);
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true ));
$conn = Connect();
if( !$conn ) {
PrintErrors("Connection could not be established.\n");
}
$tableName = "#testDataTypes_GH231";
$tableName = GetTempTableName('testDataTypes_GH231');
$columnNames = array( "c1","c2" );
for ($k = 1; $k <= 8; $k++)
{
$sqlType = GetSqlType($k);
$sqlType = SqlType($k);
$dataType = "[$columnNames[0]] int, [$columnNames[1]] $sqlType";
$sql = "CREATE TABLE [$tableName] ($dataType)";
@ -29,8 +28,8 @@ for ($k = 1; $k <= 8; $k++)
$sql = "INSERT INTO [$tableName] ($columnNames[0], $columnNames[1]) VALUES (?, ?)";
$data = GetData($k);
$phpType = GetPhpType($k);
$driverType = GetDriverType($k, strlen($data));
$phpType = PhpType($k);
$driverType = DriverType($k, strlen($data));
$params = array($k, array($data, SQLSRV_PARAM_IN, $phpType, $driverType));
$stmt2 = sqlsrv_prepare($conn, $sql, $params);
@ -59,19 +58,19 @@ function ExecProc($conn, $tableName, $columnNames, $k, $data, $sqlType)
$direction = SQLSRV_PARAM_OUT;
echo "Output parameter: \t";
CallProc($conn, $procName, $k, $direction, $data);
InvokeProc($conn, $procName, $k, $direction, $data);
$direction = SQLSRV_PARAM_INOUT;
echo "InOut parameter: \t";
CallProc($conn, $procName, $k, $direction, $data);
InvokeProc($conn, $procName, $k, $direction, $data);
$stmt2 = sqlsrv_query($conn, "DROP PROC [$procName]");
sqlsrv_free_stmt($stmt2);
}
function CallProc($conn, $procName, $k, $direction, $data)
function InvokeProc($conn, $procName, $k, $direction, $data)
{
$driverType = GetDriverType($k, strlen($data));
$driverType = DriverType($k, strlen($data));
$callArgs = "?, ?";
// Data to initialize $callResult variable. This variable should be shorter than inserted data in the table
@ -106,7 +105,7 @@ function GetData($k)
return $data;
}
function GetPhpType($k)
function PhpType($k)
{
$phpType = SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR);
if ($k == 7) {
@ -116,7 +115,7 @@ function GetPhpType($k)
return $phpType;
}
function GetSqlType($k)
function SqlType($k)
{
switch ($k)
{
@ -133,7 +132,7 @@ function GetSqlType($k)
return ("udt");
}
function GetDriverType($k, $dataSize)
function DriverType($k, $dataSize)
{
switch ($k)
{

View file

@ -5,12 +5,10 @@ A variation of the example in GitHub issue 308. A NULL value returned as output
--SKIPIF--
--FILE--
<?php
require_once("tools.inc");
require_once("autonomous_setup.php");
require_once("MsCommon.inc");
// Connect
$conn = sqlsrv_connect($serverName, $connectionInfo) ?: FatalError("Failed to connect");
$conn = Connect() ?: FatalError("Failed to connect");
$procName = GetTempProcName();

View file

@ -5,12 +5,10 @@ A variation of the example in GitHub issue 330. A -1 value returned as numrow of
--SKIPIF--
--FILE--
<?php
require_once("tools.inc");
require_once("autonomous_setup.php");
require_once("MsCommon.inc");
// Connect
$conn = sqlsrv_connect($serverName, $connectionInfo) ?: FatalError("Failed to connect");
$conn = Connect() ?: FatalError("Failed to connect");
$stmt = sqlsrv_query($conn, "IF EXISTS (SELECT * FROM [sys].[objects] WHERE (name LIKE 'non_existent_table_name%') AND type in (N'U'))
BEGIN

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -29,76 +29,6 @@ define("_SQL_SS_TIMESTAMPOFFSET", -155);
define("_CHUNK_SIZE", 8192);
define("_EPSILON", 0.00001);
function StartTest($testName)
{
echo "\n...Starting '$testName' test...\n";
if (!extension_loaded("sqlsrv"))
{
die("sqlsrv driver cannot be loaded.");
}
}
function EndTest($testName)
{
echo "...Test '$testName' completed successfully.\n";
}
function GetTempTableName($table = '', $temporary = true)
{
// A temporary table name with the '#' prefix will be automatically
// dropped once the connection is closed. Otherwise, the caller
// should take care of dropping the temp table afterwards.
$timestamp = round(microtime(true)*1000);
$prefix = '';
if ($temporary)
$prefix = '#';
if (strlen($table) == 0)
$table = 'php_test_table';
return $prefix . $table . '_' . $timestamp;
}
function GetTempProcName($proc = '', $temporary = true)
{
// A temporary stored procedure name with the '#' prefix will be
// automatically dropped once the connection is closed. Otherwise,
// the caller should take care of dropping the temp procedure afterwards.
$timestamp = round(microtime(true)*1000);
$prefix = '';
if ($temporary)
$prefix = '#';
if (strlen($proc) == 0)
$proc = 'php_test_proc';
return $prefix . $proc . '_' . $timestamp;
}
function FatalError($errorMsg)
{
handle_errors();
die($errorMsg);
}
function handle_errors()
{
$errors = sqlsrv_errors(SQLSRV_ERR_ERRORS);
if(count($errors) == 0)
{
$errors = sqlsrv_errors(SQLSRV_ERR_ALL);
}
$count = count($errors);
for($i = 0; $i < $count; $i++)
{
echo $errors[$i]['message'];
}
}
function Verify($stmt, $metadata, $numFields, $encoding)
{
$i = 0;
@ -125,14 +55,14 @@ function ConvertDataToString($type, $data)
// Convert raw data to strings for datetime and binary types only
// Do nothing for other types
//
if (IsDateTime($type))
if (IsDateTimeType($type))
{
if ($type != _SQL_SS_TIME2)
return date_format( $data, 'Y-m-d H:i:s' );
else
return date_format( $data, 'H:i:s' );
}
else if (IsBinary($type))
else if (IsBinaryType($type))
{
return bin2hex($data);
}
@ -217,7 +147,7 @@ function CheckData($colType, $actual, $expected)
{
$success = true;
if (IsNumeric($colType))
if (IsNumericType($colType))
{
if (! CompareNumericData($actual, $expected))
{
@ -229,7 +159,7 @@ function CheckData($colType, $actual, $expected)
$actual = trim($actual);
$len = strlen($expected);
if (IsDateTime($colType))
if (IsDateTimeType($colType))
{
if ($colType != _SQL_SS_TIME2)
$len = min(strlen("YYYY-MM-DD HH:mm:ss"), $len);
@ -354,7 +284,7 @@ function CompareBinaryData($actual, $expected)
return $matched;
}
function CompareStreamData($actual, $expected, $isUnicode)
function CompareStreamData($actual, $expected, $IsUnicodeType)
{
// this function assumes $actual is a stream of character data
$matched = true;
@ -366,7 +296,7 @@ function CompareStreamData($actual, $expected, $isUnicode)
// it's unicode, the character of data is also two bytes
$shift = 1;
if ($isUnicode)
if ($IsUnicodeType)
$shift = 2;
$len = strlen($str);
@ -410,14 +340,14 @@ function CompareBinaryStream($metadata, $rowIndex, $colIndex, $actual, $expected
$colType = $metadata[$colIndex]['Type'];
$matched = false;
if (IsBinary($colType))
if (IsBinaryType($colType))
{
$matched = CompareBinaryData($actual, $expected);
}
else
{
// stream of characters
$matched = CompareStreamData($actual, $expected, IsUnicode($colType));
$matched = CompareStreamData($actual, $expected, IsUnicodeType($colType));
}
if (! $matched)
@ -428,14 +358,14 @@ function CompareBinaryStream($metadata, $rowIndex, $colIndex, $actual, $expected
return $matched;
}
function CompareStringToFile($rowIndex, $colName, $actual, $file, $isBinary)
function CompareStringToFile($rowIndex, $colName, $actual, $file, $IsBinaryType)
{
$matched = true;
$pos = 0;
while ($matched && ! feof($file))
{
$expected = fread($file, _CHUNK_SIZE);
if ($isBinary)
if ($IsBinaryType)
{
$str = unpack("H*", $expected);
$expected = $str[1];
@ -463,7 +393,7 @@ function CompareStreamToFile($rowIndex, $colName, $stream, $file, $colType)
// one from stream resource and one from a file
// Moreover, the data can be binary or character/unicode character
$isBinary = IsBinary($colType);
$IsBinaryType = IsBinaryType($colType);
$matched = true;
while ($matched && ! feof($file) && ! feof ($stream))
@ -471,7 +401,7 @@ function CompareStreamToFile($rowIndex, $colName, $stream, $file, $colType)
$expected = fread($file, _CHUNK_SIZE);
$actual = fread($stream, _CHUNK_SIZE);
if ($isBinary)
if ($IsBinaryType)
{
$str = unpack("H*", $expected);
$expected = $str[1];
@ -492,7 +422,7 @@ function CompareStreamToFile($rowIndex, $colName, $stream, $file, $colType)
// it's unicode, the character of data is also two bytes
$shift = 1;
if (IsUnicode($colType))
if (IsUnicodeType($colType))
$shift = 2;
$i = 0;
@ -553,9 +483,9 @@ function CompareData($metadata, $rowIndex, $colIndex, $actual, $expected, $isStr
{
FatalError("Field $colName of row $rowIndex is missing\n");
}
if (! IsUpdatable($colName))
if (! IsColumnUpdatable($colName))
{
return true; // do nothing for non-IsUpdatable fields
return true; // do nothing for non-IsColumnUpdatable fields
}
if ($isStream)
@ -570,8 +500,8 @@ function CompareData($metadata, $rowIndex, $colIndex, $actual, $expected, $isStr
function CompareLOBToFile($rowIndex, $colType, $colName, $actual, $filename, $readStream)
{
$isBinary = IsBinary($colType);
$mode = ($isBinary)? "rb" : "r";
$IsBinaryType = IsBinaryType($colType);
$mode = ($IsBinaryType)? "rb" : "r";
$file = fopen($filename, $mode);
echo "...reading LOB data from '$filename'...";
@ -583,7 +513,7 @@ function CompareLOBToFile($rowIndex, $colType, $colName, $actual, $filename, $re
}
else
{
$matched = CompareStringToFile($rowIndex, $colName, $actual, $file, $isBinary);
$matched = CompareStringToFile($rowIndex, $colName, $actual, $file, $IsBinaryType);
}
fclose($file);
@ -597,7 +527,7 @@ function VerifyLOBData($metadata, $rowIndex, $colIndex, $lobColumn, $actual, $ex
$colType = $metadata[$colIndex]['Type'];
$matched = false;
if ($readStream && IsStreamable($colType))
if ($readStream && IsStreamableType($colType))
{
if ($colIndex != $lobColumn)
{
@ -636,7 +566,7 @@ function SimplifyDataArray($data, $metadata, $row)
$colName = $metadata[$j]['Name'];
$colType = $metadata[$j]['Type'];
if (!IsUpdatable($colName))
if (!IsColumnUpdatable($colName))
{
$skipCount++;
array_push($dataArray, "");
@ -669,14 +599,14 @@ function InsertDataToArray($query, $metadata, $row)
$type = $metadata[$j]['Type'];
$col = $j + 1;
if (!IsUpdatable($colName))
if (!IsColumnUpdatable($colName))
{
$skipCount++;
array_push($dataArray, "");
}
else
{
$data = GetInsertData($query, $type, $row, $col, $skipCount);
$data = GetInsertDataByType($query, $type, $row, $col, $skipCount);
array_push($dataArray, $data);
}
}
@ -684,7 +614,7 @@ function InsertDataToArray($query, $metadata, $row)
return $dataArray;
}
function GetInsertData($query, $colType, $rowIndex, $colIndex, $skip)
function GetInsertDataByType($query, $colType, $rowIndex, $colIndex, $skip)
{
$data = strstr($query, "((");
$pos = 1;
@ -719,7 +649,7 @@ function GetInsertData($query, $colType, $rowIndex, $colIndex, $skip)
{
$tmp = "";
}
else if (IsXml($colType))
else if (IsXmlType($colType))
{
$str = ">')";
$pos = strpos($data, $str);
@ -732,11 +662,11 @@ function GetInsertData($query, $colType, $rowIndex, $colIndex, $skip)
{ // N'data'
$data = substr($data, 2, strlen($data) - 3);
}
else if (IsLiteral($colType))
else if (IsLiteralType($colType))
{ // 'data'
$data = substr($data, 1, strlen($data) - 2);
}
else if (IsBinary($colType))
else if (IsBinaryType($colType))
{ // 0xdata
$data = substr($data, 2);
}
@ -744,7 +674,7 @@ function GetInsertData($query, $colType, $rowIndex, $colIndex, $skip)
return (trim($data));
}
function IsStreamable($type)
function IsStreamableType($type)
{
switch ($type)
{
@ -774,7 +704,7 @@ function IsStreamable($type)
return (false);
}
function IsNumeric($type)
function IsNumericType($type)
{
switch ($type)
{
@ -801,7 +731,7 @@ function IsNumeric($type)
return (false);
}
function IsChar($type)
function IsCharType($type)
{
switch ($type)
{
@ -823,7 +753,7 @@ function IsChar($type)
return (false);
}
function IsBinary($type)
function IsBinaryType($type)
{
switch ($type)
{
@ -839,7 +769,7 @@ function IsBinary($type)
return (false);
}
function IsDateTime($type)
function IsDateTimeType($type)
{
switch ($type)
{
@ -859,7 +789,7 @@ function IsDateTime($type)
function IsDataUnicode($colType, $data)
{
if (IsUnicode($colType))
if (IsUnicodeType($colType))
return true;
// This input string may be an XML string in unicode (i.e. // N'<xmldata>...</xmldata>')
@ -876,7 +806,7 @@ function IsDataUnicode($colType, $data)
return false;
}
function IsUnicode($type)
function IsUnicodeType($type)
{
switch ($type)
{
@ -892,12 +822,12 @@ function IsUnicode($type)
return (false);
}
function IsXml($type)
function IsXmlType($type)
{
return ($type == _SQL_SS_XML);
}
function IsUpdatable($colName)
function IsColumnUpdatable($colName)
{
$pos = strpos($colName, "_");
$type = substr($colName, $pos + 1);
@ -905,7 +835,7 @@ function IsUpdatable($colName)
return (strcasecmp($type, "timestamp") != 0);
}
function IsLiteral($type)
function IsLiteralType($type)
{
switch ($type)
{