Skip to content

Commit

Permalink
Fixed binary test
Browse files Browse the repository at this point in the history
  • Loading branch information
david-puglielli committed Apr 11, 2018
1 parent 8c681f2 commit 99a11c1
Showing 1 changed file with 30 additions and 26 deletions.
56 changes: 30 additions & 26 deletions test/functional/pdo_sqlsrv/pdo_ae_output_param_binary_size.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,26 @@ function testOutputBinary($inout)
$stmt = $conn->prepare($outSql);
trace("\nParam $pdoParamType with INOUT = $inout\n");

if ($inout && $pdoParamType != PDO::PARAM_STR) {
// if ($inout && $pdoParamType != PDO::PARAM_STR) {
if ($inout && $pdoParamType == PDO::PARAM_STR) {
// Currently do not support getting binary as strings + INOUT param
// See VSO 2829 for details
continue;
}

if (!isAEConnected() && $pdoParamType == PDO::PARAM_INT) {
// Without AE, there is no possible way to specify
// binary encoding for this output param type,
// so a value like 'd' will be incorrectly
// interpreted as integer value 100 (its ASCII value).
// Skipping this because this use case is meaningless
// anyway.
// With AE, this output param type would have caused
// an exception
continue;
}

if ($inout) {
$paramType = $pdoParamType | PDO::PARAM_INPUT_OUTPUT;
} else {
$paramType = $pdoParamType;
Expand All @@ -101,14 +118,11 @@ function testOutputBinary($inout)
if ($pdoParamType == PDO::PARAM_STR || $pdoParamType == PDO::PARAM_LOB) {
$stmt->bindParam(1, $det, $paramType, $length, PDO::SQLSRV_ENCODING_BINARY);
$stmt->bindParam(2, $rand, $paramType, $length, PDO::SQLSRV_ENCODING_BINARY);
} elseif ($pdoParamType == PDO::PARAM_BOOL || $pdoParamType == PDO::PARAM_INT) {
} else {
$det = $rand = 0;
$stmt->bindParam(1, $det, $paramType, PDO::SQLSRV_PARAM_OUT_DEFAULT_SIZE);
$stmt->bindParam(2, $rand, $paramType, PDO::SQLSRV_PARAM_OUT_DEFAULT_SIZE);
} else {
$stmt->bindParam(1, $det, $paramType, $length);
$stmt->bindParam(2, $rand, $paramType, $length);
}
}

try {
$stmt->execute();
Expand All @@ -127,12 +141,8 @@ function testOutputBinary($inout)
printValues($errMsg, $det, $rand, $input0, $input1);
}
} else {
// $pdoParamType is PDO::PARAM_INT
// This only occurs without AE -- likely a rare use case
// With AE enabled, this would have caused an exception
if (strval($det) != $ord0 || strval($rand) != $ord1) {
printValues($errMsg, $det, $rand, $ord0, $ord1);
}
echo "Something went wrong. This should not have happened\n";
printValues($errMsg, $det, $rand, $ord0, $ord1);
}
} catch (PDOException $e) {
$message = $e->getMessage();
Expand All @@ -147,20 +157,13 @@ function testOutputBinary($inout)
}
} elseif ($pdoParamType == PDO::PARAM_BOOL || PDO::PARAM_INT) {
if (isAEConnected()) {
if ($pdoParamType == PDO::PARAM_INT) {
// Expected to fail with this message
$error = "String data, right truncated for output parameter";
$found = strpos($message, $error);
} else {
// PDO::PARAM_BOOL -
// Expected error 07006 with AE enabled:
// "Restricted data type attribute violation"
// The data value returned for a parameter bound as
// SQL_PARAM_INPUT_OUTPUT or SQL_PARAM_OUTPUT could not
// be converted to the data type identified by the
// ValueType argument in SQLBindParameter.
$found = strpos($message, $errors['07006']);
}
// Expected error 07006 with AE enabled:
// "Restricted data type attribute violation"
// The data value returned for a parameter bound as
// SQL_PARAM_INPUT_OUTPUT or SQL_PARAM_OUTPUT could not
// be converted to the data type identified by the
// ValueType argument in SQLBindParameter.
$found = strpos($message, $errors['07006']);
} else {
// When not AE enabled, expected to fail with something like this message
// "Implicit conversion from data type nvarchar(max) to binary is not allowed. Use the CONVERT function to run this query."
Expand All @@ -169,6 +172,7 @@ function testOutputBinary($inout)
$found = strpos($message, $error);
}
if ($found === false) {
print "Exception: $message\n";
printValues($errMsg, $det, $rand, $input0, $input1);
}
} else {
Expand Down

0 comments on commit 99a11c1

Please sign in to comment.