diff --git a/test/functional/pdo_sqlsrv/pdo_ae_insert_numeric.phpt b/test/functional/pdo_sqlsrv/pdo_ae_insert_numeric.phpt index 7d5627a2..60273f34 100644 --- a/test/functional/pdo_sqlsrv/pdo_ae_insert_numeric.phpt +++ b/test/functional/pdo_sqlsrv/pdo_ae_insert_numeric.phpt @@ -9,6 +9,9 @@ No PDO::PARAM_ tpe specified when binding parameters require_once("MsCommon_mid-refactor.inc"); require_once("AEData.inc"); $dataTypes = array("bit", "tinyint", "smallint", "int", "bigint", "decimal(18,5)", "numeric(10,5)", "float", "real"); + +// Note the size of a float is platform dependent, with a precision of roughly 14 digits +// http://php.net/manual/en/language.types.float.php try { $conn = connect(); foreach ($dataTypes as $dataType) { @@ -26,7 +29,7 @@ try { if ($r === false) { isIncompatibleTypesError($stmt, $dataType, "default type"); } else { - echo "****Encrypted default type is compatible with encrypted $dataType****\n"; + echo "-----Encrypted default type is compatible with encrypted $dataType-----\n"; fetchAll($conn, $tbname); } dropTable($conn, $tbname); @@ -37,49 +40,49 @@ try { echo $e->getMessage(); } ?> ---EXPECT-- +--EXPECTREGEX-- Testing bit: -****Encrypted default type is compatible with encrypted bit**** +-----Encrypted default type is compatible with encrypted bit----- c_det: 1 c_rand: 0 Testing tinyint: -****Encrypted default type is compatible with encrypted tinyint**** +-----Encrypted default type is compatible with encrypted tinyint----- c_det: 0 c_rand: 255 Testing smallint: -****Encrypted default type is compatible with encrypted smallint**** +-----Encrypted default type is compatible with encrypted smallint----- c_det: -32767 c_rand: 32767 Testing int: -****Encrypted default type is compatible with encrypted int**** +-----Encrypted default type is compatible with encrypted int----- c_det: -2147483647 c_rand: 2147483647 Testing bigint: -****Encrypted default type is compatible with encrypted bigint**** +-----Encrypted default type is compatible with encrypted bigint----- c_det: -922337203685479936 c_rand: 922337203685479936 -Testing decimal(18,5): -****Encrypted default type is compatible with encrypted decimal(18,5)**** -c_det: -9223372036854.80000 -c_rand: 9223372036854.80000 +Testing decimal\(18,5\): +-----Encrypted default type is compatible with encrypted decimal\(18,5\)----- +c_det: -9223372036854\.80000 +c_rand: 9223372036854\.80000 -Testing numeric(10,5): -****Encrypted default type is compatible with encrypted numeric(10,5)**** -c_det: -21474.83647 -c_rand: 21474.83647 +Testing numeric\(10,5\): +-----Encrypted default type is compatible with encrypted numeric\(10,5\)----- +c_det: -21474\.83647 +c_rand: 21474\.83647 Testing float: -****Encrypted default type is compatible with encrypted float**** -c_det: -9223372036.8547993 -c_rand: 9223372036.8547993 +-----Encrypted default type is compatible with encrypted float----- +c_det: (-9223372036\.8547993|-9223372036\.8547992) +c_rand: (9223372036\.8547993|9223372036\.8547992) Testing real: -****Encrypted default type is compatible with encrypted real**** -c_det: -2147.4829 -c_rand: 2147.4829 +-----Encrypted default type is compatible with encrypted real----- +c_det: (-2147\.4829|-2147\.483) +c_rand: (2147\.4829|2147\.483) diff --git a/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_decimal.phpt b/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_decimal.phpt index 93899043..d433b911 100644 --- a/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_decimal.phpt +++ b/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_decimal.phpt @@ -80,34 +80,34 @@ try { } ?> ---EXPECT-- +--EXPECTF-- Prepare without emulate prepare: Array ( [c1_decimal] => 422 [c2_money] => 132.2220 - [c3_float] => 622.22000000000003 + [c3_float] => 622.22%S ) Prepare with emulate prepare and no bind param options: Array ( [c1_decimal] => 422 [c2_money] => 132.2220 - [c3_float] => 622.22000000000003 + [c3_float] => 622.22%S ) Prepare with emulate prepare and SQLSRV_ENCODING_SYSTEM: Array ( [c1_decimal] => 422 [c2_money] => 132.2220 - [c3_float] => 622.22000000000003 + [c3_float] => 622.22%S ) Prepare with emulate prepare and SQLSRV_ENCODING_UTF8: Array ( [c1_decimal] => 422 [c2_money] => 132.2220 - [c3_float] => 622.22000000000003 + [c3_float] => 622.22%S ) Prepare with emulate prepare and SQLSRV_ENCODING_BINARY: No results for this query diff --git a/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_float.phpt b/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_float.phpt index eea43902..dee4ff59 100644 --- a/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_float.phpt +++ b/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_float.phpt @@ -79,34 +79,34 @@ try { } ?> ---EXPECT-- +--EXPECTF-- Prepare without emulate prepare: Array ( [c1_decimal] => 411 [c2_money] => 131.1100 - [c3_float] => 611.11099999999999 + [c3_float] => 611.1109999999999%d ) Prepare with emulate prepare and no bind param options: Array ( [c1_decimal] => 411 [c2_money] => 131.1100 - [c3_float] => 611.11099999999999 + [c3_float] => 611.1109999999999%d ) Prepare with emulate prepare and SQLSRV_ENCODING_SYSTEM: Array ( [c1_decimal] => 411 [c2_money] => 131.1100 - [c3_float] => 611.11099999999999 + [c3_float] => 611.1109999999999%d ) Prepare with emulate prepare and SQLSRV_ENCODING_UTF8: Array ( [c1_decimal] => 411 [c2_money] => 131.1100 - [c3_float] => 611.11099999999999 + [c3_float] => 611.1109999999999%d ) Prepare with emulate prepare and SQLSRV_ENCODING_BINARY: No results for this query diff --git a/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_money.phpt b/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_money.phpt index ee4b3699..ae581204 100644 --- a/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_money.phpt +++ b/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_money.phpt @@ -80,34 +80,34 @@ try { } ?> ---EXPECT-- +--EXPECTF-- Prepare without emulate prepare: Array ( [c1_decimal] => 433 [c2_money] => 133.3333 - [c3_float] => 633.33333000000005 + [c3_float] => 633.3333300000000%d ) Prepare with emulate prepare and no bind param options: Array ( [c1_decimal] => 433 [c2_money] => 133.3333 - [c3_float] => 633.33333000000005 + [c3_float] => 633.3333300000000%d ) Prepare with emulate prepare and SQLSRV_ENCODING_SYSTEM: Array ( [c1_decimal] => 433 [c2_money] => 133.3333 - [c3_float] => 633.33333000000005 + [c3_float] => 633.3333300000000%d ) Prepare with emulate prepare and SQLSRV_ENCODING_UTF8: Array ( [c1_decimal] => 433 [c2_money] => 133.3333 - [c3_float] => 633.33333000000005 + [c3_float] => 633.3333300000000%d ) Prepare with emulate prepare and SQLSRV_ENCODING_BINARY: No results for this query diff --git a/test/functional/pdo_sqlsrv/pdo_test_non_LOB_types.phpt b/test/functional/pdo_sqlsrv/pdo_test_non_LOB_types.phpt index cd709eb1..37866235 100644 --- a/test/functional/pdo_sqlsrv/pdo_test_non_LOB_types.phpt +++ b/test/functional/pdo_sqlsrv/pdo_test_non_LOB_types.phpt @@ -47,6 +47,10 @@ try { verifyResult($result); // test not streamable types + // The size of a float is platform dependent, with a precision of roughly 14 digits + // http://php.net/manual/en/language.types.float.php + // For example, the input value for column [real_type] in setup\test_types.sql is 1.18E-38 + // but in some distros the fetched value is 1.1799999E-38 $tsql = "SELECT * FROM [test_types]"; $stmt = $conn->query($tsql); $result = $stmt->fetch(PDO::FETCH_NUM); @@ -60,19 +64,19 @@ unset($stmt); unset($conn); ?> ---EXPECT-- +--EXPECTREGEX-- Array -( - [0] => 9223372036854775807 - [1] => 2147483647 - [2] => 32767 - [3] => 255 - [4] => 1 - [5] => 9999999999999999999999999999999999999 - [6] => 922337203685477.5807 - [7] => 214748.3647 - [8] => 1.79E+308 - [9] => 1.1799999E-38 - [10] => 1968-12-12 16:20:00.000 - [11] => -) \ No newline at end of file +\( + \[0\] => 9223372036854775807 + \[1\] => 2147483647 + \[2\] => 32767 + \[3\] => 255 + \[4\] => 1 + \[5\] => 9999999999999999999999999999999999999 + \[6\] => 922337203685477\.5807 + \[7\] => 214748\.3647 + \[8\] => 1\.79E\+308 + \[9\] => (1\.18E-38|1\.1799999E-38) + \[10\] => 1968-12-12 16:20:00.000 + \[11\] => +\) \ No newline at end of file diff --git a/test/functional/pdo_sqlsrv/pdostatement_fetchAll.phpt b/test/functional/pdo_sqlsrv/pdostatement_fetchAll.phpt index 5f1a4f43..6a30232c 100644 --- a/test/functional/pdo_sqlsrv/pdostatement_fetchAll.phpt +++ b/test/functional/pdo_sqlsrv/pdostatement_fetchAll.phpt @@ -180,9 +180,9 @@ array(2) { [5]=> string(10) "STRINGCOL2" ["FloatCol"]=> - string(18) "222.22200000000001" + string(%d) "222.222%S" [6]=> - string(18) "222.22200000000001" + string(%d) "222.222%S" ["XmlCol"]=> string(431) " 2 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417." [7]=> @@ -395,7 +395,7 @@ object(stdClass)#%x (%x) { ["NVarCharCol"]=> string(10) "STRINGCOL2" ["FloatCol"]=> - string(18) "222.22200000000001" + string(%d) "222.222%S" ["XmlCol"]=> string(431) " 2 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417." } @@ -414,7 +414,7 @@ array(8) { [5]=> string(10) "STRINGCOL2" [6]=> - string(18) "222.22200000000001" + string(%d) "222.222%S" [7]=> string(431) " 2 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417." } @@ -425,7 +425,7 @@ string(10) "STRINGCOL2" string(23) "2000-11-11 11:11:11.223" string(10) "STRINGCOL2" string(10) "STRINGCOL2" -string(18) "222.22200000000001" +string(%d) "222.222%S" string(431) " 2 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417." Test_9 : FETCH_INVALID : diff --git a/test/functional/pdo_sqlsrv/pdostatement_nextRowset.phpt b/test/functional/pdo_sqlsrv/pdostatement_nextRowset.phpt index f235ed94..fa63c225 100644 --- a/test/functional/pdo_sqlsrv/pdostatement_nextRowset.phpt +++ b/test/functional/pdo_sqlsrv/pdostatement_nextRowset.phpt @@ -31,7 +31,7 @@ try { var_dump($e); } ?> ---EXPECT-- +--EXPECTF-- array(1) { [0]=> array(62) { @@ -224,9 +224,9 @@ array(2) { [5]=> string(10) "STRINGCOL2" ["FloatCol"]=> - string(18) "222.22200000000001" + string(%d) "222.222%S" [6]=> - string(18) "222.22200000000001" + string(%d) "222.222%S" ["XmlCol"]=> string(431) " 2 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417." [7]=> diff --git a/test/functional/sqlsrv/53_0021.phpt b/test/functional/sqlsrv/53_0021.phpt index 8d010299..c9bbf201 100644 --- a/test/functional/sqlsrv/53_0021.phpt +++ b/test/functional/sqlsrv/53_0021.phpt @@ -12,7 +12,12 @@ Test for integer, float, and datetime types vs various sql server types. require( 'MsCommon.inc' ); -function get_fields( $stmt ) { +$epsilon = 0.00001; +$decimals = ['9999999999999999999999999999999999999', '-10000000000000000000000000000000000001', '0']; + +function get_fields( $stmt, $round ) { + + global $epsilon, $decimals; // bigint $field = sqlsrv_get_field( $stmt, 0, SQLSRV_PHPTYPE_INT ); @@ -71,7 +76,22 @@ function get_fields( $stmt ) { } else { var_dump( sqlsrv_errors( SQLSRV_ERR_WARNINGS ) ); - echo "$field\n"; + // The size of a float is platform dependent, with a precision of roughly 14 digits + // http://php.net/manual/en/language.types.float.php + // For example, in Ubuntu 18.04 or macOS Mojave the returned value is 1.0E+37 or -1.0E+37 + // but in Alpine Linux it is 9.9999999999997E+36 or -9.9999999999997E+36 + if ($decimals[$round] == '0') { + if ($field != 0) { + echo "Expected 0 but got $field\n"; + } + } else { + $expected = floatval($decimals[$round]); + $diff = abs(($field - $expected) / $expected); + + if ($diff > $epsilon) { + echo "Expected $expected but got $field -- difference is $diff\n"; + } + } } // datetime @@ -147,7 +167,7 @@ function get_fields( $stmt ) { } // maximum values - get_fields( $stmt ); + get_fields( $stmt, 0 ); $success = sqlsrv_fetch( $stmt ); if( !$success ) { @@ -156,7 +176,7 @@ function get_fields( $stmt ) { } // minimum values - get_fields( $stmt ); + get_fields( $stmt, 1 ); $success = sqlsrv_fetch( $stmt ); if( !$success ) { @@ -165,7 +185,7 @@ function get_fields( $stmt ) { } // zero values - get_fields( $stmt ); + get_fields( $stmt, 2 ); $stmt = sqlsrv_query( $conn, "SELECT int_type, decimal_type, datetime_type, real_type FROM [test_types]" ); if( !$stmt ) { @@ -258,7 +278,6 @@ NULL NULL 1 NULL -1.0E+37 NULL 12/12/1968 04:20:00 NULL @@ -296,7 +315,6 @@ NULL NULL 0 NULL --1.0E+37 NULL 12/12/1968 04:20:00 NULL @@ -319,7 +337,6 @@ NULL NULL 0 NULL -0 NULL 12/12/1968 04:20:00 NULL diff --git a/test/functional/sqlsrv/MsCommon.inc b/test/functional/sqlsrv/MsCommon.inc index dec27c55..195430d5 100644 --- a/test/functional/sqlsrv/MsCommon.inc +++ b/test/functional/sqlsrv/MsCommon.inc @@ -84,6 +84,12 @@ function isDaasMode() return ($daasMode ? true : false); } +function isLocaleDisabled() +{ + global $daasMode, $localeDisabled; + return ($daasMode || $localeDisabled); +} + function isSQLAzure() { // 'SQL Azure' indicates SQL Database or SQL Data Warehouse @@ -491,10 +497,11 @@ function handleErrors() function setUSAnsiLocale() { - // Do not run locale tests in Azure - if (isDaasMode()) { + // Do not run locale tests if locale disabled + if (isLocaleDisabled()) { return; } + if (!isWindows()) { // macOS the locale names are different in Linux or macOS $locale = strtoupper(PHP_OS) === 'LINUX' ? "en_US.ISO-8859-1" : "en_US.ISO8859-1"; @@ -505,8 +512,8 @@ function setUSAnsiLocale() function resetLocaleToDefault() { - // Do not run locale tests in Azure - if (isDaasMode()) { + // Do not run locale tests if locale disabled + if (isLocaleDisabled()) { return; } // Like setUSAnsiLocale() above, this method is only needed in non-Windows environment @@ -522,8 +529,8 @@ function isLocaleSupported() if (isWindows()) { return true; } - // Do not run locale tests in Azure - if (isDaasMode()) { + // Do not run locale tests if locale disabled + if (isLocaleDisabled()) { return false; } if (AE\isDataEncrypted()) { diff --git a/test/functional/sqlsrv/MsSetup.inc b/test/functional/sqlsrv/MsSetup.inc index 8335c13b..f328e17c 100644 --- a/test/functional/sqlsrv/MsSetup.inc +++ b/test/functional/sqlsrv/MsSetup.inc @@ -25,6 +25,7 @@ $daasMode = false; $marsMode = true; $traceEnabled = false; +$localeDisabled = false; $adServer = 'TARGET_AD_SERVER'; $adDatabase = 'TARGET_AD_DATABASE'; diff --git a/test/functional/sqlsrv/sqlsrv_get_field.phpt b/test/functional/sqlsrv/sqlsrv_get_field.phpt index 9247d0ba..9d63a1f5 100644 --- a/test/functional/sqlsrv/sqlsrv_get_field.phpt +++ b/test/functional/sqlsrv/sqlsrv_get_field.phpt @@ -268,7 +268,7 @@ NULL NULL 1 NULL -1\.0E\+37 +(1\.0E\+37|9.9999999999997E\+36) NULL 12\/12\/1968 04\:20\:00 NULL @@ -306,7 +306,7 @@ NULL NULL 0 NULL -\-1\.0E\+37 +(\-1\.0E\+37|-9.9999999999997E\+36) NULL 12\/12\/1968 04\:20\:00 NULL diff --git a/test/functional/sqlsrv/srv_007_login_timeout.phpt b/test/functional/sqlsrv/srv_007_login_timeout.phpt index eda8cf3a..8145c370 100644 --- a/test/functional/sqlsrv/srv_007_login_timeout.phpt +++ b/test/functional/sqlsrv/srv_007_login_timeout.phpt @@ -7,21 +7,24 @@ Intentionally provide an invalid server name and set LoginTimeout. Verify the ti --FILE-- $timeout)); $numAttempts++; @@ -38,7 +41,7 @@ do { echo "Connection failed at $elapsed secs. Leeway is $leeway sec but the difference is $diff\n"; } else { // The test will fail but this helps us decide if this test should be redesigned - echo "$numAttempts\t"; + echo "Attempts: $numAttempts, Time difference: $diff\n"; sleep(5); } } diff --git a/test/functional/sqlsrv/srv_230_sqlsrv_buffered_numeric_types.phpt b/test/functional/sqlsrv/srv_230_sqlsrv_buffered_numeric_types.phpt index 99a915da..1725d3b3 100644 --- a/test/functional/sqlsrv/srv_230_sqlsrv_buffered_numeric_types.phpt +++ b/test/functional/sqlsrv/srv_230_sqlsrv_buffered_numeric_types.phpt @@ -67,6 +67,10 @@ var_dump($array); $array = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_NUMERIC); var_dump($array); +// The size of a float is platform dependent, with a precision of roughly 14 digits +// http://php.net/manual/en/language.types.float.php +$epsilon = 0.00001; + $numFields = sqlsrv_num_fields($stmt); $meta = sqlsrv_field_metadata($stmt); $rowcount = sqlsrv_num_rows($stmt); @@ -81,8 +85,21 @@ for ($i = 0; $i < $rowcount; $i++) { $field = sqlsrv_get_field($stmt, $j, SQLSRV_PHPTYPE_INT); var_dump($field); } - $field = sqlsrv_get_field($stmt, $j, SQLSRV_PHPTYPE_FLOAT); - var_dump($field); + $field1 = sqlsrv_get_field($stmt, $j, SQLSRV_PHPTYPE_FLOAT); + if ($j > 5) { + // these are the zero fields + $expected = 0.0; + if ($field1 !== $expected) { + echo "Expected $expected but got $field1\n"; + } + } else { + $expected = floatval($field); + $diff = abs(($field1 - $expected) / $expected); + + if ($diff > $epsilon) { + echo "Expected $expected but got $field1 -- difference is $diff\n"; + } + } } } @@ -136,78 +153,60 @@ array(9) { column: a string(15) "1234567890.1234" -float(1234567890.1234) column: neg_a string(16) "-1234567890.1234" -float(-1234567890.1234) column: b string(1) "1" int(1) -float(1) column: neg_b string(2) "-1" int(-1) -float(-1) column: c string(7) ".500000" -float(0.5) column: neg_c string(8) "-.550000" -float(-0.55) column: zero string(1) "0" int(0) -float(0) column: zerof string(1) "0" -float(0) column: zerod string(7) ".000000" -float(0) column: a string(3) "0.5" -float(0.5) column: neg_a string(5) "-0.55" -float(-0.55) column: b string(6) "100000" int(100000) -float(100000) column: neg_b string(8) "-1234567" int(-1234567) -float(-1234567) column: c string(17) "1234567890.123400" -float(1234567890.1234) column: neg_c string(18) "-1234567890.123400" -float(-1234567890.1234) column: zero string(1) "0" int(0) -float(0) column: zerof string(1) "0" -float(0) column: zerod -string(7) ".000000" -float(0) +string(7) ".000000" \ No newline at end of file