Fixed two failing tests (#991)
This commit is contained in:
parent
f369ce6212
commit
7e0bf91eec
|
@ -17,6 +17,7 @@ function bindTypeNoEncoding($conn, $sql, $input)
|
||||||
$stmt->setAttribute(constant('PDO::SQLSRV_ATTR_ENCODING'), PDO::SQLSRV_ENCODING_BINARY);
|
$stmt->setAttribute(constant('PDO::SQLSRV_ATTR_ENCODING'), PDO::SQLSRV_ENCODING_BINARY);
|
||||||
$stmt->bindParam(2, $input, PDO::PARAM_LOB);
|
$stmt->bindParam(2, $input, PDO::PARAM_LOB);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
|
echo "bindTypeNoEncoding: expected to fail!\n";
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
$error = '*An encoding was specified for parameter 1. Only PDO::PARAM_LOB and PDO::PARAM_STR can take an encoding option.';
|
$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())) {
|
if (!fnmatch($error, $e->getMessage())) {
|
||||||
|
@ -36,6 +37,7 @@ function bindDefaultEncoding($conn, $sql, $input)
|
||||||
$stmt->setAttribute(constant('PDO::SQLSRV_ATTR_ENCODING'), PDO::SQLSRV_ENCODING_BINARY);
|
$stmt->setAttribute(constant('PDO::SQLSRV_ATTR_ENCODING'), PDO::SQLSRV_ENCODING_BINARY);
|
||||||
$stmt->bindParam(2, $input, PDO::PARAM_LOB);
|
$stmt->bindParam(2, $input, PDO::PARAM_LOB);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
|
echo "bindDefaultEncoding: expected to fail!\n";
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
$error = '*Invalid encoding specified for parameter 1.';
|
$error = '*Invalid encoding specified for parameter 1.';
|
||||||
if (!fnmatch($error, $e->getMessage())) {
|
if (!fnmatch($error, $e->getMessage())) {
|
||||||
|
@ -52,8 +54,9 @@ function insertData($conn, $sql, $input)
|
||||||
|
|
||||||
$stmt = $conn->prepare($sql);
|
$stmt = $conn->prepare($sql);
|
||||||
$stmt->bindParam(1, $value);
|
$stmt->bindParam(1, $value);
|
||||||
$stmt->setAttribute(constant('PDO::SQLSRV_ATTR_ENCODING'), PDO::SQLSRV_ENCODING_BINARY);
|
// Specify binary encoding for the second parameter only such that the first
|
||||||
$stmt->bindParam(2, $input, PDO::PARAM_LOB);
|
// parameter is unaffected
|
||||||
|
$stmt->bindParam(2, $input, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
echo "Error unexpected in insertData\n";
|
echo "Error unexpected in insertData\n";
|
||||||
|
@ -68,6 +71,7 @@ function invalidEncoding1($conn, $sql)
|
||||||
$stmt->bindColumn(1, $id, PDO::PARAM_INT, 0, PDO::SQLSRV_ENCODING_UTF8);
|
$stmt->bindColumn(1, $id, PDO::PARAM_INT, 0, PDO::SQLSRV_ENCODING_UTF8);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$stmt->fetch(PDO::FETCH_BOUND);
|
$stmt->fetch(PDO::FETCH_BOUND);
|
||||||
|
echo "invalidEncoding1: expected to fail!\n";
|
||||||
} catch (PDOException $e) {
|
} 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.';
|
$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())) {
|
if (!fnmatch($error, $e->getMessage())) {
|
||||||
|
@ -84,6 +88,7 @@ function invalidEncoding2($conn, $sql)
|
||||||
$stmt->bindColumn('Value', $val1, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_DEFAULT);
|
$stmt->bindColumn('Value', $val1, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_DEFAULT);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$stmt->fetch(PDO::FETCH_BOUND);
|
$stmt->fetch(PDO::FETCH_BOUND);
|
||||||
|
echo "invalidEncoding2: expected to fail!\n";
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
$error = '*Invalid encoding specified for column 1.';
|
$error = '*Invalid encoding specified for column 1.';
|
||||||
if (!fnmatch($error, $e->getMessage())) {
|
if (!fnmatch($error, $e->getMessage())) {
|
||||||
|
@ -100,6 +105,7 @@ function invalidEncoding3($conn, $sql)
|
||||||
$stmt->bindColumn(1, $id, PDO::PARAM_STR, 0, "dummy");
|
$stmt->bindColumn(1, $id, PDO::PARAM_STR, 0, "dummy");
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$stmt->fetch(PDO::FETCH_BOUND);
|
$stmt->fetch(PDO::FETCH_BOUND);
|
||||||
|
echo "invalidEncoding3: expected to fail!\n";
|
||||||
} catch (PDOException $e) {
|
} 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.';
|
$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())) {
|
if (!fnmatch($error, $e->getMessage())) {
|
||||||
|
|
|
@ -11,15 +11,23 @@ $serverName = "WRONG_SERVER_NAME";
|
||||||
|
|
||||||
$t0 = microtime(true);
|
$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);
|
$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";
|
print "Done";
|
||||||
?>
|
?>
|
||||||
|
--EXPECT--
|
||||||
--EXPECTREGEX--
|
|
||||||
Connection attempt time: [7-9]\.[0-9]+ \[sec\]
|
|
||||||
Done
|
Done
|
||||||
|
|
Loading…
Reference in a new issue