Skip to content

Commit 7e0bf91

Browse files
authored
Fixed two failing tests (#991)
1 parent f369ce6 commit 7e0bf91

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

test/functional/pdo_sqlsrv/pdo_035_binary_encoding_error_bound_by_name_errors.phpt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ function bindTypeNoEncoding($conn, $sql, $input)
1717
$stmt->setAttribute(constant('PDO::SQLSRV_ATTR_ENCODING'), PDO::SQLSRV_ENCODING_BINARY);
1818
$stmt->bindParam(2, $input, PDO::PARAM_LOB);
1919
$stmt->execute();
20+
echo "bindTypeNoEncoding: expected to fail!\n";
2021
} catch (PDOException $e) {
2122
$error = '*An encoding was specified for parameter 1. Only PDO::PARAM_LOB and PDO::PARAM_STR can take an encoding option.';
2223
if (!fnmatch($error, $e->getMessage())) {
@@ -36,6 +37,7 @@ function bindDefaultEncoding($conn, $sql, $input)
3637
$stmt->setAttribute(constant('PDO::SQLSRV_ATTR_ENCODING'), PDO::SQLSRV_ENCODING_BINARY);
3738
$stmt->bindParam(2, $input, PDO::PARAM_LOB);
3839
$stmt->execute();
40+
echo "bindDefaultEncoding: expected to fail!\n";
3941
} catch (PDOException $e) {
4042
$error = '*Invalid encoding specified for parameter 1.';
4143
if (!fnmatch($error, $e->getMessage())) {
@@ -52,8 +54,9 @@ function insertData($conn, $sql, $input)
5254

5355
$stmt = $conn->prepare($sql);
5456
$stmt->bindParam(1, $value);
55-
$stmt->setAttribute(constant('PDO::SQLSRV_ATTR_ENCODING'), PDO::SQLSRV_ENCODING_BINARY);
56-
$stmt->bindParam(2, $input, PDO::PARAM_LOB);
57+
// Specify binary encoding for the second parameter only such that the first
58+
// parameter is unaffected
59+
$stmt->bindParam(2, $input, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY);
5760
$stmt->execute();
5861
} catch (PDOException $e) {
5962
echo "Error unexpected in insertData\n";
@@ -68,6 +71,7 @@ function invalidEncoding1($conn, $sql)
6871
$stmt->bindColumn(1, $id, PDO::PARAM_INT, 0, PDO::SQLSRV_ENCODING_UTF8);
6972
$stmt->execute();
7073
$stmt->fetch(PDO::FETCH_BOUND);
74+
echo "invalidEncoding1: expected to fail!\n";
7175
} catch (PDOException $e) {
7276
$error = '*An encoding was specified for column 1. Only PDO::PARAM_LOB and PDO::PARAM_STR column types can take an encoding option.';
7377
if (!fnmatch($error, $e->getMessage())) {
@@ -84,6 +88,7 @@ function invalidEncoding2($conn, $sql)
8488
$stmt->bindColumn('Value', $val1, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_DEFAULT);
8589
$stmt->execute();
8690
$stmt->fetch(PDO::FETCH_BOUND);
91+
echo "invalidEncoding2: expected to fail!\n";
8792
} catch (PDOException $e) {
8893
$error = '*Invalid encoding specified for column 1.';
8994
if (!fnmatch($error, $e->getMessage())) {
@@ -100,6 +105,7 @@ function invalidEncoding3($conn, $sql)
100105
$stmt->bindColumn(1, $id, PDO::PARAM_STR, 0, "dummy");
101106
$stmt->execute();
102107
$stmt->fetch(PDO::FETCH_BOUND);
108+
echo "invalidEncoding3: expected to fail!\n";
103109
} catch (PDOException $e) {
104110
$error = '*An invalid type or value was given as bound column driver data for column 1. Only encoding constants such as PDO::SQLSRV_ENCODING_UTF8 may be used as bound column driver data.';
105111
if (!fnmatch($error, $e->getMessage())) {

test/functional/sqlsrv/srv_007_login_timeout.phpt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,23 @@ $serverName = "WRONG_SERVER_NAME";
1111

1212
$t0 = microtime(true);
1313

14-
$conn = sqlsrv_connect($serverName , array("LoginTimeout" => 8));
14+
// Based on the following reference, a login timeout of less than approximately 10 seconds
15+
// is not reliable. The defaut is 15 seconds so we fix it at 20 seconds.
16+
// https://docs.microsoft.com/sql/connect/odbc/windows/features-of-the-microsoft-odbc-driver-for-sql-server-on-windows
17+
18+
$timeout = 20;
19+
$conn = sqlsrv_connect($serverName , array("LoginTimeout" => $timeout));
1520

1621
$t1 = microtime(true);
1722

18-
echo "Connection attempt time: " . ($t1 - $t0) . " [sec]\n";
23+
$elapsed = $t1 - $t0;
24+
$diff = abs($elapsed - $timeout);
25+
26+
if ($elapsed < $timeout || $diff > 1.0) {
27+
echo "Connection failed at $elapsed secs. Leeway is 1.0 sec but the difference is $diff\n";
28+
}
1929

2030
print "Done";
2131
?>
22-
23-
--EXPECTREGEX--
24-
Connection attempt time: [7-9]\.[0-9]+ \[sec\]
32+
--EXPECT--
2533
Done

0 commit comments

Comments
 (0)