add helper function for checking error messages

This commit is contained in:
v-kaywon 2017-12-19 11:41:28 -08:00
parent 57d7400f2c
commit 294537ecb3
3 changed files with 31 additions and 11 deletions

View file

@ -57,6 +57,16 @@ function createVariantTable($conn, $tableName)
}
}
function checkError($e, $expMsg, $aeExpMsg)
{
$error = $e->getMessage();
if (!isAEConnected()) {
if (strpos($error, $expMsg) === false) echo $error;
} else {
if (strpos($error, $aeExpMsg) === false) echo $error;
}
}
try {
// Connect
$conn = connect();
@ -71,11 +81,9 @@ try {
dropTable($conn, $tableName);
unset($conn);
} catch (Exception $e) {
$error = $e->getMessage();
if (!(!isAEConnected() && strpos($error, "Implicit conversion from data type sql_variant to nvarchar(max) is not allowed. Use the CONVERT function to run this query.") !== false) &&
!(isAEConnected() && strpos($error, "Invalid Descriptor Index") !== false)) {
echo $error;
}
$expMsg = "Implicit conversion from data type sql_variant to nvarchar(max) is not allowed. Use the CONVERT function to run this query.";
$aeExpMsg = "Invalid Descriptor Index";
checkError($e, $expMsg, $aeExpMsg);
}
echo "Done\n";

View file

@ -70,7 +70,10 @@ try {
print_r("Prepare with emulate prepare and and SQLSRV_ENCODING_SYSTEM:\n");
$stmt = prepareStmt($conn, $query, $options, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_SYSTEM);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
// Linux supports binding UTF8 data with SQLSRV_ENCODING_SYSTEM since the default encoding in Linux is UTF8
// The combination of Column Encryption and Unix platforms support SQLSRV_ENCODING_SYSTEM because:
// With Column Encryption enabled, binding parameters uses exact datatypes as the column definition
// the default encoding in Linux and Mac is UTF8
$success = true;
if (!(strtoupper( substr( php_uname( 's' ),0,3 ) ) === 'WIN') && isAEConnected()) {
if ($row['name'] != "가각" || $row['status'] != 1 || $row['age'] != 30) {
@ -78,6 +81,7 @@ try {
$success = false;
}
} else {
// the default encoding in Windows is non-UTF8, thus binding UTF8 parameters does not work
if ($stmt->rowCount() != 0) {
print_r("Binding UTF8 data when encoding is SQLSRV_ENCODING_SYSTEM should not work.\n");
$success = false;

View file

@ -6,6 +6,16 @@ Test UTF8 Encoding with emulate prepare
<?php
require_once("MsCommon_mid-refactor.inc");
function checkError($e, $expMsg, $aeExpMsg)
{
$error = $e->getMessage();
if (!isAEConnected()) {
if (strpos($error, $expMsg) === false) echo $error;
} else {
if (strpos($error, $aeExpMsg) === false) echo $error;
}
}
try {
$inValue1 = pack('H*', '3C586D6C54657374446174613E4A65207072C3A966C3A87265206C27C3A974C3A93C2F586D6C54657374446174613E');
$inValueLen = strlen($inValue1);
@ -72,11 +82,9 @@ try {
dropTable($conn, $tbname);
unset($conn);
} catch (PDOexception $e) {
$error = $e->getMessage();
if (!(!isAEConnected() && strpos($error, "Statement with emulate prepare on does not support output or input_output parameters.") !== false) &&
!(isAEConnected() && strpos($error, "Invalid Descriptor Index") !== false)) {
echo $error;
}
$expMsg = "Statement with emulate prepare on does not support output or input_output parameters.";
$aeExpMsg = "Invalid Descriptor Index";
checkError($e, $expMsg, $aeExpMsg);
}
?>
--EXPECT--