This commit is contained in:
yitam 2017-03-08 14:17:21 -08:00
Родитель 45ea247c3f
Коммит 194f37f8d5
4 изменённых файлов: 351 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,116 @@
--TEST--
Test fetching datatime fields as strings
--FILE--
<?php
include 'tools.inc';
function FetchDateTime_AsString($conn)
{
$tableName = GetTempTableName();
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_timestamp] timestamp, [c3_datetime] datetime, [c4_smalldatetime] smalldatetime)");
sqlsrv_free_stmt($stmt);
$numRows = 0;
$query = GetQuery($tableName, ++$numRows);
$stmt = sqlsrv_query($conn, $query);
sqlsrv_free_stmt($stmt);
$query = GetQuery($tableName, ++$numRows);
$stmt = sqlsrv_query($conn, $query);
sqlsrv_free_stmt($stmt);
$query = GetQuery($tableName, ++$numRows);
$stmt = sqlsrv_query($conn, $query);
sqlsrv_free_stmt($stmt);
$query = GetQuery($tableName, ++$numRows);
$stmt = sqlsrv_query($conn, $query);
sqlsrv_free_stmt($stmt);
$query = "SELECT [c3_datetime], [c4_smalldatetime] FROM $tableName ORDER BY c2_timestamp";
$stmt1 = sqlsrv_query($conn, $query);
$stmt2 = sqlsrv_query($conn, $query);
FetchData($stmt1, $stmt2, $numRows);
sqlsrv_free_stmt($stmt1);
sqlsrv_free_stmt($stmt2);
}
function FetchData($stmt1, $stmt2, $numRows)
{
$rowFetched = 0;
do {
$obj = sqlsrv_fetch_object($stmt1);
$row = sqlsrv_fetch_array($stmt2, SQLSRV_FETCH_ASSOC);
$value1 = $obj->c3_datetime;
$value2 = $row['c3_datetime'];
if ($value1 !== $value2)
echo "Data corrupted: $value1 !== $value2\n";
} while (++$rowFetched < $numRows);
}
function GetQuery($tableName, $index)
{
$query = "";
switch ($index)
{
case 1:
$query = "INSERT INTO $tableName ([c1_int], [c3_datetime], [c4_smalldatetime]) VALUES ((2073189157), ('1753-01-01 00:00:00.000'), (null))";
break;
case 2:
$query = "INSERT INTO $tableName ([c1_int], [c3_datetime], [c4_smalldatetime]) VALUES ((-920147222), ('3895-08-29 00:41:03.351'), ('1936-01-05 21:34:00'))";
break;
case 3:
$query = "INSERT INTO $tableName ([c1_int], [c3_datetime], [c4_smalldatetime]) VALUES ((-2147483648), ('1753-01-01 00:00:00.000'), ('1915-11-08 19:46:00'))";
break;
case 4:
$query = "INSERT INTO $tableName ([c1_int], [c3_datetime], [c4_smalldatetime]) VALUES ((1269199053), (null), ('2075-04-27 22:16:00'))";
break;
default:
break;
}
return $query;
}
function Repro()
{
StartTest("sqlsrv_fetch_datetime_as_strings");
try
{
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
sqlsrv_get_config('WarningsReturnAsErrors');
require_once("autonomous_setup.php");
// Connect
$connectionInfo = array("UID"=>$username, "PWD"=>$password, 'ReturnDatesAsStrings'=>true);
$conn = sqlsrv_connect($serverName, $connectionInfo);
if( !$conn ) { FatalError("Could not connect.\n"); }
FetchDateTime_AsString($conn);
sqlsrv_close($conn);
}
catch (Exception $e)
{
echo $e->getMessage();
}
echo "\nDone\n";
EndTest("sqlsrv_fetch_datetime_as_strings");
}
Repro();
?>
--EXPECT--

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

Просмотреть файл

@ -0,0 +1,66 @@
--TEST--
Test insert various numeric data types and fetch them back as strings
--FILE--
<?php
include 'tools.inc';
function ParamQuery($conn, $type, $sqlsrvType, $inValue)
{
$tableName = GetTempTableName();
$stmt = sqlsrv_query($conn, "CREATE TABLE [$tableName] ([col1] int, [col2] $type)");
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query($conn, "INSERT INTO [$tableName] VALUES (?, ?)", array(1, array($inValue, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_FLOAT, $sqlsrvType)));
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query($conn, "SELECT * FROM $tableName");
sqlsrv_fetch($stmt);
$value = sqlsrv_get_field($stmt, 1, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
CompareNumericData($value, $inValue);
sqlsrv_free_stmt($stmt);
}
function Repro()
{
StartTest("sqlsrv_param_query_data_types");
try
{
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
sqlsrv_get_config('WarningsReturnAsErrors');
require_once("autonomous_setup.php");
$database = "tempdb";
// Connect
$connectionInfo = array("UID"=>$username, "PWD"=>$password);
$conn = sqlsrv_connect($serverName, $connectionInfo);
if( !$conn ) { FatalError("Could not connect.\n"); }
ParamQuery($conn, "float", SQLSRV_SQLTYPE_FLOAT, 12.345);
ParamQuery($conn, "money", SQLSRV_SQLTYPE_MONEY, 56.78);
ParamQuery($conn, "numeric(32,4)", SQLSRV_SQLTYPE_NUMERIC(32, 4), 12.34);
ParamQuery($conn, "real", SQLSRV_SQLTYPE_REAL, 98.760);
ParamQuery($conn, "smallmoney", SQLSRV_SQLTYPE_SMALLMONEY, 56.78);
sqlsrv_close($conn);
}
catch (Exception $e)
{
echo $e->getMessage();
}
echo "\nDone\n";
EndTest("sqlsrv_param_query_data_types");
}
Repro();
?>
--EXPECT--

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

Просмотреть файл

@ -0,0 +1,78 @@
--TEST--
Test sending queries (query or prepare) with a timeout specified. Errors are expected.
--FILE--
<?php
include 'tools.inc';
function QueryTimeout($conn, $exec)
{
$tableName = GetTempTableName();
$stmt = sqlsrv_query($conn, "CREATE TABLE [$tableName] ([c1_int] int, [c2_tinyint] tinyint, [c3_smallint] smallint, [c4_bigint] bigint, [c5_bit] bit, [c6_float] float, [c7_real] real, [c8_decimal] decimal(28,4), [c9_numeric] numeric(32,4), [c10_money] money, [c11_smallmoney] smallmoney, [c12_char] char(512), [c13_varchar] varchar(512), [c14_varchar_max] varchar(max), [c15_uniqueidentifier] uniqueidentifier, [c16_datetime] datetime, [c17_smalldatetime] smalldatetime, [c18_timestamp] timestamp)");
sqlsrv_free_stmt($stmt);
if ($exec)
{
$stmt = sqlsrv_query($conn, "WAITFOR DELAY '00:00:03'; SELECT * FROM $tableName", array(), array('QueryTimeout' => 1));
}
else
{
$stmt = sqlsrv_prepare($conn, "WAITFOR DELAY '00:00:05'; SELECT * FROM $tableName", array(), array('QueryTimeout' => 1));
sqlsrv_execute($stmt);
}
$errors = sqlsrv_errors(SQLSRV_ERR_ALL);
$e = $errors[0];
print($e['message'] . "\n");
print($e['code'] . "\n");
print($e['SQLSTATE'] . "\n");
}
function Repro()
{
StartTest("sqlsrv_statement_query_timeout");
try
{
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
sqlsrv_get_config('WarningsReturnAsErrors');
require_once("autonomous_setup.php");
$database = "tempdb";
// Connect
$connectionInfo = array("UID"=>$username, "PWD"=>$password);
$conn = sqlsrv_connect($serverName, $connectionInfo);
if( !$conn ) { FatalError("Could not connect.\n"); }
QueryTimeout($conn, true);
QueryTimeout($conn, false);
sqlsrv_close($conn);
}
catch (Exception $e)
{
echo $e->getMessage();
}
echo "\nDone\n";
EndTest("sqlsrv_statement_query_timeout");
}
Repro();
?>
--EXPECT--

...Starting 'sqlsrv_statement_query_timeout' test...
[Microsoft][ODBC Driver 13 for SQL Server]Query timeout expired
0
HYT00
[Microsoft][ODBC Driver 13 for SQL Server]Query timeout expired
0
HYT00
Done
...Test 'sqlsrv_statement_query_timeout' completed successfully.

Просмотреть файл

@ -0,0 +1,91 @@
--TEST--
Test sending queries (query or prepare) with a timeout specified using transactions. Errors are expected.
--FILE--
<?php
include 'tools.inc';
function QueryTimeout($conn1, $conn2, $commit)
{
$tableName = GetTempTableName('testQueryTimeout');
$stmt = sqlsrv_query($conn1, "CREATE TABLE $tableName ([c1_int] int, [c2_tinyint] tinyint, [c3_smallint] smallint, [c4_bigint] bigint, [c5_bit] bit, [c6_float] float, [c7_real] real, [c8_decimal] decimal(28,4), [c9_numeric] numeric(32,4), [c10_money] money, [c11_smallmoney] smallmoney)");
sqlsrv_free_stmt($stmt);
sqlsrv_begin_transaction($conn1);
$query = "INSERT INTO $tableName VALUES ((-2147483648), (127), (null), (9223372036854775807), (0), (1), (0), (null), (0.8654), (922337203685477.5807), (-214748.3648))";
$stmt = sqlsrv_query($conn1, $query);
$numRows = sqlsrv_rows_affected($stmt);
if ($numRows !== 1)
echo "Number of rows affected unexpected!\n";
$query = "INSERT INTO $tableName VALUES ((2147483647), (154), (-5459), (1), (0), (-1.79E+308), (1), (0.4430), (0), (0.2511), (0.7570))";
$stmt = sqlsrv_query($conn1, $query);
$numRows = sqlsrv_rows_affected($stmt);
if ($numRows !== 1)
echo "Number of rows affected unexpected!\n";
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query($conn2, "SELECT * FROM $tableName", array(), array('QueryTimeout' => 1));
$errors = sqlsrv_errors(SQLSRV_ERR_ALL);
$e = $errors[0];
print($e['message'] . "\n");
print($e['code'] . "\n");
print($e['SQLSTATE'] . "\n");
if ($commit)
sqlsrv_commit($conn1);
else
sqlsrv_rollback($conn1);
sqlsrv_query($conn2, "DROP TABLE $tableName");
}
function Repro()
{
StartTest("sqlsrv_statement_query_timeout_transaction");
try
{
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
sqlsrv_get_config('WarningsReturnAsErrors');
require_once("autonomous_setup.php");
// Connect
$connectionInfo = array("UID"=>$username, "PWD"=>$password, 'ConnectionPooling'=>0);
$conn1 = sqlsrv_connect($serverName, $connectionInfo);
if( !$conn1 ) { FatalError("Could not connect.\n"); }
$conn2 = sqlsrv_connect($serverName, $connectionInfo);
if( !$conn2 ) { FatalError("Could not connect.\n"); }
QueryTimeout($conn1, $conn2, true);
QueryTimeout($conn1, $conn2, false);
sqlsrv_close($conn1);
sqlsrv_close($conn2);
}
catch (Exception $e)
{
echo $e->getMessage();
}
echo "\nDone\n";
EndTest("sqlsrv_statement_query_timeout_transaction");
}
Repro();
?>
--EXPECT--

...Starting 'sqlsrv_statement_query_timeout_transaction' test...
[Microsoft][ODBC Driver 13 for SQL Server]Query timeout expired
0
HYT00
[Microsoft][ODBC Driver 13 for SQL Server]Query timeout expired
0
HYT00
Done
...Test 'sqlsrv_statement_query_timeout_transaction' completed successfully.