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