polich PDO side ae related tests

This commit is contained in:
v-kaywon 2018-03-02 16:34:47 -08:00
parent 239d71569c
commit 03845da0c8
15 changed files with 1141 additions and 1514 deletions

View file

@ -1,7 +1,10 @@
--TEST-- --TEST--
Test for inserting and retrieving encrypted data of numeric types Test for retrieving encrypted data from binary types columns using PDO::bindColumn
--DESCRIPTION-- --DESCRIPTION--
Use PDOstatement::bindParam with all PDO::PARAM_ types Test conversion from binary types column to output of PDO::PARAM types
With or without AE, conversion works if:
1. From any binary type column to PDO::PARAM_STR
2. From any binary type column to PDO::PARAM_LOB
--SKIPIF-- --SKIPIF--
<?php require('skipif_mid-refactor.inc'); ?> <?php require('skipif_mid-refactor.inc'); ?>
--FILE-- --FILE--
@ -15,25 +18,24 @@ $lengths = array(1, 8, 64, 512, 4000);
try { try {
$conn = connect("", array(), PDO::ERRMODE_SILENT); $conn = connect("", array(), PDO::ERRMODE_SILENT);
foreach ($dataTypes as $dataType) { foreach ($dataTypes as $dataType) {
$maxtype = strpos($dataType, "(max)"); $maxcol = strpos($dataType, "(max)");
foreach ($lengths as $length) { foreach ($lengths as $m) {
if ($maxtype !== false) { if ($maxcol !== false) {
$type = $dataType; $typeFull = $dataType;
} else { } else {
$type = "$dataType($length)"; $typeFull = "$dataType($m)";
} }
echo "\nTesting $type:\n"; echo "\nTesting $typeFull:\n";
//create and populate table //create and populate table containing binary(m) or varbinary(m) columns
$tbname = "test_binary"; $tbname = "test_" . str_replace(array('(', ')'), '', $dataType) . $m;
$colMetaArr = array(new ColumnMeta($type, "c_det"), new ColumnMeta($type, "c_rand", null, "randomized")); $colMetaArr = array(new ColumnMeta($typeFull, "c_det"), new ColumnMeta($typeFull, "c_rand", null, "randomized"));
createTable($conn, $tbname, $colMetaArr); createTable($conn, $tbname, $colMetaArr);
$input0 = str_repeat("d", $length); $inputValues = array(str_repeat("d", $m), str_repeat("r", $m));
$input1 = str_repeat("r", $length); insertRow($conn, $tbname, array("c_det" => new BindParamOp(1, $inputValues[0], "PDO::PARAM_LOB", 0, "PDO::SQLSRV_ENCODING_BINARY"),
insertRow($conn, $tbname, array("c_det" => new BindParamOp(1, $input0, "PDO::PARAM_LOB", 0, "PDO::SQLSRV_ENCODING_BINARY"), "c_rand" => new BindParamOp(2, $inputValues[1], "PDO::PARAM_LOB", 0, "PDO::SQLSRV_ENCODING_BINARY")), "prepareBindParam");
"c_rand" => new BindParamOp(2, $input1, "PDO::PARAM_LOB", 0, "PDO::SQLSRV_ENCODING_BINARY")), "prepareBindParam");
// fetch with PDO::bindColumn and PDO::FETCH_BOUND // fetch by specifying PDO::PARAM_ types with PDO::bindColumn
$query = "SELECT c_det, c_rand FROM $tbname"; $query = "SELECT c_det, c_rand FROM $tbname";
foreach ($pdoParamTypes as $pdoParamType) { foreach ($pdoParamTypes as $pdoParamType) {
$det = ""; $det = "";
@ -44,19 +46,23 @@ try {
$stmt->bindColumn('c_rand', $rand, constant($pdoParamType)); $stmt->bindColumn('c_rand', $rand, constant($pdoParamType));
$row = $stmt->fetch(PDO::FETCH_BOUND); $row = $stmt->fetch(PDO::FETCH_BOUND);
// check the case when fetching as PDO::PARAM_BOOL, PDO::PARAM_NULL or PDO::PARAM_INT
// with or without AE: should not work
if ($pdoParamType == "PDO::PARAM_BOOL" || $pdoParamType == "PDO::PARAM_NULL" || $pdoParamType == "PDO::PARAM_INT") { if ($pdoParamType == "PDO::PARAM_BOOL" || $pdoParamType == "PDO::PARAM_NULL" || $pdoParamType == "PDO::PARAM_INT") {
if (!is_null($det) || !is_null($rand)) { if (!is_null($det) || !is_null($rand)) {
echo "Retrieving encrypted $type data as $pdoParamType should not work\n"; echo "Retrieving $typeFull data as $pdoParamType should not be supported\n";
} }
// check the case when fetching as PDO::PARAM_STR or PDO::PARAM_LOB
// with or without AE: should work
} else { } else {
if (strlen($det) == $length && strlen($rand) == $length) { if (strlen($det) == $m && strlen($rand) == $m) {
echo "****PDO param type $pdoParamType is compatible with encrypted $type****\n"; echo "****Retrieving $typeFull data as $pdoParamType is supported****\n";
} else { } else {
echo "Data corruption when fetching encrypted $type as PDO param type $pdoParamType\n"; echo "Retrieving $typeFull data as $pdoParamType fails\n";
print_r($stmt->errorInfo());
} }
} }
} }
// cleanup
dropTable($conn, $tbname); dropTable($conn, $tbname);
} }
} }
@ -68,61 +74,61 @@ try {
?> ?>
--EXPECT-- --EXPECT--
Testing binary(1): Testing binary(1):
****PDO param type PDO::PARAM_STR is compatible with encrypted binary(1)**** ****Retrieving binary(1) data as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with encrypted binary(1)**** ****Retrieving binary(1) data as PDO::PARAM_LOB is supported****
Testing binary(8): Testing binary(8):
****PDO param type PDO::PARAM_STR is compatible with encrypted binary(8)**** ****Retrieving binary(8) data as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with encrypted binary(8)**** ****Retrieving binary(8) data as PDO::PARAM_LOB is supported****
Testing binary(64): Testing binary(64):
****PDO param type PDO::PARAM_STR is compatible with encrypted binary(64)**** ****Retrieving binary(64) data as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with encrypted binary(64)**** ****Retrieving binary(64) data as PDO::PARAM_LOB is supported****
Testing binary(512): Testing binary(512):
****PDO param type PDO::PARAM_STR is compatible with encrypted binary(512)**** ****Retrieving binary(512) data as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with encrypted binary(512)**** ****Retrieving binary(512) data as PDO::PARAM_LOB is supported****
Testing binary(4000): Testing binary(4000):
****PDO param type PDO::PARAM_STR is compatible with encrypted binary(4000)**** ****Retrieving binary(4000) data as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with encrypted binary(4000)**** ****Retrieving binary(4000) data as PDO::PARAM_LOB is supported****
Testing varbinary(1): Testing varbinary(1):
****PDO param type PDO::PARAM_STR is compatible with encrypted varbinary(1)**** ****Retrieving varbinary(1) data as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with encrypted varbinary(1)**** ****Retrieving varbinary(1) data as PDO::PARAM_LOB is supported****
Testing varbinary(8): Testing varbinary(8):
****PDO param type PDO::PARAM_STR is compatible with encrypted varbinary(8)**** ****Retrieving varbinary(8) data as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with encrypted varbinary(8)**** ****Retrieving varbinary(8) data as PDO::PARAM_LOB is supported****
Testing varbinary(64): Testing varbinary(64):
****PDO param type PDO::PARAM_STR is compatible with encrypted varbinary(64)**** ****Retrieving varbinary(64) data as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with encrypted varbinary(64)**** ****Retrieving varbinary(64) data as PDO::PARAM_LOB is supported****
Testing varbinary(512): Testing varbinary(512):
****PDO param type PDO::PARAM_STR is compatible with encrypted varbinary(512)**** ****Retrieving varbinary(512) data as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with encrypted varbinary(512)**** ****Retrieving varbinary(512) data as PDO::PARAM_LOB is supported****
Testing varbinary(4000): Testing varbinary(4000):
****PDO param type PDO::PARAM_STR is compatible with encrypted varbinary(4000)**** ****Retrieving varbinary(4000) data as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with encrypted varbinary(4000)**** ****Retrieving varbinary(4000) data as PDO::PARAM_LOB is supported****
Testing varbinary(max): Testing varbinary(max):
****PDO param type PDO::PARAM_STR is compatible with encrypted varbinary(max)**** ****Retrieving varbinary(max) data as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with encrypted varbinary(max)**** ****Retrieving varbinary(max) data as PDO::PARAM_LOB is supported****
Testing varbinary(max): Testing varbinary(max):
****PDO param type PDO::PARAM_STR is compatible with encrypted varbinary(max)**** ****Retrieving varbinary(max) data as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with encrypted varbinary(max)**** ****Retrieving varbinary(max) data as PDO::PARAM_LOB is supported****
Testing varbinary(max): Testing varbinary(max):
****PDO param type PDO::PARAM_STR is compatible with encrypted varbinary(max)**** ****Retrieving varbinary(max) data as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with encrypted varbinary(max)**** ****Retrieving varbinary(max) data as PDO::PARAM_LOB is supported****
Testing varbinary(max): Testing varbinary(max):
****PDO param type PDO::PARAM_STR is compatible with encrypted varbinary(max)**** ****Retrieving varbinary(max) data as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with encrypted varbinary(max)**** ****Retrieving varbinary(max) data as PDO::PARAM_LOB is supported****
Testing varbinary(max): Testing varbinary(max):
****PDO param type PDO::PARAM_STR is compatible with encrypted varbinary(max)**** ****Retrieving varbinary(max) data as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with encrypted varbinary(max)**** ****Retrieving varbinary(max) data as PDO::PARAM_LOB is supported****

View file

@ -1,7 +1,10 @@
--TEST-- --TEST--
Test for inserting and retrieving encrypted data of numeric types Test for retrieving encrypted data from char types columns using PDO::bindColumn
--DESCRIPTION-- --DESCRIPTION--
Use PDOstatement::bindParam with all PDO::PARAM_ types Test conversion from char types column to output of PDO::PARAM types
With or without AE, conversion works if:
1. From any char type column to PDO::PARAM_STR
2. From any char type column to PDO::PARAM_LOB
--SKIPIF-- --SKIPIF--
<?php require('skipif_mid-refactor.inc'); ?> <?php require('skipif_mid-refactor.inc'); ?>
--FILE-- --FILE--
@ -11,52 +14,54 @@ require_once("AEData.inc");
$dataTypes = array("char", "varchar", "varchar(max)"); $dataTypes = array("char", "varchar", "varchar(max)");
$lengths = array(1, 8, 64, 512, 4096, 8000); $lengths = array(1, 8, 64, 512, 4096, 8000);
$encTypes = array("deterministic", "randomized");
try { try {
$conn = connect("", array(), PDO::ERRMODE_SILENT); $conn = connect("", array(), PDO::ERRMODE_SILENT);
foreach ($dataTypes as $dataType) { foreach ($dataTypes as $dataType) {
$maxtype = strpos($dataType, "(max)"); $maxcol = strpos($dataType, "(max)");
foreach ($lengths as $length) { foreach ($lengths as $m) {
if ($maxtype !== false) { if ($maxcol !== false) {
$type = $dataType; $typeFull = $dataType;
} else { } else {
$type = "$dataType($length)"; $typeFull = "$dataType($m)";
} }
echo "\nTesting $type:\n"; echo "\nTesting $typeFull:\n";
//create and populate table //create and populate table containing char(m) or varchar(m) columns
foreach($encTypes as $encType) { $tbname = "test_" . str_replace(array('(', ')'), '', $dataType) . $m;
$tbname = getTableName(); $colMetaArr = array(new ColumnMeta($typeFull, "c1", null, "ramdomized"));
$colMetaArr = array(new ColumnMeta($type, "c1", null, $encType)); createTable($conn, $tbname, $colMetaArr);
createTable($conn, $tbname, $colMetaArr); $inputValue = str_repeat("d", $m);
$input = str_repeat("d", $length); insertRow($conn, $tbname, array("c1" => $inputValue));
insertRow($conn, $tbname, array("c1" => $input));
// fetch with PDO::bindColumn and PDO::FETCH_BOUND // fetch by specifying PDO::PARAM_ types with PDO::bindColumn
$query = "SELECT c1 FROM $tbname"; $query = "SELECT c1 FROM $tbname";
foreach ($pdoParamTypes as $pdoParamType) { foreach ($pdoParamTypes as $pdoParamType) {
$det = ""; $det = "";
$rand = ""; $rand = "";
$stmt = $conn->prepare($query); $stmt = $conn->prepare($query);
$stmt->execute(); $stmt->execute();
$stmt->bindColumn('c1', $c1, constant($pdoParamType)); $stmt->bindColumn('c1', $c1, constant($pdoParamType));
$row = $stmt->fetch(PDO::FETCH_BOUND); $row = $stmt->fetch(PDO::FETCH_BOUND);
if ($pdoParamType == "PDO::PARAM_BOOL" || $pdoParamType == "PDO::PARAM_NULL" || $pdoParamType == "PDO::PARAM_INT") { // check the case when fetching as PDO::PARAM_BOOL, PDO::PARAM_NULL or PDO::PARAM_INT
if (!empty($det) || !empty($rand)) { // with or without AE: should not work
echo "Fetching $type as PDO param type $pdoParamType should be empty\n"; if ($pdoParamType == "PDO::PARAM_BOOL" || $pdoParamType == "PDO::PARAM_NULL" || $pdoParamType == "PDO::PARAM_INT") {
} if (!empty($det) || !empty($rand)) {
echo "Retrieving $typeFull data as $pdoParamType should not be supported\n";
}
// check the case when fetching as PDO::PARAM_STR or PDO::PARAM_LOB
// with or without AE: should work
} else {
if (strlen($c1) == $m) {
echo "****Retrieving $typeFull as $pdoParamType is supported****\n";
} else { } else {
if (strlen($c1) == $length) { echo "Retrieving $typeFull as $pdoParamType fails\n";
echo "****PDO param type $pdoParamType is compatible with $encType encrypted $type****\n";
} else {
echo "PDO param type $pdoParamType is incompatible with $encType encrypted $type\n";
}
} }
} }
dropTable($conn, $tbname);
} }
// cleanup
dropTable($conn, $tbname);
} }
} }
unset($stmt); unset($stmt);
@ -67,109 +72,73 @@ try {
?> ?>
--EXPECT-- --EXPECT--
Testing char(1): Testing char(1):
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted char(1)**** ****Retrieving char(1) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted char(1)**** ****Retrieving char(1) as PDO::PARAM_LOB is supported****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted char(1)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted char(1)****
Testing char(8): Testing char(8):
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted char(8)**** ****Retrieving char(8) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted char(8)**** ****Retrieving char(8) as PDO::PARAM_LOB is supported****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted char(8)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted char(8)****
Testing char(64): Testing char(64):
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted char(64)**** ****Retrieving char(64) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted char(64)**** ****Retrieving char(64) as PDO::PARAM_LOB is supported****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted char(64)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted char(64)****
Testing char(512): Testing char(512):
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted char(512)**** ****Retrieving char(512) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted char(512)**** ****Retrieving char(512) as PDO::PARAM_LOB is supported****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted char(512)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted char(512)****
Testing char(4096): Testing char(4096):
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted char(4096)**** ****Retrieving char(4096) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted char(4096)**** ****Retrieving char(4096) as PDO::PARAM_LOB is supported****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted char(4096)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted char(4096)****
Testing char(8000): Testing char(8000):
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted char(8000)**** ****Retrieving char(8000) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted char(8000)**** ****Retrieving char(8000) as PDO::PARAM_LOB is supported****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted char(8000)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted char(8000)****
Testing varchar(1): Testing varchar(1):
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted varchar(1)**** ****Retrieving varchar(1) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted varchar(1)**** ****Retrieving varchar(1) as PDO::PARAM_LOB is supported****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted varchar(1)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted varchar(1)****
Testing varchar(8): Testing varchar(8):
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted varchar(8)**** ****Retrieving varchar(8) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted varchar(8)**** ****Retrieving varchar(8) as PDO::PARAM_LOB is supported****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted varchar(8)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted varchar(8)****
Testing varchar(64): Testing varchar(64):
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted varchar(64)**** ****Retrieving varchar(64) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted varchar(64)**** ****Retrieving varchar(64) as PDO::PARAM_LOB is supported****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted varchar(64)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted varchar(64)****
Testing varchar(512): Testing varchar(512):
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted varchar(512)**** ****Retrieving varchar(512) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted varchar(512)**** ****Retrieving varchar(512) as PDO::PARAM_LOB is supported****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted varchar(512)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted varchar(512)****
Testing varchar(4096): Testing varchar(4096):
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted varchar(4096)**** ****Retrieving varchar(4096) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted varchar(4096)**** ****Retrieving varchar(4096) as PDO::PARAM_LOB is supported****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted varchar(4096)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted varchar(4096)****
Testing varchar(8000): Testing varchar(8000):
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted varchar(8000)**** ****Retrieving varchar(8000) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted varchar(8000)**** ****Retrieving varchar(8000) as PDO::PARAM_LOB is supported****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted varchar(8000)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted varchar(8000)****
Testing varchar(max): Testing varchar(max):
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted varchar(max)**** ****Retrieving varchar(max) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted varchar(max)**** ****Retrieving varchar(max) as PDO::PARAM_LOB is supported****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted varchar(max)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted varchar(max)****
Testing varchar(max): Testing varchar(max):
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted varchar(max)**** ****Retrieving varchar(max) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted varchar(max)**** ****Retrieving varchar(max) as PDO::PARAM_LOB is supported****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted varchar(max)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted varchar(max)****
Testing varchar(max): Testing varchar(max):
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted varchar(max)**** ****Retrieving varchar(max) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted varchar(max)**** ****Retrieving varchar(max) as PDO::PARAM_LOB is supported****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted varchar(max)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted varchar(max)****
Testing varchar(max): Testing varchar(max):
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted varchar(max)**** ****Retrieving varchar(max) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted varchar(max)**** ****Retrieving varchar(max) as PDO::PARAM_LOB is supported****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted varchar(max)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted varchar(max)****
Testing varchar(max): Testing varchar(max):
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted varchar(max)**** ****Retrieving varchar(max) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted varchar(max)**** ****Retrieving varchar(max) as PDO::PARAM_LOB is supported****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted varchar(max)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted varchar(max)****
Testing varchar(max): Testing varchar(max):
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted varchar(max)**** ****Retrieving varchar(max) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted varchar(max)**** ****Retrieving varchar(max) as PDO::PARAM_LOB is supported****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted varchar(max)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted varchar(max)****

View file

@ -1,7 +1,10 @@
--TEST-- --TEST--
Test for inserting and retrieving encrypted data of datetime types Test for retrieving encrypted data from datetime types columns using PDO::bindColumn
--DESCRIPTION-- --DESCRIPTION--
Use PDOstatement::bindParam with all PDO::PARAM_ types Test conversion from datetime types column to output of PDO::PARAM types
With or without AE, conversion works if:
1. From any datetime type column to PDO::PARAM_STR
2. From any datetime type column to PDO::PARAM_LOB
--SKIPIF-- --SKIPIF--
<?php require('skipif_mid-refactor.inc'); ?> <?php require('skipif_mid-refactor.inc'); ?>
--FILE-- --FILE--
@ -10,19 +13,20 @@ require_once("MsCommon_mid-refactor.inc");
require_once("AEData.inc"); require_once("AEData.inc");
$dataTypes = array("date", "datetime", "smalldatetime"); $dataTypes = array("date", "datetime", "smalldatetime");
try { try {
$conn = connect("", array(), PDO::ERRMODE_SILENT); $conn = connect("", array(), PDO::ERRMODE_SILENT);
foreach ($dataTypes as $dataType) { foreach ($dataTypes as $dataType) {
echo "\nTesting $dataType:\n"; echo "\nTesting $dataType:\n";
// create and populate table // create and populate table containing date, datetime or smalldatetime columns
$tbname = getTableName(); $tbname = "test_" . $dataType;
$colMetaArr = array(new ColumnMeta($dataType, "c_det"), new ColumnMeta($dataType, "c_rand", null, "randomized")); $colMetaArr = array(new ColumnMeta($dataType, "c_det"), new ColumnMeta($dataType, "c_rand", null, "randomized"));
createTable($conn, $tbname, $colMetaArr); createTable($conn, $tbname, $colMetaArr);
$inputValues = array_slice(${explode("(", $dataType)[0] . "_params"}, 1, 2); $inputValues = array_slice(${explode("(", $dataType)[0] . "_params"}, 1, 2);
insertRow($conn, $tbname, array("c_det" => $inputValues[0], "c_rand" => $inputValues[1])); insertRow($conn, $tbname, array("c_det" => $inputValues[0], "c_rand" => $inputValues[1]));
// fetch with PDO::bindColumn and PDO::FETCH_BOUND // fetch by specifying PDO::PARAM_ types with PDO::bindColumn
$query = "SELECT c_det, c_rand FROM $tbname"; $query = "SELECT c_det, c_rand FROM $tbname";
foreach ($pdoParamTypes as $pdoParamType) { foreach ($pdoParamTypes as $pdoParamType) {
$det = ""; $det = "";
@ -33,16 +37,23 @@ try {
$stmt->bindColumn('c_rand', $rand, constant($pdoParamType)); $stmt->bindColumn('c_rand', $rand, constant($pdoParamType));
$row = $stmt->fetch(PDO::FETCH_BOUND); $row = $stmt->fetch(PDO::FETCH_BOUND);
// check the case when fetching as PDO::PARAM_BOOL, PDO::PARAM_NULL or PDO::PARAM_INT
// with or without AE; should not work
if ($pdoParamType == "PDO::PARAM_BOOL" || $pdoParamType == "PDO::PARAM_NULL" || $pdoParamType == "PDO::PARAM_INT") { if ($pdoParamType == "PDO::PARAM_BOOL" || $pdoParamType == "PDO::PARAM_NULL" || $pdoParamType == "PDO::PARAM_INT") {
if (!is_null($det) || !is_null($rand)) { if (!is_null($det) || !is_null($rand)) {
echo "Retrieving encrypted $type data as $pdoParamType should not work\n"; echo "Retrieving $dataType data as $pdoParamType should not be supported\n";
} }
// check the case when fetching as PDO::PARAM_STR or PDO::PARAM_LOB
// with or without AE: should work
} else { } else {
echo "****PDO param type $pdoParamType is compatible with encrypted $dataType****\n"; if (strpos($det, $inputValues[0]) !== false && strpos($rand, $inputValues[1]) !== false) {
echo "c_det: $det\n"; echo "****Retrieving $dataType as $pdoParamType is supported****\n";
echo "c_rand: $rand\n"; } else {
echo "Retrieving $dataType as $pdoParamType fails\n";
}
} }
} }
// cleanup
dropTable($conn, $tbname); dropTable($conn, $tbname);
} }
unset($stmt); unset($stmt);
@ -53,25 +64,13 @@ try {
?> ?>
--EXPECT-- --EXPECT--
Testing date: Testing date:
****PDO param type PDO::PARAM_STR is compatible with encrypted date**** ****Retrieving date as PDO::PARAM_STR is supported****
c_det: 0001-01-01 ****Retrieving date as PDO::PARAM_LOB is supported****
c_rand: 9999-12-31
****PDO param type PDO::PARAM_LOB is compatible with encrypted date****
c_det: 0001-01-01
c_rand: 9999-12-31
Testing datetime: Testing datetime:
****PDO param type PDO::PARAM_STR is compatible with encrypted datetime**** ****Retrieving datetime as PDO::PARAM_STR is supported****
c_det: 1753-01-01 00:00:00.000 ****Retrieving datetime as PDO::PARAM_LOB is supported****
c_rand: 9999-12-31 23:59:59.997
****PDO param type PDO::PARAM_LOB is compatible with encrypted datetime****
c_det: 1753-01-01 00:00:00.000
c_rand: 9999-12-31 23:59:59.997
Testing smalldatetime: Testing smalldatetime:
****PDO param type PDO::PARAM_STR is compatible with encrypted smalldatetime**** ****Retrieving smalldatetime as PDO::PARAM_STR is supported****
c_det: 1900-01-01 00:00:00 ****Retrieving smalldatetime as PDO::PARAM_LOB is supported****
c_rand: 2079-06-05 23:59:00
****PDO param type PDO::PARAM_LOB is compatible with encrypted smalldatetime****
c_det: 1900-01-01 00:00:00
c_rand: 2079-06-05 23:59:00

View file

@ -1,7 +1,13 @@
--TEST-- --TEST--
Test for inserting and retrieving encrypted data of numeric types Test for retrieving encrypted data from datetime types columns with different precisions using PDO::bindColumn
--DESCRIPTION-- --DESCRIPTION--
Use PDOstatement::bindParam with all PDO::PARAM_ types Test conversion from datetime types column to output of PDO::PARAM types
With or without AE, conversion works if:
1. From any datetime type column to PDO::PARAM_STR
2. From any datetime type column to PDO::PARAM_LOB
TODO: cannot insert into a datetime2(0) using the PDO_SQLSRV driver
returns operand type clash error between smalldatetime and datetime2(0)
to see error, uncomment 0 from the $precision array
--SKIPIF-- --SKIPIF--
<?php require('skipif_mid-refactor.inc'); ?> <?php require('skipif_mid-refactor.inc'); ?>
--FILE-- --FILE--
@ -9,6 +15,20 @@ Use PDOstatement::bindParam with all PDO::PARAM_ types
require_once("MsCommon_mid-refactor.inc"); require_once("MsCommon_mid-refactor.inc");
require_once("AEData.inc"); require_once("AEData.inc");
function compareDate($dtout, $dtin, $dataType) {
if ($dataType == "datetimeoffset") {
$dtarr = explode(' ', $dtin);
if (strpos($dtout, $dtarr[0]) !== false && strpos($dtout, $dtarr[1]) !== false && strpos($dtout, $dtarr[2]) !== false) {
return true;
}
} else {
if (strpos($dtout, $dtin) !== false) {
return true;
}
}
return false;
}
$dataTypes = array("datetime2", "datetimeoffset", "time"); $dataTypes = array("datetime2", "datetimeoffset", "time");
$precisions = array(/*0,*/ 1, 2, 4, 7); $precisions = array(/*0,*/ 1, 2, 4, 7);
$inputValuesInit = array("datetime2" => array("0001-01-01 00:00:00", "9999-12-31 23:59:59"), $inputValuesInit = array("datetime2" => array("0001-01-01 00:00:00", "9999-12-31 23:59:59"),
@ -18,31 +38,31 @@ $inputValuesInit = array("datetime2" => array("0001-01-01 00:00:00", "9999-12-31
try { try {
$conn = connect("", array(), PDO::ERRMODE_SILENT); $conn = connect("", array(), PDO::ERRMODE_SILENT);
foreach ($dataTypes as $dataType) { foreach ($dataTypes as $dataType) {
foreach ($precisions as $precision) { foreach ($precisions as $m) {
// change the input values depending on the precision // add $m number of decimal digits to the some input values
$inputValues[0] = $inputValuesInit[$dataType][0]; $inputValues[0] = $inputValuesInit[$dataType][0];
$inputValues[1] = $inputValuesInit[$dataType][1]; $inputValues[1] = $inputValuesInit[$dataType][1];
if ($precision != 0) { if ($m != 0) {
if ($dataType == "datetime2") { if ($dataType == "datetime2") {
$inputValues[1] .= "." . str_repeat("9", $precision); $inputValues[1] .= "." . str_repeat("9", $m);
} else if ($dataType == "datetimeoffset") { } else if ($dataType == "datetimeoffset") {
$inputPieces = explode(" ", $inputValues[1]); $dtoffsetPieces = explode(" ", $inputValues[1]);
$inputValues[1] = $inputPieces[0] . " " . $inputPieces[1] . "." . str_repeat("9", $precision) . " " . $inputPieces[2]; $inputValues[1] = $dtoffsetPieces[0] . " " . $dtoffsetPieces[1] . "." . str_repeat("9", $m) . " " . $dtoffsetPieces[2];
} else if ($dataType == "time") { } else if ($dataType == "time") {
$inputValues[0] .= "." . str_repeat("0", $precision); $inputValues[0] .= "." . str_repeat("0", $m);
$inputValues[1] .= "." . str_repeat("9", $precision); $inputValues[1] .= "." . str_repeat("9", $m);
} }
} }
$type = "$dataType($precision)"; $typeFull = "$dataType($m)";
echo "\nTesting $type:\n"; echo "\nTesting $typeFull:\n";
//create and populate table //create and populate table containing datetime2(m), datetimeoffset(m) or time(m) columns
$tbname = "test_datetime"; $tbname = "test_" . $dataType . $m;
$colMetaArr = array(new ColumnMeta($type, "c_det"), new ColumnMeta($type, "c_rand", null, "randomized")); $colMetaArr = array(new ColumnMeta($typeFull, "c_det"), new ColumnMeta($typeFull, "c_rand", null, "randomized"));
createTable($conn, $tbname, $colMetaArr); createTable($conn, $tbname, $colMetaArr);
insertRow($conn, $tbname, array("c_det" => $inputValues[0], "c_rand" => $inputValues[1])); insertRow($conn, $tbname, array("c_det" => $inputValues[0], "c_rand" => $inputValues[1]));
// fetch with PDO::bindColumn and PDO::FETCH_BOUND // fetch by specifying PDO::PARAM_ types with PDO:bindColumn
$query = "SELECT c_det, c_rand FROM $tbname"; $query = "SELECT c_det, c_rand FROM $tbname";
foreach ($pdoParamTypes as $pdoParamType) { foreach ($pdoParamTypes as $pdoParamType) {
$det = ""; $det = "";
@ -53,16 +73,23 @@ try {
$stmt->bindColumn('c_rand', $rand, constant($pdoParamType)); $stmt->bindColumn('c_rand', $rand, constant($pdoParamType));
$row = $stmt->fetch(PDO::FETCH_BOUND); $row = $stmt->fetch(PDO::FETCH_BOUND);
// check the case when fetching as PDO::PARAM_BOOL, PDO::PARAM_NULL or PDO::PARAM_INT
// with or without AE; should not work
if ($pdoParamType == "PDO::PARAM_BOOL" || $pdoParamType == "PDO::PARAM_NULL" || $pdoParamType == "PDO::PARAM_INT") { if ($pdoParamType == "PDO::PARAM_BOOL" || $pdoParamType == "PDO::PARAM_NULL" || $pdoParamType == "PDO::PARAM_INT") {
if (!is_null($det) || !is_null($rand)) { if (!is_null($det) || !is_null($rand)) {
echo "Retrieving encrypted $type data as $pdoParamType should not work\n"; echo "Retrieving $typeFull data as $pdoParamType should not be supported\n";
} }
// check the case when fetching as PDO::PARAM_STR or PDO::PARAM_LOB
// with or without AE: should work
} else { } else {
echo "****PDO param type $pdoParamType is compatible with encrypted $type****\n"; if (compareDate($det, $inputValues[0], $dataType) && compareDate($rand, $inputValues[1], $dataType)) {
echo "c_det: $det\n"; echo "****Retrieving $typeFull as $pdoParamType is supported****\n";
echo "c_rand: $rand\n"; } else {
echo "Retrieving $typeFull as $pdoParamType fails\n";
}
} }
} }
// cleanup
dropTable($conn, $tbname); dropTable($conn, $tbname);
} }
} }
@ -74,97 +101,49 @@ try {
?> ?>
--EXPECT-- --EXPECT--
Testing datetime2(1): Testing datetime2(1):
****PDO param type PDO::PARAM_STR is compatible with encrypted datetime2(1)**** ****Retrieving datetime2(1) as PDO::PARAM_STR is supported****
c_det: 0001-01-01 00:00:00.0 ****Retrieving datetime2(1) as PDO::PARAM_LOB is supported****
c_rand: 9999-12-31 23:59:59.9
****PDO param type PDO::PARAM_LOB is compatible with encrypted datetime2(1)****
c_det: 0001-01-01 00:00:00.0
c_rand: 9999-12-31 23:59:59.9
Testing datetime2(2): Testing datetime2(2):
****PDO param type PDO::PARAM_STR is compatible with encrypted datetime2(2)**** ****Retrieving datetime2(2) as PDO::PARAM_STR is supported****
c_det: 0001-01-01 00:00:00.00 ****Retrieving datetime2(2) as PDO::PARAM_LOB is supported****
c_rand: 9999-12-31 23:59:59.99
****PDO param type PDO::PARAM_LOB is compatible with encrypted datetime2(2)****
c_det: 0001-01-01 00:00:00.00
c_rand: 9999-12-31 23:59:59.99
Testing datetime2(4): Testing datetime2(4):
****PDO param type PDO::PARAM_STR is compatible with encrypted datetime2(4)**** ****Retrieving datetime2(4) as PDO::PARAM_STR is supported****
c_det: 0001-01-01 00:00:00.0000 ****Retrieving datetime2(4) as PDO::PARAM_LOB is supported****
c_rand: 9999-12-31 23:59:59.9999
****PDO param type PDO::PARAM_LOB is compatible with encrypted datetime2(4)****
c_det: 0001-01-01 00:00:00.0000
c_rand: 9999-12-31 23:59:59.9999
Testing datetime2(7): Testing datetime2(7):
****PDO param type PDO::PARAM_STR is compatible with encrypted datetime2(7)**** ****Retrieving datetime2(7) as PDO::PARAM_STR is supported****
c_det: 0001-01-01 00:00:00.0000000 ****Retrieving datetime2(7) as PDO::PARAM_LOB is supported****
c_rand: 9999-12-31 23:59:59.9999999
****PDO param type PDO::PARAM_LOB is compatible with encrypted datetime2(7)****
c_det: 0001-01-01 00:00:00.0000000
c_rand: 9999-12-31 23:59:59.9999999
Testing datetimeoffset(1): Testing datetimeoffset(1):
****PDO param type PDO::PARAM_STR is compatible with encrypted datetimeoffset(1)**** ****Retrieving datetimeoffset(1) as PDO::PARAM_STR is supported****
c_det: 0001-01-01 00:00:00.0 -14:00 ****Retrieving datetimeoffset(1) as PDO::PARAM_LOB is supported****
c_rand: 9999-12-31 23:59:59.9 +14:00
****PDO param type PDO::PARAM_LOB is compatible with encrypted datetimeoffset(1)****
c_det: 0001-01-01 00:00:00.0 -14:00
c_rand: 9999-12-31 23:59:59.9 +14:00
Testing datetimeoffset(2): Testing datetimeoffset(2):
****PDO param type PDO::PARAM_STR is compatible with encrypted datetimeoffset(2)**** ****Retrieving datetimeoffset(2) as PDO::PARAM_STR is supported****
c_det: 0001-01-01 00:00:00.00 -14:00 ****Retrieving datetimeoffset(2) as PDO::PARAM_LOB is supported****
c_rand: 9999-12-31 23:59:59.99 +14:00
****PDO param type PDO::PARAM_LOB is compatible with encrypted datetimeoffset(2)****
c_det: 0001-01-01 00:00:00.00 -14:00
c_rand: 9999-12-31 23:59:59.99 +14:00
Testing datetimeoffset(4): Testing datetimeoffset(4):
****PDO param type PDO::PARAM_STR is compatible with encrypted datetimeoffset(4)**** ****Retrieving datetimeoffset(4) as PDO::PARAM_STR is supported****
c_det: 0001-01-01 00:00:00.0000 -14:00 ****Retrieving datetimeoffset(4) as PDO::PARAM_LOB is supported****
c_rand: 9999-12-31 23:59:59.9999 +14:00
****PDO param type PDO::PARAM_LOB is compatible with encrypted datetimeoffset(4)****
c_det: 0001-01-01 00:00:00.0000 -14:00
c_rand: 9999-12-31 23:59:59.9999 +14:00
Testing datetimeoffset(7): Testing datetimeoffset(7):
****PDO param type PDO::PARAM_STR is compatible with encrypted datetimeoffset(7)**** ****Retrieving datetimeoffset(7) as PDO::PARAM_STR is supported****
c_det: 0001-01-01 00:00:00.0000000 -14:00 ****Retrieving datetimeoffset(7) as PDO::PARAM_LOB is supported****
c_rand: 9999-12-31 23:59:59.9999999 +14:00
****PDO param type PDO::PARAM_LOB is compatible with encrypted datetimeoffset(7)****
c_det: 0001-01-01 00:00:00.0000000 -14:00
c_rand: 9999-12-31 23:59:59.9999999 +14:00
Testing time(1): Testing time(1):
****PDO param type PDO::PARAM_STR is compatible with encrypted time(1)**** ****Retrieving time(1) as PDO::PARAM_STR is supported****
c_det: 00:00:00.0 ****Retrieving time(1) as PDO::PARAM_LOB is supported****
c_rand: 23:59:59.9
****PDO param type PDO::PARAM_LOB is compatible with encrypted time(1)****
c_det: 00:00:00.0
c_rand: 23:59:59.9
Testing time(2): Testing time(2):
****PDO param type PDO::PARAM_STR is compatible with encrypted time(2)**** ****Retrieving time(2) as PDO::PARAM_STR is supported****
c_det: 00:00:00.00 ****Retrieving time(2) as PDO::PARAM_LOB is supported****
c_rand: 23:59:59.99
****PDO param type PDO::PARAM_LOB is compatible with encrypted time(2)****
c_det: 00:00:00.00
c_rand: 23:59:59.99
Testing time(4): Testing time(4):
****PDO param type PDO::PARAM_STR is compatible with encrypted time(4)**** ****Retrieving time(4) as PDO::PARAM_STR is supported****
c_det: 00:00:00.0000 ****Retrieving time(4) as PDO::PARAM_LOB is supported****
c_rand: 23:59:59.9999
****PDO param type PDO::PARAM_LOB is compatible with encrypted time(4)****
c_det: 00:00:00.0000
c_rand: 23:59:59.9999
Testing time(7): Testing time(7):
****PDO param type PDO::PARAM_STR is compatible with encrypted time(7)**** ****Retrieving time(7) as PDO::PARAM_STR is supported****
c_det: 00:00:00.0000000 ****Retrieving time(7) as PDO::PARAM_LOB is supported****
c_rand: 23:59:59.9999999
****PDO param type PDO::PARAM_LOB is compatible with encrypted time(7)****
c_det: 00:00:00.0000000
c_rand: 23:59:59.9999999

View file

@ -1,7 +1,16 @@
--TEST-- --TEST--
Test for inserting and retrieving encrypted data of numeric types Test for retrieving encrypted data from decimal types columns using PDO::bindColumn
--DESCRIPTION-- --DESCRIPTION--
Use PDOstatement::bindParam with all PDO::PARAM_ types Test conversion from decimal types column to output of PDO::PARAM types
With or without AE, conversion works if:
1. From any decimal type column to PDO::PARAM_STR
2. From any decimal type column to PDO::PARAM_LOB
TODO: behavior for teching decimals as PARAM_BOOL and PARAM_INT varies depending on the number being fetched
1. if the number is less than 1, returns 0 (even though the number being fetched is 0.9)
2. 2. if the number is greater than 1 and the number of digits is less than 11, returns the correctly rounded integer (e.g., returns 922 when fetching 922.3)
3. if the number is greater than 1 and the number of digits is greater than 11, returns NULL
need to investigate which should be the correct behavior
for this test, assume to correct behavior is to return NULL
--SKIPIF-- --SKIPIF--
<?php require('skipif_mid-refactor.inc'); ?> <?php require('skipif_mid-refactor.inc'); ?>
--FILE-- --FILE--
@ -20,21 +29,22 @@ $inputPrecision = 38;
try { try {
$conn = connect("", array(), PDO::ERRMODE_SILENT); $conn = connect("", array(), PDO::ERRMODE_SILENT);
foreach ($dataTypes as $dataType) { foreach ($dataTypes as $dataType) {
foreach ($precisions as $precision => $scales) { foreach ($precisions as $m1 => $scales) {
foreach ($scales as $scale) { foreach ($scales as $m2) {
// change the input values depending on the precision and scale // change the number of integers in the input values to be $m1 - $m2
$precDiff = $inputPrecision - ($precision - $scale); $precDiff = $inputPrecision - ($m1 - $m2);
$inputValues = $inputValuesInit; $inputValues = $inputValuesInit;
foreach ($inputValues as &$inputValue) { foreach ($inputValues as &$inputValue) {
$inputValue = $inputValue / pow(10, $precDiff); $inputValue = $inputValue / pow(10, $precDiff);
} }
// epsilon for comparing doubles
// 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 // float in PHP only has a precision of roughtly 14 digits: http://php.net/manual/en/language.types.float.php
$epsilon; $epsilon;
if ($precision < 14) { if ($m1 < 14) {
$epsilon = pow(10, $scale * -1); $epsilon = pow(10, $m2 * -1);
} else { } else {
$numint = $precision - $scale; $numint = $m1 - $m2;
if ($numint < 14) { if ($numint < 14) {
$epsilon = pow(10, (14 - $numint) * -1); $epsilon = pow(10, (14 - $numint) * -1);
} else { } else {
@ -42,16 +52,16 @@ try {
} }
} }
$type = "$dataType($precision, $scale)"; $typeFull = "$dataType($m1, $m2)";
echo "\nTesting $type:\n"; echo "\nTesting $typeFull:\n";
//create and populate table //create and populate table containing decimal(m1, m2) or numeric(m1, m2) columns
$tbname = "test_decimal"; $tbname = "test_" . $dataType . $m1 . $m2;
$colMetaArr = array(new ColumnMeta($type, "c_det"), new ColumnMeta($type, "c_rand", null, "randomized")); $colMetaArr = array(new ColumnMeta($typeFull, "c_det"), new ColumnMeta($typeFull, "c_rand", null, "randomized"));
createTable($conn, $tbname, $colMetaArr); createTable($conn, $tbname, $colMetaArr);
insertRow($conn, $tbname, array("c_det" => $inputValues[0], "c_rand" => $inputValues[1])); insertRow($conn, $tbname, array("c_det" => $inputValues[0], "c_rand" => $inputValues[1]));
// fetch with PDO::bindColumn and PDO::FETCH_BOUND // fetch by specifying PDO::PARAM_ types with PDO::bindColumn
$query = "SELECT c_det, c_rand FROM $tbname"; $query = "SELECT c_det, c_rand FROM $tbname";
foreach ($pdoParamTypes as $pdoParamType) { foreach ($pdoParamTypes as $pdoParamType) {
$det = ""; $det = "";
@ -62,25 +72,23 @@ try {
$stmt->bindColumn('c_rand', $rand, constant($pdoParamType)); $stmt->bindColumn('c_rand', $rand, constant($pdoParamType));
$row = $stmt->fetch(PDO::FETCH_BOUND); $row = $stmt->fetch(PDO::FETCH_BOUND);
// assumes the correct behavior of fetching decimal types as PDO::PARAM_BOOL, PDO::PARAM_NULL and PDO::PARAM_INT is to return NULL // check the case when fetching as PDO::PARAM_BOOL, PDO::PARAM_NULL or PDO::PARAM_INT
// behavior for fetching decimals as PARAM_BOOL and PARAM_INT varies depending on the number being fetched: // with or without AE; should not work
// 1. if the number is less than 1, returns 0 (even though the number being fetched is 0.9) // assume to correct behavior is to return NULL, see description
// 2. if the number is greater than 1 and the number of digits is less than 11, returns the correctly rounded integer (e.g., returns 922 when fetching 922.3)
// 3. if the number is greater than 1 and the number of digits is greater than 11, returns NULL
// see VSO item 2730
if ($pdoParamType == "PDO::PARAM_BOOL" || $pdoParamType == "PDO::PARAM_NULL" || $pdoParamType == "PDO::PARAM_INT") { if ($pdoParamType == "PDO::PARAM_BOOL" || $pdoParamType == "PDO::PARAM_NULL" || $pdoParamType == "PDO::PARAM_INT") {
if (!is_null($det) || !is_null($rand)) { if (!is_null($det) || !is_null($rand)) {
echo "Fetching $type as PDO param type $pdoParamType should return NULL\n"; echo "Retrieving $typeFull data as $pdoParamType should return NULL\n";
} }
} else { } else {
if (abs($det - $inputValues[0]) > $epsilon || if (abs($det - $inputValues[0]) < $epsilon &&
abs($rand - $inputValues[1]) > $epsilon) { abs($rand - $inputValues[1]) < $epsilon) {
echo "PDO param type $pdoParamType should be compatible with $type\n"; echo "****Retrieving $typeFull as $pdoParamType is supported****\n";
} else { } else {
echo "****PDO param type $pdoParamType is compatible with $type****\n"; echo "Retrieving $typeFull as $pdoParamType fails\n";
} }
} }
} }
// cleanup
dropTable($conn, $tbname); dropTable($conn, $tbname);
} }
} }
@ -93,141 +101,141 @@ try {
?> ?>
--EXPECT-- --EXPECT--
Testing decimal(1, 0): Testing decimal(1, 0):
Fetching decimal(1, 0) as PDO param type PDO::PARAM_BOOL should return NULL Retrieving decimal(1, 0) data as PDO::PARAM_BOOL should return NULL
Fetching decimal(1, 0) as PDO param type PDO::PARAM_INT should return NULL Retrieving decimal(1, 0) data as PDO::PARAM_INT should return NULL
****PDO param type PDO::PARAM_STR is compatible with decimal(1, 0)**** ****Retrieving decimal(1, 0) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with decimal(1, 0)**** ****Retrieving decimal(1, 0) as PDO::PARAM_LOB is supported****
Testing decimal(1, 1): Testing decimal(1, 1):
Fetching decimal(1, 1) as PDO param type PDO::PARAM_BOOL should return NULL Retrieving decimal(1, 1) data as PDO::PARAM_BOOL should return NULL
Fetching decimal(1, 1) as PDO param type PDO::PARAM_INT should return NULL Retrieving decimal(1, 1) data as PDO::PARAM_INT should return NULL
****PDO param type PDO::PARAM_STR is compatible with decimal(1, 1)**** ****Retrieving decimal(1, 1) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with decimal(1, 1)**** ****Retrieving decimal(1, 1) as PDO::PARAM_LOB is supported****
Testing decimal(4, 0): Testing decimal(4, 0):
Fetching decimal(4, 0) as PDO param type PDO::PARAM_BOOL should return NULL Retrieving decimal(4, 0) data as PDO::PARAM_BOOL should return NULL
Fetching decimal(4, 0) as PDO param type PDO::PARAM_INT should return NULL Retrieving decimal(4, 0) data as PDO::PARAM_INT should return NULL
****PDO param type PDO::PARAM_STR is compatible with decimal(4, 0)**** ****Retrieving decimal(4, 0) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with decimal(4, 0)**** ****Retrieving decimal(4, 0) as PDO::PARAM_LOB is supported****
Testing decimal(4, 1): Testing decimal(4, 1):
Fetching decimal(4, 1) as PDO param type PDO::PARAM_BOOL should return NULL Retrieving decimal(4, 1) data as PDO::PARAM_BOOL should return NULL
Fetching decimal(4, 1) as PDO param type PDO::PARAM_INT should return NULL Retrieving decimal(4, 1) data as PDO::PARAM_INT should return NULL
****PDO param type PDO::PARAM_STR is compatible with decimal(4, 1)**** ****Retrieving decimal(4, 1) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with decimal(4, 1)**** ****Retrieving decimal(4, 1) as PDO::PARAM_LOB is supported****
Testing decimal(4, 4): Testing decimal(4, 4):
Fetching decimal(4, 4) as PDO param type PDO::PARAM_BOOL should return NULL Retrieving decimal(4, 4) data as PDO::PARAM_BOOL should return NULL
Fetching decimal(4, 4) as PDO param type PDO::PARAM_INT should return NULL Retrieving decimal(4, 4) data as PDO::PARAM_INT should return NULL
****PDO param type PDO::PARAM_STR is compatible with decimal(4, 4)**** ****Retrieving decimal(4, 4) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with decimal(4, 4)**** ****Retrieving decimal(4, 4) as PDO::PARAM_LOB is supported****
Testing decimal(16, 0): Testing decimal(16, 0):
****PDO param type PDO::PARAM_STR is compatible with decimal(16, 0)**** ****Retrieving decimal(16, 0) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with decimal(16, 0)**** ****Retrieving decimal(16, 0) as PDO::PARAM_LOB is supported****
Testing decimal(16, 1): Testing decimal(16, 1):
****PDO param type PDO::PARAM_STR is compatible with decimal(16, 1)**** ****Retrieving decimal(16, 1) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with decimal(16, 1)**** ****Retrieving decimal(16, 1) as PDO::PARAM_LOB is supported****
Testing decimal(16, 4): Testing decimal(16, 4):
****PDO param type PDO::PARAM_STR is compatible with decimal(16, 4)**** ****Retrieving decimal(16, 4) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with decimal(16, 4)**** ****Retrieving decimal(16, 4) as PDO::PARAM_LOB is supported****
Testing decimal(16, 16): Testing decimal(16, 16):
Fetching decimal(16, 16) as PDO param type PDO::PARAM_BOOL should return NULL Retrieving decimal(16, 16) data as PDO::PARAM_BOOL should return NULL
Fetching decimal(16, 16) as PDO param type PDO::PARAM_INT should return NULL Retrieving decimal(16, 16) data as PDO::PARAM_INT should return NULL
****PDO param type PDO::PARAM_STR is compatible with decimal(16, 16)**** ****Retrieving decimal(16, 16) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with decimal(16, 16)**** ****Retrieving decimal(16, 16) as PDO::PARAM_LOB is supported****
Testing decimal(38, 0): Testing decimal(38, 0):
****PDO param type PDO::PARAM_STR is compatible with decimal(38, 0)**** ****Retrieving decimal(38, 0) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with decimal(38, 0)**** ****Retrieving decimal(38, 0) as PDO::PARAM_LOB is supported****
Testing decimal(38, 1): Testing decimal(38, 1):
****PDO param type PDO::PARAM_STR is compatible with decimal(38, 1)**** ****Retrieving decimal(38, 1) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with decimal(38, 1)**** ****Retrieving decimal(38, 1) as PDO::PARAM_LOB is supported****
Testing decimal(38, 4): Testing decimal(38, 4):
****PDO param type PDO::PARAM_STR is compatible with decimal(38, 4)**** ****Retrieving decimal(38, 4) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with decimal(38, 4)**** ****Retrieving decimal(38, 4) as PDO::PARAM_LOB is supported****
Testing decimal(38, 16): Testing decimal(38, 16):
****PDO param type PDO::PARAM_STR is compatible with decimal(38, 16)**** ****Retrieving decimal(38, 16) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with decimal(38, 16)**** ****Retrieving decimal(38, 16) as PDO::PARAM_LOB is supported****
Testing decimal(38, 38): Testing decimal(38, 38):
Fetching decimal(38, 38) as PDO param type PDO::PARAM_BOOL should return NULL Retrieving decimal(38, 38) data as PDO::PARAM_BOOL should return NULL
Fetching decimal(38, 38) as PDO param type PDO::PARAM_INT should return NULL Retrieving decimal(38, 38) data as PDO::PARAM_INT should return NULL
****PDO param type PDO::PARAM_STR is compatible with decimal(38, 38)**** ****Retrieving decimal(38, 38) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with decimal(38, 38)**** ****Retrieving decimal(38, 38) as PDO::PARAM_LOB is supported****
Testing numeric(1, 0): Testing numeric(1, 0):
Fetching numeric(1, 0) as PDO param type PDO::PARAM_BOOL should return NULL Retrieving numeric(1, 0) data as PDO::PARAM_BOOL should return NULL
Fetching numeric(1, 0) as PDO param type PDO::PARAM_INT should return NULL Retrieving numeric(1, 0) data as PDO::PARAM_INT should return NULL
****PDO param type PDO::PARAM_STR is compatible with numeric(1, 0)**** ****Retrieving numeric(1, 0) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with numeric(1, 0)**** ****Retrieving numeric(1, 0) as PDO::PARAM_LOB is supported****
Testing numeric(1, 1): Testing numeric(1, 1):
Fetching numeric(1, 1) as PDO param type PDO::PARAM_BOOL should return NULL Retrieving numeric(1, 1) data as PDO::PARAM_BOOL should return NULL
Fetching numeric(1, 1) as PDO param type PDO::PARAM_INT should return NULL Retrieving numeric(1, 1) data as PDO::PARAM_INT should return NULL
****PDO param type PDO::PARAM_STR is compatible with numeric(1, 1)**** ****Retrieving numeric(1, 1) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with numeric(1, 1)**** ****Retrieving numeric(1, 1) as PDO::PARAM_LOB is supported****
Testing numeric(4, 0): Testing numeric(4, 0):
Fetching numeric(4, 0) as PDO param type PDO::PARAM_BOOL should return NULL Retrieving numeric(4, 0) data as PDO::PARAM_BOOL should return NULL
Fetching numeric(4, 0) as PDO param type PDO::PARAM_INT should return NULL Retrieving numeric(4, 0) data as PDO::PARAM_INT should return NULL
****PDO param type PDO::PARAM_STR is compatible with numeric(4, 0)**** ****Retrieving numeric(4, 0) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with numeric(4, 0)**** ****Retrieving numeric(4, 0) as PDO::PARAM_LOB is supported****
Testing numeric(4, 1): Testing numeric(4, 1):
Fetching numeric(4, 1) as PDO param type PDO::PARAM_BOOL should return NULL Retrieving numeric(4, 1) data as PDO::PARAM_BOOL should return NULL
Fetching numeric(4, 1) as PDO param type PDO::PARAM_INT should return NULL Retrieving numeric(4, 1) data as PDO::PARAM_INT should return NULL
****PDO param type PDO::PARAM_STR is compatible with numeric(4, 1)**** ****Retrieving numeric(4, 1) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with numeric(4, 1)**** ****Retrieving numeric(4, 1) as PDO::PARAM_LOB is supported****
Testing numeric(4, 4): Testing numeric(4, 4):
Fetching numeric(4, 4) as PDO param type PDO::PARAM_BOOL should return NULL Retrieving numeric(4, 4) data as PDO::PARAM_BOOL should return NULL
Fetching numeric(4, 4) as PDO param type PDO::PARAM_INT should return NULL Retrieving numeric(4, 4) data as PDO::PARAM_INT should return NULL
****PDO param type PDO::PARAM_STR is compatible with numeric(4, 4)**** ****Retrieving numeric(4, 4) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with numeric(4, 4)**** ****Retrieving numeric(4, 4) as PDO::PARAM_LOB is supported****
Testing numeric(16, 0): Testing numeric(16, 0):
****PDO param type PDO::PARAM_STR is compatible with numeric(16, 0)**** ****Retrieving numeric(16, 0) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with numeric(16, 0)**** ****Retrieving numeric(16, 0) as PDO::PARAM_LOB is supported****
Testing numeric(16, 1): Testing numeric(16, 1):
****PDO param type PDO::PARAM_STR is compatible with numeric(16, 1)**** ****Retrieving numeric(16, 1) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with numeric(16, 1)**** ****Retrieving numeric(16, 1) as PDO::PARAM_LOB is supported****
Testing numeric(16, 4): Testing numeric(16, 4):
****PDO param type PDO::PARAM_STR is compatible with numeric(16, 4)**** ****Retrieving numeric(16, 4) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with numeric(16, 4)**** ****Retrieving numeric(16, 4) as PDO::PARAM_LOB is supported****
Testing numeric(16, 16): Testing numeric(16, 16):
Fetching numeric(16, 16) as PDO param type PDO::PARAM_BOOL should return NULL Retrieving numeric(16, 16) data as PDO::PARAM_BOOL should return NULL
Fetching numeric(16, 16) as PDO param type PDO::PARAM_INT should return NULL Retrieving numeric(16, 16) data as PDO::PARAM_INT should return NULL
****PDO param type PDO::PARAM_STR is compatible with numeric(16, 16)**** ****Retrieving numeric(16, 16) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with numeric(16, 16)**** ****Retrieving numeric(16, 16) as PDO::PARAM_LOB is supported****
Testing numeric(38, 0): Testing numeric(38, 0):
****PDO param type PDO::PARAM_STR is compatible with numeric(38, 0)**** ****Retrieving numeric(38, 0) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with numeric(38, 0)**** ****Retrieving numeric(38, 0) as PDO::PARAM_LOB is supported****
Testing numeric(38, 1): Testing numeric(38, 1):
****PDO param type PDO::PARAM_STR is compatible with numeric(38, 1)**** ****Retrieving numeric(38, 1) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with numeric(38, 1)**** ****Retrieving numeric(38, 1) as PDO::PARAM_LOB is supported****
Testing numeric(38, 4): Testing numeric(38, 4):
****PDO param type PDO::PARAM_STR is compatible with numeric(38, 4)**** ****Retrieving numeric(38, 4) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with numeric(38, 4)**** ****Retrieving numeric(38, 4) as PDO::PARAM_LOB is supported****
Testing numeric(38, 16): Testing numeric(38, 16):
****PDO param type PDO::PARAM_STR is compatible with numeric(38, 16)**** ****Retrieving numeric(38, 16) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with numeric(38, 16)**** ****Retrieving numeric(38, 16) as PDO::PARAM_LOB is supported****
Testing numeric(38, 38): Testing numeric(38, 38):
Fetching numeric(38, 38) as PDO param type PDO::PARAM_BOOL should return NULL Retrieving numeric(38, 38) data as PDO::PARAM_BOOL should return NULL
Fetching numeric(38, 38) as PDO param type PDO::PARAM_INT should return NULL Retrieving numeric(38, 38) data as PDO::PARAM_INT should return NULL
****PDO param type PDO::PARAM_STR is compatible with numeric(38, 38)**** ****Retrieving numeric(38, 38) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with numeric(38, 38)**** ****Retrieving numeric(38, 38) as PDO::PARAM_LOB is supported****

View file

@ -1,7 +1,10 @@
--TEST-- --TEST--
Test for inserting and retrieving encrypted data of numeric types Test for retrieving encrypted data from float types columns using PDO::bindColumn
--DESCRIPTION-- --DESCRIPTION--
Use PDOstatement::bindParam with all PDO::PARAM_ types Test conversion from float types column to output of PDO::PARAM types
With or without AE, conversion works if:
1. From any float type column to PDO::PARAM_STR
2. From any float type column to PDO::PARAM_LOB
--SKIPIF-- --SKIPIF--
<?php require('skipif_mid-refactor.inc'); ?> <?php require('skipif_mid-refactor.inc'); ?>
--FILE-- --FILE--
@ -12,20 +15,31 @@ require_once("AEData.inc");
$dataType = "float"; $dataType = "float";
$bits = array(1, 12, 24, 36, 53); $bits = array(1, 12, 24, 36, 53);
$inputValues = array(9223372036854775808.9223372036854775808, -9223372036854775808.9223372036854775808); $inputValues = array(9223372036854775808.9223372036854775808, -9223372036854775808.9223372036854775808);
$numint = 19;
try { try {
$conn = connect("", array(), PDO::ERRMODE_SILENT); $conn = connect("", array(), PDO::ERRMODE_SILENT);
foreach ($bits as $bit) { foreach ($bits as $m) {
$type = "$dataType($bit)"; // compute the epsilon for comparing doubles
echo "\nTesting $type:\n"; // when $m <= 24, the precision is 7 digits
// when $m > 24, the precision is 15 digits, but PHP float only supports up to 14 digits
$epsilon;
if ($m <= 24) {
$epsilon = pow(10, $numint - 7);
} else {
$epsilon = pow(10, $numint - 14);
}
//create and populate table $typeFull = "$dataType($m)";
$tbname = "test_float"; echo "\nTesting $typeFull:\n";
$colMetaArr = array(new ColumnMeta($type, "c_det"), new ColumnMeta($type, "c_rand", null, "randomized"));
//create and populate table containing float(m) columns
$tbname = "test_" . $dataType . $m;
$colMetaArr = array(new ColumnMeta($typeFull, "c_det"), new ColumnMeta($typeFull, "c_rand", null, "randomized"));
createTable($conn, $tbname, $colMetaArr); createTable($conn, $tbname, $colMetaArr);
insertRow($conn, $tbname, array("c_det" => $inputValues[0], "c_rand" => $inputValues[1])); insertRow($conn, $tbname, array("c_det" => $inputValues[0], "c_rand" => $inputValues[1]));
// fetch with PDO::bindColumn and PDO::FETCH_BOUND // fetchby specifying PDO::PARAM_ types with PDO::bindColumn
$query = "SELECT c_det, c_rand FROM $tbname"; $query = "SELECT c_det, c_rand FROM $tbname";
foreach ($pdoParamTypes as $pdoParamType) { foreach ($pdoParamTypes as $pdoParamType) {
$det = ""; $det = "";
@ -36,14 +50,18 @@ try {
$stmt->bindColumn('c_rand', $rand, constant($pdoParamType)); $stmt->bindColumn('c_rand', $rand, constant($pdoParamType));
$row = $stmt->fetch(PDO::FETCH_BOUND); $row = $stmt->fetch(PDO::FETCH_BOUND);
// check the case when fetching as PDO::PARAM_BOOL, PDO::PARAM_NULL or PDO::PARAM_INT
// with or without AE; should not work
if ($pdoParamType == "PDO::PARAM_BOOL" || $pdoParamType == "PDO::PARAM_NULL" || $pdoParamType == "PDO::PARAM_INT") { if ($pdoParamType == "PDO::PARAM_BOOL" || $pdoParamType == "PDO::PARAM_NULL" || $pdoParamType == "PDO::PARAM_INT") {
if (!is_null($det) || !is_null($rand)) { if (!is_null($det) || !is_null($rand)) {
echo "Fetching $type as PDO param type $pdoParamType should return NULL\n"; echo "Retriving $typeFull data as $pdoParamType should return NULL\n";
} }
} else { } else {
echo "****PDO param type $pdoParamType is compatible with encrypted $type****\n"; if (abs($det - $inputValues[0]) < $epsilon && abs($rand - $inputValues[1]) < $epsilon) {
echo "c_det: $det\n"; echo "****Retrieving $typeFull as $pdoParamType is supported****\n";
echo "c_rand: $rand\n"; } else {
echo "Retrieving $typeFull as $pdoParamType fails\n";
}
} }
} }
dropTable($conn, $tbname); dropTable($conn, $tbname);
@ -56,41 +74,21 @@ try {
?> ?>
--EXPECT-- --EXPECT--
Testing float(1): Testing float(1):
****PDO param type PDO::PARAM_STR is compatible with encrypted float(1)**** ****Retrieving float(1) as PDO::PARAM_STR is supported****
c_det: 9.223372E+18 ****Retrieving float(1) as PDO::PARAM_LOB is supported****
c_rand: -9.223372E+18
****PDO param type PDO::PARAM_LOB is compatible with encrypted float(1)****
c_det: 9.223372E+18
c_rand: -9.223372E+18
Testing float(12): Testing float(12):
****PDO param type PDO::PARAM_STR is compatible with encrypted float(12)**** ****Retrieving float(12) as PDO::PARAM_STR is supported****
c_det: 9.223372E+18 ****Retrieving float(12) as PDO::PARAM_LOB is supported****
c_rand: -9.223372E+18
****PDO param type PDO::PARAM_LOB is compatible with encrypted float(12)****
c_det: 9.223372E+18
c_rand: -9.223372E+18
Testing float(24): Testing float(24):
****PDO param type PDO::PARAM_STR is compatible with encrypted float(24)**** ****Retrieving float(24) as PDO::PARAM_STR is supported****
c_det: 9.223372E+18 ****Retrieving float(24) as PDO::PARAM_LOB is supported****
c_rand: -9.223372E+18
****PDO param type PDO::PARAM_LOB is compatible with encrypted float(24)****
c_det: 9.223372E+18
c_rand: -9.223372E+18
Testing float(36): Testing float(36):
****PDO param type PDO::PARAM_STR is compatible with encrypted float(36)**** ****Retrieving float(36) as PDO::PARAM_STR is supported****
c_det: 9.2233720368548004E+18 ****Retrieving float(36) as PDO::PARAM_LOB is supported****
c_rand: -9.2233720368548004E+18
****PDO param type PDO::PARAM_LOB is compatible with encrypted float(36)****
c_det: 9.2233720368548004E+18
c_rand: -9.2233720368548004E+18
Testing float(53): Testing float(53):
****PDO param type PDO::PARAM_STR is compatible with encrypted float(53)**** ****Retrieving float(53) as PDO::PARAM_STR is supported****
c_det: 9.2233720368548004E+18 ****Retrieving float(53) as PDO::PARAM_LOB is supported****
c_rand: -9.2233720368548004E+18
****PDO param type PDO::PARAM_LOB is compatible with encrypted float(53)****
c_det: 9.2233720368548004E+18
c_rand: -9.2233720368548004E+18

View file

@ -1,7 +1,10 @@
--TEST-- --TEST--
Test for inserting and retrieving encrypted data of numeric types Test for retrieving encrypted data from nchar types columns using PDO::bindColumn
--DESCRIPTION-- --DESCRIPTION--
Use PDOstatement::bindParam with all PDO::PARAM_ types Test conversion from nchar types column to output of PDO::PARAM types
With or without AE, conversion works if:
1. From any nchar type column to PDO::PARAM_STR
2. From any nchar type column to PDO::PARAM_LOB
--SKIPIF-- --SKIPIF--
<?php require('skipif_mid-refactor.inc'); ?> <?php require('skipif_mid-refactor.inc'); ?>
--FILE-- --FILE--
@ -11,51 +14,54 @@ require_once("AEData.inc");
$dataTypes = array("nchar", "nvarchar", "nvarchar(max)"); $dataTypes = array("nchar", "nvarchar", "nvarchar(max)");
$lengths = array(1, 8, 64, 512, 4000); $lengths = array(1, 8, 64, 512, 4000);
$encTypes = array("deterministic", "randomized");
try { try {
$conn = connect("", array(), PDO::ERRMODE_SILENT); $conn = connect("", array(), PDO::ERRMODE_SILENT);
foreach ($dataTypes as $dataType) { foreach ($dataTypes as $dataType) {
$maxtype = strpos($dataType, "(max)"); $maxcol = strpos($dataType, "(max)");
foreach ($lengths as $length) { foreach ($lengths as $m) {
if ($maxtype !== false) { if ($maxcol !== false) {
$type = $dataType; $typeFull = $dataType;
} else { } else {
$type = "$dataType($length)"; $typeFull = "$dataType($m)";
} }
echo "\nTesting $type:\n"; echo "\nTesting $typeFull:\n";
//create and populate table //create and populate table containing nchar(m) or nvarchar(m) columns
foreach($encTypes as $encType) { $tbname = "test_" . str_replace(array('(', ')'), '', $dataType) . $m;
$tbname = getTableName(); $colMetaArr = array(new ColumnMeta($typeFull, "c1"));
$colMetaArr = array(new ColumnMeta($type, "c1", null, $encType)); createTable($conn, $tbname, $colMetaArr);
createTable($conn, $tbname, $colMetaArr); $inputValue = str_repeat("d", $m);
$input = str_repeat("d", $length); insertRow($conn, $tbname, array("c1" => $inputValue));
insertRow($conn, $tbname, array("c1" => $input));
// fetch with PDO::bindColumn and PDO::FETCH_BOUND // fetch by specifying PDO::PARAM_ types with PDO::bindColumn
$query = "SELECT c1 FROM $tbname"; $query = "SELECT c1 FROM $tbname";
foreach ($pdoParamTypes as $pdoParamType) { foreach ($pdoParamTypes as $pdoParamType) {
$det = ""; $det = "";
$rand = ""; $rand = "";
$stmt = $conn->prepare($query); $stmt = $conn->prepare($query);
$stmt->execute(); $stmt->execute();
$stmt->bindColumn('c1', $c1, constant($pdoParamType)); $stmt->bindColumn('c1', $c1, constant($pdoParamType));
$row = $stmt->fetch(PDO::FETCH_BOUND); $row = $stmt->fetch(PDO::FETCH_BOUND);
if ($pdoParamType == "PDO::PARAM_BOOL" || $pdoParamType == "PDO::PARAM_NULL" || $pdoParamType == "PDO::PARAM_INT") {
if (!empty($det) || !empty($rand)) { // check the case when fetching as PDO::PARAM_BOOL, PDO::PARAM_NULL or PDO::PARAM_INT
echo "Fetching $type as PDO param type $pdoParamType should be empty\n"; // with or without AE: should not work
} if ($pdoParamType == "PDO::PARAM_BOOL" || $pdoParamType == "PDO::PARAM_NULL" || $pdoParamType == "PDO::PARAM_INT") {
if (!empty($det) || !empty($rand)) {
echo "Retrieving $typeFull data as $pdoParamType should not be supported\n";
}
// check the case when fetching as PDO::PARAM_STR or PDO::PARAM_LOB
// with or without AE: should work
} else {
if (strlen($c1) == $m) {
echo "****Retrieving $typeFull as $pdoParamType is supported****\n";
} else { } else {
if (strlen($c1) == $length) { echo "Retrieving $typeFull as $pdoParamType fails\n";
echo "****PDO param type $pdoParamType is compatible with $encType encrypted $type****\n";
} else {
echo "PDO param type $pdoParamType is incompatible with $encType encrypted $type\n";
}
} }
} }
dropTable($conn, $tbname);
} }
// cleanup
dropTable($conn, $tbname);
} }
} }
unset($stmt); unset($stmt);
@ -66,91 +72,61 @@ try {
?> ?>
--EXPECT-- --EXPECT--
Testing nchar(1): Testing nchar(1):
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nchar(1)**** ****Retrieving nchar(1) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted nchar(1)**** ****Retrieving nchar(1) as PDO::PARAM_LOB is supported****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted nchar(1)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted nchar(1)****
Testing nchar(8): Testing nchar(8):
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nchar(8)**** ****Retrieving nchar(8) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted nchar(8)**** ****Retrieving nchar(8) as PDO::PARAM_LOB is supported****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted nchar(8)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted nchar(8)****
Testing nchar(64): Testing nchar(64):
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nchar(64)**** ****Retrieving nchar(64) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted nchar(64)**** ****Retrieving nchar(64) as PDO::PARAM_LOB is supported****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted nchar(64)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted nchar(64)****
Testing nchar(512): Testing nchar(512):
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nchar(512)**** ****Retrieving nchar(512) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted nchar(512)**** ****Retrieving nchar(512) as PDO::PARAM_LOB is supported****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted nchar(512)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted nchar(512)****
Testing nchar(4000): Testing nchar(4000):
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nchar(4000)**** ****Retrieving nchar(4000) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted nchar(4000)**** ****Retrieving nchar(4000) as PDO::PARAM_LOB is supported****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted nchar(4000)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted nchar(4000)****
Testing nvarchar(1): Testing nvarchar(1):
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nvarchar(1)**** ****Retrieving nvarchar(1) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted nvarchar(1)**** ****Retrieving nvarchar(1) as PDO::PARAM_LOB is supported****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted nvarchar(1)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted nvarchar(1)****
Testing nvarchar(8): Testing nvarchar(8):
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nvarchar(8)**** ****Retrieving nvarchar(8) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted nvarchar(8)**** ****Retrieving nvarchar(8) as PDO::PARAM_LOB is supported****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted nvarchar(8)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted nvarchar(8)****
Testing nvarchar(64): Testing nvarchar(64):
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nvarchar(64)**** ****Retrieving nvarchar(64) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted nvarchar(64)**** ****Retrieving nvarchar(64) as PDO::PARAM_LOB is supported****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted nvarchar(64)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted nvarchar(64)****
Testing nvarchar(512): Testing nvarchar(512):
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nvarchar(512)**** ****Retrieving nvarchar(512) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted nvarchar(512)**** ****Retrieving nvarchar(512) as PDO::PARAM_LOB is supported****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted nvarchar(512)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted nvarchar(512)****
Testing nvarchar(4000): Testing nvarchar(4000):
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nvarchar(4000)**** ****Retrieving nvarchar(4000) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted nvarchar(4000)**** ****Retrieving nvarchar(4000) as PDO::PARAM_LOB is supported****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted nvarchar(4000)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted nvarchar(4000)****
Testing nvarchar(max): Testing nvarchar(max):
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nvarchar(max)**** ****Retrieving nvarchar(max) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted nvarchar(max)**** ****Retrieving nvarchar(max) as PDO::PARAM_LOB is supported****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted nvarchar(max)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted nvarchar(max)****
Testing nvarchar(max): Testing nvarchar(max):
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nvarchar(max)**** ****Retrieving nvarchar(max) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted nvarchar(max)**** ****Retrieving nvarchar(max) as PDO::PARAM_LOB is supported****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted nvarchar(max)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted nvarchar(max)****
Testing nvarchar(max): Testing nvarchar(max):
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nvarchar(max)**** ****Retrieving nvarchar(max) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted nvarchar(max)**** ****Retrieving nvarchar(max) as PDO::PARAM_LOB is supported****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted nvarchar(max)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted nvarchar(max)****
Testing nvarchar(max): Testing nvarchar(max):
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nvarchar(max)**** ****Retrieving nvarchar(max) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted nvarchar(max)**** ****Retrieving nvarchar(max) as PDO::PARAM_LOB is supported****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted nvarchar(max)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted nvarchar(max)****
Testing nvarchar(max): Testing nvarchar(max):
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nvarchar(max)**** ****Retrieving nvarchar(max) as PDO::PARAM_STR is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted nvarchar(max)**** ****Retrieving nvarchar(max) as PDO::PARAM_LOB is supported****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted nvarchar(max)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted nvarchar(max)****

View file

@ -1,7 +1,12 @@
--TEST-- --TEST--
Test for inserting and retrieving encrypted data of numeric types Test for retrieving encrypted data from numeric types columns using PDO::bindColumn
--DESCRIPTION-- --DESCRIPTION--
Use PDOstatement::bindParam with all PDO::PARAM_ types Test conversion from numeric types column to output of PDO::PARAM types
With or without AE, conversion works if:
1. From any numeric type except for bigint column to PDO::PARAM_BOOL
2. From any numeric type except for bigint column to PDO::PARAM_INT
3. From any numeric type column to PDO::PARAM_STR
4. From any numeric type column to PDO::PARAM_LOB
--SKIPIF-- --SKIPIF--
<?php require('skipif_mid-refactor.inc'); ?> <?php require('skipif_mid-refactor.inc'); ?>
--FILE-- --FILE--
@ -10,19 +15,21 @@ require_once("MsCommon_mid-refactor.inc");
require_once("AEData.inc"); require_once("AEData.inc");
$dataTypes = array( "bit", "tinyint", "smallint", "int", "bigint", "real"); $dataTypes = array( "bit", "tinyint", "smallint", "int", "bigint", "real");
$epsilon = 1;
try { try {
$conn = connect("", array(), PDO::ERRMODE_SILENT); $conn = connect("", array(), PDO::ERRMODE_SILENT);
foreach ($dataTypes as $dataType) { foreach ($dataTypes as $dataType) {
echo "\nTesting $dataType:\n"; echo "\nTesting $dataType:\n";
// create and populate table // create and populate table containing bit, tinyint, smallint, int, bigint, or real columns
$tbname = getTableName(); $tbname = "test_" . $dataType;
$colMetaArr = array(new ColumnMeta($dataType, "c_det"), new ColumnMeta($dataType, "c_rand", null, "randomized")); $colMetaArr = array(new ColumnMeta($dataType, "c_det"), new ColumnMeta($dataType, "c_rand", null, "randomized"));
createTable($conn, $tbname, $colMetaArr); createTable($conn, $tbname, $colMetaArr);
$inputValues = array_slice(${explode("(", $dataType)[0] . "_params"}, 1, 2); $inputValues = array_slice(${explode("(", $dataType)[0] . "_params"}, 1, 2);
insertRow($conn, $tbname, array("c_det" => $inputValues[0], "c_rand" => $inputValues[1])); insertRow($conn, $tbname, array("c_det" => $inputValues[0], "c_rand" => $inputValues[1]));
// fetch with PDO::bindColumn and PDO::FETCH_BOUND // fetch by specifying PDO::PARAM_ types with PDO::bindColumn
$query = "SELECT c_det, c_rand FROM $tbname"; $query = "SELECT c_det, c_rand FROM $tbname";
foreach ($pdoParamTypes as $pdoParamType) { foreach ($pdoParamTypes as $pdoParamType) {
$det = ""; $det = "";
@ -32,13 +39,48 @@ try {
$stmt->bindColumn('c_det', $det, constant($pdoParamType)); $stmt->bindColumn('c_det', $det, constant($pdoParamType));
$stmt->bindColumn('c_rand', $rand, constant($pdoParamType)); $stmt->bindColumn('c_rand', $rand, constant($pdoParamType));
$row = $stmt->fetch(PDO::FETCH_BOUND); $row = $stmt->fetch(PDO::FETCH_BOUND);
if ($row != false) {
if (is_null($det) || is_null($rand)) { // check the case when fetching as PDO::PARAM_NULL
echo "PDO param type $pdoParamType is not compatible with encrypted $dataType\n"; // with or without AE: should not work
if ($pdoParamType == "PDO::PARAM_NULL") {
if (!is_null($det) || !is_null($rand)) {
echo "Retrieving $dataType data as $pdoParamType should not be supported\n";
}
// check the case when fetching as PDO::PARAM_BOOL or PDO::PARAM_INT
// with or without AE: should only not work with bigint
} else if ($pdoParamType == "PDO::PARAM_BOOL" || $pdoParamType == "PDO::PARAM_INT") {
if ($dataType == "bigint") {
if (!is_null($det) || !is_null($rand)) {
echo "Retrieving $dataType data as $pdoParamType should not be supported\n";
}
} else if ($dataType == "real") {
if (abs($det - $inputValues[0]) < $epsilon && abs($rand - $inputValues[1]) < $epsilon) {
echo "****Retrieving $dataType as $pdoParamType is supported****\n";
} else {
echo "Retrieving $dataType as $pdoParamType fails\n";
}
} else { } else {
echo "****PDO param type $pdoParamType is compatible with encrypted $dataType****\n"; if ($det == $inputValues[0] && $rand == $inputValues[1]) {
echo "c_det: $det\n"; echo "****Retrieving $dataType as $pdoParamType is supported****\n";
echo "c_rand: $rand\n"; } else {
echo "Retrieving $dataType as $pdoParamType fails\n";
}
}
// check the case when fetching as PDO::PARAM_BOOL, PDO::PARAM_INT, PDO::PARAM_STR or PDO::PARAM_LOB
// with or without AE: should work
} else {
if ($dataType == "real") {
if (abs($det - $inputValues[0]) < $epsilon && abs($rand - $inputValues[1]) < $epsilon) {
echo "****Retrieving $dataType as $pdoParamType is supported****\n";
} else {
echo "Retrieving $dataType as $pdoParamType fails\n";
}
} else {
if ($det == $inputValues[0] && $rand == $inputValues[1]) {
echo "****Retrieving $dataType as $pdoParamType is supported****\n";
} else {
echo "Retrieving $dataType as $pdoParamType fails\n";
}
} }
} }
} }
@ -52,87 +94,35 @@ try {
?> ?>
--EXPECT-- --EXPECT--
Testing bit: Testing bit:
****PDO param type PDO::PARAM_BOOL is compatible with encrypted bit**** ****Retrieving bit as PDO::PARAM_BOOL is supported****
c_det: 1 ****Retrieving bit as PDO::PARAM_INT is supported****
c_rand: 0 ****Retrieving bit as PDO::PARAM_STR is supported****
PDO param type PDO::PARAM_NULL is not compatible with encrypted bit ****Retrieving bit as PDO::PARAM_LOB is supported****
****PDO param type PDO::PARAM_INT is compatible with encrypted bit****
c_det: 1
c_rand: 0
****PDO param type PDO::PARAM_STR is compatible with encrypted bit****
c_det: 1
c_rand: 0
****PDO param type PDO::PARAM_LOB is compatible with encrypted bit****
c_det: 1
c_rand: 0
Testing tinyint: Testing tinyint:
****PDO param type PDO::PARAM_BOOL is compatible with encrypted tinyint**** ****Retrieving tinyint as PDO::PARAM_BOOL is supported****
c_det: 0 ****Retrieving tinyint as PDO::PARAM_INT is supported****
c_rand: 255 ****Retrieving tinyint as PDO::PARAM_STR is supported****
PDO param type PDO::PARAM_NULL is not compatible with encrypted tinyint ****Retrieving tinyint as PDO::PARAM_LOB is supported****
****PDO param type PDO::PARAM_INT is compatible with encrypted tinyint****
c_det: 0
c_rand: 255
****PDO param type PDO::PARAM_STR is compatible with encrypted tinyint****
c_det: 0
c_rand: 255
****PDO param type PDO::PARAM_LOB is compatible with encrypted tinyint****
c_det: 0
c_rand: 255
Testing smallint: Testing smallint:
****PDO param type PDO::PARAM_BOOL is compatible with encrypted smallint**** ****Retrieving smallint as PDO::PARAM_BOOL is supported****
c_det: -32767 ****Retrieving smallint as PDO::PARAM_INT is supported****
c_rand: 32767 ****Retrieving smallint as PDO::PARAM_STR is supported****
PDO param type PDO::PARAM_NULL is not compatible with encrypted smallint ****Retrieving smallint as PDO::PARAM_LOB is supported****
****PDO param type PDO::PARAM_INT is compatible with encrypted smallint****
c_det: -32767
c_rand: 32767
****PDO param type PDO::PARAM_STR is compatible with encrypted smallint****
c_det: -32767
c_rand: 32767
****PDO param type PDO::PARAM_LOB is compatible with encrypted smallint****
c_det: -32767
c_rand: 32767
Testing int: Testing int:
****PDO param type PDO::PARAM_BOOL is compatible with encrypted int**** ****Retrieving int as PDO::PARAM_BOOL is supported****
c_det: -2147483647 ****Retrieving int as PDO::PARAM_INT is supported****
c_rand: 2147483647 ****Retrieving int as PDO::PARAM_STR is supported****
PDO param type PDO::PARAM_NULL is not compatible with encrypted int ****Retrieving int as PDO::PARAM_LOB is supported****
****PDO param type PDO::PARAM_INT is compatible with encrypted int****
c_det: -2147483647
c_rand: 2147483647
****PDO param type PDO::PARAM_STR is compatible with encrypted int****
c_det: -2147483647
c_rand: 2147483647
****PDO param type PDO::PARAM_LOB is compatible with encrypted int****
c_det: -2147483647
c_rand: 2147483647
Testing bigint: Testing bigint:
PDO param type PDO::PARAM_BOOL is not compatible with encrypted bigint ****Retrieving bigint as PDO::PARAM_STR is supported****
PDO param type PDO::PARAM_NULL is not compatible with encrypted bigint ****Retrieving bigint as PDO::PARAM_LOB is supported****
PDO param type PDO::PARAM_INT is not compatible with encrypted bigint
****PDO param type PDO::PARAM_STR is compatible with encrypted bigint****
c_det: -922337203685479936
c_rand: 922337203685479936
****PDO param type PDO::PARAM_LOB is compatible with encrypted bigint****
c_det: -922337203685479936
c_rand: 922337203685479936
Testing real: Testing real:
****PDO param type PDO::PARAM_BOOL is compatible with encrypted real**** ****Retrieving real as PDO::PARAM_BOOL is supported****
c_det: -2147 ****Retrieving real as PDO::PARAM_INT is supported****
c_rand: 2147 ****Retrieving real as PDO::PARAM_STR is supported****
PDO param type PDO::PARAM_NULL is not compatible with encrypted real ****Retrieving real as PDO::PARAM_LOB is supported****
****PDO param type PDO::PARAM_INT is compatible with encrypted real****
c_det: -2147
c_rand: 2147
****PDO param type PDO::PARAM_STR is compatible with encrypted real****
c_det: -2147.4829
c_rand: 2147.4829
****PDO param type PDO::PARAM_LOB is compatible with encrypted real****
c_det: -2147.4829
c_rand: 2147.4829

View file

@ -1,7 +1,10 @@
--TEST-- --TEST--
Test for inserting and retrieving encrypted data of string types Test for inserting encrypted data into binary types columns with different sizes
--DESCRIPTION-- --DESCRIPTION--
Use PDOstatement::bindParam with all PDO::PARAM_ types Test conversions between different binary types of different sizes
With or without Always Encrypted, implicit conversion works if:
1. From input of PDO::PARAM_STR to a any binary column
2. From input of PDO::PARAM_LOB to a any binary column
--SKIPIF-- --SKIPIF--
<?php require('skipif_mid-refactor.inc'); ?> <?php require('skipif_mid-refactor.inc'); ?>
--FILE-- --FILE--
@ -15,68 +18,74 @@ $lengths = array(2, 8, 64, 512, 4000);
try { try {
$conn = connect("", array(), PDO::ERRMODE_SILENT); $conn = connect("", array(), PDO::ERRMODE_SILENT);
foreach ($dataTypes as $dataType) { foreach ($dataTypes as $dataType) {
$maxtype = strpos($dataType, "(max)"); $maxcol = strpos($dataType, "(max)");
foreach ($lengths as $length) { foreach ($lengths as $m) {
if ($maxtype !== false) { if ($maxcol !== false) {
$type = $dataType; $typeFull = $dataType;
} else { } else {
$type = "$dataType($length)"; $typeFull = "$dataType($m)";
} }
echo "\nTesting $type:\n"; echo "\nTesting $typeFull:\n";
//create and populate table // create table containing binary(m) or varbinary(m) columns
$tbname = "test_binary"; $tbname = "test_" . str_replace(array('(', ')'), '', $dataType) . $m;
$colMetaArr = array(new ColumnMeta($type, "c_det"), new ColumnMeta($type, "c_rand", null, "randomized")); $colMetaArr = array(new ColumnMeta($typeFull, "c_det"), new ColumnMeta($typeFull, "c_rand", null, "randomized"));
createTable($conn, $tbname, $colMetaArr); createTable($conn, $tbname, $colMetaArr);
$input0 = str_repeat("d", $length); $inputValues = array(str_repeat("d", $m), str_repeat("r", $m));
$input1 = str_repeat("r", $length);
// prepare statement for inserting into table // insert by specifying PDO::PARAM_ types
foreach ($pdoParamTypes as $pdoParamType) { foreach ($pdoParamTypes as $pdoParamType) {
// insert a row
$r; $r;
if ($pdoParamType == 'PDO::PARAM_STR' || $pdoParamType == 'PDO::PARAM_LOB') { if ($pdoParamType == 'PDO::PARAM_STR' || $pdoParamType == 'PDO::PARAM_LOB') {
$stmt = insertRow($conn, $tbname, array("c_det" => new BindParamOp(1, $input0, $pdoParamType, 0, "PDO::SQLSRV_ENCODING_BINARY"), $stmt = insertRow($conn, $tbname, array("c_det" => new BindParamOp(1, $inputValues[0], $pdoParamType, 0, "PDO::SQLSRV_ENCODING_BINARY"),
"c_rand" => new BindParamOp(2, $input1, $pdoParamType, 0, "PDO::SQLSRV_ENCODING_BINARY")), "prepareBindParam", $r); "c_rand" => new BindParamOp(2, $inputValues[1], $pdoParamType, 0, "PDO::SQLSRV_ENCODING_BINARY")), "prepareBindParam", $r);
} else { } else {
$stmt = insertRow($conn, $tbname, array("c_det" => new BindParamOp(1, $input0, $pdoParamType), "c_rand" => new BindParamOp(2, $input1, $pdoParamType)), "prepareBindParam", $r); $stmt = insertRow($conn, $tbname, array("c_det" => new BindParamOp(1, $inputValues[0], $pdoParamType), "c_rand" => new BindParamOp(2, $inputValues[1], $pdoParamType)), "prepareBindParam", $r);
} }
if ($pdoParamType == "PDO::PARAM_STR" || $pdoParamType == "PDO::PARAM_LOB") { // check the case when inserting as PDO::PARAM_BOOL or PDO::PARAM_INT
if ($r === false) { // with or without AE: should not work
echo "$pdoParamType(PDO::SQLSRV_ENCODING_BINARY) should be compatible with encrypted $type\n"; if ($pdoParamType == "PDO::PARAM_BOOL" || $pdoParamType == "PDO::PARAM_INT") {
} else {
$sql = "SELECT c_det, c_rand FROM $tbname";
$stmt = $conn->query($sql);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if (strlen($row['c_det']) == $length && strlen($row['c_rand']) == $length) {
echo "****PDO param type $pdoParamType(PDO::SQLSRV_ENCODING_BINARY) is compatible with $type****\n";
} else {
echo "PDO param type $pdoParamType is incompatible with $type\n";
}
}
} elseif (!isAEConnected()) {
if ($r !== false) { if ($r !== false) {
echo "PDO param type $pdoParamType should not be compatible with $type\n"; echo "Conversion from $pdoParamType to $typeFull should not be supported\n";
} }
} else { // check the case when inserting as PDO::PARAM_NULL
if ($pdoParamType == "PDO::PARAM_BOOL" || $pdoParamType == "PDO::PARAM_INT") { // with AE: NULL is inserted
if ($r !== false) { // without AE: insertion fails
echo "PDO param type $pdoParamType should not be compatible with $type\n"; } elseif ($pdoParamType == "PDO::PARAM_NULL") {
$sql = "SELECT c_det, c_rand FROM $tbname"; if (isAEConnected()) {
$stmt = $conn->query($sql); if ($r === false) {
$row = $stmt->fetch(PDO::FETCH_ASSOC); echo "Conversion from $pdoParamType to $typeFull should be supported\n";
//var_dump($row);
} else { } else {
$sql = "SELECT c_det, c_rand FROM $tbname"; $sql = "SELECT c_det, c_rand FROM $tbname";
$stmt = $conn->query($sql); $stmt = $conn->query($sql);
$row = $stmt->fetch(PDO::FETCH_ASSOC); $row = $stmt->fetch(PDO::FETCH_ASSOC);
if (!is_null($row['c_det']) && !is_null($row['c_rand'])) { if (!is_null($row['c_det']) && !is_null($row['c_rand'])) {
"Data inserted with $pdoParamType should be null\n"; echo "Conversion from $pdoParamType to $typeFull should insert NULL\n";
} }
} }
} else {
if ($r !== false) {
echo "Conversion from $pdoParamType to $typeFull should not be supported\n";
}
}
// check the case when inserting as PDO::PARAM_STR or PDO::PARAM_LOB
// with or without AE: should work
} else {
if ($r === false) {
echo "Conversion from $pdoParamType to $typeFull should be supported\n";
} else {
$sql = "SELECT c_det, c_rand FROM $tbname";
$stmt = $conn->query($sql);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if (strlen($row['c_det']) == $m && strlen($row['c_rand']) == $m) {
echo "****Conversion from $pdoParamType to $typeFull is supported****\n";
} else {
echo "Conversion from $pdoParamType to $typeFull causes data corruption\n";
}
} }
} }
// cleanup
$conn->query("TRUNCATE TABLE $tbname"); $conn->query("TRUNCATE TABLE $tbname");
} }
dropTable($conn, $tbname); dropTable($conn, $tbname);
@ -90,61 +99,61 @@ try {
?> ?>
--EXPECT-- --EXPECT--
Testing binary(2): Testing binary(2):
****PDO param type PDO::PARAM_STR(PDO::SQLSRV_ENCODING_BINARY) is compatible with binary(2)**** ****Conversion from PDO::PARAM_STR to binary(2) is supported****
****PDO param type PDO::PARAM_LOB(PDO::SQLSRV_ENCODING_BINARY) is compatible with binary(2)**** ****Conversion from PDO::PARAM_LOB to binary(2) is supported****
Testing binary(8): Testing binary(8):
****PDO param type PDO::PARAM_STR(PDO::SQLSRV_ENCODING_BINARY) is compatible with binary(8)**** ****Conversion from PDO::PARAM_STR to binary(8) is supported****
****PDO param type PDO::PARAM_LOB(PDO::SQLSRV_ENCODING_BINARY) is compatible with binary(8)**** ****Conversion from PDO::PARAM_LOB to binary(8) is supported****
Testing binary(64): Testing binary(64):
****PDO param type PDO::PARAM_STR(PDO::SQLSRV_ENCODING_BINARY) is compatible with binary(64)**** ****Conversion from PDO::PARAM_STR to binary(64) is supported****
****PDO param type PDO::PARAM_LOB(PDO::SQLSRV_ENCODING_BINARY) is compatible with binary(64)**** ****Conversion from PDO::PARAM_LOB to binary(64) is supported****
Testing binary(512): Testing binary(512):
****PDO param type PDO::PARAM_STR(PDO::SQLSRV_ENCODING_BINARY) is compatible with binary(512)**** ****Conversion from PDO::PARAM_STR to binary(512) is supported****
****PDO param type PDO::PARAM_LOB(PDO::SQLSRV_ENCODING_BINARY) is compatible with binary(512)**** ****Conversion from PDO::PARAM_LOB to binary(512) is supported****
Testing binary(4000): Testing binary(4000):
****PDO param type PDO::PARAM_STR(PDO::SQLSRV_ENCODING_BINARY) is compatible with binary(4000)**** ****Conversion from PDO::PARAM_STR to binary(4000) is supported****
****PDO param type PDO::PARAM_LOB(PDO::SQLSRV_ENCODING_BINARY) is compatible with binary(4000)**** ****Conversion from PDO::PARAM_LOB to binary(4000) is supported****
Testing varbinary(2): Testing varbinary(2):
****PDO param type PDO::PARAM_STR(PDO::SQLSRV_ENCODING_BINARY) is compatible with varbinary(2)**** ****Conversion from PDO::PARAM_STR to varbinary(2) is supported****
****PDO param type PDO::PARAM_LOB(PDO::SQLSRV_ENCODING_BINARY) is compatible with varbinary(2)**** ****Conversion from PDO::PARAM_LOB to varbinary(2) is supported****
Testing varbinary(8): Testing varbinary(8):
****PDO param type PDO::PARAM_STR(PDO::SQLSRV_ENCODING_BINARY) is compatible with varbinary(8)**** ****Conversion from PDO::PARAM_STR to varbinary(8) is supported****
****PDO param type PDO::PARAM_LOB(PDO::SQLSRV_ENCODING_BINARY) is compatible with varbinary(8)**** ****Conversion from PDO::PARAM_LOB to varbinary(8) is supported****
Testing varbinary(64): Testing varbinary(64):
****PDO param type PDO::PARAM_STR(PDO::SQLSRV_ENCODING_BINARY) is compatible with varbinary(64)**** ****Conversion from PDO::PARAM_STR to varbinary(64) is supported****
****PDO param type PDO::PARAM_LOB(PDO::SQLSRV_ENCODING_BINARY) is compatible with varbinary(64)**** ****Conversion from PDO::PARAM_LOB to varbinary(64) is supported****
Testing varbinary(512): Testing varbinary(512):
****PDO param type PDO::PARAM_STR(PDO::SQLSRV_ENCODING_BINARY) is compatible with varbinary(512)**** ****Conversion from PDO::PARAM_STR to varbinary(512) is supported****
****PDO param type PDO::PARAM_LOB(PDO::SQLSRV_ENCODING_BINARY) is compatible with varbinary(512)**** ****Conversion from PDO::PARAM_LOB to varbinary(512) is supported****
Testing varbinary(4000): Testing varbinary(4000):
****PDO param type PDO::PARAM_STR(PDO::SQLSRV_ENCODING_BINARY) is compatible with varbinary(4000)**** ****Conversion from PDO::PARAM_STR to varbinary(4000) is supported****
****PDO param type PDO::PARAM_LOB(PDO::SQLSRV_ENCODING_BINARY) is compatible with varbinary(4000)**** ****Conversion from PDO::PARAM_LOB to varbinary(4000) is supported****
Testing varbinary(max): Testing varbinary(max):
****PDO param type PDO::PARAM_STR(PDO::SQLSRV_ENCODING_BINARY) is compatible with varbinary(max)**** ****Conversion from PDO::PARAM_STR to varbinary(max) is supported****
****PDO param type PDO::PARAM_LOB(PDO::SQLSRV_ENCODING_BINARY) is compatible with varbinary(max)**** ****Conversion from PDO::PARAM_LOB to varbinary(max) is supported****
Testing varbinary(max): Testing varbinary(max):
****PDO param type PDO::PARAM_STR(PDO::SQLSRV_ENCODING_BINARY) is compatible with varbinary(max)**** ****Conversion from PDO::PARAM_STR to varbinary(max) is supported****
****PDO param type PDO::PARAM_LOB(PDO::SQLSRV_ENCODING_BINARY) is compatible with varbinary(max)**** ****Conversion from PDO::PARAM_LOB to varbinary(max) is supported****
Testing varbinary(max): Testing varbinary(max):
****PDO param type PDO::PARAM_STR(PDO::SQLSRV_ENCODING_BINARY) is compatible with varbinary(max)**** ****Conversion from PDO::PARAM_STR to varbinary(max) is supported****
****PDO param type PDO::PARAM_LOB(PDO::SQLSRV_ENCODING_BINARY) is compatible with varbinary(max)**** ****Conversion from PDO::PARAM_LOB to varbinary(max) is supported****
Testing varbinary(max): Testing varbinary(max):
****PDO param type PDO::PARAM_STR(PDO::SQLSRV_ENCODING_BINARY) is compatible with varbinary(max)**** ****Conversion from PDO::PARAM_STR to varbinary(max) is supported****
****PDO param type PDO::PARAM_LOB(PDO::SQLSRV_ENCODING_BINARY) is compatible with varbinary(max)**** ****Conversion from PDO::PARAM_LOB to varbinary(max) is supported****
Testing varbinary(max): Testing varbinary(max):
****PDO param type PDO::PARAM_STR(PDO::SQLSRV_ENCODING_BINARY) is compatible with varbinary(max)**** ****Conversion from PDO::PARAM_STR to varbinary(max) is supported****
****PDO param type PDO::PARAM_LOB(PDO::SQLSRV_ENCODING_BINARY) is compatible with varbinary(max)**** ****Conversion from PDO::PARAM_LOB to varbinary(max) is supported****

View file

@ -1,7 +1,12 @@
--TEST-- --TEST--
Test for inserting and retrieving encrypted data of string types Test for inserting encrypted data into char types columns with different sizes
--DESCRIPTION-- --DESCRIPTION--
Use PDOstatement::bindParam with all PDO::PARAM_ types Test conversions between different char types of different sizes
With or without Always Encrypted, implicit conversion works if:
1. From input of PDO::PARAM_BOOL to a any char column
2. From input of PDO::PARAM_INT to a any char column
3. From input of PDO::PARAM_STR to a any char column
4. From input of PDO::PARAM_LOB to a any char column
--SKIPIF-- --SKIPIF--
<?php require('skipif_mid-refactor.inc'); ?> <?php require('skipif_mid-refactor.inc'); ?>
--FILE-- --FILE--
@ -11,49 +16,59 @@ require_once("AEData.inc");
$dataTypes = array("char", "varchar", "varchar(max)"); $dataTypes = array("char", "varchar", "varchar(max)");
$lengths = array(1, 8, 64, 512, 4096, 8000); $lengths = array(1, 8, 64, 512, 4096, 8000);
$encTypes = array("deterministic", "randomized");
try { try {
$conn = connect(); $conn = connect();
foreach ($dataTypes as $dataType) { foreach ($dataTypes as $dataType) {
$maxtype = strpos($dataType, "(max)"); $maxcol = strpos($dataType, "(max)");
foreach ($lengths as $length) { foreach ($lengths as $m) {
if ($maxtype !== false) { if ($maxcol !== false) {
$type = $dataType; $typeFull = $dataType;
} else { } else {
$type = "$dataType($length)"; $typeFull = "$dataType($m)";
} }
echo "\nTesting $type:\n"; echo "\nTesting $typeFull:\n";
foreach($encTypes as $encType) { //create table containing char(m) or varchar(m) columns
//create and populate table $tbname = "test_" . str_replace(array('(', ')'), '', $dataType) . $m;
$tbname = getTableName(); $colMetaArr = array(new ColumnMeta($typeFull, "c1", null, "randomized"));
$colMetaArr = array(new ColumnMeta($type, "c1", null, $encType)); createTable($conn, $tbname, $colMetaArr);
createTable($conn, $tbname, $colMetaArr); $input = str_repeat("d", $m);
$input = str_repeat("d", $length);
// prepare statement for inserting into table // insert by specifying PDO::PARAM_ types
foreach ($pdoParamTypes as $pdoParamType) { foreach ($pdoParamTypes as $pdoParamType) {
// insert a row $r;
$r; $stmt = insertRow($conn, $tbname, array( "c1" => new BindParamOp(1, $input, $pdoParamType)), "prepareBindParam", $r);
$stmt = insertRow($conn, $tbname, array( "c1" => new BindParamOp(1, $input, $pdoParamType)), "prepareBindParam", $r);
// check the case when inserting as PDO::PARAM_NULL
// with or without AE: NULL is inserted
if ($pdoParamType == "PDO::PARAM_NULL") {
if ($r === false) { if ($r === false) {
isIncompatibleTypesError($stmt, $type, $pdoParamType); echo "Conversion from $pdoParamType to $typeFull should be supported\n";
} else { } else {
$sql = "SELECT c1 FROM $tbname"; $sql = "SELECT c1 FROM $tbname";
$stmt = $conn->query($sql); $stmt = $conn->query($sql);
$row = $stmt->fetch(PDO::FETCH_ASSOC); $row = $stmt->fetch(PDO::FETCH_ASSOC);
if (strlen($row['c1']) == $length) { if (!is_null($row['c1'])) {
echo "****PDO param type $pdoParamType is compatible with $encType encrypted $type****\n"; echo "Conversion from $pdoParamType to $typeFull should insert NULL\n";
} else {
echo "PDO param type $pdoParamType is incompatible with $encType encrypted $type\n";
} }
} }
$conn->query("TRUNCATE TABLE $tbname"); // check the case when inserting as PDO::PARAM_BOOL, PDO::PARAM_INT, PDO::PARAM_STR or PDO{{PARAM_LOB
// with or without AE: should work
} else {
$sql = "SELECT c1 FROM $tbname";
$stmt = $conn->query($sql);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if (strlen($row['c1']) == $m) {
echo "****Conversion from $pdoParamType to $typeFull is supported****\n";
} else {
echo "Conversion from $pdoParamType to $typeFull causes data corruption\n";
}
} }
dropTable($conn, $tbname); // cleanup
$conn->query("TRUNCATE TABLE $tbname");
} }
dropTable($conn, $tbname);
} }
} }
unset($stmt); unset($stmt);
@ -64,217 +79,109 @@ try {
?> ?>
--EXPECT-- --EXPECT--
Testing char(1): Testing char(1):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted char(1)**** ****Conversion from PDO::PARAM_BOOL to char(1) is supported****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted char(1) ****Conversion from PDO::PARAM_INT to char(1) is supported****
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted char(1)**** ****Conversion from PDO::PARAM_STR to char(1) is supported****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted char(1)**** ****Conversion from PDO::PARAM_LOB to char(1) is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted char(1)****
****PDO param type PDO::PARAM_BOOL is compatible with randomized encrypted char(1)****
PDO param type PDO::PARAM_NULL is incompatible with randomized encrypted char(1)
****PDO param type PDO::PARAM_INT is compatible with randomized encrypted char(1)****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted char(1)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted char(1)****
Testing char(8): Testing char(8):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted char(8)**** ****Conversion from PDO::PARAM_BOOL to char(8) is supported****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted char(8) ****Conversion from PDO::PARAM_INT to char(8) is supported****
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted char(8)**** ****Conversion from PDO::PARAM_STR to char(8) is supported****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted char(8)**** ****Conversion from PDO::PARAM_LOB to char(8) is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted char(8)****
****PDO param type PDO::PARAM_BOOL is compatible with randomized encrypted char(8)****
PDO param type PDO::PARAM_NULL is incompatible with randomized encrypted char(8)
****PDO param type PDO::PARAM_INT is compatible with randomized encrypted char(8)****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted char(8)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted char(8)****
Testing char(64): Testing char(64):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted char(64)**** ****Conversion from PDO::PARAM_BOOL to char(64) is supported****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted char(64) ****Conversion from PDO::PARAM_INT to char(64) is supported****
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted char(64)**** ****Conversion from PDO::PARAM_STR to char(64) is supported****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted char(64)**** ****Conversion from PDO::PARAM_LOB to char(64) is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted char(64)****
****PDO param type PDO::PARAM_BOOL is compatible with randomized encrypted char(64)****
PDO param type PDO::PARAM_NULL is incompatible with randomized encrypted char(64)
****PDO param type PDO::PARAM_INT is compatible with randomized encrypted char(64)****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted char(64)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted char(64)****
Testing char(512): Testing char(512):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted char(512)**** ****Conversion from PDO::PARAM_BOOL to char(512) is supported****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted char(512) ****Conversion from PDO::PARAM_INT to char(512) is supported****
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted char(512)**** ****Conversion from PDO::PARAM_STR to char(512) is supported****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted char(512)**** ****Conversion from PDO::PARAM_LOB to char(512) is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted char(512)****
****PDO param type PDO::PARAM_BOOL is compatible with randomized encrypted char(512)****
PDO param type PDO::PARAM_NULL is incompatible with randomized encrypted char(512)
****PDO param type PDO::PARAM_INT is compatible with randomized encrypted char(512)****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted char(512)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted char(512)****
Testing char(4096): Testing char(4096):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted char(4096)**** ****Conversion from PDO::PARAM_BOOL to char(4096) is supported****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted char(4096) ****Conversion from PDO::PARAM_INT to char(4096) is supported****
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted char(4096)**** ****Conversion from PDO::PARAM_STR to char(4096) is supported****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted char(4096)**** ****Conversion from PDO::PARAM_LOB to char(4096) is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted char(4096)****
****PDO param type PDO::PARAM_BOOL is compatible with randomized encrypted char(4096)****
PDO param type PDO::PARAM_NULL is incompatible with randomized encrypted char(4096)
****PDO param type PDO::PARAM_INT is compatible with randomized encrypted char(4096)****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted char(4096)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted char(4096)****
Testing char(8000): Testing char(8000):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted char(8000)**** ****Conversion from PDO::PARAM_BOOL to char(8000) is supported****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted char(8000) ****Conversion from PDO::PARAM_INT to char(8000) is supported****
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted char(8000)**** ****Conversion from PDO::PARAM_STR to char(8000) is supported****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted char(8000)**** ****Conversion from PDO::PARAM_LOB to char(8000) is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted char(8000)****
****PDO param type PDO::PARAM_BOOL is compatible with randomized encrypted char(8000)****
PDO param type PDO::PARAM_NULL is incompatible with randomized encrypted char(8000)
****PDO param type PDO::PARAM_INT is compatible with randomized encrypted char(8000)****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted char(8000)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted char(8000)****
Testing varchar(1): Testing varchar(1):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted varchar(1)**** ****Conversion from PDO::PARAM_BOOL to varchar(1) is supported****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted varchar(1) ****Conversion from PDO::PARAM_INT to varchar(1) is supported****
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted varchar(1)**** ****Conversion from PDO::PARAM_STR to varchar(1) is supported****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted varchar(1)**** ****Conversion from PDO::PARAM_LOB to varchar(1) is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted varchar(1)****
****PDO param type PDO::PARAM_BOOL is compatible with randomized encrypted varchar(1)****
PDO param type PDO::PARAM_NULL is incompatible with randomized encrypted varchar(1)
****PDO param type PDO::PARAM_INT is compatible with randomized encrypted varchar(1)****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted varchar(1)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted varchar(1)****
Testing varchar(8): Testing varchar(8):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted varchar(8)**** ****Conversion from PDO::PARAM_BOOL to varchar(8) is supported****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted varchar(8) ****Conversion from PDO::PARAM_INT to varchar(8) is supported****
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted varchar(8)**** ****Conversion from PDO::PARAM_STR to varchar(8) is supported****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted varchar(8)**** ****Conversion from PDO::PARAM_LOB to varchar(8) is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted varchar(8)****
****PDO param type PDO::PARAM_BOOL is compatible with randomized encrypted varchar(8)****
PDO param type PDO::PARAM_NULL is incompatible with randomized encrypted varchar(8)
****PDO param type PDO::PARAM_INT is compatible with randomized encrypted varchar(8)****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted varchar(8)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted varchar(8)****
Testing varchar(64): Testing varchar(64):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted varchar(64)**** ****Conversion from PDO::PARAM_BOOL to varchar(64) is supported****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted varchar(64) ****Conversion from PDO::PARAM_INT to varchar(64) is supported****
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted varchar(64)**** ****Conversion from PDO::PARAM_STR to varchar(64) is supported****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted varchar(64)**** ****Conversion from PDO::PARAM_LOB to varchar(64) is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted varchar(64)****
****PDO param type PDO::PARAM_BOOL is compatible with randomized encrypted varchar(64)****
PDO param type PDO::PARAM_NULL is incompatible with randomized encrypted varchar(64)
****PDO param type PDO::PARAM_INT is compatible with randomized encrypted varchar(64)****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted varchar(64)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted varchar(64)****
Testing varchar(512): Testing varchar(512):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted varchar(512)**** ****Conversion from PDO::PARAM_BOOL to varchar(512) is supported****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted varchar(512) ****Conversion from PDO::PARAM_INT to varchar(512) is supported****
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted varchar(512)**** ****Conversion from PDO::PARAM_STR to varchar(512) is supported****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted varchar(512)**** ****Conversion from PDO::PARAM_LOB to varchar(512) is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted varchar(512)****
****PDO param type PDO::PARAM_BOOL is compatible with randomized encrypted varchar(512)****
PDO param type PDO::PARAM_NULL is incompatible with randomized encrypted varchar(512)
****PDO param type PDO::PARAM_INT is compatible with randomized encrypted varchar(512)****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted varchar(512)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted varchar(512)****
Testing varchar(4096): Testing varchar(4096):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted varchar(4096)**** ****Conversion from PDO::PARAM_BOOL to varchar(4096) is supported****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted varchar(4096) ****Conversion from PDO::PARAM_INT to varchar(4096) is supported****
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted varchar(4096)**** ****Conversion from PDO::PARAM_STR to varchar(4096) is supported****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted varchar(4096)**** ****Conversion from PDO::PARAM_LOB to varchar(4096) is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted varchar(4096)****
****PDO param type PDO::PARAM_BOOL is compatible with randomized encrypted varchar(4096)****
PDO param type PDO::PARAM_NULL is incompatible with randomized encrypted varchar(4096)
****PDO param type PDO::PARAM_INT is compatible with randomized encrypted varchar(4096)****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted varchar(4096)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted varchar(4096)****
Testing varchar(8000): Testing varchar(8000):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted varchar(8000)**** ****Conversion from PDO::PARAM_BOOL to varchar(8000) is supported****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted varchar(8000) ****Conversion from PDO::PARAM_INT to varchar(8000) is supported****
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted varchar(8000)**** ****Conversion from PDO::PARAM_STR to varchar(8000) is supported****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted varchar(8000)**** ****Conversion from PDO::PARAM_LOB to varchar(8000) is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted varchar(8000)****
****PDO param type PDO::PARAM_BOOL is compatible with randomized encrypted varchar(8000)****
PDO param type PDO::PARAM_NULL is incompatible with randomized encrypted varchar(8000)
****PDO param type PDO::PARAM_INT is compatible with randomized encrypted varchar(8000)****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted varchar(8000)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted varchar(8000)****
Testing varchar(max): Testing varchar(max):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted varchar(max)**** ****Conversion from PDO::PARAM_BOOL to varchar(max) is supported****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted varchar(max) ****Conversion from PDO::PARAM_INT to varchar(max) is supported****
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted varchar(max)**** ****Conversion from PDO::PARAM_STR to varchar(max) is supported****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted varchar(max)**** ****Conversion from PDO::PARAM_LOB to varchar(max) is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted varchar(max)****
****PDO param type PDO::PARAM_BOOL is compatible with randomized encrypted varchar(max)****
PDO param type PDO::PARAM_NULL is incompatible with randomized encrypted varchar(max)
****PDO param type PDO::PARAM_INT is compatible with randomized encrypted varchar(max)****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted varchar(max)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted varchar(max)****
Testing varchar(max): Testing varchar(max):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted varchar(max)**** ****Conversion from PDO::PARAM_BOOL to varchar(max) is supported****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted varchar(max) ****Conversion from PDO::PARAM_INT to varchar(max) is supported****
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted varchar(max)**** ****Conversion from PDO::PARAM_STR to varchar(max) is supported****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted varchar(max)**** ****Conversion from PDO::PARAM_LOB to varchar(max) is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted varchar(max)****
****PDO param type PDO::PARAM_BOOL is compatible with randomized encrypted varchar(max)****
PDO param type PDO::PARAM_NULL is incompatible with randomized encrypted varchar(max)
****PDO param type PDO::PARAM_INT is compatible with randomized encrypted varchar(max)****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted varchar(max)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted varchar(max)****
Testing varchar(max): Testing varchar(max):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted varchar(max)**** ****Conversion from PDO::PARAM_BOOL to varchar(max) is supported****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted varchar(max) ****Conversion from PDO::PARAM_INT to varchar(max) is supported****
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted varchar(max)**** ****Conversion from PDO::PARAM_STR to varchar(max) is supported****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted varchar(max)**** ****Conversion from PDO::PARAM_LOB to varchar(max) is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted varchar(max)****
****PDO param type PDO::PARAM_BOOL is compatible with randomized encrypted varchar(max)****
PDO param type PDO::PARAM_NULL is incompatible with randomized encrypted varchar(max)
****PDO param type PDO::PARAM_INT is compatible with randomized encrypted varchar(max)****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted varchar(max)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted varchar(max)****
Testing varchar(max): Testing varchar(max):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted varchar(max)**** ****Conversion from PDO::PARAM_BOOL to varchar(max) is supported****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted varchar(max) ****Conversion from PDO::PARAM_INT to varchar(max) is supported****
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted varchar(max)**** ****Conversion from PDO::PARAM_STR to varchar(max) is supported****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted varchar(max)**** ****Conversion from PDO::PARAM_LOB to varchar(max) is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted varchar(max)****
****PDO param type PDO::PARAM_BOOL is compatible with randomized encrypted varchar(max)****
PDO param type PDO::PARAM_NULL is incompatible with randomized encrypted varchar(max)
****PDO param type PDO::PARAM_INT is compatible with randomized encrypted varchar(max)****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted varchar(max)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted varchar(max)****
Testing varchar(max): Testing varchar(max):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted varchar(max)**** ****Conversion from PDO::PARAM_BOOL to varchar(max) is supported****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted varchar(max) ****Conversion from PDO::PARAM_INT to varchar(max) is supported****
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted varchar(max)**** ****Conversion from PDO::PARAM_STR to varchar(max) is supported****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted varchar(max)**** ****Conversion from PDO::PARAM_LOB to varchar(max) is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted varchar(max)****
****PDO param type PDO::PARAM_BOOL is compatible with randomized encrypted varchar(max)****
PDO param type PDO::PARAM_NULL is incompatible with randomized encrypted varchar(max)
****PDO param type PDO::PARAM_INT is compatible with randomized encrypted varchar(max)****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted varchar(max)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted varchar(max)****
Testing varchar(max): Testing varchar(max):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted varchar(max)**** ****Conversion from PDO::PARAM_BOOL to varchar(max) is supported****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted varchar(max) ****Conversion from PDO::PARAM_INT to varchar(max) is supported****
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted varchar(max)**** ****Conversion from PDO::PARAM_STR to varchar(max) is supported****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted varchar(max)**** ****Conversion from PDO::PARAM_LOB to varchar(max) is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted varchar(max)****
****PDO param type PDO::PARAM_BOOL is compatible with randomized encrypted varchar(max)****
PDO param type PDO::PARAM_NULL is incompatible with randomized encrypted varchar(max)
****PDO param type PDO::PARAM_INT is compatible with randomized encrypted varchar(max)****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted varchar(max)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted varchar(max)****

View file

@ -1,7 +1,12 @@
--TEST-- --TEST--
Test for inserting and retrieving encrypted data of datetime types Test for inserting encrypted data into datetime types columns
--DESCRIPTION-- --DESCRIPTION--
Use PDOstatement::bindParam with all PDO::PARAM_ types Test conversions between different datetime types
With or without Always Encrypted, implicit conversion works if:
1. From input of PDO::PARAM_BOOL to a any datetime column
2. From input of PDO::PARAM_INT to a any datetime column
3. From input of PDO::PARAM_STR to a any datetime column
4. From input of PDO::PARAM_LOB to a any datetime column
--SKIPIF-- --SKIPIF--
<?php require('skipif_mid-refactor.inc'); ?> <?php require('skipif_mid-refactor.inc'); ?>
--FILE-- --FILE--
@ -10,27 +15,47 @@ require_once("MsCommon_mid-refactor.inc");
require_once("AEData.inc"); require_once("AEData.inc");
$dataTypes = array( "date", "datetime", "smalldatetime"); $dataTypes = array( "date", "datetime", "smalldatetime");
try { try {
$conn = connect(); $conn = connect();
foreach ($dataTypes as $dataType) { foreach ($dataTypes as $dataType) {
echo "\nTesting $dataType:\n"; echo "\nTesting $dataType:\n";
// create table // create table containing date, datetime or smalldatetime columns
$tbname = getTableName(); $tbname = "test_" . $dataType;
$colMetaArr = array( new ColumnMeta($dataType, "c_det"), new ColumnMeta($dataType, "c_rand", null, "randomized")); $colMetaArr = array( new ColumnMeta($dataType, "c_det"), new ColumnMeta($dataType, "c_rand", null, "randomized"));
createTable($conn, $tbname, $colMetaArr); createTable($conn, $tbname, $colMetaArr);
// prepare statement for inserting into table // insert by specifying PDO::PARAM_ types
foreach ($pdoParamTypes as $pdoParamType) { foreach ($pdoParamTypes as $pdoParamType) {
// insert a row
$inputValues = array_slice(${explode("(", $dataType)[0] . "_params"}, 1, 2); $inputValues = array_slice(${explode("(", $dataType)[0] . "_params"}, 1, 2);
$r; $r;
$stmt = insertRow($conn, $tbname, array( "c_det" => new BindParamOp(1, $inputValues[0], $pdoParamType), "c_rand" => new BindParamOp(2, $inputValues[1], $pdoParamType)), "prepareBindParam", $r); $stmt = insertRow($conn, $tbname, array( "c_det" => new BindParamOp(1, $inputValues[0], $pdoParamType), "c_rand" => new BindParamOp(2, $inputValues[1], $pdoParamType)), "prepareBindParam", $r);
if ($r === false) {
isIncompatibleTypesError($stmt, $dataType, $pdoParamType); // check the case when inserting as PDO::PARAM_NULL
// with or without AE: NULL is inserted
if ($pdoParamType == "PDO::PARAM_NULL") {
if ($r === false) {
echo "Conversion from $pdoParamType to $dataType should be supported\n";
} else {
$sql = "SELECT c_det, c_rand FROM $tbname";
$stmt = $conn->query($sql);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if (!is_null($row['c_det']) || !is_null($row['c_rand'])) {
echo "Conversion from $pdoParamType to $dataType should insert NULL\n";
}
}
// check the case when inserting as PDO::PARAM_BOOL, PDO::PARAM_INT, PDO::PARAM_STR or PDO::PARAM_LOB
// with or without AE: should work
} else { } else {
echo "****PDO param type $pdoParamType is compatible with encrypted $dataType****\n"; $sql = "SELECT c_det, c_rand FROM $tbname";
fetchAll($conn, $tbname); $stmt = $conn->query($sql);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if (strpos($row['c_det'], $inputValues[0]) !== false && strpos($row['c_rand'], $inputValues[1]) !== false) {
echo "****Conversion from $pdoParamType to $dataType is supported****\n";
} else {
echo "Conversion from $pdoParamType to $dataType causes data corruption\n";
}
} }
$conn->query("TRUNCATE TABLE $tbname"); $conn->query("TRUNCATE TABLE $tbname");
} }
@ -44,52 +69,19 @@ try {
?> ?>
--EXPECT-- --EXPECT--
Testing date: Testing date:
****PDO param type PDO::PARAM_BOOL is compatible with encrypted date**** ****Conversion from PDO::PARAM_BOOL to date is supported****
c_det: 0001-01-01 ****Conversion from PDO::PARAM_INT to date is supported****
c_rand: 9999-12-31 ****Conversion from PDO::PARAM_STR to date is supported****
****PDO param type PDO::PARAM_NULL is compatible with encrypted date**** ****Conversion from PDO::PARAM_LOB to date is supported****
c_det:
c_rand:
****PDO param type PDO::PARAM_INT is compatible with encrypted date****
c_det: 0001-01-01
c_rand: 9999-12-31
****PDO param type PDO::PARAM_STR is compatible with encrypted date****
c_det: 0001-01-01
c_rand: 9999-12-31
****PDO param type PDO::PARAM_LOB is compatible with encrypted date****
c_det: 0001-01-01
c_rand: 9999-12-31
Testing datetime: Testing datetime:
****PDO param type PDO::PARAM_BOOL is compatible with encrypted datetime**** ****Conversion from PDO::PARAM_BOOL to datetime is supported****
c_det: 1753-01-01 00:00:00.000 ****Conversion from PDO::PARAM_INT to datetime is supported****
c_rand: 9999-12-31 23:59:59.997 ****Conversion from PDO::PARAM_STR to datetime is supported****
****PDO param type PDO::PARAM_NULL is compatible with encrypted datetime**** ****Conversion from PDO::PARAM_LOB to datetime is supported****
c_det:
c_rand:
****PDO param type PDO::PARAM_INT is compatible with encrypted datetime****
c_det: 1753-01-01 00:00:00.000
c_rand: 9999-12-31 23:59:59.997
****PDO param type PDO::PARAM_STR is compatible with encrypted datetime****
c_det: 1753-01-01 00:00:00.000
c_rand: 9999-12-31 23:59:59.997
****PDO param type PDO::PARAM_LOB is compatible with encrypted datetime****
c_det: 1753-01-01 00:00:00.000
c_rand: 9999-12-31 23:59:59.997
Testing smalldatetime: Testing smalldatetime:
****PDO param type PDO::PARAM_BOOL is compatible with encrypted smalldatetime**** ****Conversion from PDO::PARAM_BOOL to smalldatetime is supported****
c_det: 1900-01-01 00:00:00 ****Conversion from PDO::PARAM_INT to smalldatetime is supported****
c_rand: 2079-06-05 23:59:00 ****Conversion from PDO::PARAM_STR to smalldatetime is supported****
****PDO param type PDO::PARAM_NULL is compatible with encrypted smalldatetime**** ****Conversion from PDO::PARAM_LOB to smalldatetime is supported****
c_det:
c_rand:
****PDO param type PDO::PARAM_INT is compatible with encrypted smalldatetime****
c_det: 1900-01-01 00:00:00
c_rand: 2079-06-05 23:59:00
****PDO param type PDO::PARAM_STR is compatible with encrypted smalldatetime****
c_det: 1900-01-01 00:00:00
c_rand: 2079-06-05 23:59:00
****PDO param type PDO::PARAM_LOB is compatible with encrypted smalldatetime****
c_det: 1900-01-01 00:00:00
c_rand: 2079-06-05 23:59:00

View file

@ -1,7 +1,12 @@
--TEST-- --TEST--
Test for inserting and retrieving encrypted data of datetime types Test for inserting encrypted data into datetime types with different precisions columns
--DESCRIPTION-- --DESCRIPTION--
Use PDOstatement::bindParam with all PDO::PARAM_ types Test conversions between different datetime types
With or without Always Encrypted, implicit conversion works if:
1. From input of PDO::PARAM_BOOL to a any datetime column
2. From input of PDO::PARAM_INT to a any datetime column
3. From input of PDO::PARAM_STR to a any datetime column
4. From input of PDO::PARAM_LOB to a any datetime column
--SKIPIF-- --SKIPIF--
<?php require('skipif_mid-refactor.inc'); ?> <?php require('skipif_mid-refactor.inc'); ?>
--FILE-- --FILE--
@ -9,6 +14,20 @@ Use PDOstatement::bindParam with all PDO::PARAM_ types
require_once("MsCommon_mid-refactor.inc"); require_once("MsCommon_mid-refactor.inc");
require_once("AEData.inc"); require_once("AEData.inc");
function compareDate($dtout, $dtin, $dataType) {
if ($dataType == "datetimeoffset") {
$dtarr = explode(' ', $dtin);
if (strpos($dtout, $dtarr[0]) !== false && strpos($dtout, $dtarr[1]) !== false && strpos($dtout, $dtarr[2]) !== false) {
return true;
}
} else {
if (strpos($dtout, $dtin) !== false) {
return true;
}
}
return false;
}
$dataTypes = array("datetime2", "datetimeoffset", "time"); $dataTypes = array("datetime2", "datetimeoffset", "time");
$precisions = array(/*0,*/ 1, 2, 4, 7); $precisions = array(/*0,*/ 1, 2, 4, 7);
$inputValuesInit = array("datetime2" => array("0001-01-01 00:00:00", "9999-12-31 23:59:59"), $inputValuesInit = array("datetime2" => array("0001-01-01 00:00:00", "9999-12-31 23:59:59"),
@ -18,38 +37,58 @@ $inputValuesInit = array("datetime2" => array("0001-01-01 00:00:00", "9999-12-31
try { try {
$conn = connect("", array(), PDO::ERRMODE_SILENT); $conn = connect("", array(), PDO::ERRMODE_SILENT);
foreach ($dataTypes as $dataType) { foreach ($dataTypes as $dataType) {
foreach ($precisions as $precision) { foreach ($precisions as $m) {
// change the input values depending on the precision // add $m number of decimal digits to the some input values
$inputValues[0] = $inputValuesInit[$dataType][0]; $inputValues[0] = $inputValuesInit[$dataType][0];
$inputValues[1] = $inputValuesInit[$dataType][1]; $inputValues[1] = $inputValuesInit[$dataType][1];
if ($precision != 0) { if ($m != 0) {
if ($dataType == "datetime2") { if ($dataType == "datetime2") {
$inputValues[1] .= "." . str_repeat("9", $precision); $inputValues[1] .= "." . str_repeat("9", $m);
} else if ($dataType == "datetimeoffset") { } else if ($dataType == "datetimeoffset") {
$inputPieces = explode(" ", $inputValues[1]); $dtoffsetPieces = explode(" ", $inputValues[1]);
$inputValues[1] = $inputPieces[0] . " " . $inputPieces[1] . "." . str_repeat("9", $precision) . " " . $inputPieces[2]; $inputValues[1] = $dtoffsetPieces[0] . " " . $dtoffsetPieces[1] . "." . str_repeat("9", $m) . " " . $dtoffsetPieces[2];
} else if ($dataType == "time") { } else if ($dataType == "time") {
$inputValues[0] .= "." . str_repeat("0", $precision); $inputValues[0] .= "." . str_repeat("0", $m);
$inputValues[1] .= "." . str_repeat("9", $precision); $inputValues[1] .= "." . str_repeat("9", $m);
} }
} }
$type = "$dataType($precision)"; $typeFull = "$dataType($m)";
echo "\nTesting $type:\n"; echo "\nTesting $typeFull:\n";
//create and populate table //create table containing datetime2(m), datetimeoffset(m), or time(m) columns
$tbname = "test_datetime"; $tbname = "test_" . $dataType . $m;
$colMetaArr = array(new ColumnMeta($type, "c_det"), new ColumnMeta($type, "c_rand", null, "randomized")); $colMetaArr = array(new ColumnMeta($typeFull, "c_det"), new ColumnMeta($typeFull, "c_rand", null, "randomized"));
createTable($conn, $tbname, $colMetaArr); createTable($conn, $tbname, $colMetaArr);
// prepare statement for inserting into table // insert by specifying PDO::PARAM_ types
foreach ($pdoParamTypes as $pdoParamType) { foreach ($pdoParamTypes as $pdoParamType) {
// insert a row $r;
$stmt = insertRow($conn, $tbname, array( "c_det" => new BindParamOp(1, $inputValues[0], $pdoParamType), "c_rand" => new BindParamOp(2, $inputValues[1], $pdoParamType)), "prepareBindParam", $r); $stmt = insertRow($conn, $tbname, array( "c_det" => new BindParamOp(1, $inputValues[0], $pdoParamType), "c_rand" => new BindParamOp(2, $inputValues[1], $pdoParamType)), "prepareBindParam", $r);
if ($r === false) {
isIncompatibleTypesError($stmt, $dataType, $pdoParamType); // check the case when inserting as PDO::PARAM_NULL
// with or without AE: NULL is inserted
if ($pdoParamType == "PDO::PARAM_NULL") {
if ($r === false) {
echo "Conversion from $pdoParamType to $typeFull should be supported\n";
} else {
$sql = "SELECT c_det, c_rand FROM $tbname";
$stmt = $conn->query($sql);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if (!is_null($row['c_det']) || !is_null($row['c_rand'])) {
echo "Conversion from $pdoParamType to $typeFull should insert NULL\n";
}
}
// check the case when inserting as PDO::PARAM_BOOL, PDO::PARAM_INT, PDO::PARAM_STR or PDO::PARAM_LOB
// with or without AE: should work
} else { } else {
echo "****PDO param type $pdoParamType is compatible with encrypted $dataType****\n"; $sql = "SELECT c_det, c_rand FROM $tbname";
fetchAll($conn, $tbname); $stmt = $conn->query($sql);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if (compareDate($row['c_det'], $inputValues[0], $dataType) && compareDate($row['c_rand'], $inputValues[1], $dataType)) {
echo "****Conversion from $pdoParamType to $typeFull is supported****\n";
} else {
echo "Conversion from $pdoParamType to $typeFull causes data corruption\n";
}
} }
$conn->query("TRUNCATE TABLE $tbname"); $conn->query("TRUNCATE TABLE $tbname");
} }
@ -64,205 +103,73 @@ try {
?> ?>
--EXPECT-- --EXPECT--
Testing datetime2(1): Testing datetime2(1):
****PDO param type PDO::PARAM_BOOL is compatible with encrypted datetime2**** ****Conversion from PDO::PARAM_BOOL to datetime2(1) is supported****
c_det: 0001-01-01 00:00:00.0 ****Conversion from PDO::PARAM_INT to datetime2(1) is supported****
c_rand: 9999-12-31 23:59:59.9 ****Conversion from PDO::PARAM_STR to datetime2(1) is supported****
****PDO param type PDO::PARAM_NULL is compatible with encrypted datetime2**** ****Conversion from PDO::PARAM_LOB to datetime2(1) is supported****
c_det:
c_rand:
****PDO param type PDO::PARAM_INT is compatible with encrypted datetime2****
c_det: 0001-01-01 00:00:00.0
c_rand: 9999-12-31 23:59:59.9
****PDO param type PDO::PARAM_STR is compatible with encrypted datetime2****
c_det: 0001-01-01 00:00:00.0
c_rand: 9999-12-31 23:59:59.9
****PDO param type PDO::PARAM_LOB is compatible with encrypted datetime2****
c_det: 0001-01-01 00:00:00.0
c_rand: 9999-12-31 23:59:59.9
Testing datetime2(2): Testing datetime2(2):
****PDO param type PDO::PARAM_BOOL is compatible with encrypted datetime2**** ****Conversion from PDO::PARAM_BOOL to datetime2(2) is supported****
c_det: 0001-01-01 00:00:00.00 ****Conversion from PDO::PARAM_INT to datetime2(2) is supported****
c_rand: 9999-12-31 23:59:59.99 ****Conversion from PDO::PARAM_STR to datetime2(2) is supported****
****PDO param type PDO::PARAM_NULL is compatible with encrypted datetime2**** ****Conversion from PDO::PARAM_LOB to datetime2(2) is supported****
c_det:
c_rand:
****PDO param type PDO::PARAM_INT is compatible with encrypted datetime2****
c_det: 0001-01-01 00:00:00.00
c_rand: 9999-12-31 23:59:59.99
****PDO param type PDO::PARAM_STR is compatible with encrypted datetime2****
c_det: 0001-01-01 00:00:00.00
c_rand: 9999-12-31 23:59:59.99
****PDO param type PDO::PARAM_LOB is compatible with encrypted datetime2****
c_det: 0001-01-01 00:00:00.00
c_rand: 9999-12-31 23:59:59.99
Testing datetime2(4): Testing datetime2(4):
****PDO param type PDO::PARAM_BOOL is compatible with encrypted datetime2**** ****Conversion from PDO::PARAM_BOOL to datetime2(4) is supported****
c_det: 0001-01-01 00:00:00.0000 ****Conversion from PDO::PARAM_INT to datetime2(4) is supported****
c_rand: 9999-12-31 23:59:59.9999 ****Conversion from PDO::PARAM_STR to datetime2(4) is supported****
****PDO param type PDO::PARAM_NULL is compatible with encrypted datetime2**** ****Conversion from PDO::PARAM_LOB to datetime2(4) is supported****
c_det:
c_rand:
****PDO param type PDO::PARAM_INT is compatible with encrypted datetime2****
c_det: 0001-01-01 00:00:00.0000
c_rand: 9999-12-31 23:59:59.9999
****PDO param type PDO::PARAM_STR is compatible with encrypted datetime2****
c_det: 0001-01-01 00:00:00.0000
c_rand: 9999-12-31 23:59:59.9999
****PDO param type PDO::PARAM_LOB is compatible with encrypted datetime2****
c_det: 0001-01-01 00:00:00.0000
c_rand: 9999-12-31 23:59:59.9999
Testing datetime2(7): Testing datetime2(7):
****PDO param type PDO::PARAM_BOOL is compatible with encrypted datetime2**** ****Conversion from PDO::PARAM_BOOL to datetime2(7) is supported****
c_det: 0001-01-01 00:00:00.0000000 ****Conversion from PDO::PARAM_INT to datetime2(7) is supported****
c_rand: 9999-12-31 23:59:59.9999999 ****Conversion from PDO::PARAM_STR to datetime2(7) is supported****
****PDO param type PDO::PARAM_NULL is compatible with encrypted datetime2**** ****Conversion from PDO::PARAM_LOB to datetime2(7) is supported****
c_det:
c_rand:
****PDO param type PDO::PARAM_INT is compatible with encrypted datetime2****
c_det: 0001-01-01 00:00:00.0000000
c_rand: 9999-12-31 23:59:59.9999999
****PDO param type PDO::PARAM_STR is compatible with encrypted datetime2****
c_det: 0001-01-01 00:00:00.0000000
c_rand: 9999-12-31 23:59:59.9999999
****PDO param type PDO::PARAM_LOB is compatible with encrypted datetime2****
c_det: 0001-01-01 00:00:00.0000000
c_rand: 9999-12-31 23:59:59.9999999
Testing datetimeoffset(1): Testing datetimeoffset(1):
****PDO param type PDO::PARAM_BOOL is compatible with encrypted datetimeoffset**** ****Conversion from PDO::PARAM_BOOL to datetimeoffset(1) is supported****
c_det: 0001-01-01 00:00:00.0 -14:00 ****Conversion from PDO::PARAM_INT to datetimeoffset(1) is supported****
c_rand: 9999-12-31 23:59:59.9 +14:00 ****Conversion from PDO::PARAM_STR to datetimeoffset(1) is supported****
****PDO param type PDO::PARAM_NULL is compatible with encrypted datetimeoffset**** ****Conversion from PDO::PARAM_LOB to datetimeoffset(1) is supported****
c_det:
c_rand:
****PDO param type PDO::PARAM_INT is compatible with encrypted datetimeoffset****
c_det: 0001-01-01 00:00:00.0 -14:00
c_rand: 9999-12-31 23:59:59.9 +14:00
****PDO param type PDO::PARAM_STR is compatible with encrypted datetimeoffset****
c_det: 0001-01-01 00:00:00.0 -14:00
c_rand: 9999-12-31 23:59:59.9 +14:00
****PDO param type PDO::PARAM_LOB is compatible with encrypted datetimeoffset****
c_det: 0001-01-01 00:00:00.0 -14:00
c_rand: 9999-12-31 23:59:59.9 +14:00
Testing datetimeoffset(2): Testing datetimeoffset(2):
****PDO param type PDO::PARAM_BOOL is compatible with encrypted datetimeoffset**** ****Conversion from PDO::PARAM_BOOL to datetimeoffset(2) is supported****
c_det: 0001-01-01 00:00:00.00 -14:00 ****Conversion from PDO::PARAM_INT to datetimeoffset(2) is supported****
c_rand: 9999-12-31 23:59:59.99 +14:00 ****Conversion from PDO::PARAM_STR to datetimeoffset(2) is supported****
****PDO param type PDO::PARAM_NULL is compatible with encrypted datetimeoffset**** ****Conversion from PDO::PARAM_LOB to datetimeoffset(2) is supported****
c_det:
c_rand:
****PDO param type PDO::PARAM_INT is compatible with encrypted datetimeoffset****
c_det: 0001-01-01 00:00:00.00 -14:00
c_rand: 9999-12-31 23:59:59.99 +14:00
****PDO param type PDO::PARAM_STR is compatible with encrypted datetimeoffset****
c_det: 0001-01-01 00:00:00.00 -14:00
c_rand: 9999-12-31 23:59:59.99 +14:00
****PDO param type PDO::PARAM_LOB is compatible with encrypted datetimeoffset****
c_det: 0001-01-01 00:00:00.00 -14:00
c_rand: 9999-12-31 23:59:59.99 +14:00
Testing datetimeoffset(4): Testing datetimeoffset(4):
****PDO param type PDO::PARAM_BOOL is compatible with encrypted datetimeoffset**** ****Conversion from PDO::PARAM_BOOL to datetimeoffset(4) is supported****
c_det: 0001-01-01 00:00:00.0000 -14:00 ****Conversion from PDO::PARAM_INT to datetimeoffset(4) is supported****
c_rand: 9999-12-31 23:59:59.9999 +14:00 ****Conversion from PDO::PARAM_STR to datetimeoffset(4) is supported****
****PDO param type PDO::PARAM_NULL is compatible with encrypted datetimeoffset**** ****Conversion from PDO::PARAM_LOB to datetimeoffset(4) is supported****
c_det:
c_rand:
****PDO param type PDO::PARAM_INT is compatible with encrypted datetimeoffset****
c_det: 0001-01-01 00:00:00.0000 -14:00
c_rand: 9999-12-31 23:59:59.9999 +14:00
****PDO param type PDO::PARAM_STR is compatible with encrypted datetimeoffset****
c_det: 0001-01-01 00:00:00.0000 -14:00
c_rand: 9999-12-31 23:59:59.9999 +14:00
****PDO param type PDO::PARAM_LOB is compatible with encrypted datetimeoffset****
c_det: 0001-01-01 00:00:00.0000 -14:00
c_rand: 9999-12-31 23:59:59.9999 +14:00
Testing datetimeoffset(7): Testing datetimeoffset(7):
****PDO param type PDO::PARAM_BOOL is compatible with encrypted datetimeoffset**** ****Conversion from PDO::PARAM_BOOL to datetimeoffset(7) is supported****
c_det: 0001-01-01 00:00:00.0000000 -14:00 ****Conversion from PDO::PARAM_INT to datetimeoffset(7) is supported****
c_rand: 9999-12-31 23:59:59.9999999 +14:00 ****Conversion from PDO::PARAM_STR to datetimeoffset(7) is supported****
****PDO param type PDO::PARAM_NULL is compatible with encrypted datetimeoffset**** ****Conversion from PDO::PARAM_LOB to datetimeoffset(7) is supported****
c_det:
c_rand:
****PDO param type PDO::PARAM_INT is compatible with encrypted datetimeoffset****
c_det: 0001-01-01 00:00:00.0000000 -14:00
c_rand: 9999-12-31 23:59:59.9999999 +14:00
****PDO param type PDO::PARAM_STR is compatible with encrypted datetimeoffset****
c_det: 0001-01-01 00:00:00.0000000 -14:00
c_rand: 9999-12-31 23:59:59.9999999 +14:00
****PDO param type PDO::PARAM_LOB is compatible with encrypted datetimeoffset****
c_det: 0001-01-01 00:00:00.0000000 -14:00
c_rand: 9999-12-31 23:59:59.9999999 +14:00
Testing time(1): Testing time(1):
****PDO param type PDO::PARAM_BOOL is compatible with encrypted time**** ****Conversion from PDO::PARAM_BOOL to time(1) is supported****
c_det: 00:00:00.0 ****Conversion from PDO::PARAM_INT to time(1) is supported****
c_rand: 23:59:59.9 ****Conversion from PDO::PARAM_STR to time(1) is supported****
****PDO param type PDO::PARAM_NULL is compatible with encrypted time**** ****Conversion from PDO::PARAM_LOB to time(1) is supported****
c_det:
c_rand:
****PDO param type PDO::PARAM_INT is compatible with encrypted time****
c_det: 00:00:00.0
c_rand: 23:59:59.9
****PDO param type PDO::PARAM_STR is compatible with encrypted time****
c_det: 00:00:00.0
c_rand: 23:59:59.9
****PDO param type PDO::PARAM_LOB is compatible with encrypted time****
c_det: 00:00:00.0
c_rand: 23:59:59.9
Testing time(2): Testing time(2):
****PDO param type PDO::PARAM_BOOL is compatible with encrypted time**** ****Conversion from PDO::PARAM_BOOL to time(2) is supported****
c_det: 00:00:00.00 ****Conversion from PDO::PARAM_INT to time(2) is supported****
c_rand: 23:59:59.99 ****Conversion from PDO::PARAM_STR to time(2) is supported****
****PDO param type PDO::PARAM_NULL is compatible with encrypted time**** ****Conversion from PDO::PARAM_LOB to time(2) is supported****
c_det:
c_rand:
****PDO param type PDO::PARAM_INT is compatible with encrypted time****
c_det: 00:00:00.00
c_rand: 23:59:59.99
****PDO param type PDO::PARAM_STR is compatible with encrypted time****
c_det: 00:00:00.00
c_rand: 23:59:59.99
****PDO param type PDO::PARAM_LOB is compatible with encrypted time****
c_det: 00:00:00.00
c_rand: 23:59:59.99
Testing time(4): Testing time(4):
****PDO param type PDO::PARAM_BOOL is compatible with encrypted time**** ****Conversion from PDO::PARAM_BOOL to time(4) is supported****
c_det: 00:00:00.0000 ****Conversion from PDO::PARAM_INT to time(4) is supported****
c_rand: 23:59:59.9999 ****Conversion from PDO::PARAM_STR to time(4) is supported****
****PDO param type PDO::PARAM_NULL is compatible with encrypted time**** ****Conversion from PDO::PARAM_LOB to time(4) is supported****
c_det:
c_rand:
****PDO param type PDO::PARAM_INT is compatible with encrypted time****
c_det: 00:00:00.0000
c_rand: 23:59:59.9999
****PDO param type PDO::PARAM_STR is compatible with encrypted time****
c_det: 00:00:00.0000
c_rand: 23:59:59.9999
****PDO param type PDO::PARAM_LOB is compatible with encrypted time****
c_det: 00:00:00.0000
c_rand: 23:59:59.9999
Testing time(7): Testing time(7):
****PDO param type PDO::PARAM_BOOL is compatible with encrypted time**** ****Conversion from PDO::PARAM_BOOL to time(7) is supported****
c_det: 00:00:00.0000000 ****Conversion from PDO::PARAM_INT to time(7) is supported****
c_rand: 23:59:59.9999999 ****Conversion from PDO::PARAM_STR to time(7) is supported****
****PDO param type PDO::PARAM_NULL is compatible with encrypted time**** ****Conversion from PDO::PARAM_LOB to time(7) is supported****
c_det:
c_rand:
****PDO param type PDO::PARAM_INT is compatible with encrypted time****
c_det: 00:00:00.0000000
c_rand: 23:59:59.9999999
****PDO param type PDO::PARAM_STR is compatible with encrypted time****
c_det: 00:00:00.0000000
c_rand: 23:59:59.9999999
****PDO param type PDO::PARAM_LOB is compatible with encrypted time****
c_det: 00:00:00.0000000
c_rand: 23:59:59.9999999

View file

@ -1,7 +1,12 @@
--TEST-- --TEST--
Test for inserting and retrieving encrypted data of numeric types Test for inserting encrypted data into float types columns
--DESCRIPTION-- --DESCRIPTION--
Use PDOstatement::bindParam with all PDO::PARAM_ types Test conversions between different float types
With or without Always Encrypted, implicit conversion works if:
1. From input of PDO::PARAM_BOOL to a float column
2. From input of PDO::PARAM_INT to a float column
3. From input of PDO::PARAM_STR to a float column
4. From input of PDO::PARAM_LOB to a float column
--SKIPIF-- --SKIPIF--
<?php require('skipif_mid-refactor.inc'); ?> <?php require('skipif_mid-refactor.inc'); ?>
--FILE-- --FILE--
@ -12,29 +17,60 @@ require_once("AEData.inc");
$dataType = "float"; $dataType = "float";
$bits = array(1, 12, 24, 36, 53); $bits = array(1, 12, 24, 36, 53);
$inputValues = array(9223372036854775808.9223372036854775808, -9223372036854775808.9223372036854775808); $inputValues = array(9223372036854775808.9223372036854775808, -9223372036854775808.9223372036854775808);
$numint = 19;
try { try {
$conn = connect(); $conn = connect();
foreach ($bits as $bit) { foreach ($bits as $m) {
$type = "$dataType($bit)"; // compute the epsilon for comparing doubles
echo "\nTesting $type:\n"; // when $m <= 24, the precision is 7 digits
// when $m > 24, the precision is 15 digits, but PHP float only supports up to 14 digits
$epsilon;
if ($m <= 24) {
$epsilon = pow(10, $numint - 7);
} else {
$epsilon = pow(10, $numint - 14);
}
//create and populate table $typeFull = "$dataType($m)";
$tbname = "test_float1"; echo "\nTesting $typeFull:\n";
$colMetaArr = array(new ColumnMeta($type, "c_det"), new ColumnMeta($type, "c_rand", null, "randomized"));
//create table containing float(m) columns
$tbname = "test_" . $dataType . $m;
$colMetaArr = array(new ColumnMeta($typeFull, "c_det"), new ColumnMeta($typeFull, "c_rand", null, "randomized"));
createTable($conn, $tbname, $colMetaArr); createTable($conn, $tbname, $colMetaArr);
// test each PDO::PARAM_ type // insert by specifying PDO::PARAM_ types
foreach ($pdoParamTypes as $pdoParamType) { foreach ($pdoParamTypes as $pdoParamType) {
// insert a row
$r; $r;
$stmt = insertRow($conn, $tbname, array( "c_det" => new BindParamOp(1, $inputValues[0], $pdoParamType), "c_rand" => new BindParamOp(2, $inputValues[1], $pdoParamType)), "prepareBindParam", $r); $stmt = insertRow($conn, $tbname, array( "c_det" => new BindParamOp(1, $inputValues[0], $pdoParamType), "c_rand" => new BindParamOp(2, $inputValues[1], $pdoParamType)), "prepareBindParam", $r);
if ($r === false) {
isIncompatibleTypesError($stmt, $type, $pdoParamType); // check the case when inserting as PDO::PARAM_NULL
// with or without AE: NULL is inserted
if ($pdoParamType == "PDO::PARAM_NULL") {
if ($r === false) {
echo "Conversion from $pdoParamType to $typeFull should be supported\n";
} else {
$sql = "SELECT c_det, c_rand FROM $tbname";
$stmt = $conn->query($sql);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if (!is_null($row['c_det']) || !is_null($row['c_rand'])) {
echo "Conversion from $pdoParamType to $typeFull should insert NULL\n";
}
}
// check the case when inserting as PDO::PARAM_BOOL, PDO::PARAM_INT, PDO::PARAM_STR or PDO::PARAM_LOB
// with or without AE: should work
} else { } else {
echo "****PDO param type $pdoParamType is compatible with encrypted $type****\n"; $sql = "SELECT c_det, c_rand FROM $tbname";
fetchAll($conn, $tbname); $stmt = $conn->query($sql);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if (abs($row['c_det'] - $inputValues[0]) < $epsilon && abs($row['c_rand'] - $inputValues[1]) < $epsilon) {
echo "****Conversion from $pdoParamType to $typeFull is supported****\n";
} else {
echo "Conversion from $pdoParamType to $typeFull causes data corruption\n";
}
} }
// cleanup
$conn->query("TRUNCATE TABLE $tbname"); $conn->query("TRUNCATE TABLE $tbname");
} }
dropTable($conn, $tbname); dropTable($conn, $tbname);
@ -47,86 +83,31 @@ try {
?> ?>
--EXPECT-- --EXPECT--
Testing float(1): Testing float(1):
****PDO param type PDO::PARAM_BOOL is compatible with encrypted float(1)**** ****Conversion from PDO::PARAM_BOOL to float(1) is supported****
c_det: 9.223372E+18 ****Conversion from PDO::PARAM_INT to float(1) is supported****
c_rand: -9.223372E+18 ****Conversion from PDO::PARAM_STR to float(1) is supported****
****PDO param type PDO::PARAM_NULL is compatible with encrypted float(1)**** ****Conversion from PDO::PARAM_LOB to float(1) is supported****
c_det:
c_rand:
****PDO param type PDO::PARAM_INT is compatible with encrypted float(1)****
c_det: 9.223372E+18
c_rand: -9.223372E+18
****PDO param type PDO::PARAM_STR is compatible with encrypted float(1)****
c_det: 9.223372E+18
c_rand: -9.223372E+18
****PDO param type PDO::PARAM_LOB is compatible with encrypted float(1)****
c_det: 9.223372E+18
c_rand: -9.223372E+18
Testing float(12): Testing float(12):
****PDO param type PDO::PARAM_BOOL is compatible with encrypted float(12)**** ****Conversion from PDO::PARAM_BOOL to float(12) is supported****
c_det: 9.223372E+18 ****Conversion from PDO::PARAM_INT to float(12) is supported****
c_rand: -9.223372E+18 ****Conversion from PDO::PARAM_STR to float(12) is supported****
****PDO param type PDO::PARAM_NULL is compatible with encrypted float(12)**** ****Conversion from PDO::PARAM_LOB to float(12) is supported****
c_det:
c_rand:
****PDO param type PDO::PARAM_INT is compatible with encrypted float(12)****
c_det: 9.223372E+18
c_rand: -9.223372E+18
****PDO param type PDO::PARAM_STR is compatible with encrypted float(12)****
c_det: 9.223372E+18
c_rand: -9.223372E+18
****PDO param type PDO::PARAM_LOB is compatible with encrypted float(12)****
c_det: 9.223372E+18
c_rand: -9.223372E+18
Testing float(24): Testing float(24):
****PDO param type PDO::PARAM_BOOL is compatible with encrypted float(24)**** ****Conversion from PDO::PARAM_BOOL to float(24) is supported****
c_det: 9.223372E+18 ****Conversion from PDO::PARAM_INT to float(24) is supported****
c_rand: -9.223372E+18 ****Conversion from PDO::PARAM_STR to float(24) is supported****
****PDO param type PDO::PARAM_NULL is compatible with encrypted float(24)**** ****Conversion from PDO::PARAM_LOB to float(24) is supported****
c_det:
c_rand:
****PDO param type PDO::PARAM_INT is compatible with encrypted float(24)****
c_det: 9.223372E+18
c_rand: -9.223372E+18
****PDO param type PDO::PARAM_STR is compatible with encrypted float(24)****
c_det: 9.223372E+18
c_rand: -9.223372E+18
****PDO param type PDO::PARAM_LOB is compatible with encrypted float(24)****
c_det: 9.223372E+18
c_rand: -9.223372E+18
Testing float(36): Testing float(36):
****PDO param type PDO::PARAM_BOOL is compatible with encrypted float(36)**** ****Conversion from PDO::PARAM_BOOL to float(36) is supported****
c_det: 9.2233720368547758E+18 ****Conversion from PDO::PARAM_INT to float(36) is supported****
c_rand: -9.2233720368547758E+18 ****Conversion from PDO::PARAM_STR to float(36) is supported****
****PDO param type PDO::PARAM_NULL is compatible with encrypted float(36)**** ****Conversion from PDO::PARAM_LOB to float(36) is supported****
c_det:
c_rand:
****PDO param type PDO::PARAM_INT is compatible with encrypted float(36)****
c_det: 9.2233720368547758E+18
c_rand: -9.2233720368547758E+18
****PDO param type PDO::PARAM_STR is compatible with encrypted float(36)****
c_det: 9.2233720368548004E+18
c_rand: -9.2233720368548004E+18
****PDO param type PDO::PARAM_LOB is compatible with encrypted float(36)****
c_det: 9.2233720368547758E+18
c_rand: -9.2233720368547758E+18
Testing float(53): Testing float(53):
****PDO param type PDO::PARAM_BOOL is compatible with encrypted float(53)**** ****Conversion from PDO::PARAM_BOOL to float(53) is supported****
c_det: 9.2233720368547758E+18 ****Conversion from PDO::PARAM_INT to float(53) is supported****
c_rand: -9.2233720368547758E+18 ****Conversion from PDO::PARAM_STR to float(53) is supported****
****PDO param type PDO::PARAM_NULL is compatible with encrypted float(53)**** ****Conversion from PDO::PARAM_LOB to float(53) is supported****
c_det:
c_rand:
****PDO param type PDO::PARAM_INT is compatible with encrypted float(53)****
c_det: 9.2233720368547758E+18
c_rand: -9.2233720368547758E+18
****PDO param type PDO::PARAM_STR is compatible with encrypted float(53)****
c_det: 9.2233720368548004E+18
c_rand: -9.2233720368548004E+18
****PDO param type PDO::PARAM_LOB is compatible with encrypted float(53)****
c_det: 9.2233720368547758E+18
c_rand: -9.2233720368547758E+18

View file

@ -1,7 +1,12 @@
--TEST-- --TEST--
Test for inserting and retrieving encrypted data of string types Test for inserting encrypted data into nchar types columns with different sizes
--DESCRIPTION-- --DESCRIPTION--
Use PDOstatement::bindParam with all PDO::PARAM_ types Test conversions between different nchar types of different sizes
With or without Always Encrypted, implicit conversion works if:
1. From input of PDO::PARAM_BOOL to a any nchar column
2. From input of PDO::PARAM_INT to a any nchar column
3. From input of PDO::PARAM_STR to a any nchar column
4. From input of PDO::PARAM_LOB to a any nchar column
--SKIPIF-- --SKIPIF--
<?php require('skipif_mid-refactor.inc'); ?> <?php require('skipif_mid-refactor.inc'); ?>
--FILE-- --FILE--
@ -11,49 +16,59 @@ require_once("AEData.inc");
$dataTypes = array("nchar", "nvarchar", "nvarchar(max)"); $dataTypes = array("nchar", "nvarchar", "nvarchar(max)");
$lengths = array(1, 8, 64, 512, 4000); $lengths = array(1, 8, 64, 512, 4000);
$encTypes = array("deterministic", "randomized");
try { try {
$conn = connect(); $conn = connect();
foreach ($dataTypes as $dataType) { foreach ($dataTypes as $dataType) {
$maxtype = strpos($dataType, "(max)"); $maxcol = strpos($dataType, "(max)");
foreach ($lengths as $length) { foreach ($lengths as $m) {
if ($maxtype !== false) { if ($maxcol !== false) {
$type = $dataType; $typeFull = $dataType;
} else { } else {
$type = "$dataType($length)"; $typeFull = "$dataType($m)";
} }
echo "\nTesting $type:\n"; echo "\nTesting $typeFull:\n";
foreach($encTypes as $encType) { //create table containing nchar(m) or nvarchar(m) columns
//create and populate table $tbname = "test_" . str_replace(array('(', ')'), '', $dataType) . $m;
$tbname = getTableName(); $colMetaArr = array(new ColumnMeta($typeFull, "c1"));
$colMetaArr = array(new ColumnMeta($type, "c1", null, $encType)); createTable($conn, $tbname, $colMetaArr);
createTable($conn, $tbname, $colMetaArr); $input = str_repeat("d", $m);
$input = str_repeat("d", $length);
// prepare statement for inserting into table // insert by specifying PDO::PARAM_ types
foreach ($pdoParamTypes as $pdoParamType) { foreach ($pdoParamTypes as $pdoParamType) {
// insert a row $r;
$r; $stmt = insertRow($conn, $tbname, array( "c1" => new BindParamOp(1, $input, $pdoParamType)), "prepareBindParam", $r);
$stmt = insertRow($conn, $tbname, array( "c1" => new BindParamOp(1, $input, $pdoParamType)), "prepareBindParam", $r);
// check the case when inserting as PDO::PARAM_NULL
// with or without AE: NULL is inserted
if ($pdoParamType == "PDO::PARAM_NULL") {
if ($r === false) { if ($r === false) {
isIncompatibleTypesError($stmt, $type, $pdoParamType); echo "Conversion from $pdoParamType to $typeFull should be supported\n";
} else { } else {
$sql = "SELECT c1 FROM $tbname"; $sql = "SELECT c1 FROM $tbname";
$stmt = $conn->query($sql); $stmt = $conn->query($sql);
$row = $stmt->fetch(PDO::FETCH_ASSOC); $row = $stmt->fetch(PDO::FETCH_ASSOC);
if (strlen($row['c1']) == $length) { if (!is_null($row['c1'])) {
echo "****PDO param type $pdoParamType is compatible with $encType encrypted $type****\n"; echo "Conversion from $pdoParamType to $typeFull should insert NULL\n";
} else {
echo "PDO param type $pdoParamType is incompatible with $encType encrypted $type\n";
} }
} }
$conn->query("TRUNCATE TABLE $tbname"); // check the case when inserting as PDO::PARAM_BOOL, PDO::PARAM_INT, PDO::PARAM_STR or PDO{{PARAM_LOB
// with or without AE: should work
} else {
$sql = "SELECT c1 FROM $tbname";
$stmt = $conn->query($sql);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if (strlen($row['c1']) == $m) {
echo "****Conversion from $pdoParamType to $typeFull is supported****\n";
} else {
echo "Conversion from $pdoParamType to $typeFull causes data corruption\n";
}
} }
dropTable($conn, $tbname); // cleanup
$conn->query("TRUNCATE TABLE $tbname");
} }
dropTable($conn, $tbname);
} }
} }
unset($stmt); unset($stmt);
@ -64,181 +79,91 @@ try {
?> ?>
--EXPECT-- --EXPECT--
Testing nchar(1): Testing nchar(1):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted nchar(1)**** ****Conversion from PDO::PARAM_BOOL to nchar(1) is supported****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted nchar(1) ****Conversion from PDO::PARAM_INT to nchar(1) is supported****
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted nchar(1)**** ****Conversion from PDO::PARAM_STR to nchar(1) is supported****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nchar(1)**** ****Conversion from PDO::PARAM_LOB to nchar(1) is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted nchar(1)****
****PDO param type PDO::PARAM_BOOL is compatible with randomized encrypted nchar(1)****
PDO param type PDO::PARAM_NULL is incompatible with randomized encrypted nchar(1)
****PDO param type PDO::PARAM_INT is compatible with randomized encrypted nchar(1)****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted nchar(1)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted nchar(1)****
Testing nchar(8): Testing nchar(8):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted nchar(8)**** ****Conversion from PDO::PARAM_BOOL to nchar(8) is supported****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted nchar(8) ****Conversion from PDO::PARAM_INT to nchar(8) is supported****
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted nchar(8)**** ****Conversion from PDO::PARAM_STR to nchar(8) is supported****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nchar(8)**** ****Conversion from PDO::PARAM_LOB to nchar(8) is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted nchar(8)****
****PDO param type PDO::PARAM_BOOL is compatible with randomized encrypted nchar(8)****
PDO param type PDO::PARAM_NULL is incompatible with randomized encrypted nchar(8)
****PDO param type PDO::PARAM_INT is compatible with randomized encrypted nchar(8)****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted nchar(8)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted nchar(8)****
Testing nchar(64): Testing nchar(64):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted nchar(64)**** ****Conversion from PDO::PARAM_BOOL to nchar(64) is supported****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted nchar(64) ****Conversion from PDO::PARAM_INT to nchar(64) is supported****
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted nchar(64)**** ****Conversion from PDO::PARAM_STR to nchar(64) is supported****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nchar(64)**** ****Conversion from PDO::PARAM_LOB to nchar(64) is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted nchar(64)****
****PDO param type PDO::PARAM_BOOL is compatible with randomized encrypted nchar(64)****
PDO param type PDO::PARAM_NULL is incompatible with randomized encrypted nchar(64)
****PDO param type PDO::PARAM_INT is compatible with randomized encrypted nchar(64)****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted nchar(64)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted nchar(64)****
Testing nchar(512): Testing nchar(512):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted nchar(512)**** ****Conversion from PDO::PARAM_BOOL to nchar(512) is supported****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted nchar(512) ****Conversion from PDO::PARAM_INT to nchar(512) is supported****
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted nchar(512)**** ****Conversion from PDO::PARAM_STR to nchar(512) is supported****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nchar(512)**** ****Conversion from PDO::PARAM_LOB to nchar(512) is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted nchar(512)****
****PDO param type PDO::PARAM_BOOL is compatible with randomized encrypted nchar(512)****
PDO param type PDO::PARAM_NULL is incompatible with randomized encrypted nchar(512)
****PDO param type PDO::PARAM_INT is compatible with randomized encrypted nchar(512)****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted nchar(512)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted nchar(512)****
Testing nchar(4000): Testing nchar(4000):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted nchar(4000)**** ****Conversion from PDO::PARAM_BOOL to nchar(4000) is supported****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted nchar(4000) ****Conversion from PDO::PARAM_INT to nchar(4000) is supported****
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted nchar(4000)**** ****Conversion from PDO::PARAM_STR to nchar(4000) is supported****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nchar(4000)**** ****Conversion from PDO::PARAM_LOB to nchar(4000) is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted nchar(4000)****
****PDO param type PDO::PARAM_BOOL is compatible with randomized encrypted nchar(4000)****
PDO param type PDO::PARAM_NULL is incompatible with randomized encrypted nchar(4000)
****PDO param type PDO::PARAM_INT is compatible with randomized encrypted nchar(4000)****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted nchar(4000)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted nchar(4000)****
Testing nvarchar(1): Testing nvarchar(1):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted nvarchar(1)**** ****Conversion from PDO::PARAM_BOOL to nvarchar(1) is supported****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted nvarchar(1) ****Conversion from PDO::PARAM_INT to nvarchar(1) is supported****
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted nvarchar(1)**** ****Conversion from PDO::PARAM_STR to nvarchar(1) is supported****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nvarchar(1)**** ****Conversion from PDO::PARAM_LOB to nvarchar(1) is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted nvarchar(1)****
****PDO param type PDO::PARAM_BOOL is compatible with randomized encrypted nvarchar(1)****
PDO param type PDO::PARAM_NULL is incompatible with randomized encrypted nvarchar(1)
****PDO param type PDO::PARAM_INT is compatible with randomized encrypted nvarchar(1)****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted nvarchar(1)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted nvarchar(1)****
Testing nvarchar(8): Testing nvarchar(8):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted nvarchar(8)**** ****Conversion from PDO::PARAM_BOOL to nvarchar(8) is supported****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted nvarchar(8) ****Conversion from PDO::PARAM_INT to nvarchar(8) is supported****
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted nvarchar(8)**** ****Conversion from PDO::PARAM_STR to nvarchar(8) is supported****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nvarchar(8)**** ****Conversion from PDO::PARAM_LOB to nvarchar(8) is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted nvarchar(8)****
****PDO param type PDO::PARAM_BOOL is compatible with randomized encrypted nvarchar(8)****
PDO param type PDO::PARAM_NULL is incompatible with randomized encrypted nvarchar(8)
****PDO param type PDO::PARAM_INT is compatible with randomized encrypted nvarchar(8)****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted nvarchar(8)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted nvarchar(8)****
Testing nvarchar(64): Testing nvarchar(64):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted nvarchar(64)**** ****Conversion from PDO::PARAM_BOOL to nvarchar(64) is supported****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted nvarchar(64) ****Conversion from PDO::PARAM_INT to nvarchar(64) is supported****
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted nvarchar(64)**** ****Conversion from PDO::PARAM_STR to nvarchar(64) is supported****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nvarchar(64)**** ****Conversion from PDO::PARAM_LOB to nvarchar(64) is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted nvarchar(64)****
****PDO param type PDO::PARAM_BOOL is compatible with randomized encrypted nvarchar(64)****
PDO param type PDO::PARAM_NULL is incompatible with randomized encrypted nvarchar(64)
****PDO param type PDO::PARAM_INT is compatible with randomized encrypted nvarchar(64)****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted nvarchar(64)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted nvarchar(64)****
Testing nvarchar(512): Testing nvarchar(512):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted nvarchar(512)**** ****Conversion from PDO::PARAM_BOOL to nvarchar(512) is supported****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted nvarchar(512) ****Conversion from PDO::PARAM_INT to nvarchar(512) is supported****
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted nvarchar(512)**** ****Conversion from PDO::PARAM_STR to nvarchar(512) is supported****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nvarchar(512)**** ****Conversion from PDO::PARAM_LOB to nvarchar(512) is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted nvarchar(512)****
****PDO param type PDO::PARAM_BOOL is compatible with randomized encrypted nvarchar(512)****
PDO param type PDO::PARAM_NULL is incompatible with randomized encrypted nvarchar(512)
****PDO param type PDO::PARAM_INT is compatible with randomized encrypted nvarchar(512)****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted nvarchar(512)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted nvarchar(512)****
Testing nvarchar(4000): Testing nvarchar(4000):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted nvarchar(4000)**** ****Conversion from PDO::PARAM_BOOL to nvarchar(4000) is supported****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted nvarchar(4000) ****Conversion from PDO::PARAM_INT to nvarchar(4000) is supported****
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted nvarchar(4000)**** ****Conversion from PDO::PARAM_STR to nvarchar(4000) is supported****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nvarchar(4000)**** ****Conversion from PDO::PARAM_LOB to nvarchar(4000) is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted nvarchar(4000)****
****PDO param type PDO::PARAM_BOOL is compatible with randomized encrypted nvarchar(4000)****
PDO param type PDO::PARAM_NULL is incompatible with randomized encrypted nvarchar(4000)
****PDO param type PDO::PARAM_INT is compatible with randomized encrypted nvarchar(4000)****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted nvarchar(4000)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted nvarchar(4000)****
Testing nvarchar(max): Testing nvarchar(max):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted nvarchar(max)**** ****Conversion from PDO::PARAM_BOOL to nvarchar(max) is supported****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted nvarchar(max) ****Conversion from PDO::PARAM_INT to nvarchar(max) is supported****
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted nvarchar(max)**** ****Conversion from PDO::PARAM_STR to nvarchar(max) is supported****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nvarchar(max)**** ****Conversion from PDO::PARAM_LOB to nvarchar(max) is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted nvarchar(max)****
****PDO param type PDO::PARAM_BOOL is compatible with randomized encrypted nvarchar(max)****
PDO param type PDO::PARAM_NULL is incompatible with randomized encrypted nvarchar(max)
****PDO param type PDO::PARAM_INT is compatible with randomized encrypted nvarchar(max)****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted nvarchar(max)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted nvarchar(max)****
Testing nvarchar(max): Testing nvarchar(max):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted nvarchar(max)**** ****Conversion from PDO::PARAM_BOOL to nvarchar(max) is supported****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted nvarchar(max) ****Conversion from PDO::PARAM_INT to nvarchar(max) is supported****
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted nvarchar(max)**** ****Conversion from PDO::PARAM_STR to nvarchar(max) is supported****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nvarchar(max)**** ****Conversion from PDO::PARAM_LOB to nvarchar(max) is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted nvarchar(max)****
****PDO param type PDO::PARAM_BOOL is compatible with randomized encrypted nvarchar(max)****
PDO param type PDO::PARAM_NULL is incompatible with randomized encrypted nvarchar(max)
****PDO param type PDO::PARAM_INT is compatible with randomized encrypted nvarchar(max)****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted nvarchar(max)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted nvarchar(max)****
Testing nvarchar(max): Testing nvarchar(max):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted nvarchar(max)**** ****Conversion from PDO::PARAM_BOOL to nvarchar(max) is supported****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted nvarchar(max) ****Conversion from PDO::PARAM_INT to nvarchar(max) is supported****
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted nvarchar(max)**** ****Conversion from PDO::PARAM_STR to nvarchar(max) is supported****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nvarchar(max)**** ****Conversion from PDO::PARAM_LOB to nvarchar(max) is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted nvarchar(max)****
****PDO param type PDO::PARAM_BOOL is compatible with randomized encrypted nvarchar(max)****
PDO param type PDO::PARAM_NULL is incompatible with randomized encrypted nvarchar(max)
****PDO param type PDO::PARAM_INT is compatible with randomized encrypted nvarchar(max)****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted nvarchar(max)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted nvarchar(max)****
Testing nvarchar(max): Testing nvarchar(max):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted nvarchar(max)**** ****Conversion from PDO::PARAM_BOOL to nvarchar(max) is supported****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted nvarchar(max) ****Conversion from PDO::PARAM_INT to nvarchar(max) is supported****
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted nvarchar(max)**** ****Conversion from PDO::PARAM_STR to nvarchar(max) is supported****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nvarchar(max)**** ****Conversion from PDO::PARAM_LOB to nvarchar(max) is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted nvarchar(max)****
****PDO param type PDO::PARAM_BOOL is compatible with randomized encrypted nvarchar(max)****
PDO param type PDO::PARAM_NULL is incompatible with randomized encrypted nvarchar(max)
****PDO param type PDO::PARAM_INT is compatible with randomized encrypted nvarchar(max)****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted nvarchar(max)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted nvarchar(max)****
Testing nvarchar(max): Testing nvarchar(max):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted nvarchar(max)**** ****Conversion from PDO::PARAM_BOOL to nvarchar(max) is supported****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted nvarchar(max) ****Conversion from PDO::PARAM_INT to nvarchar(max) is supported****
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted nvarchar(max)**** ****Conversion from PDO::PARAM_STR to nvarchar(max) is supported****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nvarchar(max)**** ****Conversion from PDO::PARAM_LOB to nvarchar(max) is supported****
****PDO param type PDO::PARAM_LOB is compatible with deterministic encrypted nvarchar(max)****
****PDO param type PDO::PARAM_BOOL is compatible with randomized encrypted nvarchar(max)****
PDO param type PDO::PARAM_NULL is incompatible with randomized encrypted nvarchar(max)
****PDO param type PDO::PARAM_INT is compatible with randomized encrypted nvarchar(max)****
****PDO param type PDO::PARAM_STR is compatible with randomized encrypted nvarchar(max)****
****PDO param type PDO::PARAM_LOB is compatible with randomized encrypted nvarchar(max)****

View file

@ -1,35 +1,87 @@
--TEST-- --TEST--
Test for inserting and retrieving encrypted data of numeric types Test for inserting encrypted data into numeric types columns
--DESCRIPTION-- --DESCRIPTION--
Use PDOstatement::bindParam with all PDO::PARAM_ types Test conversions between different numeric types
With or without Always Encrypted, implicit conversion works if:
1. From input of PDO::PARAM_BOOL to a real column
2. From input of PDO::PARAM_INT to a any numeric column
3. From input of PDO::PARAM_STR to a any numeric column
4. From input of PDO::PARAM_LOB to a any numeric column
--SKIPIF-- --SKIPIF--
<?php require('skipif_mid-refactor.inc'); ?> <?php require('skipif_mid-refactor.inc'); ?>
--FILE-- --FILE--
<?php <?php
require_once("MsCommon_mid-refactor.inc"); require_once("MsCommon_mid-refactor.inc");
require_once("AEData.inc"); require_once("AEData.inc");
$dataTypes = array( "bit", "tinyint", "smallint", "int", "bigint", "real" ); $dataTypes = array( "bit", "tinyint", "smallint", "int", "bigint", "real" );
$epsilon = 1;
try { try {
$conn = connect(); $conn = connect();
foreach ($dataTypes as $dataType) { foreach ($dataTypes as $dataType) {
echo "\nTesting $dataType:\n"; echo "\nTesting $dataType:\n";
// create table // create table containing bit, tinyint, smallint, int, bigint, or real columns
$tbname = getTableName(); $tbname = "test_" . $dataType;
$colMetaArr = array(new ColumnMeta($dataType, "c_det"), new ColumnMeta($dataType, "c_rand", null, "randomized")); $colMetaArr = array(new ColumnMeta($dataType, "c_det"), new ColumnMeta($dataType, "c_rand", null, "randomized"));
createTable($conn, $tbname, $colMetaArr); createTable($conn, $tbname, $colMetaArr);
// test each PDO::PARAM_ type // insert by specifying PDO::PARAM_ types
foreach ($pdoParamTypes as $pdoParamType) { foreach ($pdoParamTypes as $pdoParamType) {
// insert a row
$inputValues = array_slice(${explode("(", $dataType)[0] . "_params"}, 1, 2); $inputValues = array_slice(${explode("(", $dataType)[0] . "_params"}, 1, 2);
$r; $r;
$stmt = insertRow($conn, $tbname, array( "c_det" => new BindParamOp(1, $inputValues[0], $pdoParamType), "c_rand" => new BindParamOp(2, $inputValues[1], $pdoParamType)), "prepareBindParam", $r); $stmt = insertRow($conn, $tbname, array( "c_det" => new BindParamOp(1, $inputValues[0], $pdoParamType), "c_rand" => new BindParamOp(2, $inputValues[1], $pdoParamType)), "prepareBindParam", $r);
if ($r === false) {
isIncompatibleTypesError($stmt, $dataType, $pdoParamType); // check the case when inserting as PDO::PARAM_NULL
// with or without AE: NULL is inserted
if ($pdoParamType == "PDO::PARAM_NULL") {
if ($r === false) {
echo "Conversion from $pdoParamType to $dataType should be supported\n";
} else {
$sql = "SELECT c_det, c_rand FROM $tbname";
$stmt = $conn->query($sql);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if (!is_null($row['c_det']) || !is_null($row['c_rand'])) {
echo "Conversion from $pdoParamType to $dataType should insert NULL\n";
}
}
// check the case when inserting as PDO::PARAM_BOOL
// with or without AE: 1 or 0 should be inserted when inserting into an integer column
// double is inserted when inserting into a real column
} else if ($pdoParamType == "PDO::PARAM_BOOL") {
$sql = "SELECT c_det, c_rand FROM $tbname";
$stmt = $conn->query($sql);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if ($dataType == "real") {
if (abs($row['c_det'] - $inputValues[0]) < $epsilon && abs($row['c_rand'] - $inputValues[1]) < $epsilon) {
echo "****Conversion from $pdoParamType to $dataType is supported****\n";
} else {
echo "Conversion from $pdoParamType to $dataType causes data corruption\n";
}
} else {
if ($row['c_det'] != ($inputValues[0] != 0) && $row['c_rand'] != ($inputValues[1] != 0)) {
echo "Conversion from $pdoParamType to $dataType insert a boolean\n";
}
}
// check the case when inserting as PDO::PARAM_INT, PDO::PARAM_STR or PDO::PARAM_LOB
} else { } else {
echo "****PDO param type $pdoParamType is compatible with encrypted $dataType****\n"; $sql = "SELECT c_det, c_rand FROM $tbname";
fetchAll($conn, $tbname); $stmt = $conn->query($sql);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if ($dataType == "real") {
if (abs($row['c_det'] - $inputValues[0]) < $epsilon && abs($row['c_rand'] - $inputValues[1]) < $epsilon) {
echo "****Conversion from $pdoParamType to $dataType is supported****\n";
} else {
echo "Conversion from $pdoParamType to $dataType causes data corruption\n";
}
} else {
if ($row['c_det'] == $inputValues[0] && $row['c_rand'] == $inputValues[1]) {
echo "****Conversion from $pdoParamType to $dataType is supported****\n";
} else {
echo "Conversion from $pdoParamType to $dataType causes data corruption\n";
}
}
} }
$conn->query("TRUNCATE TABLE $tbname"); $conn->query("TRUNCATE TABLE $tbname");
} }
@ -43,103 +95,32 @@ try {
?> ?>
--EXPECT-- --EXPECT--
Testing bit: Testing bit:
****PDO param type PDO::PARAM_BOOL is compatible with encrypted bit**** ****Conversion from PDO::PARAM_INT to bit is supported****
c_det: 1 ****Conversion from PDO::PARAM_STR to bit is supported****
c_rand: 0 ****Conversion from PDO::PARAM_LOB to bit is supported****
****PDO param type PDO::PARAM_NULL is compatible with encrypted bit****
c_det:
c_rand:
****PDO param type PDO::PARAM_INT is compatible with encrypted bit****
c_det: 1
c_rand: 0
****PDO param type PDO::PARAM_STR is compatible with encrypted bit****
c_det: 1
c_rand: 0
****PDO param type PDO::PARAM_LOB is compatible with encrypted bit****
c_det: 1
c_rand: 0
Testing tinyint: Testing tinyint:
****PDO param type PDO::PARAM_BOOL is compatible with encrypted tinyint**** ****Conversion from PDO::PARAM_INT to tinyint is supported****
c_det: 0 ****Conversion from PDO::PARAM_STR to tinyint is supported****
c_rand: 1 ****Conversion from PDO::PARAM_LOB to tinyint is supported****
****PDO param type PDO::PARAM_NULL is compatible with encrypted tinyint****
c_det:
c_rand:
****PDO param type PDO::PARAM_INT is compatible with encrypted tinyint****
c_det: 0
c_rand: 255
****PDO param type PDO::PARAM_STR is compatible with encrypted tinyint****
c_det: 0
c_rand: 255
****PDO param type PDO::PARAM_LOB is compatible with encrypted tinyint****
c_det: 0
c_rand: 255
Testing smallint: Testing smallint:
****PDO param type PDO::PARAM_BOOL is compatible with encrypted smallint**** ****Conversion from PDO::PARAM_INT to smallint is supported****
c_det: 1 ****Conversion from PDO::PARAM_STR to smallint is supported****
c_rand: 1 ****Conversion from PDO::PARAM_LOB to smallint is supported****
****PDO param type PDO::PARAM_NULL is compatible with encrypted smallint****
c_det:
c_rand:
****PDO param type PDO::PARAM_INT is compatible with encrypted smallint****
c_det: -32767
c_rand: 32767
****PDO param type PDO::PARAM_STR is compatible with encrypted smallint****
c_det: -32767
c_rand: 32767
****PDO param type PDO::PARAM_LOB is compatible with encrypted smallint****
c_det: -32767
c_rand: 32767
Testing int: Testing int:
****PDO param type PDO::PARAM_BOOL is compatible with encrypted int**** ****Conversion from PDO::PARAM_INT to int is supported****
c_det: 1 ****Conversion from PDO::PARAM_STR to int is supported****
c_rand: 1 ****Conversion from PDO::PARAM_LOB to int is supported****
****PDO param type PDO::PARAM_NULL is compatible with encrypted int****
c_det:
c_rand:
****PDO param type PDO::PARAM_INT is compatible with encrypted int****
c_det: -2147483647
c_rand: 2147483647
****PDO param type PDO::PARAM_STR is compatible with encrypted int****
c_det: -2147483647
c_rand: 2147483647
****PDO param type PDO::PARAM_LOB is compatible with encrypted int****
c_det: -2147483647
c_rand: 2147483647
Testing bigint: Testing bigint:
****PDO param type PDO::PARAM_BOOL is compatible with encrypted bigint**** ****Conversion from PDO::PARAM_INT to bigint is supported****
c_det: 1 ****Conversion from PDO::PARAM_STR to bigint is supported****
c_rand: 1 ****Conversion from PDO::PARAM_LOB to bigint is supported****
****PDO param type PDO::PARAM_NULL is compatible with encrypted bigint****
c_det:
c_rand:
****PDO param type PDO::PARAM_INT is compatible with encrypted bigint****
c_det: -922337203685479936
c_rand: 922337203685479936
****PDO param type PDO::PARAM_STR is compatible with encrypted bigint****
c_det: -922337203685479936
c_rand: 922337203685479936
****PDO param type PDO::PARAM_LOB is compatible with encrypted bigint****
c_det: -922337203685479936
c_rand: 922337203685479936
Testing real: Testing real:
****PDO param type PDO::PARAM_BOOL is compatible with encrypted real**** ****Conversion from PDO::PARAM_BOOL to real is supported****
c_det: -2147.4829 ****Conversion from PDO::PARAM_INT to real is supported****
c_rand: 2147.4829 ****Conversion from PDO::PARAM_STR to real is supported****
****PDO param type PDO::PARAM_NULL is compatible with encrypted real**** ****Conversion from PDO::PARAM_LOB to real is supported****
c_det:
c_rand:
****PDO param type PDO::PARAM_INT is compatible with encrypted real****
c_det: -2147.4829
c_rand: 2147.4829
****PDO param type PDO::PARAM_STR is compatible with encrypted real****
c_det: -2147.4829
c_rand: 2147.4829
****PDO param type PDO::PARAM_LOB is compatible with encrypted real****
c_det: -2147.4829
c_rand: 2147.4829