From 294537ecb3af7504ae89cd27e04d43aebfa73c92 Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Tue, 19 Dec 2017 11:41:28 -0800 Subject: [PATCH] add helper function for checking error messages --- .../pdo_param_output_select_variant.phpt | 18 +++++++++++++----- .../pdo_prepare_emulatePrepare_unicode.phpt | 6 +++++- .../test_encoding_UTF8_emulate_prepare.phpt | 18 +++++++++++++----- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/test/functional/pdo_sqlsrv/pdo_param_output_select_variant.phpt b/test/functional/pdo_sqlsrv/pdo_param_output_select_variant.phpt index f96c7712..70ac158d 100644 --- a/test/functional/pdo_sqlsrv/pdo_param_output_select_variant.phpt +++ b/test/functional/pdo_sqlsrv/pdo_param_output_select_variant.phpt @@ -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"; diff --git a/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_unicode.phpt b/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_unicode.phpt index 8c104967..025f94c3 100644 --- a/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_unicode.phpt +++ b/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_unicode.phpt @@ -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; diff --git a/test/functional/pdo_sqlsrv/test_encoding_UTF8_emulate_prepare.phpt b/test/functional/pdo_sqlsrv/test_encoding_UTF8_emulate_prepare.phpt index 8a7e4ad7..7b8baa5c 100644 --- a/test/functional/pdo_sqlsrv/test_encoding_UTF8_emulate_prepare.phpt +++ b/test/functional/pdo_sqlsrv/test_encoding_UTF8_emulate_prepare.phpt @@ -6,6 +6,16 @@ Test UTF8 Encoding with emulate prepare 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--