From 035b1573ca9fd6be8f3152e513d7e855f6a27b83 Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Fri, 9 Mar 2018 15:52:47 -0800 Subject: [PATCH 1/5] tests combination between output sqltypes and column types withdifferent sizes, scales, and precision --- ...v_ae_output_param_sqltype_binary_size.phpt | 279 ++++++++++++++++ ...srv_ae_output_param_sqltype_char_size.phpt | 316 ++++++++++++++++++ ...rv_ae_output_param_sqltype_float_bits.phpt | 122 +++++++ ...lsrv_ae_output_param_sqltype_int_conv.phpt | 112 +++++++ ...rv_ae_output_param_sqltype_nchar_size.phpt | 274 +++++++++++++++ 5 files changed, 1103 insertions(+) create mode 100644 test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_binary_size.phpt create mode 100644 test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_char_size.phpt create mode 100644 test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_float_bits.phpt create mode 100644 test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_int_conv.phpt create mode 100644 test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_nchar_size.phpt diff --git a/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_binary_size.phpt b/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_binary_size.phpt new file mode 100644 index 00000000..5416364f --- /dev/null +++ b/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_binary_size.phpt @@ -0,0 +1,279 @@ +--TEST-- +Test for retrieving encrypted data of binary types with different sizes as output parameters +--DESCRIPTION-- +Test implicit conversions between different binary types of different sizes +With Always Encrypted, implicit conversion works if: +1. From a binary(m) column to a SQLSRV_SQLTYPE_BINARY(n) output parameter where m == n +2. From a binary(m) column to a SQLSRV_SQLTYPE_VARBINARY(n) output parameter where m == n +3. From a varbinary(m) column to a SQLSRV_SQLTYPE_BINARY(n) output parameter where m == n +4. From a varbinary(m) column to a SQLSRV_SQLTYPE_VARBINARY(n) output parameter where m == n +Without AlwaysEncrypted, implicit conversion works if: +1. From a binary(m) column to a SQLSRV_SQLTYPE_BINARY(n) output parameter where m, n == any value +2. From a binary(m) column to a SQLSRV_SQLTYPE_VARBINARY(n) output parameter where m <= n (exclude SQLSRV_SQLTYPE_VARBINARY('max')) +3. From a varbinary(m) column to a SQLSRV_SQLTYPE_BINARY(n) output parameter where m, n == any value +4. From a varbinary(m) column to a SQLSRV_SQLTYPE_VARBINARY(n) output parameter where m, n == any value +--SKIPIF-- + +--FILE-- + $inputs[0], "c_rand" => $inputs[1]), $r, AE\INSERT_PREPARE_PARAMS); + + // create a stored procedure and sql string for calling the stored procedure + $spname = 'selectAllColumns'; + createProc($conn, $spname, "@c_det $typeFull OUTPUT, @c_rand $typeFull OUTPUT", "SELECT @c_det = c_det, @c_rand = c_rand FROM $tbname"); + $sql = AE\getCallProcSqlPlaceholders($spname, 2); + + // retrieve by specifying SQLSRV_SQLTYPE_BINARY(n) or SQLSRV_SQLTYPE_VARBINARY(n) as SQLSRV_PARAM_OUT or SQLSRV_PARAM_INOUT + foreach($directions as $dir) { + echo "Testing as $dir:\n"; + foreach($sqlTypes as $sqlType) { + $maxsqltype = strpos($sqlType, "max"); + foreach($sqltypeLengths as $n) { + $sqltypeconst; + $sqltypeFull; + if ($maxsqltype !== false) { + $sqltypeconst = SQLSRV_SQLTYPE_VARBINARY('max'); + $sqltypeFull = $sqlType; + } else { + $sqltypeconst = call_user_func($sqlType, $n); + $sqltypeFull = "$sqlType($n)"; + } + + $c_detOut = ''; + $c_randOut = ''; + $stmt = sqlsrv_prepare($conn, $sql, array(array(&$c_detOut, constant($dir), SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY), $sqltypeconst), array(&$c_randOut, constant($dir), SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY), $sqltypeconst))); + $r = sqlsrv_execute($stmt); + + // check the case when SQLSRV_SQLTYPE length (n) is not the same as the column length (m) + // with AE: should not work + // without AE: should work, except when a SQLSRV_SQLTYPE_VARBINARY length (n) is less than a binary column length (m) for SQLSRV_PARAM_OUT + if (($n != $m || $maxsqltype || $maxcol) && !($maxcol && $maxsqltype)) { + if (AE\isColEncrypted()) { + if ($r !== false) { + var_dump($n); + var_dump($m); + echo "AE: Conversion from $typeFull to output $sqltypeFull should not be supported\n"; + } else { + if (sqlsrv_errors()[0]['SQLSTATE'] != "22018") { + echo "AE: Conversion from $typeFull to output $sqltypeFull expects an operand type clash error, actual error is incorrect\n"; + var_dump(sqlsrv_errors()); + } + } + } else { + if (strpos($sqltypeFull, "VARBINARY") !== false && $dataType == "binary" && $m > $n && strpos($sqltypeFull, "max") === false && $dir == "SQLSRV_PARAM_OUT") { + if ($r !== false) { + echo "Conversions from $typeFull to output $sqltypeFull should not be supported\n"; + } + } else { + if ($r === false) { + if (strpos($sqltypeFull, "VARBINARY") !== false || $dataType != "binary" || $m <= $n) { + echo "Conversions from $typeFull to output $sqltypeFull should be supported\n"; + } + } + if (trim($c_detOut) != $inputValues[0] || trim($c_randOut) != $inputValues[1]) { + echo "Conversion from $typeFull to output $sqltypeFull causes data corruption\n"; + } + } + } + // check the case then SQLSRV_SQLTYPE length (n) is the same as the column length (m) + // should work with AE or non AE + } else { + if ($r === false) { + echo "Conversion from $typeFull to output $sqltypeFull should be supported\n"; + var_dump(sqlsrv_errors()); + } else { + if (trim($c_detOut) == $inputValues[0] && trim($c_randOut) == $inputValues[1]) { + echo "****Conversion from $typeFull to output $sqltypeFull is supported****\n"; + } else { + echo "Conversion from $typeFull to output $sqltypeFull causes data corruption\n"; + } + } + } + // cleanup + sqlsrv_free_stmt($stmt); + } + } + } + dropTable($conn, $tbname); + } +} +sqlsrv_close($conn); + +?> +--EXPECT-- +Testing binary(1): +Testing as SQLSRV_PARAM_OUT: +****Conversion from binary(1) to output SQLSRV_SQLTYPE_BINARY(1) is supported**** +****Conversion from binary(1) to output SQLSRV_SQLTYPE_VARBINARY(1) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from binary(1) to output SQLSRV_SQLTYPE_BINARY(1) is supported**** +****Conversion from binary(1) to output SQLSRV_SQLTYPE_VARBINARY(1) is supported**** + +Testing binary(8): +Testing as SQLSRV_PARAM_OUT: +****Conversion from binary(8) to output SQLSRV_SQLTYPE_BINARY(8) is supported**** +****Conversion from binary(8) to output SQLSRV_SQLTYPE_VARBINARY(8) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from binary(8) to output SQLSRV_SQLTYPE_BINARY(8) is supported**** +****Conversion from binary(8) to output SQLSRV_SQLTYPE_VARBINARY(8) is supported**** + +Testing binary(64): +Testing as SQLSRV_PARAM_OUT: +****Conversion from binary(64) to output SQLSRV_SQLTYPE_BINARY(64) is supported**** +****Conversion from binary(64) to output SQLSRV_SQLTYPE_VARBINARY(64) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from binary(64) to output SQLSRV_SQLTYPE_BINARY(64) is supported**** +****Conversion from binary(64) to output SQLSRV_SQLTYPE_VARBINARY(64) is supported**** + +Testing binary(512): +Testing as SQLSRV_PARAM_OUT: +****Conversion from binary(512) to output SQLSRV_SQLTYPE_BINARY(512) is supported**** +****Conversion from binary(512) to output SQLSRV_SQLTYPE_VARBINARY(512) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from binary(512) to output SQLSRV_SQLTYPE_BINARY(512) is supported**** +****Conversion from binary(512) to output SQLSRV_SQLTYPE_VARBINARY(512) is supported**** + +Testing binary(4000): +Testing as SQLSRV_PARAM_OUT: +****Conversion from binary(4000) to output SQLSRV_SQLTYPE_BINARY(4000) is supported**** +****Conversion from binary(4000) to output SQLSRV_SQLTYPE_VARBINARY(4000) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from binary(4000) to output SQLSRV_SQLTYPE_BINARY(4000) is supported**** +****Conversion from binary(4000) to output SQLSRV_SQLTYPE_VARBINARY(4000) is supported**** + +Testing varbinary(1): +Testing as SQLSRV_PARAM_OUT: +****Conversion from varbinary(1) to output SQLSRV_SQLTYPE_BINARY(1) is supported**** +****Conversion from varbinary(1) to output SQLSRV_SQLTYPE_VARBINARY(1) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from varbinary(1) to output SQLSRV_SQLTYPE_BINARY(1) is supported**** +****Conversion from varbinary(1) to output SQLSRV_SQLTYPE_VARBINARY(1) is supported**** + +Testing varbinary(8): +Testing as SQLSRV_PARAM_OUT: +****Conversion from varbinary(8) to output SQLSRV_SQLTYPE_BINARY(8) is supported**** +****Conversion from varbinary(8) to output SQLSRV_SQLTYPE_VARBINARY(8) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from varbinary(8) to output SQLSRV_SQLTYPE_BINARY(8) is supported**** +****Conversion from varbinary(8) to output SQLSRV_SQLTYPE_VARBINARY(8) is supported**** + +Testing varbinary(64): +Testing as SQLSRV_PARAM_OUT: +****Conversion from varbinary(64) to output SQLSRV_SQLTYPE_BINARY(64) is supported**** +****Conversion from varbinary(64) to output SQLSRV_SQLTYPE_VARBINARY(64) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from varbinary(64) to output SQLSRV_SQLTYPE_BINARY(64) is supported**** +****Conversion from varbinary(64) to output SQLSRV_SQLTYPE_VARBINARY(64) is supported**** + +Testing varbinary(512): +Testing as SQLSRV_PARAM_OUT: +****Conversion from varbinary(512) to output SQLSRV_SQLTYPE_BINARY(512) is supported**** +****Conversion from varbinary(512) to output SQLSRV_SQLTYPE_VARBINARY(512) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from varbinary(512) to output SQLSRV_SQLTYPE_BINARY(512) is supported**** +****Conversion from varbinary(512) to output SQLSRV_SQLTYPE_VARBINARY(512) is supported**** + +Testing varbinary(4000): +Testing as SQLSRV_PARAM_OUT: +****Conversion from varbinary(4000) to output SQLSRV_SQLTYPE_BINARY(4000) is supported**** +****Conversion from varbinary(4000) to output SQLSRV_SQLTYPE_VARBINARY(4000) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from varbinary(4000) to output SQLSRV_SQLTYPE_BINARY(4000) is supported**** +****Conversion from varbinary(4000) to output SQLSRV_SQLTYPE_VARBINARY(4000) is supported**** + +Testing varbinary(max): +Testing as SQLSRV_PARAM_OUT: +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** + +Testing varbinary(max): +Testing as SQLSRV_PARAM_OUT: +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** + +Testing varbinary(max): +Testing as SQLSRV_PARAM_OUT: +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** + +Testing varbinary(max): +Testing as SQLSRV_PARAM_OUT: +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** + +Testing varbinary(max): +Testing as SQLSRV_PARAM_OUT: +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** +****Conversion from varbinary(max) to output SQLSRV_SQLTYPE_VARBINARY('max') is supported**** \ No newline at end of file diff --git a/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_char_size.phpt b/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_char_size.phpt new file mode 100644 index 00000000..b17def17 --- /dev/null +++ b/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_char_size.phpt @@ -0,0 +1,316 @@ +--TEST-- +Test for retrieving encrypted data of char types with different sizes as output parameters +--DESCRIPTION-- +Test implicit conversions between different char types of different sizes +With Always Encrypted, implicit conversion works if: +1. From a char(m) column to a SQLSRV_SQLTYPE_CHAR(n) output parameter where m == n +2. From a char(m) column to a SQLSRV_SQLTYPE_VARCHAR(n) output parameter where m == n +3. From a varchar(m) column to a SQLSRV_SQLTYPE_CHAR(n) output parameter where m == n +4. From a varchar(m) column to a SQLSRV_SQLTYPE_VARCHAR(n) output parameter where m == n +Without AlwaysEncrypted, implicit conversion works if: +1. From a char(m) column to a SQLSRV_SQLTYPE_CHAR(n) output parameter where m, n == any value +2. From a char(m) column to a SQLSRV_SQLTYPE_VARCHAR(n) output parameter where m <= n (exclude SQLSRV_SQLTYPE_VARCHAR('max')) +3. From a varchar(m) column to a SQLSRV_SQLTYPE_CHAR(n) output parameter where m, n == any value +4. From a varchar(m) column to a SQLSRV_SQLTYPE_VARCHAR(n) output parameter where m, n == any value +--SKIPIF-- + +--FILE-- + $inputValue)); + + // create a stored procedure and sql string for calling the stored procedure + $spname = 'selectAllColumns'; + createProc($conn, $spname, "@c1 $typeFull OUTPUT", "SELECT @c1 = c1 FROM $tbname"); + $sql = AE\getCallProcSqlPlaceholders($spname, 1); + + // retrieve by specifying SQLSRV_SQLTYPE_CHAR(n) or SQLSRV_SQLTYPE_VARCHAR(n) as SQLSRV_PARAM_OUT or SQLSRV_PARAM_INOUT + foreach($directions as $dir) { + echo "Testing as $dir:\n"; + foreach($sqlTypes as $sqlType) { + $maxsqltype = strpos($sqlType, "max"); + foreach($sqltypeLengths as $n) { + $sqltypeconst; + $sqltypeFull; + if ($maxsqltype !== false) { + $sqltypeconst = SQLSRV_SQLTYPE_VARCHAR('max'); + $sqltypeFull = $sqlType; + } else { + $sqltypeconst = call_user_func($sqlType, $n); + $sqltypeFull = "$sqlType($n)"; + } + + $c1 = ''; + $stmt = sqlsrv_prepare($conn, $sql, array(array(&$c1, constant($dir), null, $sqltypeconst))); + $r = sqlsrv_execute($stmt); + + // check the case when SQLSRV_SQLTYPE length (n) is not the same as the column length (m) + // with AE: should not work + // without AE: should work, except when a SQLSRV_SQLTYPE_VARCHAR length (n) is less than a char column length (m) + if (($n != $m || $maxsqltype || $maxcol) && !($maxcol && $maxsqltype)) { + if (AE\isColEncrypted()) { + if ($r !== false) { + var_dump($n); + var_dump($m); + echo "AE: Conversion from $typeFull to output $sqltypeFull should not be supported\n"; + } else { + if (sqlsrv_errors()[0]['SQLSTATE'] != "22018") { + echo "AE: Conversion from $typeFull to output $sqltypeFull expects an operand type clash error, actual error is incorrect\n"; + var_dump(sqlsrv_errors()); + } + } + } else { + if (strpos($sqltypeFull, "VARCHAR") !== false && $dataType == "char" && $m > $n && strpos($sqltypeFull, "max") === false) { + if ($r !== false) { + echo "Conversions from $typeFull to output $sqltypeFull should not be supported\n"; + } + } else { + if ($r === false) { + if (strpos($sqltypeFull, "VARCHAR") !== false || $dataType != "char" || $m <= $n) { + echo "Conversions from $typeFull to output $sqltypeFull should be supported\n"; + } + } + if (trim($c1) != $inputValue) { + echo "Conversion from $typeFull to output $sqltypeFull causes data corruption\n"; + } + } + } + // check the case then SQLSRV_SQLTYPE length (n) is the same as the column length (m) + // should work with AE or non AE + } else { + if ($r === false) { + echo "Conversion from $typeFull to output $sqltypeFull should be supported\n"; + } else { + if (trim($c1) == $inputValue) { + echo "****Conversion from $typeFull to output $sqltypeFull is supported****\n"; + } else { + echo "Conversion from $typeFull to output $sqltypeFull causes data corruption\n"; + } + } + } + // cleanup + sqlsrv_free_stmt($stmt); + } + } + } + dropTable($conn, $tbname); + } +} +sqlsrv_close($conn); + +?> +--EXPECT-- +Testing char(1): +Testing as SQLSRV_PARAM_OUT: +****Conversion from char(1) to output SQLSRV_SQLTYPE_CHAR(1) is supported**** +****Conversion from char(1) to output SQLSRV_SQLTYPE_VARCHAR(1) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from char(1) to output SQLSRV_SQLTYPE_CHAR(1) is supported**** +****Conversion from char(1) to output SQLSRV_SQLTYPE_VARCHAR(1) is supported**** + +Testing char(8): +Testing as SQLSRV_PARAM_OUT: +****Conversion from char(8) to output SQLSRV_SQLTYPE_CHAR(8) is supported**** +****Conversion from char(8) to output SQLSRV_SQLTYPE_VARCHAR(8) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from char(8) to output SQLSRV_SQLTYPE_CHAR(8) is supported**** +****Conversion from char(8) to output SQLSRV_SQLTYPE_VARCHAR(8) is supported**** + +Testing char(64): +Testing as SQLSRV_PARAM_OUT: +****Conversion from char(64) to output SQLSRV_SQLTYPE_CHAR(64) is supported**** +****Conversion from char(64) to output SQLSRV_SQLTYPE_VARCHAR(64) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from char(64) to output SQLSRV_SQLTYPE_CHAR(64) is supported**** +****Conversion from char(64) to output SQLSRV_SQLTYPE_VARCHAR(64) is supported**** + +Testing char(512): +Testing as SQLSRV_PARAM_OUT: +****Conversion from char(512) to output SQLSRV_SQLTYPE_CHAR(512) is supported**** +****Conversion from char(512) to output SQLSRV_SQLTYPE_VARCHAR(512) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from char(512) to output SQLSRV_SQLTYPE_CHAR(512) is supported**** +****Conversion from char(512) to output SQLSRV_SQLTYPE_VARCHAR(512) is supported**** + +Testing char(4096): +Testing as SQLSRV_PARAM_OUT: +****Conversion from char(4096) to output SQLSRV_SQLTYPE_CHAR(4096) is supported**** +****Conversion from char(4096) to output SQLSRV_SQLTYPE_VARCHAR(4096) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from char(4096) to output SQLSRV_SQLTYPE_CHAR(4096) is supported**** +****Conversion from char(4096) to output SQLSRV_SQLTYPE_VARCHAR(4096) is supported**** + +Testing char(8000): +Testing as SQLSRV_PARAM_OUT: +****Conversion from char(8000) to output SQLSRV_SQLTYPE_CHAR(8000) is supported**** +****Conversion from char(8000) to output SQLSRV_SQLTYPE_VARCHAR(8000) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from char(8000) to output SQLSRV_SQLTYPE_CHAR(8000) is supported**** +****Conversion from char(8000) to output SQLSRV_SQLTYPE_VARCHAR(8000) is supported**** + +Testing varchar(1): +Testing as SQLSRV_PARAM_OUT: +****Conversion from varchar(1) to output SQLSRV_SQLTYPE_CHAR(1) is supported**** +****Conversion from varchar(1) to output SQLSRV_SQLTYPE_VARCHAR(1) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from varchar(1) to output SQLSRV_SQLTYPE_CHAR(1) is supported**** +****Conversion from varchar(1) to output SQLSRV_SQLTYPE_VARCHAR(1) is supported**** + +Testing varchar(8): +Testing as SQLSRV_PARAM_OUT: +****Conversion from varchar(8) to output SQLSRV_SQLTYPE_CHAR(8) is supported**** +****Conversion from varchar(8) to output SQLSRV_SQLTYPE_VARCHAR(8) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from varchar(8) to output SQLSRV_SQLTYPE_CHAR(8) is supported**** +****Conversion from varchar(8) to output SQLSRV_SQLTYPE_VARCHAR(8) is supported**** + +Testing varchar(64): +Testing as SQLSRV_PARAM_OUT: +****Conversion from varchar(64) to output SQLSRV_SQLTYPE_CHAR(64) is supported**** +****Conversion from varchar(64) to output SQLSRV_SQLTYPE_VARCHAR(64) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from varchar(64) to output SQLSRV_SQLTYPE_CHAR(64) is supported**** +****Conversion from varchar(64) to output SQLSRV_SQLTYPE_VARCHAR(64) is supported**** + +Testing varchar(512): +Testing as SQLSRV_PARAM_OUT: +****Conversion from varchar(512) to output SQLSRV_SQLTYPE_CHAR(512) is supported**** +****Conversion from varchar(512) to output SQLSRV_SQLTYPE_VARCHAR(512) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from varchar(512) to output SQLSRV_SQLTYPE_CHAR(512) is supported**** +****Conversion from varchar(512) to output SQLSRV_SQLTYPE_VARCHAR(512) is supported**** + +Testing varchar(4096): +Testing as SQLSRV_PARAM_OUT: +****Conversion from varchar(4096) to output SQLSRV_SQLTYPE_CHAR(4096) is supported**** +****Conversion from varchar(4096) to output SQLSRV_SQLTYPE_VARCHAR(4096) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from varchar(4096) to output SQLSRV_SQLTYPE_CHAR(4096) is supported**** +****Conversion from varchar(4096) to output SQLSRV_SQLTYPE_VARCHAR(4096) is supported**** + +Testing varchar(8000): +Testing as SQLSRV_PARAM_OUT: +****Conversion from varchar(8000) to output SQLSRV_SQLTYPE_CHAR(8000) is supported**** +****Conversion from varchar(8000) to output SQLSRV_SQLTYPE_VARCHAR(8000) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from varchar(8000) to output SQLSRV_SQLTYPE_CHAR(8000) is supported**** +****Conversion from varchar(8000) to output SQLSRV_SQLTYPE_VARCHAR(8000) is supported**** + +Testing varchar(max): +Testing as SQLSRV_PARAM_OUT: +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** + +Testing varchar(max): +Testing as SQLSRV_PARAM_OUT: +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** + +Testing varchar(max): +Testing as SQLSRV_PARAM_OUT: +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** + +Testing varchar(max): +Testing as SQLSRV_PARAM_OUT: +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** + +Testing varchar(max): +Testing as SQLSRV_PARAM_OUT: +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** + +Testing varchar(max): +Testing as SQLSRV_PARAM_OUT: +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** +****Conversion from varchar(max) to output SQLSRV_SQLTYPE_VARCHAR('max') is supported**** \ No newline at end of file diff --git a/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_float_bits.phpt b/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_float_bits.phpt new file mode 100644 index 00000000..bbda75e6 --- /dev/null +++ b/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_float_bits.phpt @@ -0,0 +1,122 @@ +--TEST-- +Test for retrieving encrypted data of float types with different number of bits as output parameters +--DESCRIPTION-- +Test implicit conversions between different number of bits +With Always Encrypted, implicit conversion works if: +1. From a float(m) column to a SQLSRV_SQLTYPE_FLOAT output parameter where m > 24 +Without Always Encrypted, implicit conversion between different number of bits works +--SKIPIF-- + +--FILE-- + $inputValues[0], "c_rand" => $inputValues[1])); + + // create a stored procedure and sql string for calling the stored procedure + $spname = 'selectAllColumns'; + createProc($conn, $spname, "@c_det $typeFull OUTPUT, @c_rand $typeFull OUTPUT", "SELECT @c_det = c_det, @c_rand = c_rand FROM $tbname"); + $sql = AE\getCallProcSqlPlaceholders($spname, 2); + + // retrieve by specifying SQLSRV_SQLTYPE_FLOAT as SQLSRV_PARAM_OUT or SQLSRV_PARAM_INOUT + foreach($directions as $dir) { + echo "Testing as $dir:\n"; + + $c_detOut = 0.0; + $c_randOut = 0.0; + $stmt = sqlsrv_prepare($conn, $sql, array(array(&$c_detOut, constant($dir), null, constant($sqlType)), array(&$c_randOut, constant($dir), null, constant($sqlType)))); + $r = sqlsrv_execute($stmt); + + // check the case when the column number of bits is less than 25 + // with AE: should not work + // without AE: should work + if ($m < 25) { + if (AE\isColEncrypted()) { + if ($r !== false) { + echo "AE: Conversion between $typeFull to output $sqlType should not be supported\n"; + } else { + if (sqlsrv_errors()[0]['SQLSTATE'] != "22018") { + echo "AE: Conversion from $typeFull to output $sqlType expects an operand type clash error, actual error is incorrect\n"; + var_dump(sqlsrv_errors()); + } else { + echo "Test successfully done\n"; + } + } + } else { + if ($r === false) { + echo "Conversion from $typeFull to output $sqlType should be supported\n"; + } else { + if (abs($c_detOut - $inputValues[0]) > $epsilon || abs($c_randOut - $inputValues[1]) > $epsilon) { + echo "Conversion from $typeFull to output $sqlType causes data corruption\n"; + } else { + echo "Test successfully done\n"; + } + } + } + // check the case when the column number of bits 25 or more + // should work with or without AE + } else { + if ($r === false) { + echo "Conversion from $typeFull to output $sqlType should be supported\n"; + } else { + if (abs($c_detOut - $inputValues[0]) < $epsilon && abs($c_randOut - $inputValues[1]) < $epsilon) { + echo "****Conversion from $typeFull to output $sqlType is supported****\n"; + } else { + echo "Conversion from $typeFull to output $sqlType causes data corruption\n"; + } + } + } + // cleanup + sqlsrv_free_stmt($stmt); + } + dropTable($conn, $tbname); +} +sqlsrv_close($conn); + +?> +--EXPECT-- +Testing float(1): +Testing as SQLSRV_PARAM_OUT: +Test successfully done +Testing as SQLSRV_PARAM_INOUT: +Test successfully done + +Testing float(12): +Testing as SQLSRV_PARAM_OUT: +Test successfully done +Testing as SQLSRV_PARAM_INOUT: +Test successfully done + +Testing float(24): +Testing as SQLSRV_PARAM_OUT: +Test successfully done +Testing as SQLSRV_PARAM_INOUT: +Test successfully done + +Testing float(36): +Testing as SQLSRV_PARAM_OUT: +****Conversion from float(36) to output SQLSRV_SQLTYPE_FLOAT is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from float(36) to output SQLSRV_SQLTYPE_FLOAT is supported**** + +Testing float(53): +Testing as SQLSRV_PARAM_OUT: +****Conversion from float(53) to output SQLSRV_SQLTYPE_FLOAT is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from float(53) to output SQLSRV_SQLTYPE_FLOAT is supported**** \ No newline at end of file diff --git a/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_int_conv.phpt b/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_int_conv.phpt new file mode 100644 index 00000000..310e21ab --- /dev/null +++ b/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_int_conv.phpt @@ -0,0 +1,112 @@ +--TEST-- +Test for retrieving encrypted data of int types as output parameters +--DESCRIPTION-- +Test implicit conversions between different integer types +With Always Encrypted, implicit conversion works if the column type and the SQLSRV_SQLTYPE are the same +Without AlwaysEncrypted, implicit conversion between different integer types works +--SKIPIF-- + +--FILE-- + $inputValues[0], "c_rand" => $inputValues[1])); + + // create a stored procedure and sql string for calling the stored procedure + $spname = 'selectAllColumns'; + createProc($conn, $spname, "@c_det $dataType OUTPUT, @c_rand $dataType OUTPUT", "SELECT @c_det = c_det, @c_rand = c_rand FROM $tbname"); + $sql = AE\getCallProcSqlPlaceholders($spname, 2); + + // retrieve by specifying different SQLSRV_SQLTYPE ingeter constants as SQLSRV_PARAM_OUT or SQLSRV_PARAM_INOUT + foreach($directions as $dir) { + echo "Testing as $dir:\n"; + foreach($sqlTypes as $sqlType) { + $c_detOut = 0; + $c_randOut = 0; + $stmt = sqlsrv_prepare($conn, $sql, array(array(&$c_detOut, constant($dir), null, constant($sqlType)), array(&$c_randOut, constant($dir), null, constant($sqlType)))); + $r = sqlsrv_execute($stmt); + + // check the case if the column type is not the same as the SQLSRV_SQLTYPE + if ($sqlType != "SQLSRV_SQLTYPE_" . strtoupper($dataType)) { + if (AE\isColEncrypted()) { + if ($r !== false) { + echo "AE: Conversion from $dataType to output $sqlType should not be supported\n"; + } else { + if (sqlsrv_errors()[0]['SQLSTATE'] != "22018") { + echo "AE: Conversion from $dataType to output $sqlType expects an operand type clash error, actual error is incorrect\n"; + var_dump(sqlsrv_errors()); + } + } + } else { + if ($r === false) { + echo "Conversion from $dataType to output $sqlType should be supported\n"; + } else { + if ($c_detOut != $inputValues[0] || $c_randOut != $inputValues[1]) { + echo "Conversion from $dataType to output $sqlType causes data corruption\n"; + } + } + } + // check the case if the column type is the same as the SQLSRV_SQLTYPE + } else { + if ($r === false) { + echo "Conversion from $dataType to output $sqlType should be supported\n"; + } else { + if ($c_detOut == $inputValues[0] && $c_randOut == $inputValues[1]) { + echo "****Conversion from $dataType to output $sqlType is supported****\n"; + } else { + echo "Conversion from $dataType to output $sqlType causes data corruption\n"; + } + } + } + // cleanup + sqlsrv_free_stmt($stmt); + } + } + dropTable($conn, $tbname); +} +sqlsrv_close($conn); + +?> +--EXPECT-- +Testing bit: +Testing as SQLSRV_PARAM_OUT: +****Conversion from bit to output SQLSRV_SQLTYPE_BIT is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from bit to output SQLSRV_SQLTYPE_BIT is supported**** + +Testing tinyint: +Testing as SQLSRV_PARAM_OUT: +****Conversion from tinyint to output SQLSRV_SQLTYPE_TINYINT is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from tinyint to output SQLSRV_SQLTYPE_TINYINT is supported**** + +Testing smallint: +Testing as SQLSRV_PARAM_OUT: +****Conversion from smallint to output SQLSRV_SQLTYPE_SMALLINT is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from smallint to output SQLSRV_SQLTYPE_SMALLINT is supported**** + +Testing int: +Testing as SQLSRV_PARAM_OUT: +****Conversion from int to output SQLSRV_SQLTYPE_INT is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from int to output SQLSRV_SQLTYPE_INT is supported**** + +Testing bigint: +Testing as SQLSRV_PARAM_OUT: +****Conversion from bigint to output SQLSRV_SQLTYPE_BIGINT is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from bigint to output SQLSRV_SQLTYPE_BIGINT is supported**** \ No newline at end of file diff --git a/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_nchar_size.phpt b/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_nchar_size.phpt new file mode 100644 index 00000000..a76a0d12 --- /dev/null +++ b/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_nchar_size.phpt @@ -0,0 +1,274 @@ +--TEST-- +Test for retrieving encrypted data of nchar types with different sizes as output parameters +--DESCRIPTION-- +Test implicit conversions between different nchar types of different sizes +With Always Encrypted, implicit conversion works if: +1. From a nchar(m) column to a SQLSRV_SQLTYPE_NCHAR(n) output parameter where m == n +2. From a nchar(m) column to a SQLSRV_SQLTYPE_NVARCHAR(n) output parameter where m == n +3. From a nvarchar(m) column to a SQLSRV_SQLTYPE_NCHAR(n) output parameter where m == n +4. From a nvarchar(m) column to a SQLSRV_SQLTYPE_NVARCHAR(n) output parameter where m == n +Without AlwaysEncrypted, implicit conversion works if: +1. From a nchar(m) column to a SQLSRV_SQLTYPE_NCHAR(n) output parameter where m, n == any value +2. From a nchar(m) column to a SQLSRV_SQLTYPE_NVARCHAR(n) output parameter where m <= n (exclude SQLSRV_SQLTYPE_NVARCHAR('max')) +3. From a nvarchar(m) column to a SQLSRV_SQLTYPE_NCHAR(n) output parameter where m, n == any value +4. From a nvarchar(m) column to a SQLSRV_SQLTYPE_NVARCHAR(n) output parameter where m, n == any value +--SKIPIF-- + +--FILE-- + $inputValue)); + + // create a stored procedure and sql string for calling the stored procedure + $spname = 'selectAllColumns'; + createProc($conn, $spname, "@c1 $typeFull OUTPUT", "SELECT @c1 = c1 FROM $tbname"); + $sql = AE\getCallProcSqlPlaceholders($spname, 1); + + // retrieve by specifying SQLSRV_SQLTYPE_NCHAR(n) or SQLSRV_SQLTYPE_NVARCHAR(n) as SQLSRV_PARAM_OUT or SQLSRV_PARAM_INOUT + foreach($directions as $dir) { + echo "Testing as $dir:\n"; + foreach($sqlTypes as $sqlType) { + $maxsqltype = strpos($sqlType, "max"); + foreach($sqltypeLengths as $n) { + $sqltypeconst; + $sqltypeFull; + if ($maxsqltype !== false) { + $sqltypeconst = SQLSRV_SQLTYPE_NVARCHAR('max'); + $sqltypeFull = $sqlType; + } else { + $sqltypeconst = call_user_func($sqlType, $n); + $sqltypeFull = "$sqlType($n)"; + } + + $c1 = ''; + $stmt = sqlsrv_prepare($conn, $sql, array(array(&$c1, constant($dir), null, $sqltypeconst))); + $r = sqlsrv_execute($stmt); + + // check the case when SQLSRV_SQLTYPE length (n) is not the same as the column length (m) + // with AE: should not work + // without AE: should work, except when a SQLSRV_SQLTYPE_NVARCHAR length (n) is less than a nchar column length (m) + if (($n != $m || $maxsqltype || $maxcol) && !($maxcol && $maxsqltype)) { + if (AE\isColEncrypted()) { + if ($r !== false) { + var_dump($n); + var_dump($m); + echo "AE: Conversion from $typeFull to output $sqltypeFull should not be supported\n"; + } else { + if (sqlsrv_errors()[0]['SQLSTATE'] != "22018") { + echo "AE: Conversion from $typeFull to output $sqltypeFull expects an operand type clash error, actual error is incorrect\n"; + var_dump(sqlsrv_errors()); + } + } + } else { + if (strpos($sqltypeFull, "NVARCHAR") !== false && $dataType == "nchar" && $m > $n && strpos($sqltypeFull, "max") === false) { + if ($r !== false) { + echo "Conversions from $typeFull to output $sqltypeFull should not be supported\n"; + } + } else { + if ($r === false) { + if (strpos($sqltypeFull, "NVARCHAR") !== false || $dataType != "nchar" || $m <= $n) { + echo "Conversions from $typeFull to output $sqltypeFull should be supported\n"; + } + } + if (trim($c1) != $inputValue) { + echo "Conversion from $typeFull to output $sqltypeFull causes data corruption\n"; + } + } + } + // check the case then SQLSRV_SQLTYPE length (n) is the same as the column length (m) + // should work with AE or non AE + } else { + if ($r === false) { + echo "Conversion from $typeFull to output $sqltypeFull should be supported\n"; + } else { + if (trim($c1) == $inputValue) { + echo "****Conversion from $typeFull to output $sqltypeFull is supported****\n"; + } else { + echo "Conversion from $typeFull to output $sqltypeFull causes data corruption\n"; + } + } + } + // cleanup + sqlsrv_free_stmt($stmt); + } + } + } + dropTable($conn, $tbname); + } +} +sqlsrv_close($conn); + +?> +--EXPECT-- +Testing nchar(1): +Testing as SQLSRV_PARAM_OUT: +****Conversion from nchar(1) to output SQLSRV_SQLTYPE_NCHAR(1) is supported**** +****Conversion from nchar(1) to output SQLSRV_SQLTYPE_NVARCHAR(1) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from nchar(1) to output SQLSRV_SQLTYPE_NCHAR(1) is supported**** +****Conversion from nchar(1) to output SQLSRV_SQLTYPE_NVARCHAR(1) is supported**** + +Testing nchar(8): +Testing as SQLSRV_PARAM_OUT: +****Conversion from nchar(8) to output SQLSRV_SQLTYPE_NCHAR(8) is supported**** +****Conversion from nchar(8) to output SQLSRV_SQLTYPE_NVARCHAR(8) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from nchar(8) to output SQLSRV_SQLTYPE_NCHAR(8) is supported**** +****Conversion from nchar(8) to output SQLSRV_SQLTYPE_NVARCHAR(8) is supported**** + +Testing nchar(64): +Testing as SQLSRV_PARAM_OUT: +****Conversion from nchar(64) to output SQLSRV_SQLTYPE_NCHAR(64) is supported**** +****Conversion from nchar(64) to output SQLSRV_SQLTYPE_NVARCHAR(64) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from nchar(64) to output SQLSRV_SQLTYPE_NCHAR(64) is supported**** +****Conversion from nchar(64) to output SQLSRV_SQLTYPE_NVARCHAR(64) is supported**** + +Testing nchar(512): +Testing as SQLSRV_PARAM_OUT: +****Conversion from nchar(512) to output SQLSRV_SQLTYPE_NCHAR(512) is supported**** +****Conversion from nchar(512) to output SQLSRV_SQLTYPE_NVARCHAR(512) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from nchar(512) to output SQLSRV_SQLTYPE_NCHAR(512) is supported**** +****Conversion from nchar(512) to output SQLSRV_SQLTYPE_NVARCHAR(512) is supported**** + +Testing nchar(4000): +Testing as SQLSRV_PARAM_OUT: +****Conversion from nchar(4000) to output SQLSRV_SQLTYPE_NCHAR(4000) is supported**** +****Conversion from nchar(4000) to output SQLSRV_SQLTYPE_NVARCHAR(4000) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from nchar(4000) to output SQLSRV_SQLTYPE_NCHAR(4000) is supported**** +****Conversion from nchar(4000) to output SQLSRV_SQLTYPE_NVARCHAR(4000) is supported**** + +Testing nvarchar(1): +Testing as SQLSRV_PARAM_OUT: +****Conversion from nvarchar(1) to output SQLSRV_SQLTYPE_NCHAR(1) is supported**** +****Conversion from nvarchar(1) to output SQLSRV_SQLTYPE_NVARCHAR(1) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from nvarchar(1) to output SQLSRV_SQLTYPE_NCHAR(1) is supported**** +****Conversion from nvarchar(1) to output SQLSRV_SQLTYPE_NVARCHAR(1) is supported**** + +Testing nvarchar(8): +Testing as SQLSRV_PARAM_OUT: +****Conversion from nvarchar(8) to output SQLSRV_SQLTYPE_NCHAR(8) is supported**** +****Conversion from nvarchar(8) to output SQLSRV_SQLTYPE_NVARCHAR(8) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from nvarchar(8) to output SQLSRV_SQLTYPE_NCHAR(8) is supported**** +****Conversion from nvarchar(8) to output SQLSRV_SQLTYPE_NVARCHAR(8) is supported**** + +Testing nvarchar(64): +Testing as SQLSRV_PARAM_OUT: +****Conversion from nvarchar(64) to output SQLSRV_SQLTYPE_NCHAR(64) is supported**** +****Conversion from nvarchar(64) to output SQLSRV_SQLTYPE_NVARCHAR(64) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from nvarchar(64) to output SQLSRV_SQLTYPE_NCHAR(64) is supported**** +****Conversion from nvarchar(64) to output SQLSRV_SQLTYPE_NVARCHAR(64) is supported**** + +Testing nvarchar(512): +Testing as SQLSRV_PARAM_OUT: +****Conversion from nvarchar(512) to output SQLSRV_SQLTYPE_NCHAR(512) is supported**** +****Conversion from nvarchar(512) to output SQLSRV_SQLTYPE_NVARCHAR(512) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from nvarchar(512) to output SQLSRV_SQLTYPE_NCHAR(512) is supported**** +****Conversion from nvarchar(512) to output SQLSRV_SQLTYPE_NVARCHAR(512) is supported**** + +Testing nvarchar(4000): +Testing as SQLSRV_PARAM_OUT: +****Conversion from nvarchar(4000) to output SQLSRV_SQLTYPE_NCHAR(4000) is supported**** +****Conversion from nvarchar(4000) to output SQLSRV_SQLTYPE_NVARCHAR(4000) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from nvarchar(4000) to output SQLSRV_SQLTYPE_NCHAR(4000) is supported**** +****Conversion from nvarchar(4000) to output SQLSRV_SQLTYPE_NVARCHAR(4000) is supported**** + +Testing nvarchar(max): +Testing as SQLSRV_PARAM_OUT: +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** + +Testing nvarchar(max): +Testing as SQLSRV_PARAM_OUT: +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** + +Testing nvarchar(max): +Testing as SQLSRV_PARAM_OUT: +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** + +Testing nvarchar(max): +Testing as SQLSRV_PARAM_OUT: +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** + +Testing nvarchar(max): +Testing as SQLSRV_PARAM_OUT: +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** +****Conversion from nvarchar(max) to output SQLSRV_SQLTYPE_NVARCHAR('max') is supported**** \ No newline at end of file From bc387c8b4b2ca6d20679b527654c44d8ba6ec8dd Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Fri, 9 Mar 2018 16:57:04 -0800 Subject: [PATCH 2/5] add tests for output decimal --- ...utput_param_sqltype_decimal_precision.phpt | 264 ++++++++++++++++++ 1 file changed, 264 insertions(+) create mode 100644 test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_decimal_precision.phpt diff --git a/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_decimal_precision.phpt b/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_decimal_precision.phpt new file mode 100644 index 00000000..5a83b4ca --- /dev/null +++ b/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_decimal_precision.phpt @@ -0,0 +1,264 @@ +--TEST-- +Test for retrieving encrypted data of decimal types with different precisions and scales as output parameters +--DESCRIPTION-- +Test implicit conversions between different precisions and scales +With Always Encrypted, no implicit conversion works for decimal datatypes, the precision and scale specified in the SQLSRV_SQLTYPE must be identical to the precision and scale defined in the column +Without AlwaysEncrypted, implicit conversion between precisions or scales works if: +1. From a decimal(m1, m2) column to a SQLSRV_SQLTYPE_DECIMAL(n1, n2) output parameter where n1 - n2 >= m1 - m2 +--SKIPIF-- + +--FILE-- + array(0, 1), + 4 => array(0, 1, 4), + 16 => array(0, 1, 4, 16),*/ + 19 => array(/*0,*/ 1, 4, 16, 19), + 38 => array(/*0,*/ 1, 4, 16, 37/*,38*/)); +$sqlTypes = array("SQLSRV_SQLTYPE_DECIMAL", "SQLSRV_SQLTYPE_NUMERIC"); +$sqltypePrecisions = $precisions; +$inputValuesInit = array(92233720368547758089223372036854775808, -92233720368547758089223372036854775808); +$maxInPrecision = 38; +$directions = array("SQLSRV_PARAM_OUT", "SQLSRV_PARAM_INOUT"); + +$conn = AE\connect(); + +foreach($dataTypes as $dataType) { + foreach($precisions as $m1 => $inScales) { + foreach($inScales as $m2) { + // change the number of integers in the input values to be $m1 - $m2 + $precDiff = $maxInPrecision - ($m1 - $m2); + $inputValues = $inputValuesInit; + foreach ($inputValues as &$inputValue) { + $inputValue = $inputValue / pow(10, $precDiff); + } + $typeFull = "$dataType($m1, $m2)"; + echo "\nTesting $typeFull:\n"; + + // create and populate table containing decimal(m1, m2) or numeric(m1, m2) columns + $tbname = "test_" . $dataType . $m1 . $m2; + $colMetaArr = array(new AE\ColumnMeta($typeFull, "c_det"), new AE\ColumnMeta($typeFull, "c_rand", null, false)); + AE\createTable($conn, $tbname, $colMetaArr); + $stmt = AE\insertRow($conn, $tbname, array("c_det" => $inputValues[0], "c_rand" => $inputValues[1])); + + // create a stored procedure and sql string for calling the stored procedure + $spname = 'selectAllColumns'; + createProc($conn, $spname, "@c_det $typeFull OUTPUT, @c_rand $typeFull OUTPUT", "SELECT @c_det = c_det, @c_rand = c_rand FROM $tbname"); + $sql = AE\getCallProcSqlPlaceholders($spname, 2); + + // retrieve by specifying SQLSRV_SQLTYPE_DECIMAL(n1, n2) or SQLSRV_SQLTYPE_NUMERIC(n1, n2) as SQLSRV_PARAM_OUT or SQLSRV_PARAM_INOUT + foreach($directions as $dir) { + echo "Testing as $dir:\n"; + foreach($sqlTypes as $sqlType) { + foreach($sqltypePrecisions as $n1 => $sqltypeScales) { + foreach($sqltypeScales as $n2) { + + // compute the epsilon for comparing doubles + // float in PHP only has a precision of roughtly 14 digits: http://php.net/manual/en/language.types.float.php + // the smaller precision and scale (n1 and n2 vs m1 and m2) take precedence + $epsilon; + $smallerprec = min($m1, $n1); + $smallerscale = min($m2, $n2); + if ($smallerprec < 14) { + $epsilon = pow(10, $smallerscale * -1); + } else { + $numint = $smallerprec - $smallerscale; + if ($numint < 14) { + $epsilon = pow(10, (14 - $numint) * -1); + } else { + $epsilon = pow(10, $numint - 14); + } + } + + $sqltypeFull = "$sqlType($n1, $n2)"; + $sqltypeconst = call_user_func($sqlType, $n1, $n2); + + $c_detOut = 0.0; + $c_randOut = 0.0; + $stmt = sqlsrv_prepare($conn, $sql, array(array(&$c_detOut, constant($dir), SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), $sqltypeconst), array(&$c_randOut, constant($dir), SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), $sqltypeconst))); + $r = sqlsrv_execute($stmt); + + // check the case when the SQLSRV_SQLTYPE precision (n1) is not the same as the column precision (m1) + // or the SQLSRV_SQLTYPE scale (n2) is not the same as the column precision (m2) + // with AE: should not work + // without AE: should not work if n1 - n2 < m1 - m2 + if ($n1 != $m1 || $n2 != $m2) { + if (AE\isColEncrypted()) { + if ($r !== false) { + echo "AE: Conversion from $typeFull to output $sqltypeFull should not be supported\n"; + } else { + if (sqlsrv_errors()[0]['SQLSTATE'] != "22018") { + echo "AE: Conversion from $typeFull to output $sqltypeFull expects an operand type clash error, actual error is incorrect\n"; + var_dump(sqlsrv_errors()); + } + } + } else { + if ($n1 - $n2 < $m1 - $m2) { + if ($r !== false) { + echo "Conversion from $typeFull to output $sqltypeFull should not be supported\n"; + } + } else { + if ($r === false) { + echo "Conversion from $typeFull to output $sqltypeFull should be supported\n"; + } else { + if (abs($c_detOut - $inputValues[0]) > $epsilon || abs($c_randOut - $inputValues[1]) > $epsilon) { + echo "Conversion from $typeFull to output $sqltypeFull causes data corruption\n"; + } + } + } + } + // check the case when the SQLSRV_SQLTYPE precision (n1) and scale (n2) are the same as the column precision (m1) and scale (m2) + // should work with AE or non AE + } else { + if ($r === false) { + echo "Conversion from $typeFull to output $sqltypeFull should be supported\n"; + } else { + if (abs($c_detOut - $inputValues[0]) < $epsilon && abs($c_randOut - $inputValues[1]) < $epsilon) { + echo "****Conversion from $typeFull to output $sqltypeFull is supported****\n"; + } else { + echo "Conversion from $typeFull to output $sqltypeFull causes data corruption\n"; + } + } + } + // cleanup + sqlsrv_free_stmt($stmt); + } + } + } + } + dropTable($conn, $tbname); + } + } +} +sqlsrv_close($conn); +?> +--EXPECT-- +Testing decimal(19, 1): +Testing as SQLSRV_PARAM_OUT: +****Conversion from decimal(19, 1) to output SQLSRV_SQLTYPE_DECIMAL(19, 1) is supported**** +****Conversion from decimal(19, 1) to output SQLSRV_SQLTYPE_NUMERIC(19, 1) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from decimal(19, 1) to output SQLSRV_SQLTYPE_DECIMAL(19, 1) is supported**** +****Conversion from decimal(19, 1) to output SQLSRV_SQLTYPE_NUMERIC(19, 1) is supported**** + +Testing decimal(19, 4): +Testing as SQLSRV_PARAM_OUT: +****Conversion from decimal(19, 4) to output SQLSRV_SQLTYPE_DECIMAL(19, 4) is supported**** +****Conversion from decimal(19, 4) to output SQLSRV_SQLTYPE_NUMERIC(19, 4) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from decimal(19, 4) to output SQLSRV_SQLTYPE_DECIMAL(19, 4) is supported**** +****Conversion from decimal(19, 4) to output SQLSRV_SQLTYPE_NUMERIC(19, 4) is supported**** + +Testing decimal(19, 16): +Testing as SQLSRV_PARAM_OUT: +****Conversion from decimal(19, 16) to output SQLSRV_SQLTYPE_DECIMAL(19, 16) is supported**** +****Conversion from decimal(19, 16) to output SQLSRV_SQLTYPE_NUMERIC(19, 16) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from decimal(19, 16) to output SQLSRV_SQLTYPE_DECIMAL(19, 16) is supported**** +****Conversion from decimal(19, 16) to output SQLSRV_SQLTYPE_NUMERIC(19, 16) is supported**** + +Testing decimal(19, 19): +Testing as SQLSRV_PARAM_OUT: +****Conversion from decimal(19, 19) to output SQLSRV_SQLTYPE_DECIMAL(19, 19) is supported**** +****Conversion from decimal(19, 19) to output SQLSRV_SQLTYPE_NUMERIC(19, 19) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from decimal(19, 19) to output SQLSRV_SQLTYPE_DECIMAL(19, 19) is supported**** +****Conversion from decimal(19, 19) to output SQLSRV_SQLTYPE_NUMERIC(19, 19) is supported**** + +Testing decimal(38, 1): +Testing as SQLSRV_PARAM_OUT: +****Conversion from decimal(38, 1) to output SQLSRV_SQLTYPE_DECIMAL(38, 1) is supported**** +****Conversion from decimal(38, 1) to output SQLSRV_SQLTYPE_NUMERIC(38, 1) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from decimal(38, 1) to output SQLSRV_SQLTYPE_DECIMAL(38, 1) is supported**** +****Conversion from decimal(38, 1) to output SQLSRV_SQLTYPE_NUMERIC(38, 1) is supported**** + +Testing decimal(38, 4): +Testing as SQLSRV_PARAM_OUT: +****Conversion from decimal(38, 4) to output SQLSRV_SQLTYPE_DECIMAL(38, 4) is supported**** +****Conversion from decimal(38, 4) to output SQLSRV_SQLTYPE_NUMERIC(38, 4) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from decimal(38, 4) to output SQLSRV_SQLTYPE_DECIMAL(38, 4) is supported**** +****Conversion from decimal(38, 4) to output SQLSRV_SQLTYPE_NUMERIC(38, 4) is supported**** + +Testing decimal(38, 16): +Testing as SQLSRV_PARAM_OUT: +****Conversion from decimal(38, 16) to output SQLSRV_SQLTYPE_DECIMAL(38, 16) is supported**** +****Conversion from decimal(38, 16) to output SQLSRV_SQLTYPE_NUMERIC(38, 16) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from decimal(38, 16) to output SQLSRV_SQLTYPE_DECIMAL(38, 16) is supported**** +****Conversion from decimal(38, 16) to output SQLSRV_SQLTYPE_NUMERIC(38, 16) is supported**** + +Testing decimal(38, 37): +Testing as SQLSRV_PARAM_OUT: +****Conversion from decimal(38, 37) to output SQLSRV_SQLTYPE_DECIMAL(38, 37) is supported**** +****Conversion from decimal(38, 37) to output SQLSRV_SQLTYPE_NUMERIC(38, 37) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from decimal(38, 37) to output SQLSRV_SQLTYPE_DECIMAL(38, 37) is supported**** +****Conversion from decimal(38, 37) to output SQLSRV_SQLTYPE_NUMERIC(38, 37) is supported**** + +Testing numeric(19, 1): +Testing as SQLSRV_PARAM_OUT: +****Conversion from numeric(19, 1) to output SQLSRV_SQLTYPE_DECIMAL(19, 1) is supported**** +****Conversion from numeric(19, 1) to output SQLSRV_SQLTYPE_NUMERIC(19, 1) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from numeric(19, 1) to output SQLSRV_SQLTYPE_DECIMAL(19, 1) is supported**** +****Conversion from numeric(19, 1) to output SQLSRV_SQLTYPE_NUMERIC(19, 1) is supported**** + +Testing numeric(19, 4): +Testing as SQLSRV_PARAM_OUT: +****Conversion from numeric(19, 4) to output SQLSRV_SQLTYPE_DECIMAL(19, 4) is supported**** +****Conversion from numeric(19, 4) to output SQLSRV_SQLTYPE_NUMERIC(19, 4) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from numeric(19, 4) to output SQLSRV_SQLTYPE_DECIMAL(19, 4) is supported**** +****Conversion from numeric(19, 4) to output SQLSRV_SQLTYPE_NUMERIC(19, 4) is supported**** + +Testing numeric(19, 16): +Testing as SQLSRV_PARAM_OUT: +****Conversion from numeric(19, 16) to output SQLSRV_SQLTYPE_DECIMAL(19, 16) is supported**** +****Conversion from numeric(19, 16) to output SQLSRV_SQLTYPE_NUMERIC(19, 16) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from numeric(19, 16) to output SQLSRV_SQLTYPE_DECIMAL(19, 16) is supported**** +****Conversion from numeric(19, 16) to output SQLSRV_SQLTYPE_NUMERIC(19, 16) is supported**** + +Testing numeric(19, 19): +Testing as SQLSRV_PARAM_OUT: +****Conversion from numeric(19, 19) to output SQLSRV_SQLTYPE_DECIMAL(19, 19) is supported**** +****Conversion from numeric(19, 19) to output SQLSRV_SQLTYPE_NUMERIC(19, 19) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from numeric(19, 19) to output SQLSRV_SQLTYPE_DECIMAL(19, 19) is supported**** +****Conversion from numeric(19, 19) to output SQLSRV_SQLTYPE_NUMERIC(19, 19) is supported**** + +Testing numeric(38, 1): +Testing as SQLSRV_PARAM_OUT: +****Conversion from numeric(38, 1) to output SQLSRV_SQLTYPE_DECIMAL(38, 1) is supported**** +****Conversion from numeric(38, 1) to output SQLSRV_SQLTYPE_NUMERIC(38, 1) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from numeric(38, 1) to output SQLSRV_SQLTYPE_DECIMAL(38, 1) is supported**** +****Conversion from numeric(38, 1) to output SQLSRV_SQLTYPE_NUMERIC(38, 1) is supported**** + +Testing numeric(38, 4): +Testing as SQLSRV_PARAM_OUT: +****Conversion from numeric(38, 4) to output SQLSRV_SQLTYPE_DECIMAL(38, 4) is supported**** +****Conversion from numeric(38, 4) to output SQLSRV_SQLTYPE_NUMERIC(38, 4) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from numeric(38, 4) to output SQLSRV_SQLTYPE_DECIMAL(38, 4) is supported**** +****Conversion from numeric(38, 4) to output SQLSRV_SQLTYPE_NUMERIC(38, 4) is supported**** + +Testing numeric(38, 16): +Testing as SQLSRV_PARAM_OUT: +****Conversion from numeric(38, 16) to output SQLSRV_SQLTYPE_DECIMAL(38, 16) is supported**** +****Conversion from numeric(38, 16) to output SQLSRV_SQLTYPE_NUMERIC(38, 16) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from numeric(38, 16) to output SQLSRV_SQLTYPE_DECIMAL(38, 16) is supported**** +****Conversion from numeric(38, 16) to output SQLSRV_SQLTYPE_NUMERIC(38, 16) is supported**** + +Testing numeric(38, 37): +Testing as SQLSRV_PARAM_OUT: +****Conversion from numeric(38, 37) to output SQLSRV_SQLTYPE_DECIMAL(38, 37) is supported**** +****Conversion from numeric(38, 37) to output SQLSRV_SQLTYPE_NUMERIC(38, 37) is supported**** +Testing as SQLSRV_PARAM_INOUT: +****Conversion from numeric(38, 37) to output SQLSRV_SQLTYPE_DECIMAL(38, 37) is supported**** +****Conversion from numeric(38, 37) to output SQLSRV_SQLTYPE_NUMERIC(38, 37) is supported**** \ No newline at end of file From b65d34fb237cc561cde314ad618aabbbaace0b8f Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Fri, 9 Mar 2018 17:42:43 -0800 Subject: [PATCH 3/5] fix char and nchar tests --- .../sqlsrv/sqlsrv_ae_output_param_sqltype_char_size.phpt | 2 +- .../sqlsrv/sqlsrv_ae_output_param_sqltype_nchar_size.phpt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_char_size.phpt b/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_char_size.phpt index b17def17..a27335fa 100644 --- a/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_char_size.phpt +++ b/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_char_size.phpt @@ -83,7 +83,7 @@ foreach($dataTypes as $dataType) { } } } else { - if (strpos($sqltypeFull, "VARCHAR") !== false && $dataType == "char" && $m > $n && strpos($sqltypeFull, "max") === false) { + if (strpos($sqltypeFull, "VARCHAR") !== false && $dataType == "char" && $m > $n && strpos($sqltypeFull, "max") === false && $dir == "SQLSRV_PARAM_OUT") { if ($r !== false) { echo "Conversions from $typeFull to output $sqltypeFull should not be supported\n"; } diff --git a/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_nchar_size.phpt b/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_nchar_size.phpt index a76a0d12..3ab7b31c 100644 --- a/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_nchar_size.phpt +++ b/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_nchar_size.phpt @@ -83,7 +83,7 @@ foreach($dataTypes as $dataType) { } } } else { - if (strpos($sqltypeFull, "NVARCHAR") !== false && $dataType == "nchar" && $m > $n && strpos($sqltypeFull, "max") === false) { + if (strpos($sqltypeFull, "NVARCHAR") !== false && $dataType == "nchar" && $m > $n && strpos($sqltypeFull, "max") === false && $dir == "SQLSRV_PARAM_OUT") { if ($r !== false) { echo "Conversions from $typeFull to output $sqltypeFull should not be supported\n"; } From e6af597cad1ae0d0864b2933e6e8b717fa65f523 Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Wed, 14 Mar 2018 10:55:36 -0700 Subject: [PATCH 4/5] use isDataEncrypted helper function for output tests --- .../sqlsrv/sqlsrv_ae_output_param_sqltype_binary_size.phpt | 4 ++-- .../sqlsrv/sqlsrv_ae_output_param_sqltype_char_size.phpt | 7 ++++--- .../sqlsrv_ae_output_param_sqltype_decimal_precision.phpt | 4 ++-- .../sqlsrv/sqlsrv_ae_output_param_sqltype_float_bits.phpt | 2 +- .../sqlsrv/sqlsrv_ae_output_param_sqltype_int_conv.phpt | 2 +- .../sqlsrv/sqlsrv_ae_output_param_sqltype_nchar_size.phpt | 4 ++-- 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_binary_size.phpt b/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_binary_size.phpt index 5416364f..0ca547f1 100644 --- a/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_binary_size.phpt +++ b/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_binary_size.phpt @@ -75,7 +75,7 @@ foreach($dataTypes as $dataType) { // with AE: should not work // without AE: should work, except when a SQLSRV_SQLTYPE_VARBINARY length (n) is less than a binary column length (m) for SQLSRV_PARAM_OUT if (($n != $m || $maxsqltype || $maxcol) && !($maxcol && $maxsqltype)) { - if (AE\isColEncrypted()) { + if (AE\isDataEncrypted()) { if ($r !== false) { var_dump($n); var_dump($m); @@ -87,7 +87,7 @@ foreach($dataTypes as $dataType) { } } } else { - if (strpos($sqltypeFull, "VARBINARY") !== false && $dataType == "binary" && $m > $n && strpos($sqltypeFull, "max") === false && $dir == "SQLSRV_PARAM_OUT") { + if (!AE\isColEncrypted() && strpos($sqltypeFull, "VARBINARY") !== false && $dataType == "binary" && $m > $n && strpos($sqltypeFull, "max") === false && $dir == "SQLSRV_PARAM_OUT") { if ($r !== false) { echo "Conversions from $typeFull to output $sqltypeFull should not be supported\n"; } diff --git a/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_char_size.phpt b/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_char_size.phpt index a27335fa..a2da785a 100644 --- a/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_char_size.phpt +++ b/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_char_size.phpt @@ -37,7 +37,7 @@ foreach($dataTypes as $dataType) { echo "\nTesting $typeFull:\n"; // create and populate table containing char(m) or varchar(m) columns - $tbname = "test_" . str_replace(array('(', ')'), '', $dataType) . $m; + $tbname = getTempTableName("test_" . str_replace(array('(', ')'), '', $dataType) . $m, false); $colMetaArr = array(new AE\ColumnMeta($typeFull, "c1", null, false)); AE\createTable($conn, $tbname, $colMetaArr); $stmt = AE\insertRow($conn, $tbname, array("c1" => $inputValue)); @@ -71,7 +71,7 @@ foreach($dataTypes as $dataType) { // with AE: should not work // without AE: should work, except when a SQLSRV_SQLTYPE_VARCHAR length (n) is less than a char column length (m) if (($n != $m || $maxsqltype || $maxcol) && !($maxcol && $maxsqltype)) { - if (AE\isColEncrypted()) { + if (AE\isDataEncrypted()) { if ($r !== false) { var_dump($n); var_dump($m); @@ -83,9 +83,10 @@ foreach($dataTypes as $dataType) { } } } else { - if (strpos($sqltypeFull, "VARCHAR") !== false && $dataType == "char" && $m > $n && strpos($sqltypeFull, "max") === false && $dir == "SQLSRV_PARAM_OUT") { + if (!AE\isColEncrypted() && strpos($sqltypeFull, "VARCHAR") !== false && $dataType == "char" && $m > $n && strpos($sqltypeFull, "max") === false && $dir == "SQLSRV_PARAM_OUT") { if ($r !== false) { echo "Conversions from $typeFull to output $sqltypeFull should not be supported\n"; + var_dump($c1); } } else { if ($r === false) { diff --git a/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_decimal_precision.phpt b/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_decimal_precision.phpt index 5a83b4ca..5a168581 100644 --- a/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_decimal_precision.phpt +++ b/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_decimal_precision.phpt @@ -77,7 +77,7 @@ foreach($dataTypes as $dataType) { $c_detOut = 0.0; $c_randOut = 0.0; - $stmt = sqlsrv_prepare($conn, $sql, array(array(&$c_detOut, constant($dir), SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), $sqltypeconst), array(&$c_randOut, constant($dir), SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), $sqltypeconst))); + $stmt = sqlsrv_prepare($conn, $sql, array(array(&$c_detOut, constant($dir), null, $sqltypeconst), array(&$c_randOut, constant($dir), null, $sqltypeconst))); $r = sqlsrv_execute($stmt); // check the case when the SQLSRV_SQLTYPE precision (n1) is not the same as the column precision (m1) @@ -85,7 +85,7 @@ foreach($dataTypes as $dataType) { // with AE: should not work // without AE: should not work if n1 - n2 < m1 - m2 if ($n1 != $m1 || $n2 != $m2) { - if (AE\isColEncrypted()) { + if (AE\isDataEncrypted()) { if ($r !== false) { echo "AE: Conversion from $typeFull to output $sqltypeFull should not be supported\n"; } else { diff --git a/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_float_bits.phpt b/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_float_bits.phpt index bbda75e6..3c9fe97c 100644 --- a/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_float_bits.phpt +++ b/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_float_bits.phpt @@ -47,7 +47,7 @@ foreach($bits as $m) { // with AE: should not work // without AE: should work if ($m < 25) { - if (AE\isColEncrypted()) { + if (AE\isDataEncrypted()) { if ($r !== false) { echo "AE: Conversion between $typeFull to output $sqlType should not be supported\n"; } else { diff --git a/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_int_conv.phpt b/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_int_conv.phpt index 310e21ab..589d2681 100644 --- a/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_int_conv.phpt +++ b/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_int_conv.phpt @@ -41,7 +41,7 @@ foreach ($dataTypes as $dataType) { // check the case if the column type is not the same as the SQLSRV_SQLTYPE if ($sqlType != "SQLSRV_SQLTYPE_" . strtoupper($dataType)) { - if (AE\isColEncrypted()) { + if (AE\isDataEncrypted()) { if ($r !== false) { echo "AE: Conversion from $dataType to output $sqlType should not be supported\n"; } else { diff --git a/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_nchar_size.phpt b/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_nchar_size.phpt index 3ab7b31c..c54ac50f 100644 --- a/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_nchar_size.phpt +++ b/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_nchar_size.phpt @@ -71,7 +71,7 @@ foreach($dataTypes as $dataType) { // with AE: should not work // without AE: should work, except when a SQLSRV_SQLTYPE_NVARCHAR length (n) is less than a nchar column length (m) if (($n != $m || $maxsqltype || $maxcol) && !($maxcol && $maxsqltype)) { - if (AE\isColEncrypted()) { + if (AE\isDataEncrypted()) { if ($r !== false) { var_dump($n); var_dump($m); @@ -83,7 +83,7 @@ foreach($dataTypes as $dataType) { } } } else { - if (strpos($sqltypeFull, "NVARCHAR") !== false && $dataType == "nchar" && $m > $n && strpos($sqltypeFull, "max") === false && $dir == "SQLSRV_PARAM_OUT") { + if (!AE\isColEncrypted() && strpos($sqltypeFull, "NVARCHAR") !== false && $dataType == "nchar" && $m > $n && strpos($sqltypeFull, "max") === false && $dir == "SQLSRV_PARAM_OUT") { if ($r !== false) { echo "Conversions from $typeFull to output $sqltypeFull should not be supported\n"; } From 600e338a1f548d2fadcf27a954a0ac4294c23367 Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Thu, 15 Mar 2018 13:08:04 -0700 Subject: [PATCH 5/5] address review comments --- ...v_ae_output_param_sqltype_binary_size.phpt | 19 +++++++++---------- ...srv_ae_output_param_sqltype_char_size.phpt | 19 +++++++++---------- ...utput_param_sqltype_decimal_precision.phpt | 17 +++++++++-------- ...rv_ae_output_param_sqltype_float_bits.phpt | 11 +++++++---- ...lsrv_ae_output_param_sqltype_int_conv.phpt | 7 ++++--- ...rv_ae_output_param_sqltype_nchar_size.phpt | 19 +++++++++---------- 6 files changed, 47 insertions(+), 45 deletions(-) diff --git a/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_binary_size.phpt b/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_binary_size.phpt index 0ca547f1..c264cb0f 100644 --- a/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_binary_size.phpt +++ b/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_binary_size.phpt @@ -26,10 +26,10 @@ $directions = array("SQLSRV_PARAM_OUT", "SQLSRV_PARAM_INOUT"); $inputValues = array("d", "f"); $conn = AE\connect(); -foreach($dataTypes as $dataType) { +foreach ($dataTypes as $dataType) { $maxcol = strpos($dataType, "(max)"); - foreach($lengths as $m) { - if ($maxcol !== false) { + foreach ($lengths as $m) { + if ($maxcol) { $typeFull = $dataType; } else { $typeFull = "$dataType($m)"; @@ -43,7 +43,7 @@ foreach($dataTypes as $dataType) { $inputs = array(new AE\BindParamOption($inputValues[0], null, "SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY)"), new AE\BindParamOption($inputValues[1], null, "SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY)")); $r; - $stmt = AE\insertRow($conn, $tbname, array("c_det" => $inputs[0], "c_rand" => $inputs[1]), $r, AE\INSERT_PREPARE_PARAMS); + $stmt = AE\insertRow($conn, $tbname, array($colMetaArr[0]->colName => $inputs[0], $colMetaArr[1]->colName => $inputs[1]), $r, AE\INSERT_PREPARE_PARAMS); // create a stored procedure and sql string for calling the stored procedure $spname = 'selectAllColumns'; @@ -51,14 +51,14 @@ foreach($dataTypes as $dataType) { $sql = AE\getCallProcSqlPlaceholders($spname, 2); // retrieve by specifying SQLSRV_SQLTYPE_BINARY(n) or SQLSRV_SQLTYPE_VARBINARY(n) as SQLSRV_PARAM_OUT or SQLSRV_PARAM_INOUT - foreach($directions as $dir) { + foreach ($directions as $dir) { echo "Testing as $dir:\n"; - foreach($sqlTypes as $sqlType) { + foreach ($sqlTypes as $sqlType) { $maxsqltype = strpos($sqlType, "max"); - foreach($sqltypeLengths as $n) { + foreach ($sqltypeLengths as $n) { $sqltypeconst; $sqltypeFull; - if ($maxsqltype !== false) { + if ($maxsqltype) { $sqltypeconst = SQLSRV_SQLTYPE_VARBINARY('max'); $sqltypeFull = $sqlType; } else { @@ -77,8 +77,6 @@ foreach($dataTypes as $dataType) { if (($n != $m || $maxsqltype || $maxcol) && !($maxcol && $maxsqltype)) { if (AE\isDataEncrypted()) { if ($r !== false) { - var_dump($n); - var_dump($m); echo "AE: Conversion from $typeFull to output $sqltypeFull should not be supported\n"; } else { if (sqlsrv_errors()[0]['SQLSTATE'] != "22018") { @@ -121,6 +119,7 @@ foreach($dataTypes as $dataType) { } } } + dropProc($conn, $spname); dropTable($conn, $tbname); } } diff --git a/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_char_size.phpt b/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_char_size.phpt index a2da785a..2a62659d 100644 --- a/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_char_size.phpt +++ b/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_char_size.phpt @@ -26,10 +26,10 @@ $directions = array("SQLSRV_PARAM_OUT", "SQLSRV_PARAM_INOUT"); $inputValue = "d"; $conn = AE\connect(); -foreach($dataTypes as $dataType) { +foreach ($dataTypes as $dataType) { $maxcol = strpos($dataType, "(max)"); - foreach($lengths as $m) { - if ($maxcol !== false) { + foreach ($lengths as $m) { + if ($maxcol) { $typeFull = $dataType; } else { $typeFull = "$dataType($m)"; @@ -40,7 +40,7 @@ foreach($dataTypes as $dataType) { $tbname = getTempTableName("test_" . str_replace(array('(', ')'), '', $dataType) . $m, false); $colMetaArr = array(new AE\ColumnMeta($typeFull, "c1", null, false)); AE\createTable($conn, $tbname, $colMetaArr); - $stmt = AE\insertRow($conn, $tbname, array("c1" => $inputValue)); + $stmt = AE\insertRow($conn, $tbname, array($colMetaArr[0]->colName => $inputValue)); // create a stored procedure and sql string for calling the stored procedure $spname = 'selectAllColumns'; @@ -48,14 +48,14 @@ foreach($dataTypes as $dataType) { $sql = AE\getCallProcSqlPlaceholders($spname, 1); // retrieve by specifying SQLSRV_SQLTYPE_CHAR(n) or SQLSRV_SQLTYPE_VARCHAR(n) as SQLSRV_PARAM_OUT or SQLSRV_PARAM_INOUT - foreach($directions as $dir) { + foreach ($directions as $dir) { echo "Testing as $dir:\n"; - foreach($sqlTypes as $sqlType) { + foreach ($sqlTypes as $sqlType) { $maxsqltype = strpos($sqlType, "max"); - foreach($sqltypeLengths as $n) { + foreach ($sqltypeLengths as $n) { $sqltypeconst; $sqltypeFull; - if ($maxsqltype !== false) { + if ($maxsqltype) { $sqltypeconst = SQLSRV_SQLTYPE_VARCHAR('max'); $sqltypeFull = $sqlType; } else { @@ -73,8 +73,6 @@ foreach($dataTypes as $dataType) { if (($n != $m || $maxsqltype || $maxcol) && !($maxcol && $maxsqltype)) { if (AE\isDataEncrypted()) { if ($r !== false) { - var_dump($n); - var_dump($m); echo "AE: Conversion from $typeFull to output $sqltypeFull should not be supported\n"; } else { if (sqlsrv_errors()[0]['SQLSTATE'] != "22018") { @@ -117,6 +115,7 @@ foreach($dataTypes as $dataType) { } } } + dropProc($conn, $spname); dropTable($conn, $tbname); } } diff --git a/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_decimal_precision.phpt b/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_decimal_precision.phpt index 5a168581..06021dbe 100644 --- a/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_decimal_precision.phpt +++ b/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_decimal_precision.phpt @@ -25,9 +25,9 @@ $directions = array("SQLSRV_PARAM_OUT", "SQLSRV_PARAM_INOUT"); $conn = AE\connect(); -foreach($dataTypes as $dataType) { - foreach($precisions as $m1 => $inScales) { - foreach($inScales as $m2) { +foreach ($dataTypes as $dataType) { + foreach ($precisions as $m1 => $inScales) { + foreach ($inScales as $m2) { // change the number of integers in the input values to be $m1 - $m2 $precDiff = $maxInPrecision - ($m1 - $m2); $inputValues = $inputValuesInit; @@ -41,7 +41,7 @@ foreach($dataTypes as $dataType) { $tbname = "test_" . $dataType . $m1 . $m2; $colMetaArr = array(new AE\ColumnMeta($typeFull, "c_det"), new AE\ColumnMeta($typeFull, "c_rand", null, false)); AE\createTable($conn, $tbname, $colMetaArr); - $stmt = AE\insertRow($conn, $tbname, array("c_det" => $inputValues[0], "c_rand" => $inputValues[1])); + $stmt = AE\insertRow($conn, $tbname, array($colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1])); // create a stored procedure and sql string for calling the stored procedure $spname = 'selectAllColumns'; @@ -49,11 +49,11 @@ foreach($dataTypes as $dataType) { $sql = AE\getCallProcSqlPlaceholders($spname, 2); // retrieve by specifying SQLSRV_SQLTYPE_DECIMAL(n1, n2) or SQLSRV_SQLTYPE_NUMERIC(n1, n2) as SQLSRV_PARAM_OUT or SQLSRV_PARAM_INOUT - foreach($directions as $dir) { + foreach ($directions as $dir) { echo "Testing as $dir:\n"; - foreach($sqlTypes as $sqlType) { - foreach($sqltypePrecisions as $n1 => $sqltypeScales) { - foreach($sqltypeScales as $n2) { + foreach ($sqlTypes as $sqlType) { + foreach ($sqltypePrecisions as $n1 => $sqltypeScales) { + foreach ($sqltypeScales as $n2) { // compute the epsilon for comparing doubles // float in PHP only has a precision of roughtly 14 digits: http://php.net/manual/en/language.types.float.php @@ -128,6 +128,7 @@ foreach($dataTypes as $dataType) { } } } + dropProc($conn, $spname); dropTable($conn, $tbname); } } diff --git a/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_float_bits.phpt b/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_float_bits.phpt index 3c9fe97c..54a90bfe 100644 --- a/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_float_bits.phpt +++ b/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_float_bits.phpt @@ -19,7 +19,7 @@ $directions = array("SQLSRV_PARAM_OUT", "SQLSRV_PARAM_INOUT"); $epsilon = 100000; $conn = AE\connect(); -foreach($bits as $m) { +foreach ($bits as $m) { $typeFull = "$dataType($m)"; echo "\nTesting $typeFull:\n"; @@ -27,7 +27,7 @@ foreach($bits as $m) { $tbname = "test_" . $dataType . $m; $colMetaArr = array(new AE\ColumnMeta($typeFull, "c_det"), new AE\ColumnMeta($typeFull, "c_rand", null, false)); AE\createTable($conn, $tbname, $colMetaArr); - $stmt = AE\insertRow($conn, $tbname, array("c_det" => $inputValues[0], "c_rand" => $inputValues[1])); + $stmt = AE\insertRow($conn, $tbname, array($colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1])); // create a stored procedure and sql string for calling the stored procedure $spname = 'selectAllColumns'; @@ -35,7 +35,7 @@ foreach($bits as $m) { $sql = AE\getCallProcSqlPlaceholders($spname, 2); // retrieve by specifying SQLSRV_SQLTYPE_FLOAT as SQLSRV_PARAM_OUT or SQLSRV_PARAM_INOUT - foreach($directions as $dir) { + foreach ($directions as $dir) { echo "Testing as $dir:\n"; $c_detOut = 0.0; @@ -44,7 +44,9 @@ foreach($bits as $m) { $r = sqlsrv_execute($stmt); // check the case when the column number of bits is less than 25 - // with AE: should not work + // when the number of bits is between 1 and 24, it corresponds to a storage size of 4 bytes + // when the number of bits is between 25 and 53, it corresponds to a storage size of 8 bytes + // with AE: should not work because SQLSRV_SQLTYPE_FLOAT maps to float(53) and conversion from a larger float to a smaller float is not supported // without AE: should work if ($m < 25) { if (AE\isDataEncrypted()) { @@ -85,6 +87,7 @@ foreach($bits as $m) { // cleanup sqlsrv_free_stmt($stmt); } + dropProc($conn, $spname); dropTable($conn, $tbname); } sqlsrv_close($conn); diff --git a/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_int_conv.phpt b/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_int_conv.phpt index 589d2681..a8bfb2ea 100644 --- a/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_int_conv.phpt +++ b/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_int_conv.phpt @@ -23,7 +23,7 @@ foreach ($dataTypes as $dataType) { $tbname = "test_" . $dataType; $colMetaArr = array( new AE\ColumnMeta($dataType, "c_det"), new AE\ColumnMeta($dataType, "c_rand", null, false)); AE\createTable($conn, $tbname, $colMetaArr); - $stmt = AE\insertRow($conn, $tbname, array("c_det" => $inputValues[0], "c_rand" => $inputValues[1])); + $stmt = AE\insertRow($conn, $tbname, array($colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1])); // create a stored procedure and sql string for calling the stored procedure $spname = 'selectAllColumns'; @@ -31,9 +31,9 @@ foreach ($dataTypes as $dataType) { $sql = AE\getCallProcSqlPlaceholders($spname, 2); // retrieve by specifying different SQLSRV_SQLTYPE ingeter constants as SQLSRV_PARAM_OUT or SQLSRV_PARAM_INOUT - foreach($directions as $dir) { + foreach ($directions as $dir) { echo "Testing as $dir:\n"; - foreach($sqlTypes as $sqlType) { + foreach ($sqlTypes as $sqlType) { $c_detOut = 0; $c_randOut = 0; $stmt = sqlsrv_prepare($conn, $sql, array(array(&$c_detOut, constant($dir), null, constant($sqlType)), array(&$c_randOut, constant($dir), null, constant($sqlType)))); @@ -75,6 +75,7 @@ foreach ($dataTypes as $dataType) { sqlsrv_free_stmt($stmt); } } + dropProc($conn, $spname); dropTable($conn, $tbname); } sqlsrv_close($conn); diff --git a/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_nchar_size.phpt b/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_nchar_size.phpt index c54ac50f..9efc3cc9 100644 --- a/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_nchar_size.phpt +++ b/test/functional/sqlsrv/sqlsrv_ae_output_param_sqltype_nchar_size.phpt @@ -26,10 +26,10 @@ $directions = array("SQLSRV_PARAM_OUT", "SQLSRV_PARAM_INOUT"); $inputValue = "d"; $conn = AE\connect(); -foreach($dataTypes as $dataType) { +foreach ($dataTypes as $dataType) { $maxcol = strpos($dataType, "(max)"); - foreach($lengths as $m) { - if ($maxcol !== false) { + foreach ($lengths as $m) { + if ($maxcol) { $typeFull = $dataType; } else { $typeFull = "$dataType($m)"; @@ -40,7 +40,7 @@ foreach($dataTypes as $dataType) { $tbname = "test_" . str_replace(array('(', ')'), '', $dataType) . $m; $colMetaArr = array(new AE\ColumnMeta($typeFull, "c1", null, false)); AE\createTable($conn, $tbname, $colMetaArr); - $stmt = AE\insertRow($conn, $tbname, array("c1" => $inputValue)); + $stmt = AE\insertRow($conn, $tbname, array($colMetaArr[0]->colName => $inputValue)); // create a stored procedure and sql string for calling the stored procedure $spname = 'selectAllColumns'; @@ -48,14 +48,14 @@ foreach($dataTypes as $dataType) { $sql = AE\getCallProcSqlPlaceholders($spname, 1); // retrieve by specifying SQLSRV_SQLTYPE_NCHAR(n) or SQLSRV_SQLTYPE_NVARCHAR(n) as SQLSRV_PARAM_OUT or SQLSRV_PARAM_INOUT - foreach($directions as $dir) { + foreach ($directions as $dir) { echo "Testing as $dir:\n"; - foreach($sqlTypes as $sqlType) { + foreach ($sqlTypes as $sqlType) { $maxsqltype = strpos($sqlType, "max"); - foreach($sqltypeLengths as $n) { + foreach ($sqltypeLengths as $n) { $sqltypeconst; $sqltypeFull; - if ($maxsqltype !== false) { + if ($maxsqltype) { $sqltypeconst = SQLSRV_SQLTYPE_NVARCHAR('max'); $sqltypeFull = $sqlType; } else { @@ -73,8 +73,6 @@ foreach($dataTypes as $dataType) { if (($n != $m || $maxsqltype || $maxcol) && !($maxcol && $maxsqltype)) { if (AE\isDataEncrypted()) { if ($r !== false) { - var_dump($n); - var_dump($m); echo "AE: Conversion from $typeFull to output $sqltypeFull should not be supported\n"; } else { if (sqlsrv_errors()[0]['SQLSTATE'] != "22018") { @@ -116,6 +114,7 @@ foreach($dataTypes as $dataType) { } } } + dropProc($conn, $spname); dropTable($conn, $tbname); } }