Made some tests more robusts across platforms (#1092)

This commit is contained in:
Jenny Tam 2020-02-11 11:39:31 -08:00 коммит произвёл GitHub
Родитель 5455b4dcb8
Коммит 9534f7b96d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
13 изменённых файлов: 134 добавлений и 100 удалений

Просмотреть файл

@ -9,6 +9,9 @@ No PDO::PARAM_ tpe specified when binding parameters
require_once("MsCommon_mid-refactor.inc"); require_once("MsCommon_mid-refactor.inc");
require_once("AEData.inc"); require_once("AEData.inc");
$dataTypes = array("bit", "tinyint", "smallint", "int", "bigint", "decimal(18,5)", "numeric(10,5)", "float", "real"); $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 { try {
$conn = connect(); $conn = connect();
foreach ($dataTypes as $dataType) { foreach ($dataTypes as $dataType) {
@ -26,7 +29,7 @@ try {
if ($r === false) { if ($r === false) {
isIncompatibleTypesError($stmt, $dataType, "default type"); isIncompatibleTypesError($stmt, $dataType, "default type");
} else { } else {
echo "****Encrypted default type is compatible with encrypted $dataType****\n"; echo "-----Encrypted default type is compatible with encrypted $dataType-----\n";
fetchAll($conn, $tbname); fetchAll($conn, $tbname);
} }
dropTable($conn, $tbname); dropTable($conn, $tbname);
@ -37,49 +40,49 @@ try {
echo $e->getMessage(); echo $e->getMessage();
} }
?> ?>
--EXPECT-- --EXPECTREGEX--
Testing bit: Testing bit:
****Encrypted default type is compatible with encrypted bit**** -----Encrypted default type is compatible with encrypted bit-----
c_det: 1 c_det: 1
c_rand: 0 c_rand: 0
Testing tinyint: Testing tinyint:
****Encrypted default type is compatible with encrypted tinyint**** -----Encrypted default type is compatible with encrypted tinyint-----
c_det: 0 c_det: 0
c_rand: 255 c_rand: 255
Testing smallint: Testing smallint:
****Encrypted default type is compatible with encrypted smallint**** -----Encrypted default type is compatible with encrypted smallint-----
c_det: -32767 c_det: -32767
c_rand: 32767 c_rand: 32767
Testing int: Testing int:
****Encrypted default type is compatible with encrypted int**** -----Encrypted default type is compatible with encrypted int-----
c_det: -2147483647 c_det: -2147483647
c_rand: 2147483647 c_rand: 2147483647
Testing bigint: Testing bigint:
****Encrypted default type is compatible with encrypted bigint**** -----Encrypted default type is compatible with encrypted bigint-----
c_det: -922337203685479936 c_det: -922337203685479936
c_rand: 922337203685479936 c_rand: 922337203685479936
Testing decimal(18,5): Testing decimal\(18,5\):
****Encrypted default type is compatible with encrypted decimal(18,5)**** -----Encrypted default type is compatible with encrypted decimal\(18,5\)-----
c_det: -9223372036854.80000 c_det: -9223372036854\.80000
c_rand: 9223372036854.80000 c_rand: 9223372036854\.80000
Testing numeric(10,5): Testing numeric\(10,5\):
****Encrypted default type is compatible with encrypted numeric(10,5)**** -----Encrypted default type is compatible with encrypted numeric\(10,5\)-----
c_det: -21474.83647 c_det: -21474\.83647
c_rand: 21474.83647 c_rand: 21474\.83647
Testing float: Testing float:
****Encrypted default type is compatible with encrypted float**** -----Encrypted default type is compatible with encrypted float-----
c_det: -9223372036.8547993 c_det: (-9223372036\.8547993|-9223372036\.8547992)
c_rand: 9223372036.8547993 c_rand: (9223372036\.8547993|9223372036\.8547992)
Testing real: Testing real:
****Encrypted default type is compatible with encrypted real**** -----Encrypted default type is compatible with encrypted real-----
c_det: -2147.4829 c_det: (-2147\.4829|-2147\.483)
c_rand: 2147.4829 c_rand: (2147\.4829|2147\.483)

Просмотреть файл

@ -80,34 +80,34 @@ try {
} }
?> ?>
--EXPECT-- --EXPECTF--
Prepare without emulate prepare: Prepare without emulate prepare:
Array Array
( (
[c1_decimal] => 422 [c1_decimal] => 422
[c2_money] => 132.2220 [c2_money] => 132.2220
[c3_float] => 622.22000000000003 [c3_float] => 622.22%S
) )
Prepare with emulate prepare and no bind param options: Prepare with emulate prepare and no bind param options:
Array Array
( (
[c1_decimal] => 422 [c1_decimal] => 422
[c2_money] => 132.2220 [c2_money] => 132.2220
[c3_float] => 622.22000000000003 [c3_float] => 622.22%S
) )
Prepare with emulate prepare and SQLSRV_ENCODING_SYSTEM: Prepare with emulate prepare and SQLSRV_ENCODING_SYSTEM:
Array Array
( (
[c1_decimal] => 422 [c1_decimal] => 422
[c2_money] => 132.2220 [c2_money] => 132.2220
[c3_float] => 622.22000000000003 [c3_float] => 622.22%S
) )
Prepare with emulate prepare and SQLSRV_ENCODING_UTF8: Prepare with emulate prepare and SQLSRV_ENCODING_UTF8:
Array Array
( (
[c1_decimal] => 422 [c1_decimal] => 422
[c2_money] => 132.2220 [c2_money] => 132.2220
[c3_float] => 622.22000000000003 [c3_float] => 622.22%S
) )
Prepare with emulate prepare and SQLSRV_ENCODING_BINARY: Prepare with emulate prepare and SQLSRV_ENCODING_BINARY:
No results for this query No results for this query

Просмотреть файл

@ -79,34 +79,34 @@ try {
} }
?> ?>
--EXPECT-- --EXPECTF--
Prepare without emulate prepare: Prepare without emulate prepare:
Array Array
( (
[c1_decimal] => 411 [c1_decimal] => 411
[c2_money] => 131.1100 [c2_money] => 131.1100
[c3_float] => 611.11099999999999 [c3_float] => 611.1109999999999%d
) )
Prepare with emulate prepare and no bind param options: Prepare with emulate prepare and no bind param options:
Array Array
( (
[c1_decimal] => 411 [c1_decimal] => 411
[c2_money] => 131.1100 [c2_money] => 131.1100
[c3_float] => 611.11099999999999 [c3_float] => 611.1109999999999%d
) )
Prepare with emulate prepare and SQLSRV_ENCODING_SYSTEM: Prepare with emulate prepare and SQLSRV_ENCODING_SYSTEM:
Array Array
( (
[c1_decimal] => 411 [c1_decimal] => 411
[c2_money] => 131.1100 [c2_money] => 131.1100
[c3_float] => 611.11099999999999 [c3_float] => 611.1109999999999%d
) )
Prepare with emulate prepare and SQLSRV_ENCODING_UTF8: Prepare with emulate prepare and SQLSRV_ENCODING_UTF8:
Array Array
( (
[c1_decimal] => 411 [c1_decimal] => 411
[c2_money] => 131.1100 [c2_money] => 131.1100
[c3_float] => 611.11099999999999 [c3_float] => 611.1109999999999%d
) )
Prepare with emulate prepare and SQLSRV_ENCODING_BINARY: Prepare with emulate prepare and SQLSRV_ENCODING_BINARY:
No results for this query No results for this query

Просмотреть файл

@ -80,34 +80,34 @@ try {
} }
?> ?>
--EXPECT-- --EXPECTF--
Prepare without emulate prepare: Prepare without emulate prepare:
Array Array
( (
[c1_decimal] => 433 [c1_decimal] => 433
[c2_money] => 133.3333 [c2_money] => 133.3333
[c3_float] => 633.33333000000005 [c3_float] => 633.3333300000000%d
) )
Prepare with emulate prepare and no bind param options: Prepare with emulate prepare and no bind param options:
Array Array
( (
[c1_decimal] => 433 [c1_decimal] => 433
[c2_money] => 133.3333 [c2_money] => 133.3333
[c3_float] => 633.33333000000005 [c3_float] => 633.3333300000000%d
) )
Prepare with emulate prepare and SQLSRV_ENCODING_SYSTEM: Prepare with emulate prepare and SQLSRV_ENCODING_SYSTEM:
Array Array
( (
[c1_decimal] => 433 [c1_decimal] => 433
[c2_money] => 133.3333 [c2_money] => 133.3333
[c3_float] => 633.33333000000005 [c3_float] => 633.3333300000000%d
) )
Prepare with emulate prepare and SQLSRV_ENCODING_UTF8: Prepare with emulate prepare and SQLSRV_ENCODING_UTF8:
Array Array
( (
[c1_decimal] => 433 [c1_decimal] => 433
[c2_money] => 133.3333 [c2_money] => 133.3333
[c3_float] => 633.33333000000005 [c3_float] => 633.3333300000000%d
) )
Prepare with emulate prepare and SQLSRV_ENCODING_BINARY: Prepare with emulate prepare and SQLSRV_ENCODING_BINARY:
No results for this query No results for this query

Просмотреть файл

@ -47,6 +47,10 @@ try {
verifyResult($result); verifyResult($result);
// test not streamable types // 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]"; $tsql = "SELECT * FROM [test_types]";
$stmt = $conn->query($tsql); $stmt = $conn->query($tsql);
$result = $stmt->fetch(PDO::FETCH_NUM); $result = $stmt->fetch(PDO::FETCH_NUM);
@ -60,19 +64,19 @@ unset($stmt);
unset($conn); unset($conn);
?> ?>
--EXPECT-- --EXPECTREGEX--
Array Array
( \(
[0] => 9223372036854775807 \[0\] => 9223372036854775807
[1] => 2147483647 \[1\] => 2147483647
[2] => 32767 \[2\] => 32767
[3] => 255 \[3\] => 255
[4] => 1 \[4\] => 1
[5] => 9999999999999999999999999999999999999 \[5\] => 9999999999999999999999999999999999999
[6] => 922337203685477.5807 \[6\] => 922337203685477\.5807
[7] => 214748.3647 \[7\] => 214748\.3647
[8] => 1.79E+308 \[8\] => 1\.79E\+308
[9] => 1.1799999E-38 \[9\] => (1\.18E-38|1\.1799999E-38)
[10] => 1968-12-12 16:20:00.000 \[10\] => 1968-12-12 16:20:00.000
[11] => \[11\] =>
) \)

Просмотреть файл

@ -180,9 +180,9 @@ array(2) {
[5]=> [5]=>
string(10) "STRINGCOL2" string(10) "STRINGCOL2"
["FloatCol"]=> ["FloatCol"]=>
string(18) "222.22200000000001" string(%d) "222.222%S"
[6]=> [6]=>
string(18) "222.22200000000001" string(%d) "222.222%S"
["XmlCol"]=> ["XmlCol"]=>
string(431) "<xml> 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.</xml>" string(431) "<xml> 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.</xml>"
[7]=> [7]=>
@ -395,7 +395,7 @@ object(stdClass)#%x (%x) {
["NVarCharCol"]=> ["NVarCharCol"]=>
string(10) "STRINGCOL2" string(10) "STRINGCOL2"
["FloatCol"]=> ["FloatCol"]=>
string(18) "222.22200000000001" string(%d) "222.222%S"
["XmlCol"]=> ["XmlCol"]=>
string(431) "<xml> 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.</xml>" string(431) "<xml> 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.</xml>"
} }
@ -414,7 +414,7 @@ array(8) {
[5]=> [5]=>
string(10) "STRINGCOL2" string(10) "STRINGCOL2"
[6]=> [6]=>
string(18) "222.22200000000001" string(%d) "222.222%S"
[7]=> [7]=>
string(431) "<xml> 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.</xml>" string(431) "<xml> 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.</xml>"
} }
@ -425,7 +425,7 @@ string(10) "STRINGCOL2"
string(23) "2000-11-11 11:11:11.223" string(23) "2000-11-11 11:11:11.223"
string(10) "STRINGCOL2" string(10) "STRINGCOL2"
string(10) "STRINGCOL2" string(10) "STRINGCOL2"
string(18) "222.22200000000001" string(%d) "222.222%S"
string(431) "<xml> 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.</xml>" string(431) "<xml> 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.</xml>"
Test_9 : FETCH_INVALID : Test_9 : FETCH_INVALID :

Просмотреть файл

@ -31,7 +31,7 @@ try {
var_dump($e); var_dump($e);
} }
?> ?>
--EXPECT-- --EXPECTF--
array(1) { array(1) {
[0]=> [0]=>
array(62) { array(62) {
@ -224,9 +224,9 @@ array(2) {
[5]=> [5]=>
string(10) "STRINGCOL2" string(10) "STRINGCOL2"
["FloatCol"]=> ["FloatCol"]=>
string(18) "222.22200000000001" string(%d) "222.222%S"
[6]=> [6]=>
string(18) "222.22200000000001" string(%d) "222.222%S"
["XmlCol"]=> ["XmlCol"]=>
string(431) "<xml> 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.</xml>" string(431) "<xml> 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.</xml>"
[7]=> [7]=>

Просмотреть файл

@ -12,7 +12,12 @@ Test for integer, float, and datetime types vs various sql server types.
require( 'MsCommon.inc' ); require( 'MsCommon.inc' );
function get_fields( $stmt ) { $epsilon = 0.00001;
$decimals = ['9999999999999999999999999999999999999', '-10000000000000000000000000000000000001', '0'];
function get_fields( $stmt, $round ) {
global $epsilon, $decimals;
// bigint // bigint
$field = sqlsrv_get_field( $stmt, 0, SQLSRV_PHPTYPE_INT ); $field = sqlsrv_get_field( $stmt, 0, SQLSRV_PHPTYPE_INT );
@ -71,7 +76,22 @@ function get_fields( $stmt ) {
} }
else { else {
var_dump( sqlsrv_errors( SQLSRV_ERR_WARNINGS ) ); 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 // datetime
@ -147,7 +167,7 @@ function get_fields( $stmt ) {
} }
// maximum values // maximum values
get_fields( $stmt ); get_fields( $stmt, 0 );
$success = sqlsrv_fetch( $stmt ); $success = sqlsrv_fetch( $stmt );
if( !$success ) { if( !$success ) {
@ -156,7 +176,7 @@ function get_fields( $stmt ) {
} }
// minimum values // minimum values
get_fields( $stmt ); get_fields( $stmt, 1 );
$success = sqlsrv_fetch( $stmt ); $success = sqlsrv_fetch( $stmt );
if( !$success ) { if( !$success ) {
@ -165,7 +185,7 @@ function get_fields( $stmt ) {
} }
// zero values // 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]" ); $stmt = sqlsrv_query( $conn, "SELECT int_type, decimal_type, datetime_type, real_type FROM [test_types]" );
if( !$stmt ) { if( !$stmt ) {
@ -258,7 +278,6 @@ NULL
NULL NULL
1 1
NULL NULL
1.0E+37
NULL NULL
12/12/1968 04:20:00 12/12/1968 04:20:00
NULL NULL
@ -296,7 +315,6 @@ NULL
NULL NULL
0 0
NULL NULL
-1.0E+37
NULL NULL
12/12/1968 04:20:00 12/12/1968 04:20:00
NULL NULL
@ -319,7 +337,6 @@ NULL
NULL NULL
0 0
NULL NULL
0
NULL NULL
12/12/1968 04:20:00 12/12/1968 04:20:00
NULL NULL

Просмотреть файл

@ -84,6 +84,12 @@ function isDaasMode()
return ($daasMode ? true : false); return ($daasMode ? true : false);
} }
function isLocaleDisabled()
{
global $daasMode, $localeDisabled;
return ($daasMode || $localeDisabled);
}
function isSQLAzure() function isSQLAzure()
{ {
// 'SQL Azure' indicates SQL Database or SQL Data Warehouse // 'SQL Azure' indicates SQL Database or SQL Data Warehouse
@ -491,10 +497,11 @@ function handleErrors()
function setUSAnsiLocale() function setUSAnsiLocale()
{ {
// Do not run locale tests in Azure // Do not run locale tests if locale disabled
if (isDaasMode()) { if (isLocaleDisabled()) {
return; return;
} }
if (!isWindows()) { if (!isWindows()) {
// macOS the locale names are different in Linux or macOS // macOS the locale names are different in Linux or macOS
$locale = strtoupper(PHP_OS) === 'LINUX' ? "en_US.ISO-8859-1" : "en_US.ISO8859-1"; $locale = strtoupper(PHP_OS) === 'LINUX' ? "en_US.ISO-8859-1" : "en_US.ISO8859-1";
@ -505,8 +512,8 @@ function setUSAnsiLocale()
function resetLocaleToDefault() function resetLocaleToDefault()
{ {
// Do not run locale tests in Azure // Do not run locale tests if locale disabled
if (isDaasMode()) { if (isLocaleDisabled()) {
return; return;
} }
// Like setUSAnsiLocale() above, this method is only needed in non-Windows environment // Like setUSAnsiLocale() above, this method is only needed in non-Windows environment
@ -522,8 +529,8 @@ function isLocaleSupported()
if (isWindows()) { if (isWindows()) {
return true; return true;
} }
// Do not run locale tests in Azure // Do not run locale tests if locale disabled
if (isDaasMode()) { if (isLocaleDisabled()) {
return false; return false;
} }
if (AE\isDataEncrypted()) { if (AE\isDataEncrypted()) {

Просмотреть файл

@ -25,6 +25,7 @@ $daasMode = false;
$marsMode = true; $marsMode = true;
$traceEnabled = false; $traceEnabled = false;
$localeDisabled = false;
$adServer = 'TARGET_AD_SERVER'; $adServer = 'TARGET_AD_SERVER';
$adDatabase = 'TARGET_AD_DATABASE'; $adDatabase = 'TARGET_AD_DATABASE';

Просмотреть файл

@ -268,7 +268,7 @@ NULL
NULL NULL
1 1
NULL NULL
1\.0E\+37 (1\.0E\+37|9.9999999999997E\+36)
NULL NULL
12\/12\/1968 04\:20\:00 12\/12\/1968 04\:20\:00
NULL NULL
@ -306,7 +306,7 @@ NULL
NULL NULL
0 0
NULL NULL
\-1\.0E\+37 (\-1\.0E\+37|-9.9999999999997E\+36)
NULL NULL
12\/12\/1968 04\:20\:00 12\/12\/1968 04\:20\:00
NULL NULL

Просмотреть файл

@ -7,16 +7,19 @@ Intentionally provide an invalid server name and set LoginTimeout. Verify the ti
--FILE-- --FILE--
<?php <?php
require_once('MsSetup.inc');
$serverName = "WRONG_SERVER_NAME"; $serverName = "WRONG_SERVER_NAME";
// Based on the following reference, a login timeout of less than approximately 10 seconds // Based on the following reference, a login timeout of less than approximately 10 seconds
// is not reliable. The defaut is 15 seconds so we fix it at 20 seconds. // is not reliable. The defaut is 15 seconds so we fix it at 20 seconds.
// https://docs.microsoft.com/sql/connect/odbc/windows/features-of-the-microsoft-odbc-driver-for-sql-server-on-windows // https://docs.microsoft.com/sql/connect/odbc/windows/features-of-the-microsoft-odbc-driver-for-sql-server-on-windows
$timeout = 20; $timeout = 20;
$maxAttempts = 3; $maxAttempts = 3;
$numAttempts = 0; $numAttempts = 0;
$leeway = 1.0;
// The difference in time elapsed is platform dependent, and in some distros, such as Alpine or Suse, extra delay may be caused by the attempts to resolve non-existent hostnames
// Set leeway to 2 seconds to allow some room of such errors
$leeway = 2.0;
$missed = false; $missed = false;
do { do {
@ -38,7 +41,7 @@ do {
echo "Connection failed at $elapsed secs. Leeway is $leeway sec but the difference is $diff\n"; echo "Connection failed at $elapsed secs. Leeway is $leeway sec but the difference is $diff\n";
} else { } else {
// The test will fail but this helps us decide if this test should be redesigned // 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); sleep(5);
} }
} }

Просмотреть файл

@ -67,6 +67,10 @@ var_dump($array);
$array = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_NUMERIC); $array = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_NUMERIC);
var_dump($array); 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); $numFields = sqlsrv_num_fields($stmt);
$meta = sqlsrv_field_metadata($stmt); $meta = sqlsrv_field_metadata($stmt);
$rowcount = sqlsrv_num_rows($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); $field = sqlsrv_get_field($stmt, $j, SQLSRV_PHPTYPE_INT);
var_dump($field); var_dump($field);
} }
$field = sqlsrv_get_field($stmt, $j, SQLSRV_PHPTYPE_FLOAT); $field1 = sqlsrv_get_field($stmt, $j, SQLSRV_PHPTYPE_FLOAT);
var_dump($field); 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 column: a
string(15) "1234567890.1234" string(15) "1234567890.1234"
float(1234567890.1234)
column: neg_a column: neg_a
string(16) "-1234567890.1234" string(16) "-1234567890.1234"
float(-1234567890.1234)
column: b column: b
string(1) "1" string(1) "1"
int(1) int(1)
float(1)
column: neg_b column: neg_b
string(2) "-1" string(2) "-1"
int(-1) int(-1)
float(-1)
column: c column: c
string(7) ".500000" string(7) ".500000"
float(0.5)
column: neg_c column: neg_c
string(8) "-.550000" string(8) "-.550000"
float(-0.55)
column: zero column: zero
string(1) "0" string(1) "0"
int(0) int(0)
float(0)
column: zerof column: zerof
string(1) "0" string(1) "0"
float(0)
column: zerod column: zerod
string(7) ".000000" string(7) ".000000"
float(0)
column: a column: a
string(3) "0.5" string(3) "0.5"
float(0.5)
column: neg_a column: neg_a
string(5) "-0.55" string(5) "-0.55"
float(-0.55)
column: b column: b
string(6) "100000" string(6) "100000"
int(100000) int(100000)
float(100000)
column: neg_b column: neg_b
string(8) "-1234567" string(8) "-1234567"
int(-1234567) int(-1234567)
float(-1234567)
column: c column: c
string(17) "1234567890.123400" string(17) "1234567890.123400"
float(1234567890.1234)
column: neg_c column: neg_c
string(18) "-1234567890.123400" string(18) "-1234567890.123400"
float(-1234567890.1234)
column: zero column: zero
string(1) "0" string(1) "0"
int(0) int(0)
float(0)
column: zerof column: zerof
string(1) "0" string(1) "0"
float(0)
column: zerod column: zerod
string(7) ".000000" string(7) ".000000"
float(0)