Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed two failing tests #991

Merged
merged 1 commit into from
May 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function bindTypeNoEncoding($conn, $sql, $input)
$stmt->setAttribute(constant('PDO::SQLSRV_ATTR_ENCODING'), PDO::SQLSRV_ENCODING_BINARY);
$stmt->bindParam(2, $input, PDO::PARAM_LOB);
$stmt->execute();
echo "bindTypeNoEncoding: expected to fail!\n";
} catch (PDOException $e) {
$error = '*An encoding was specified for parameter 1. Only PDO::PARAM_LOB and PDO::PARAM_STR can take an encoding option.';
if (!fnmatch($error, $e->getMessage())) {
Expand All @@ -36,6 +37,7 @@ function bindDefaultEncoding($conn, $sql, $input)
$stmt->setAttribute(constant('PDO::SQLSRV_ATTR_ENCODING'), PDO::SQLSRV_ENCODING_BINARY);
$stmt->bindParam(2, $input, PDO::PARAM_LOB);
$stmt->execute();
echo "bindDefaultEncoding: expected to fail!\n";
} catch (PDOException $e) {
$error = '*Invalid encoding specified for parameter 1.';
if (!fnmatch($error, $e->getMessage())) {
Expand All @@ -52,8 +54,9 @@ function insertData($conn, $sql, $input)

$stmt = $conn->prepare($sql);
$stmt->bindParam(1, $value);
$stmt->setAttribute(constant('PDO::SQLSRV_ATTR_ENCODING'), PDO::SQLSRV_ENCODING_BINARY);
$stmt->bindParam(2, $input, PDO::PARAM_LOB);
// Specify binary encoding for the second parameter only such that the first
// parameter is unaffected
$stmt->bindParam(2, $input, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY);
$stmt->execute();
} catch (PDOException $e) {
echo "Error unexpected in insertData\n";
Expand All @@ -68,6 +71,7 @@ function invalidEncoding1($conn, $sql)
$stmt->bindColumn(1, $id, PDO::PARAM_INT, 0, PDO::SQLSRV_ENCODING_UTF8);
$stmt->execute();
$stmt->fetch(PDO::FETCH_BOUND);
echo "invalidEncoding1: expected to fail!\n";
} catch (PDOException $e) {
$error = '*An encoding was specified for column 1. Only PDO::PARAM_LOB and PDO::PARAM_STR column types can take an encoding option.';
if (!fnmatch($error, $e->getMessage())) {
Expand All @@ -84,6 +88,7 @@ function invalidEncoding2($conn, $sql)
$stmt->bindColumn('Value', $val1, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_DEFAULT);
$stmt->execute();
$stmt->fetch(PDO::FETCH_BOUND);
echo "invalidEncoding2: expected to fail!\n";
} catch (PDOException $e) {
$error = '*Invalid encoding specified for column 1.';
if (!fnmatch($error, $e->getMessage())) {
Expand All @@ -100,6 +105,7 @@ function invalidEncoding3($conn, $sql)
$stmt->bindColumn(1, $id, PDO::PARAM_STR, 0, "dummy");
$stmt->execute();
$stmt->fetch(PDO::FETCH_BOUND);
echo "invalidEncoding3: expected to fail!\n";
} catch (PDOException $e) {
$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.';
if (!fnmatch($error, $e->getMessage())) {
Expand Down
18 changes: 13 additions & 5 deletions test/functional/sqlsrv/srv_007_login_timeout.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,23 @@ $serverName = "WRONG_SERVER_NAME";

$t0 = microtime(true);

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

$timeout = 20;
$conn = sqlsrv_connect($serverName , array("LoginTimeout" => $timeout));

$t1 = microtime(true);

echo "Connection attempt time: " . ($t1 - $t0) . " [sec]\n";
$elapsed = $t1 - $t0;
$diff = abs($elapsed - $timeout);

if ($elapsed < $timeout || $diff > 1.0) {
echo "Connection failed at $elapsed secs. Leeway is 1.0 sec but the difference is $diff\n";
}

print "Done";
?>

--EXPECTREGEX--
Connection attempt time: [7-9]\.[0-9]+ \[sec\]
--EXPECT--
Done