From 194f37f8d5203162e7a41cd204d8b44b0a87a6f4 Mon Sep 17 00:00:00 2001 From: yitam Date: Wed, 8 Mar 2017 14:17:21 -0800 Subject: [PATCH] part 5 new sqlsrv tests --- .../sqlsrv_fetch_datetime_as_strings.phpt | 116 ++++++++++++++++++ .../sqlsrv/sqlsrv_param_query_data_types.phpt | 66 ++++++++++ .../sqlsrv_statement_query_timeout.phpt | 78 ++++++++++++ ...v_statement_query_timeout_transaction.phpt | 91 ++++++++++++++ 4 files changed, 351 insertions(+) create mode 100644 test/sqlsrv/sqlsrv_fetch_datetime_as_strings.phpt create mode 100644 test/sqlsrv/sqlsrv_param_query_data_types.phpt create mode 100644 test/sqlsrv/sqlsrv_statement_query_timeout.phpt create mode 100644 test/sqlsrv/sqlsrv_statement_query_timeout_transaction.phpt diff --git a/test/sqlsrv/sqlsrv_fetch_datetime_as_strings.phpt b/test/sqlsrv/sqlsrv_fetch_datetime_as_strings.phpt new file mode 100644 index 00000000..dcfa8efd --- /dev/null +++ b/test/sqlsrv/sqlsrv_fetch_datetime_as_strings.phpt @@ -0,0 +1,116 @@ +--TEST-- +Test fetching datatime fields as strings +--FILE-- +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. diff --git a/test/sqlsrv/sqlsrv_param_query_data_types.phpt b/test/sqlsrv/sqlsrv_param_query_data_types.phpt new file mode 100644 index 00000000..8b98aae3 --- /dev/null +++ b/test/sqlsrv/sqlsrv_param_query_data_types.phpt @@ -0,0 +1,66 @@ +--TEST-- +Test insert various numeric data types and fetch them back as strings +--FILE-- +$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. diff --git a/test/sqlsrv/sqlsrv_statement_query_timeout.phpt b/test/sqlsrv/sqlsrv_statement_query_timeout.phpt new file mode 100644 index 00000000..46c7e405 --- /dev/null +++ b/test/sqlsrv/sqlsrv_statement_query_timeout.phpt @@ -0,0 +1,78 @@ +--TEST-- +Test sending queries (query or prepare) with a timeout specified. Errors are expected. +--FILE-- + 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. diff --git a/test/sqlsrv/sqlsrv_statement_query_timeout_transaction.phpt b/test/sqlsrv/sqlsrv_statement_query_timeout_transaction.phpt new file mode 100644 index 00000000..7ac329c6 --- /dev/null +++ b/test/sqlsrv/sqlsrv_statement_query_timeout_transaction.phpt @@ -0,0 +1,91 @@ +--TEST-- +Test sending queries (query or prepare) with a timeout specified using transactions. Errors are expected. +--FILE-- + 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.