From d7a1aca5c782bfad97c36e595705dd22e5dd4ba5 Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Tue, 19 Dec 2017 14:35:28 -0800 Subject: [PATCH 1/5] Testing locale issues --- test/functional/sqlsrv/MsCommon.inc | 21 ++++++++------------- test/functional/sqlsrv/MsHelper.inc | 2 +- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/test/functional/sqlsrv/MsCommon.inc b/test/functional/sqlsrv/MsCommon.inc index 964e5efe..7d5123c4 100644 --- a/test/functional/sqlsrv/MsCommon.inc +++ b/test/functional/sqlsrv/MsCommon.inc @@ -84,18 +84,6 @@ function isDaasMode() return ($daasMode ? true : false); } -// function isAEQualified($conn) -// { - // $msodbcsql_ver = sqlsrv_client_info($conn)['DriverVer']; - // $server_ver = sqlsrv_server_info($conn)['SQLServerVersion']; - // $msodbcsql_maj = explode(".", $msodbcsql_ver)[0]; - // $msodbcsql_min = explode(".", $msodbcsql_ver)[1]; - // if ($msodbcsql_maj < 17 || explode('.', $server_ver)[0] < 13) { - // return false; - // } - // return true; -// } - function startTest($testName) { if (traceMode()) { @@ -455,10 +443,17 @@ function handleErrors() } // non-UTF8 locale support in ODBC 17 and above only +// if AE enabled, only supported in Windows (AE limitations) function isLocaleSupported() { + if (isWindows()) { + return true; + } + if (AE\isDataEncrypted()) { + return false; + } + // now check ODBC version $conn = AE\connect(); - $msodbcsql_ver = sqlsrv_client_info($conn)['DriverVer']; if (explode(".", $msodbcsql_ver)[0] < 17) { return false; diff --git a/test/functional/sqlsrv/MsHelper.inc b/test/functional/sqlsrv/MsHelper.inc index 988253b1..6792bfe2 100644 --- a/test/functional/sqlsrv/MsHelper.inc +++ b/test/functional/sqlsrv/MsHelper.inc @@ -330,7 +330,7 @@ function getSeqPlaceholders($num) */ function isColEncrypted() { - global $keystore, $dataEncrypted; + global $keystore; if ($keystore === KEYSTORE_NONE) { return false; } else { From f3d04343aa7ac116cbf85e6f44660e2579797d2e Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Wed, 20 Dec 2017 08:28:34 -0800 Subject: [PATCH 2/5] Modified local supported method --- test/functional/sqlsrv/MsCommon.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functional/sqlsrv/MsCommon.inc b/test/functional/sqlsrv/MsCommon.inc index 7d5123c4..e01802e1 100644 --- a/test/functional/sqlsrv/MsCommon.inc +++ b/test/functional/sqlsrv/MsCommon.inc @@ -449,7 +449,7 @@ function isLocaleSupported() if (isWindows()) { return true; } - if (AE\isDataEncrypted()) { + if (AE\isColEncrypted()) { return false; } // now check ODBC version From 720346f45927493536925f1a3a0e99602f90e07d Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Wed, 20 Dec 2017 09:31:44 -0800 Subject: [PATCH 3/5] Modified three tests to test with or without UTF-8 data --- test/functional/sqlsrv/TC42_FetchField.phpt | 40 +++++++++++++++---- test/functional/sqlsrv/TC45_FetchObject.phpt | 34 ++++++++++++---- .../sqlsrv/TC48_FetchScrollable.phpt | 39 ++++++++++++++---- 3 files changed, 90 insertions(+), 23 deletions(-) diff --git a/test/functional/sqlsrv/TC42_FetchField.phpt b/test/functional/sqlsrv/TC42_FetchField.phpt index b1395b5a..baddc6b9 100644 --- a/test/functional/sqlsrv/TC42_FetchField.phpt +++ b/test/functional/sqlsrv/TC42_FetchField.phpt @@ -6,20 +6,22 @@ retrieving fields from a table including rows with all supported SQL types (28 t --ENV-- PHPT_EXEC=true --SKIPIF-- - + --FILE-- 'UTF-8')); } else { $conn1 = AE\connect(); @@ -63,16 +65,38 @@ function fetchFields() dropTable($conn1, $tableName); sqlsrv_close($conn1); - - endTest($testName); } +// locale must be set before 1st connection +if (!isWindows()) { + setlocale(LC_ALL, "en_US.ISO-8859-1"); +} + +$testName = "Fetch - Field"; + +// test ansi only if windows or non-UTF8 locales are supported (ODBC 17 and above) +startTest($testName); +if (isLocaleSupported()) { + try { + setUTF8Data(false); + fetchFields(); + } catch (Exception $e) { + echo $e->getMessage(); + } +} +endTest($testName); + +// test utf8 +startTest($testName); try { + setUTF8Data(true); fetchFields(); } catch (Exception $e) { echo $e->getMessage(); } +endTest($testName); ?> --EXPECT-- Test "Fetch - Field" completed successfully. +Test "Fetch - Field" completed successfully. diff --git a/test/functional/sqlsrv/TC45_FetchObject.phpt b/test/functional/sqlsrv/TC45_FetchObject.phpt index ec20c417..26767834 100644 --- a/test/functional/sqlsrv/TC45_FetchObject.phpt +++ b/test/functional/sqlsrv/TC45_FetchObject.phpt @@ -5,7 +5,13 @@ Verifies data retrieval via "sqlsrv_fetch_object". --ENV-- PHPT_EXEC=true --SKIPIF-- - + --FILE-- 'UTF-8' )); } else { $conn1 = AE\connect(); @@ -73,8 +75,6 @@ function fetchRow($minFetchMode, $maxFetchMode) dropTable($conn1, $tableName); sqlsrv_close($conn1); - - endTest($testName); } @@ -127,12 +127,30 @@ function checkData($rows, $fields, $actualValues, $expectedValues) } } +$testName = "Fetch - Object"; +// test ansi only if windows or non-UTF8 locales are supported (ODBC 17 and above) +startTest($testName); +if (isLocaleSupported()) { + try { + setUTF8Data(false); + fetchRow(0, 2); + } catch (Exception $e) { + echo $e->getMessage(); + } +} +endTest($testName); + +// test utf8 +startTest($testName); try { + setUTF8Data(true); fetchRow(0, 2); } catch (Exception $e) { echo $e->getMessage(); } +endTest($testName); ?> --EXPECT-- Test "Fetch - Object" completed successfully. +Test "Fetch - Object" completed successfully. diff --git a/test/functional/sqlsrv/TC48_FetchScrollable.phpt b/test/functional/sqlsrv/TC48_FetchScrollable.phpt index 44090245..09012e67 100644 --- a/test/functional/sqlsrv/TC48_FetchScrollable.phpt +++ b/test/functional/sqlsrv/TC48_FetchScrollable.phpt @@ -5,19 +5,22 @@ Verifies data retrieval with scrollable result sets. --ENV-- PHPT_EXEC=true --SKIPIF-- - + --FILE-- 'UTF-8')); } else { $conn1 = AE\connect(); @@ -72,8 +75,6 @@ function fetchRow($noRows) dropTable($conn1, $tableName); sqlsrv_close($conn1); - - endTest($testName); } function fetchArray($stmt, $rows, $fields) @@ -135,12 +136,36 @@ function checkData($rows, $fields, $actualValues, $expectedValues) } } +// locale must be set before 1st connection +if (!isWindows()) { + setlocale(LC_ALL, "en_US.ISO-8859-1"); +} + +$testName = "Fetch - Scrollable"; + +// test ansi only if windows or non-UTF8 locales are supported (ODBC 17 and above) +startTest($testName); +if (isLocaleSupported()) { + try { + setUTF8Data(false); + fetchRow(10); + } catch (Exception $e) { + echo $e->getMessage(); + } +} +endTest($testName); + +// test utf8 +startTest($testName); try { + setUTF8Data(true); fetchRow(10); } catch (Exception $e) { echo $e->getMessage(); } +endTest($testName); ?> --EXPECT-- Test "Fetch - Scrollable" completed successfully. +Test "Fetch - Scrollable" completed successfully. From 6b209526cd80453defa6c7363ae8929268600727 Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Wed, 20 Dec 2017 10:18:46 -0800 Subject: [PATCH 4/5] Added skipif and modified the check of isLocaleSupported() --- test/functional/sqlsrv/MsCommon.inc | 2 + test/functional/sqlsrv/TC34_PrepAndExec.phpt | 43 +++++++++++++++---- test/functional/sqlsrv/TC42_FetchField.phpt | 4 +- test/functional/sqlsrv/TC43_FetchData.phpt | 5 ++- test/functional/sqlsrv/TC44_FetchArray.phpt | 5 ++- test/functional/sqlsrv/TC45_FetchObject.phpt | 14 ++++-- .../sqlsrv/TC46_FetchNextResult.phpt | 5 ++- test/functional/sqlsrv/TC51_StreamRead.phpt | 5 ++- .../sqlsrv/TC55_StreamScrollable.phpt | 5 ++- .../sqlsrv/test_stream_large_data.phpt | 6 +-- 10 files changed, 66 insertions(+), 28 deletions(-) diff --git a/test/functional/sqlsrv/MsCommon.inc b/test/functional/sqlsrv/MsCommon.inc index e01802e1..14fe90ee 100644 --- a/test/functional/sqlsrv/MsCommon.inc +++ b/test/functional/sqlsrv/MsCommon.inc @@ -98,6 +98,8 @@ function startTest($testName) */ function endTest($testName) { + // reset the utf-8 flag + setUTF8Data(false); echo "Test \"$testName\" completed successfully.\n"; } diff --git a/test/functional/sqlsrv/TC34_PrepAndExec.phpt b/test/functional/sqlsrv/TC34_PrepAndExec.phpt index d8e5d210..d77fef2c 100644 --- a/test/functional/sqlsrv/TC34_PrepAndExec.phpt +++ b/test/functional/sqlsrv/TC34_PrepAndExec.phpt @@ -6,18 +6,25 @@ Validates that a prepared statement can be successfully executed more than once. --ENV-- PHPT_EXEC=true --SKIPIF-- - + --FILE-- 'UTF-8')); + } else { + $conn1 = AE\connect(); + } $tableName = 'TC34test'; AE\createTestTable($conn1, $tableName); @@ -80,20 +87,38 @@ function prepareAndExecute($noPasses) dropTable($conn1, $tableName); sqlsrv_close($conn1); - - endTest($testName); } +// locale must be set before 1st connection if (!isWindows()) { - setUTF8Data(true); + setlocale(LC_ALL, "en_US.ISO-8859-1"); } + +$testName = "Statement - Prepare and Execute"; + +// test ansi only if windows or non-UTF8 locales are supported (ODBC 17 and above) +startTest($testName); +if (isLocaleSupported()) { + try { + setUTF8Data(false); + prepareAndExecute(5); + } catch (Exception $e) { + echo $e->getMessage(); + } +} +endTest($testName); + +// test utf8 +startTest($testName); try { + setUTF8Data(true); prepareAndExecute(5); } catch (Exception $e) { echo $e->getMessage(); } -setUTF8Data(false); +endTest($testName); ?> --EXPECT-- Test "Statement - Prepare and Execute" completed successfully. +Test "Statement - Prepare and Execute" completed successfully. diff --git a/test/functional/sqlsrv/TC42_FetchField.phpt b/test/functional/sqlsrv/TC42_FetchField.phpt index baddc6b9..dc715b19 100644 --- a/test/functional/sqlsrv/TC42_FetchField.phpt +++ b/test/functional/sqlsrv/TC42_FetchField.phpt @@ -8,10 +8,10 @@ PHPT_EXEC=true --SKIPIF-- --FILE-- --FILE-- --FILE-- --FILE-- 'UTF-8' )); + $conn1 = AE\connect(array('CharacterSet'=>'UTF-8')); } else { $conn1 = AE\connect(); } @@ -89,7 +89,7 @@ function fetchObject($stmt, $rows, $fields, $useClass) $obj = sqlsrv_fetch_object($stmt); } if ($obj === false) { - fatalError("Row $i is missing"); + fatalError("In fetchObject: Row $i is missing"); } $values[$i] = $obj; } @@ -103,7 +103,7 @@ function fetchArray($stmt, $rows, $fields) for ($i = 0; $i < $rows; $i++) { $row = sqlsrv_fetch_array($stmt); if ($row === false) { - fatalError("Row $i is missing"); + fatalError("In fetchArray: Row $i is missing"); } $values[$i] = $row; } @@ -127,7 +127,13 @@ function checkData($rows, $fields, $actualValues, $expectedValues) } } +// locale must be set before 1st connection +if (!isWindows()) { + setlocale(LC_ALL, "en_US.ISO-8859-1"); +} + $testName = "Fetch - Object"; + // test ansi only if windows or non-UTF8 locales are supported (ODBC 17 and above) startTest($testName); if (isLocaleSupported()) { diff --git a/test/functional/sqlsrv/TC46_FetchNextResult.phpt b/test/functional/sqlsrv/TC46_FetchNextResult.phpt index 6848d2e6..bcd5e9e8 100644 --- a/test/functional/sqlsrv/TC46_FetchNextResult.phpt +++ b/test/functional/sqlsrv/TC46_FetchNextResult.phpt @@ -7,9 +7,10 @@ PHPT_EXEC=true --SKIPIF-- --FILE-- --FILE-- --FILE-- --FILE-- Date: Wed, 20 Dec 2017 21:06:07 -0800 Subject: [PATCH 5/5] Changed helper methods as per review --- test/functional/sqlsrv/MsCommon.inc | 2 -- test/functional/sqlsrv/MsHelper.inc | 12 ++---------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/test/functional/sqlsrv/MsCommon.inc b/test/functional/sqlsrv/MsCommon.inc index 14fe90ee..e01802e1 100644 --- a/test/functional/sqlsrv/MsCommon.inc +++ b/test/functional/sqlsrv/MsCommon.inc @@ -98,8 +98,6 @@ function startTest($testName) */ function endTest($testName) { - // reset the utf-8 flag - setUTF8Data(false); echo "Test \"$testName\" completed successfully.\n"; } diff --git a/test/functional/sqlsrv/MsHelper.inc b/test/functional/sqlsrv/MsHelper.inc index 6792bfe2..f7cecd4d 100644 --- a/test/functional/sqlsrv/MsHelper.inc +++ b/test/functional/sqlsrv/MsHelper.inc @@ -331,11 +331,7 @@ function getSeqPlaceholders($num) function isColEncrypted() { global $keystore; - if ($keystore === KEYSTORE_NONE) { - return false; - } else { - return true; - } + return ($keystore !== KEYSTORE_NONE); } /** @@ -345,11 +341,7 @@ function isColEncrypted() function isDataEncrypted() { global $keystore, $dataEncrypted; - if ($keystore === KEYSTORE_NONE || !$dataEncrypted) { - return false; - } else { - return true; - } + return ($keystore !== KEYSTORE_NONE && $dataEncrypted); } /**