2017-03-08 23:17:21 +01:00
|
|
|
|
--TEST--
|
|
|
|
|
Test sending queries (query or prepare) with a timeout specified using transactions. Errors are expected.
|
|
|
|
|
--FILE--
|
|
|
|
|
<?php
|
2017-10-04 23:22:56 +02:00
|
|
|
|
require_once('MsCommon.inc');
|
2017-03-08 23:17:21 +01:00
|
|
|
|
|
|
|
|
|
function QueryTimeout($conn1, $conn2, $commit)
|
|
|
|
|
{
|
2017-04-05 22:22:39 +02:00
|
|
|
|
$tableName = GetTempTableName('testQueryTimeout', false);
|
2017-10-04 23:22:56 +02:00
|
|
|
|
|
|
|
|
|
$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)");
|
2017-03-08 23:17:21 +01:00
|
|
|
|
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);
|
2017-10-04 23:22:56 +02:00
|
|
|
|
if ($numRows !== 1) {
|
2017-03-08 23:17:21 +01:00
|
|
|
|
echo "Number of rows affected unexpected!\n";
|
2017-10-04 23:22:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-08 23:17:21 +01:00
|
|
|
|
$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);
|
2017-10-04 23:22:56 +02:00
|
|
|
|
if ($numRows !== 1) {
|
2017-03-08 23:17:21 +01:00
|
|
|
|
echo "Number of rows affected unexpected!\n";
|
2017-10-04 23:22:56 +02:00
|
|
|
|
}
|
|
|
|
|
sqlsrv_free_stmt($stmt);
|
|
|
|
|
|
|
|
|
|
$stmt = sqlsrv_query($conn2, "WAITFOR DELAY '00:00:03'; 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 {
|
2017-03-08 23:17:21 +01:00
|
|
|
|
sqlsrv_rollback($conn1);
|
2017-10-04 23:22:56 +02:00
|
|
|
|
}
|
2017-03-08 23:17:21 +01:00
|
|
|
|
|
2017-10-04 23:22:56 +02:00
|
|
|
|
sqlsrv_query($conn2, "DROP TABLE $tableName");
|
2017-03-08 23:17:21 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Repro()
|
|
|
|
|
{
|
2017-10-04 23:22:56 +02:00
|
|
|
|
startTest("sqlsrv_statement_query_timeout_transaction");
|
2017-05-02 02:01:30 +02:00
|
|
|
|
echo "\nTest begins...\n";
|
2017-10-04 23:22:56 +02:00
|
|
|
|
try {
|
|
|
|
|
set_time_limit(0);
|
|
|
|
|
sqlsrv_configure('WarningsReturnAsErrors', 1);
|
|
|
|
|
|
|
|
|
|
// connect
|
|
|
|
|
$conn1 = connect(array('ConnectionPooling'=>0));
|
|
|
|
|
if (!$conn1) {
|
|
|
|
|
fatalError("Could not connect.\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$conn2 = connect(array('ConnectionPooling'=>0));
|
|
|
|
|
if (!$conn2) {
|
|
|
|
|
fatalError("Could not connect.\n");
|
|
|
|
|
}
|
2017-03-08 23:17:21 +01:00
|
|
|
|
|
|
|
|
|
QueryTimeout($conn1, $conn2, true);
|
|
|
|
|
QueryTimeout($conn1, $conn2, false);
|
2017-10-04 23:22:56 +02:00
|
|
|
|
|
|
|
|
|
sqlsrv_close($conn1);
|
|
|
|
|
sqlsrv_close($conn2);
|
|
|
|
|
} catch (Exception $e) {
|
2017-03-08 23:17:21 +01:00
|
|
|
|
echo $e->getMessage();
|
|
|
|
|
}
|
|
|
|
|
echo "\nDone\n";
|
2017-10-04 23:22:56 +02:00
|
|
|
|
endTest("sqlsrv_statement_query_timeout_transaction");
|
2017-03-08 23:17:21 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Repro();
|
|
|
|
|
|
|
|
|
|
?>
|
2017-09-13 23:45:11 +02:00
|
|
|
|
--EXPECTREGEX--
|
2017-03-08 23:17:21 +01:00
|
|
|
|
|
2017-05-02 02:01:30 +02:00
|
|
|
|
Test begins...
|
2017-09-13 23:45:11 +02:00
|
|
|
|
\[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Query timeout expired
|
2017-03-08 23:17:21 +01:00
|
|
|
|
0
|
|
|
|
|
HYT00
|
2017-09-13 23:45:11 +02:00
|
|
|
|
\[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Query timeout expired
|
2017-03-08 23:17:21 +01:00
|
|
|
|
0
|
|
|
|
|
HYT00
|
|
|
|
|
|
|
|
|
|
Done
|
2017-09-13 23:45:11 +02:00
|
|
|
|
Test \"sqlsrv_statement_query_timeout_transaction\" completed successfully\.
|