diff --git a/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_numeric.phpt b/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_numeric.phpt index 25f4367f..38049a4a 100644 --- a/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_numeric.phpt +++ b/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_numeric.phpt @@ -2,11 +2,18 @@ Test for inserting encrypted data into numeric types columns --DESCRIPTION-- Test conversions between different numeric types -With or without Always Encrypted, implicit conversion works if: +With Always Encrypted, implicit conversion works if: 1. From input of PDO::PARAM_BOOL to a real column 2. From input of PDO::PARAM_INT to a any numeric column 3. From input of PDO::PARAM_STR to a any numeric column 4. From input of PDO::PARAM_LOB to a any numeric column +Without Always Encrypted, all of the above works except for input of PDO::PARAM_STR to a bigint column in a x86 platform +PDO::PARAM_STR does not work for bigint in a x86 because in a x86 platform, the maximum value of an int is about 2147483647 +Whereas in a x64 platform, the maximum value is about 9E18 +In a x86 platform, when in integer is initialized to be > 2147483647, PHP implicitly change it to a float, represented by scientific notation +When inserting a scientific notation form numeric string, SQL Server returns a converting data type nvarchar to bigint error +Works for with AE because the sqltype used for binding parameter is determined by SQLDescribeParam, +unlike without AE, the sqltype is predicted to be nvarchar when the input is a string and the encoding is utf8 --SKIPIF-- --FILE-- @@ -14,11 +21,11 @@ With or without Always Encrypted, implicit conversion works if: require_once("MsCommon_mid-refactor.inc"); require_once("AEData.inc"); -$dataTypes = array( "bit", "tinyint", "smallint", "int", "bigint", "real" ); +$dataTypes = array("bit", "tinyint", "smallint", "int", "bigint", "real"); $epsilon = 1; try { - $conn = connect(); + $conn = connect("", array(), PDO::ERRMODE_SILENT); foreach ($dataTypes as $dataType) { echo "\nTesting $dataType:\n"; @@ -68,6 +75,26 @@ try { } } } + // check the case when inserting as PDO::PARAM_STR into a bigint column + // with AE: should work + // without AE: should not work on a x86 platform + } else if ($dataType == "bigint" && $pdoParamType == "PDO::PARAM_STR") { + if (!isAEConnected() && PHP_INT_SIZE == 4) { + if ($r !== false) { + echo "Conversion from $pdoParamType to $dataType should not be supported\n"; + } + } else { + if ($r === false) { + echo "Conversion from $pdoParamType to $dataType should be supported\n"; + } else { + $sql = "SELECT c_det, c_rand FROM $tbname"; + $stmt = $conn->query($sql); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + if ($row['c_det'] != $inputValues[0] && $row['c_rand'] != $inputValues[1]) { + echo "Conversion from $pdoParamType to $dataType causes data corruption\n"; + } + } + } // check the case when inserting as PDO::PARAM_INT, PDO::PARAM_STR or PDO::PARAM_LOB // with or without AE: should work } else { @@ -88,7 +115,6 @@ try { echo "****Conversion from $pdoParamType to $dataType is supported****\n"; } else { echo "Conversion from $pdoParamType to $dataType causes data corruption\n"; - var_dump($row); } } } @@ -120,13 +146,13 @@ Testing smallint: ****Conversion from PDO::PARAM_LOB to smallint is supported**** Testing int: +Conversion from PDO::PARAM_BOOL to int should be supported ****Conversion from PDO::PARAM_INT to int is supported**** ****Conversion from PDO::PARAM_STR to int is supported**** ****Conversion from PDO::PARAM_LOB to int is supported**** Testing bigint: ****Conversion from PDO::PARAM_INT to bigint is supported**** -****Conversion from PDO::PARAM_STR to bigint is supported**** ****Conversion from PDO::PARAM_LOB to bigint is supported**** Testing real: