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 for inserting and retrieving encrypted data of numeric types
Test for retrieving encrypted data from binary types columns using PDO::bindColumn
--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--
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
@ -15,25 +18,24 @@ $lengths = array(1, 8, 64, 512, 4000);
try {
$conn = connect("", array(), PDO::ERRMODE_SILENT);
foreach ($dataTypes as $dataType) {
$maxtype = strpos($dataType, "(max)");
foreach ($lengths as $length) {
if ($maxtype !== false) {
$type = $dataType;
$maxcol = strpos($dataType, "(max)");
foreach ($lengths as $m) {
if ($maxcol !== false) {
$typeFull = $dataType;
} else {
$type = "$dataType($length)";
$typeFull = "$dataType($m)";
}
echo "\nTesting $type:\n";
echo "\nTesting $typeFull:\n";
//create and populate table
$tbname = "test_binary";
$colMetaArr = array(new ColumnMeta($type, "c_det"), new ColumnMeta($type, "c_rand", null, "randomized"));
//create and populate table containing binary(m) or varbinary(m) columns
$tbname = "test_" . str_replace(array('(', ')'), '', $dataType) . $m;
$colMetaArr = array(new ColumnMeta($typeFull, "c_det"), new ColumnMeta($typeFull, "c_rand", null, "randomized"));
createTable($conn, $tbname, $colMetaArr);
$input0 = str_repeat("d", $length);
$input1 = str_repeat("r", $length);
insertRow($conn, $tbname, array("c_det" => new BindParamOp(1, $input0, "PDO::PARAM_LOB", 0, "PDO::SQLSRV_ENCODING_BINARY"),
"c_rand" => new BindParamOp(2, $input1, "PDO::PARAM_LOB", 0, "PDO::SQLSRV_ENCODING_BINARY")), "prepareBindParam");
$inputValues = array(str_repeat("d", $m), str_repeat("r", $m));
insertRow($conn, $tbname, array("c_det" => new BindParamOp(1, $inputValues[0], "PDO::PARAM_LOB", 0, "PDO::SQLSRV_ENCODING_BINARY"),
"c_rand" => new BindParamOp(2, $inputValues[1], "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";
foreach ($pdoParamTypes as $pdoParamType) {
$det = "";
@ -44,19 +46,23 @@ try {
$stmt->bindColumn('c_rand', $rand, constant($pdoParamType));
$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 (!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 {
if (strlen($det) == $length && strlen($rand) == $length) {
echo "****PDO param type $pdoParamType is compatible with encrypted $type****\n";
if (strlen($det) == $m && strlen($rand) == $m) {
echo "****Retrieving $typeFull data as $pdoParamType is supported****\n";
} else {
echo "Data corruption when fetching encrypted $type as PDO param type $pdoParamType\n";
print_r($stmt->errorInfo());
echo "Retrieving $typeFull data as $pdoParamType fails\n";
}
}
}
// cleanup
dropTable($conn, $tbname);
}
}
@ -68,61 +74,61 @@ try {
?>
--EXPECT--
Testing binary(1):
****PDO param type PDO::PARAM_STR is compatible with encrypted binary(1)****
****PDO param type PDO::PARAM_LOB is compatible with encrypted binary(1)****
****Retrieving binary(1) data as PDO::PARAM_STR is supported****
****Retrieving binary(1) data as PDO::PARAM_LOB is supported****
Testing binary(8):
****PDO param type PDO::PARAM_STR is compatible with encrypted binary(8)****
****PDO param type PDO::PARAM_LOB is compatible with encrypted binary(8)****
****Retrieving binary(8) data as PDO::PARAM_STR is supported****
****Retrieving binary(8) data as PDO::PARAM_LOB is supported****
Testing binary(64):
****PDO param type PDO::PARAM_STR is compatible with encrypted binary(64)****
****PDO param type PDO::PARAM_LOB is compatible with encrypted binary(64)****
****Retrieving binary(64) data as PDO::PARAM_STR is supported****
****Retrieving binary(64) data as PDO::PARAM_LOB is supported****
Testing binary(512):
****PDO param type PDO::PARAM_STR is compatible with encrypted binary(512)****
****PDO param type PDO::PARAM_LOB is compatible with encrypted binary(512)****
****Retrieving binary(512) data as PDO::PARAM_STR is supported****
****Retrieving binary(512) data as PDO::PARAM_LOB is supported****
Testing binary(4000):
****PDO param type PDO::PARAM_STR is compatible with encrypted binary(4000)****
****PDO param type PDO::PARAM_LOB is compatible with encrypted binary(4000)****
****Retrieving binary(4000) data as PDO::PARAM_STR is supported****
****Retrieving binary(4000) data as PDO::PARAM_LOB is supported****
Testing varbinary(1):
****PDO param type PDO::PARAM_STR is compatible with encrypted varbinary(1)****
****PDO param type PDO::PARAM_LOB is compatible with encrypted varbinary(1)****
****Retrieving varbinary(1) data as PDO::PARAM_STR is supported****
****Retrieving varbinary(1) data as PDO::PARAM_LOB is supported****
Testing varbinary(8):
****PDO param type PDO::PARAM_STR is compatible with encrypted varbinary(8)****
****PDO param type PDO::PARAM_LOB is compatible with encrypted varbinary(8)****
****Retrieving varbinary(8) data as PDO::PARAM_STR is supported****
****Retrieving varbinary(8) data as PDO::PARAM_LOB is supported****
Testing varbinary(64):
****PDO param type PDO::PARAM_STR is compatible with encrypted varbinary(64)****
****PDO param type PDO::PARAM_LOB is compatible with encrypted varbinary(64)****
****Retrieving varbinary(64) data as PDO::PARAM_STR is supported****
****Retrieving varbinary(64) data as PDO::PARAM_LOB is supported****
Testing varbinary(512):
****PDO param type PDO::PARAM_STR is compatible with encrypted varbinary(512)****
****PDO param type PDO::PARAM_LOB is compatible with encrypted varbinary(512)****
****Retrieving varbinary(512) data as PDO::PARAM_STR is supported****
****Retrieving varbinary(512) data as PDO::PARAM_LOB is supported****
Testing varbinary(4000):
****PDO param type PDO::PARAM_STR is compatible with encrypted varbinary(4000)****
****PDO param type PDO::PARAM_LOB is compatible with encrypted varbinary(4000)****
****Retrieving varbinary(4000) data as PDO::PARAM_STR is supported****
****Retrieving varbinary(4000) data as PDO::PARAM_LOB is supported****
Testing varbinary(max):
****PDO param type PDO::PARAM_STR is compatible with encrypted varbinary(max)****
****PDO param type PDO::PARAM_LOB is compatible with encrypted varbinary(max)****
****Retrieving varbinary(max) data as PDO::PARAM_STR is supported****
****Retrieving varbinary(max) data as PDO::PARAM_LOB is supported****
Testing varbinary(max):
****PDO param type PDO::PARAM_STR is compatible with encrypted varbinary(max)****
****PDO param type PDO::PARAM_LOB is compatible with encrypted varbinary(max)****
****Retrieving varbinary(max) data as PDO::PARAM_STR is supported****
****Retrieving varbinary(max) data as PDO::PARAM_LOB is supported****
Testing varbinary(max):
****PDO param type PDO::PARAM_STR is compatible with encrypted varbinary(max)****
****PDO param type PDO::PARAM_LOB is compatible with encrypted varbinary(max)****
****Retrieving varbinary(max) data as PDO::PARAM_STR is supported****
****Retrieving varbinary(max) data as PDO::PARAM_LOB is supported****
Testing varbinary(max):
****PDO param type PDO::PARAM_STR is compatible with encrypted varbinary(max)****
****PDO param type PDO::PARAM_LOB is compatible with encrypted varbinary(max)****
****Retrieving varbinary(max) data as PDO::PARAM_STR is supported****
****Retrieving varbinary(max) data as PDO::PARAM_LOB is supported****
Testing varbinary(max):
****PDO param type PDO::PARAM_STR is compatible with encrypted varbinary(max)****
****PDO param type PDO::PARAM_LOB is compatible with encrypted varbinary(max)****
****Retrieving varbinary(max) data as PDO::PARAM_STR is supported****
****Retrieving varbinary(max) data as PDO::PARAM_LOB is supported****

View file

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

View file

@ -1,7 +1,10 @@
--TEST--
Test for inserting and retrieving encrypted data of datetime types
Test for retrieving encrypted data from datetime types columns using PDO::bindColumn
--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--
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
@ -10,19 +13,20 @@ require_once("MsCommon_mid-refactor.inc");
require_once("AEData.inc");
$dataTypes = array("date", "datetime", "smalldatetime");
try {
$conn = connect("", array(), PDO::ERRMODE_SILENT);
foreach ($dataTypes as $dataType) {
echo "\nTesting $dataType:\n";
// create and populate table
$tbname = getTableName();
// create and populate table containing date, datetime or smalldatetime columns
$tbname = "test_" . $dataType;
$colMetaArr = array(new ColumnMeta($dataType, "c_det"), new ColumnMeta($dataType, "c_rand", null, "randomized"));
createTable($conn, $tbname, $colMetaArr);
$inputValues = array_slice(${explode("(", $dataType)[0] . "_params"}, 1, 2);
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";
foreach ($pdoParamTypes as $pdoParamType) {
$det = "";
@ -33,16 +37,23 @@ try {
$stmt->bindColumn('c_rand', $rand, constant($pdoParamType));
$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 (!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 {
echo "****PDO param type $pdoParamType is compatible with encrypted $dataType****\n";
echo "c_det: $det\n";
echo "c_rand: $rand\n";
if (strpos($det, $inputValues[0]) !== false && strpos($rand, $inputValues[1]) !== false) {
echo "****Retrieving $dataType as $pdoParamType is supported****\n";
} else {
echo "Retrieving $dataType as $pdoParamType fails\n";
}
}
}
// cleanup
dropTable($conn, $tbname);
}
unset($stmt);
@ -53,25 +64,13 @@ try {
?>
--EXPECT--
Testing date:
****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
****Retrieving date as PDO::PARAM_STR is supported****
****Retrieving date as PDO::PARAM_LOB is supported****
Testing datetime:
****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
****Retrieving datetime as PDO::PARAM_STR is supported****
****Retrieving datetime as PDO::PARAM_LOB is supported****
Testing smalldatetime:
****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
****Retrieving smalldatetime as PDO::PARAM_STR is supported****
****Retrieving smalldatetime as PDO::PARAM_LOB is supported****

View file

@ -1,7 +1,13 @@
--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--
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--
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
@ -9,6 +15,20 @@ Use PDOstatement::bindParam with all PDO::PARAM_ types
require_once("MsCommon_mid-refactor.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");
$precisions = array(/*0,*/ 1, 2, 4, 7);
$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 {
$conn = connect("", array(), PDO::ERRMODE_SILENT);
foreach ($dataTypes as $dataType) {
foreach ($precisions as $precision) {
// change the input values depending on the precision
foreach ($precisions as $m) {
// add $m number of decimal digits to the some input values
$inputValues[0] = $inputValuesInit[$dataType][0];
$inputValues[1] = $inputValuesInit[$dataType][1];
if ($precision != 0) {
if ($m != 0) {
if ($dataType == "datetime2") {
$inputValues[1] .= "." . str_repeat("9", $precision);
$inputValues[1] .= "." . str_repeat("9", $m);
} else if ($dataType == "datetimeoffset") {
$inputPieces = explode(" ", $inputValues[1]);
$inputValues[1] = $inputPieces[0] . " " . $inputPieces[1] . "." . str_repeat("9", $precision) . " " . $inputPieces[2];
$dtoffsetPieces = explode(" ", $inputValues[1]);
$inputValues[1] = $dtoffsetPieces[0] . " " . $dtoffsetPieces[1] . "." . str_repeat("9", $m) . " " . $dtoffsetPieces[2];
} else if ($dataType == "time") {
$inputValues[0] .= "." . str_repeat("0", $precision);
$inputValues[1] .= "." . str_repeat("9", $precision);
$inputValues[0] .= "." . str_repeat("0", $m);
$inputValues[1] .= "." . str_repeat("9", $m);
}
}
$type = "$dataType($precision)";
echo "\nTesting $type:\n";
$typeFull = "$dataType($m)";
echo "\nTesting $typeFull:\n";
//create and populate table
$tbname = "test_datetime";
$colMetaArr = array(new ColumnMeta($type, "c_det"), new ColumnMeta($type, "c_rand", null, "randomized"));
//create and populate table containing datetime2(m), datetimeoffset(m) or time(m) columns
$tbname = "test_" . $dataType . $m;
$colMetaArr = array(new ColumnMeta($typeFull, "c_det"), new ColumnMeta($typeFull, "c_rand", null, "randomized"));
createTable($conn, $tbname, $colMetaArr);
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";
foreach ($pdoParamTypes as $pdoParamType) {
$det = "";
@ -53,16 +73,23 @@ try {
$stmt->bindColumn('c_rand', $rand, constant($pdoParamType));
$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 (!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 {
echo "****PDO param type $pdoParamType is compatible with encrypted $type****\n";
echo "c_det: $det\n";
echo "c_rand: $rand\n";
if (compareDate($det, $inputValues[0], $dataType) && compareDate($rand, $inputValues[1], $dataType)) {
echo "****Retrieving $typeFull as $pdoParamType is supported****\n";
} else {
echo "Retrieving $typeFull as $pdoParamType fails\n";
}
}
}
// cleanup
dropTable($conn, $tbname);
}
}
@ -74,97 +101,49 @@ try {
?>
--EXPECT--
Testing datetime2(1):
****PDO param type PDO::PARAM_STR is compatible with encrypted datetime2(1)****
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(1)****
c_det: 0001-01-01 00:00:00.0
c_rand: 9999-12-31 23:59:59.9
****Retrieving datetime2(1) as PDO::PARAM_STR is supported****
****Retrieving datetime2(1) as PDO::PARAM_LOB is supported****
Testing datetime2(2):
****PDO param type PDO::PARAM_STR is compatible with encrypted datetime2(2)****
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(2)****
c_det: 0001-01-01 00:00:00.00
c_rand: 9999-12-31 23:59:59.99
****Retrieving datetime2(2) as PDO::PARAM_STR is supported****
****Retrieving datetime2(2) as PDO::PARAM_LOB is supported****
Testing datetime2(4):
****PDO param type PDO::PARAM_STR is compatible with encrypted datetime2(4)****
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(4)****
c_det: 0001-01-01 00:00:00.0000
c_rand: 9999-12-31 23:59:59.9999
****Retrieving datetime2(4) as PDO::PARAM_STR is supported****
****Retrieving datetime2(4) as PDO::PARAM_LOB is supported****
Testing datetime2(7):
****PDO param type PDO::PARAM_STR is compatible with encrypted datetime2(7)****
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(7)****
c_det: 0001-01-01 00:00:00.0000000
c_rand: 9999-12-31 23:59:59.9999999
****Retrieving datetime2(7) as PDO::PARAM_STR is supported****
****Retrieving datetime2(7) as PDO::PARAM_LOB is supported****
Testing datetimeoffset(1):
****PDO param type PDO::PARAM_STR 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
****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
****Retrieving datetimeoffset(1) as PDO::PARAM_STR is supported****
****Retrieving datetimeoffset(1) as PDO::PARAM_LOB is supported****
Testing datetimeoffset(2):
****PDO param type PDO::PARAM_STR 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
****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
****Retrieving datetimeoffset(2) as PDO::PARAM_STR is supported****
****Retrieving datetimeoffset(2) as PDO::PARAM_LOB is supported****
Testing datetimeoffset(4):
****PDO param type PDO::PARAM_STR 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
****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
****Retrieving datetimeoffset(4) as PDO::PARAM_STR is supported****
****Retrieving datetimeoffset(4) as PDO::PARAM_LOB is supported****
Testing datetimeoffset(7):
****PDO param type PDO::PARAM_STR 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
****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
****Retrieving datetimeoffset(7) as PDO::PARAM_STR is supported****
****Retrieving datetimeoffset(7) as PDO::PARAM_LOB is supported****
Testing time(1):
****PDO param type PDO::PARAM_STR is compatible with encrypted time(1)****
c_det: 00:00:00.0
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
****Retrieving time(1) as PDO::PARAM_STR is supported****
****Retrieving time(1) as PDO::PARAM_LOB is supported****
Testing time(2):
****PDO param type PDO::PARAM_STR is compatible with encrypted time(2)****
c_det: 00:00:00.00
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
****Retrieving time(2) as PDO::PARAM_STR is supported****
****Retrieving time(2) as PDO::PARAM_LOB is supported****
Testing time(4):
****PDO param type PDO::PARAM_STR is compatible with encrypted time(4)****
c_det: 00:00:00.0000
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
****Retrieving time(4) as PDO::PARAM_STR is supported****
****Retrieving time(4) as PDO::PARAM_LOB is supported****
Testing time(7):
****PDO param type PDO::PARAM_STR is compatible with encrypted time(7)****
c_det: 00:00:00.0000000
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
****Retrieving time(7) as PDO::PARAM_STR is supported****
****Retrieving time(7) as PDO::PARAM_LOB is supported****

View file

@ -1,7 +1,16 @@
--TEST--
Test for inserting and retrieving encrypted data of numeric types
Test for retrieving encrypted data from decimal types columns using PDO::bindColumn
--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--
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
@ -20,21 +29,22 @@ $inputPrecision = 38;
try {
$conn = connect("", array(), PDO::ERRMODE_SILENT);
foreach ($dataTypes as $dataType) {
foreach ($precisions as $precision => $scales) {
foreach ($scales as $scale) {
// change the input values depending on the precision and scale
$precDiff = $inputPrecision - ($precision - $scale);
foreach ($precisions as $m1 => $scales) {
foreach ($scales as $m2) {
// change the number of integers in the input values to be $m1 - $m2
$precDiff = $inputPrecision - ($m1 - $m2);
$inputValues = $inputValuesInit;
foreach ($inputValues as &$inputValue) {
$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
$epsilon;
if ($precision < 14) {
$epsilon = pow(10, $scale * -1);
if ($m1 < 14) {
$epsilon = pow(10, $m2 * -1);
} else {
$numint = $precision - $scale;
$numint = $m1 - $m2;
if ($numint < 14) {
$epsilon = pow(10, (14 - $numint) * -1);
} else {
@ -42,16 +52,16 @@ try {
}
}
$type = "$dataType($precision, $scale)";
echo "\nTesting $type:\n";
$typeFull = "$dataType($m1, $m2)";
echo "\nTesting $typeFull:\n";
//create and populate table
$tbname = "test_decimal";
$colMetaArr = array(new ColumnMeta($type, "c_det"), new ColumnMeta($type, "c_rand", null, "randomized"));
//create and populate table containing decimal(m1, m2) or numeric(m1, m2) columns
$tbname = "test_" . $dataType . $m1 . $m2;
$colMetaArr = array(new ColumnMeta($typeFull, "c_det"), new ColumnMeta($typeFull, "c_rand", null, "randomized"));
createTable($conn, $tbname, $colMetaArr);
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";
foreach ($pdoParamTypes as $pdoParamType) {
$det = "";
@ -62,25 +72,23 @@ try {
$stmt->bindColumn('c_rand', $rand, constant($pdoParamType));
$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
// behavior for fetching 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. 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
// check the case when fetching as PDO::PARAM_BOOL, PDO::PARAM_NULL or PDO::PARAM_INT
// with or without AE; should not work
// assume to correct behavior is to return NULL, see description
if ($pdoParamType == "PDO::PARAM_BOOL" || $pdoParamType == "PDO::PARAM_NULL" || $pdoParamType == "PDO::PARAM_INT") {
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 {
if (abs($det - $inputValues[0]) > $epsilon ||
abs($rand - $inputValues[1]) > $epsilon) {
echo "PDO param type $pdoParamType should be compatible with $type\n";
if (abs($det - $inputValues[0]) < $epsilon &&
abs($rand - $inputValues[1]) < $epsilon) {
echo "****Retrieving $typeFull as $pdoParamType is supported****\n";
} else {
echo "****PDO param type $pdoParamType is compatible with $type****\n";
echo "Retrieving $typeFull as $pdoParamType fails\n";
}
}
}
// cleanup
dropTable($conn, $tbname);
}
}
@ -93,141 +101,141 @@ try {
?>
--EXPECT--
Testing decimal(1, 0):
Fetching decimal(1, 0) as PDO param type PDO::PARAM_BOOL should return NULL
Fetching decimal(1, 0) as PDO param type PDO::PARAM_INT should return NULL
****PDO param type PDO::PARAM_STR is compatible with decimal(1, 0)****
****PDO param type PDO::PARAM_LOB is compatible with decimal(1, 0)****
Retrieving decimal(1, 0) data as PDO::PARAM_BOOL should return NULL
Retrieving decimal(1, 0) data as PDO::PARAM_INT should return NULL
****Retrieving decimal(1, 0) as PDO::PARAM_STR is supported****
****Retrieving decimal(1, 0) as PDO::PARAM_LOB is supported****
Testing decimal(1, 1):
Fetching decimal(1, 1) as PDO param type PDO::PARAM_BOOL should return NULL
Fetching decimal(1, 1) as PDO param type PDO::PARAM_INT should return NULL
****PDO param type PDO::PARAM_STR is compatible with decimal(1, 1)****
****PDO param type PDO::PARAM_LOB is compatible with decimal(1, 1)****
Retrieving decimal(1, 1) data as PDO::PARAM_BOOL should return NULL
Retrieving decimal(1, 1) data as PDO::PARAM_INT should return NULL
****Retrieving decimal(1, 1) as PDO::PARAM_STR is supported****
****Retrieving decimal(1, 1) as PDO::PARAM_LOB is supported****
Testing decimal(4, 0):
Fetching decimal(4, 0) as PDO param type PDO::PARAM_BOOL should return NULL
Fetching decimal(4, 0) as PDO param type PDO::PARAM_INT should return NULL
****PDO param type PDO::PARAM_STR is compatible with decimal(4, 0)****
****PDO param type PDO::PARAM_LOB is compatible with decimal(4, 0)****
Retrieving decimal(4, 0) data as PDO::PARAM_BOOL should return NULL
Retrieving decimal(4, 0) data as PDO::PARAM_INT should return NULL
****Retrieving decimal(4, 0) as PDO::PARAM_STR is supported****
****Retrieving decimal(4, 0) as PDO::PARAM_LOB is supported****
Testing decimal(4, 1):
Fetching decimal(4, 1) as PDO param type PDO::PARAM_BOOL should return NULL
Fetching decimal(4, 1) as PDO param type PDO::PARAM_INT should return NULL
****PDO param type PDO::PARAM_STR is compatible with decimal(4, 1)****
****PDO param type PDO::PARAM_LOB is compatible with decimal(4, 1)****
Retrieving decimal(4, 1) data as PDO::PARAM_BOOL should return NULL
Retrieving decimal(4, 1) data as PDO::PARAM_INT should return NULL
****Retrieving decimal(4, 1) as PDO::PARAM_STR is supported****
****Retrieving decimal(4, 1) as PDO::PARAM_LOB is supported****
Testing decimal(4, 4):
Fetching decimal(4, 4) as PDO param type PDO::PARAM_BOOL should return NULL
Fetching decimal(4, 4) as PDO param type PDO::PARAM_INT should return NULL
****PDO param type PDO::PARAM_STR is compatible with decimal(4, 4)****
****PDO param type PDO::PARAM_LOB is compatible with decimal(4, 4)****
Retrieving decimal(4, 4) data as PDO::PARAM_BOOL should return NULL
Retrieving decimal(4, 4) data as PDO::PARAM_INT should return NULL
****Retrieving decimal(4, 4) as PDO::PARAM_STR is supported****
****Retrieving decimal(4, 4) as PDO::PARAM_LOB is supported****
Testing decimal(16, 0):
****PDO param type PDO::PARAM_STR is compatible with decimal(16, 0)****
****PDO param type PDO::PARAM_LOB is compatible with decimal(16, 0)****
****Retrieving decimal(16, 0) as PDO::PARAM_STR is supported****
****Retrieving decimal(16, 0) as PDO::PARAM_LOB is supported****
Testing decimal(16, 1):
****PDO param type PDO::PARAM_STR is compatible with decimal(16, 1)****
****PDO param type PDO::PARAM_LOB is compatible with decimal(16, 1)****
****Retrieving decimal(16, 1) as PDO::PARAM_STR is supported****
****Retrieving decimal(16, 1) as PDO::PARAM_LOB is supported****
Testing decimal(16, 4):
****PDO param type PDO::PARAM_STR is compatible with decimal(16, 4)****
****PDO param type PDO::PARAM_LOB is compatible with decimal(16, 4)****
****Retrieving decimal(16, 4) as PDO::PARAM_STR is supported****
****Retrieving decimal(16, 4) as PDO::PARAM_LOB is supported****
Testing decimal(16, 16):
Fetching decimal(16, 16) as PDO param type PDO::PARAM_BOOL should return NULL
Fetching decimal(16, 16) as PDO param type PDO::PARAM_INT should return NULL
****PDO param type PDO::PARAM_STR is compatible with decimal(16, 16)****
****PDO param type PDO::PARAM_LOB is compatible with decimal(16, 16)****
Retrieving decimal(16, 16) data as PDO::PARAM_BOOL should return NULL
Retrieving decimal(16, 16) data as PDO::PARAM_INT should return NULL
****Retrieving decimal(16, 16) as PDO::PARAM_STR is supported****
****Retrieving decimal(16, 16) as PDO::PARAM_LOB is supported****
Testing decimal(38, 0):
****PDO param type PDO::PARAM_STR is compatible with decimal(38, 0)****
****PDO param type PDO::PARAM_LOB is compatible with decimal(38, 0)****
****Retrieving decimal(38, 0) as PDO::PARAM_STR is supported****
****Retrieving decimal(38, 0) as PDO::PARAM_LOB is supported****
Testing decimal(38, 1):
****PDO param type PDO::PARAM_STR is compatible with decimal(38, 1)****
****PDO param type PDO::PARAM_LOB is compatible with decimal(38, 1)****
****Retrieving decimal(38, 1) as PDO::PARAM_STR is supported****
****Retrieving decimal(38, 1) as PDO::PARAM_LOB is supported****
Testing decimal(38, 4):
****PDO param type PDO::PARAM_STR is compatible with decimal(38, 4)****
****PDO param type PDO::PARAM_LOB is compatible with decimal(38, 4)****
****Retrieving decimal(38, 4) as PDO::PARAM_STR is supported****
****Retrieving decimal(38, 4) as PDO::PARAM_LOB is supported****
Testing decimal(38, 16):
****PDO param type PDO::PARAM_STR is compatible with decimal(38, 16)****
****PDO param type PDO::PARAM_LOB is compatible with decimal(38, 16)****
****Retrieving decimal(38, 16) as PDO::PARAM_STR is supported****
****Retrieving decimal(38, 16) as PDO::PARAM_LOB is supported****
Testing decimal(38, 38):
Fetching decimal(38, 38) as PDO param type PDO::PARAM_BOOL should return NULL
Fetching decimal(38, 38) as PDO param type PDO::PARAM_INT should return NULL
****PDO param type PDO::PARAM_STR is compatible with decimal(38, 38)****
****PDO param type PDO::PARAM_LOB is compatible with decimal(38, 38)****
Retrieving decimal(38, 38) data as PDO::PARAM_BOOL should return NULL
Retrieving decimal(38, 38) data as PDO::PARAM_INT should return NULL
****Retrieving decimal(38, 38) as PDO::PARAM_STR is supported****
****Retrieving decimal(38, 38) as PDO::PARAM_LOB is supported****
Testing numeric(1, 0):
Fetching numeric(1, 0) as PDO param type PDO::PARAM_BOOL should return NULL
Fetching numeric(1, 0) as PDO param type PDO::PARAM_INT should return NULL
****PDO param type PDO::PARAM_STR is compatible with numeric(1, 0)****
****PDO param type PDO::PARAM_LOB is compatible with numeric(1, 0)****
Retrieving numeric(1, 0) data as PDO::PARAM_BOOL should return NULL
Retrieving numeric(1, 0) data as PDO::PARAM_INT should return NULL
****Retrieving numeric(1, 0) as PDO::PARAM_STR is supported****
****Retrieving numeric(1, 0) as PDO::PARAM_LOB is supported****
Testing numeric(1, 1):
Fetching numeric(1, 1) as PDO param type PDO::PARAM_BOOL should return NULL
Fetching numeric(1, 1) as PDO param type PDO::PARAM_INT should return NULL
****PDO param type PDO::PARAM_STR is compatible with numeric(1, 1)****
****PDO param type PDO::PARAM_LOB is compatible with numeric(1, 1)****
Retrieving numeric(1, 1) data as PDO::PARAM_BOOL should return NULL
Retrieving numeric(1, 1) data as PDO::PARAM_INT should return NULL
****Retrieving numeric(1, 1) as PDO::PARAM_STR is supported****
****Retrieving numeric(1, 1) as PDO::PARAM_LOB is supported****
Testing numeric(4, 0):
Fetching numeric(4, 0) as PDO param type PDO::PARAM_BOOL should return NULL
Fetching numeric(4, 0) as PDO param type PDO::PARAM_INT should return NULL
****PDO param type PDO::PARAM_STR is compatible with numeric(4, 0)****
****PDO param type PDO::PARAM_LOB is compatible with numeric(4, 0)****
Retrieving numeric(4, 0) data as PDO::PARAM_BOOL should return NULL
Retrieving numeric(4, 0) data as PDO::PARAM_INT should return NULL
****Retrieving numeric(4, 0) as PDO::PARAM_STR is supported****
****Retrieving numeric(4, 0) as PDO::PARAM_LOB is supported****
Testing numeric(4, 1):
Fetching numeric(4, 1) as PDO param type PDO::PARAM_BOOL should return NULL
Fetching numeric(4, 1) as PDO param type PDO::PARAM_INT should return NULL
****PDO param type PDO::PARAM_STR is compatible with numeric(4, 1)****
****PDO param type PDO::PARAM_LOB is compatible with numeric(4, 1)****
Retrieving numeric(4, 1) data as PDO::PARAM_BOOL should return NULL
Retrieving numeric(4, 1) data as PDO::PARAM_INT should return NULL
****Retrieving numeric(4, 1) as PDO::PARAM_STR is supported****
****Retrieving numeric(4, 1) as PDO::PARAM_LOB is supported****
Testing numeric(4, 4):
Fetching numeric(4, 4) as PDO param type PDO::PARAM_BOOL should return NULL
Fetching numeric(4, 4) as PDO param type PDO::PARAM_INT should return NULL
****PDO param type PDO::PARAM_STR is compatible with numeric(4, 4)****
****PDO param type PDO::PARAM_LOB is compatible with numeric(4, 4)****
Retrieving numeric(4, 4) data as PDO::PARAM_BOOL should return NULL
Retrieving numeric(4, 4) data as PDO::PARAM_INT should return NULL
****Retrieving numeric(4, 4) as PDO::PARAM_STR is supported****
****Retrieving numeric(4, 4) as PDO::PARAM_LOB is supported****
Testing numeric(16, 0):
****PDO param type PDO::PARAM_STR is compatible with numeric(16, 0)****
****PDO param type PDO::PARAM_LOB is compatible with numeric(16, 0)****
****Retrieving numeric(16, 0) as PDO::PARAM_STR is supported****
****Retrieving numeric(16, 0) as PDO::PARAM_LOB is supported****
Testing numeric(16, 1):
****PDO param type PDO::PARAM_STR is compatible with numeric(16, 1)****
****PDO param type PDO::PARAM_LOB is compatible with numeric(16, 1)****
****Retrieving numeric(16, 1) as PDO::PARAM_STR is supported****
****Retrieving numeric(16, 1) as PDO::PARAM_LOB is supported****
Testing numeric(16, 4):
****PDO param type PDO::PARAM_STR is compatible with numeric(16, 4)****
****PDO param type PDO::PARAM_LOB is compatible with numeric(16, 4)****
****Retrieving numeric(16, 4) as PDO::PARAM_STR is supported****
****Retrieving numeric(16, 4) as PDO::PARAM_LOB is supported****
Testing numeric(16, 16):
Fetching numeric(16, 16) as PDO param type PDO::PARAM_BOOL should return NULL
Fetching numeric(16, 16) as PDO param type PDO::PARAM_INT should return NULL
****PDO param type PDO::PARAM_STR is compatible with numeric(16, 16)****
****PDO param type PDO::PARAM_LOB is compatible with numeric(16, 16)****
Retrieving numeric(16, 16) data as PDO::PARAM_BOOL should return NULL
Retrieving numeric(16, 16) data as PDO::PARAM_INT should return NULL
****Retrieving numeric(16, 16) as PDO::PARAM_STR is supported****
****Retrieving numeric(16, 16) as PDO::PARAM_LOB is supported****
Testing numeric(38, 0):
****PDO param type PDO::PARAM_STR is compatible with numeric(38, 0)****
****PDO param type PDO::PARAM_LOB is compatible with numeric(38, 0)****
****Retrieving numeric(38, 0) as PDO::PARAM_STR is supported****
****Retrieving numeric(38, 0) as PDO::PARAM_LOB is supported****
Testing numeric(38, 1):
****PDO param type PDO::PARAM_STR is compatible with numeric(38, 1)****
****PDO param type PDO::PARAM_LOB is compatible with numeric(38, 1)****
****Retrieving numeric(38, 1) as PDO::PARAM_STR is supported****
****Retrieving numeric(38, 1) as PDO::PARAM_LOB is supported****
Testing numeric(38, 4):
****PDO param type PDO::PARAM_STR is compatible with numeric(38, 4)****
****PDO param type PDO::PARAM_LOB is compatible with numeric(38, 4)****
****Retrieving numeric(38, 4) as PDO::PARAM_STR is supported****
****Retrieving numeric(38, 4) as PDO::PARAM_LOB is supported****
Testing numeric(38, 16):
****PDO param type PDO::PARAM_STR is compatible with numeric(38, 16)****
****PDO param type PDO::PARAM_LOB is compatible with numeric(38, 16)****
****Retrieving numeric(38, 16) as PDO::PARAM_STR is supported****
****Retrieving numeric(38, 16) as PDO::PARAM_LOB is supported****
Testing numeric(38, 38):
Fetching numeric(38, 38) as PDO param type PDO::PARAM_BOOL should return NULL
Fetching numeric(38, 38) as PDO param type PDO::PARAM_INT should return NULL
****PDO param type PDO::PARAM_STR is compatible with numeric(38, 38)****
****PDO param type PDO::PARAM_LOB is compatible with numeric(38, 38)****
Retrieving numeric(38, 38) data as PDO::PARAM_BOOL should return NULL
Retrieving numeric(38, 38) data as PDO::PARAM_INT should return NULL
****Retrieving numeric(38, 38) as PDO::PARAM_STR is supported****
****Retrieving numeric(38, 38) as PDO::PARAM_LOB is supported****

View file

@ -1,7 +1,10 @@
--TEST--
Test for inserting and retrieving encrypted data of numeric types
Test for retrieving encrypted data from float types columns using PDO::bindColumn
--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--
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
@ -12,20 +15,31 @@ require_once("AEData.inc");
$dataType = "float";
$bits = array(1, 12, 24, 36, 53);
$inputValues = array(9223372036854775808.9223372036854775808, -9223372036854775808.9223372036854775808);
$numint = 19;
try {
$conn = connect("", array(), PDO::ERRMODE_SILENT);
foreach ($bits as $bit) {
$type = "$dataType($bit)";
echo "\nTesting $type:\n";
foreach ($bits as $m) {
// compute the epsilon for comparing doubles
// 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
$tbname = "test_float";
$colMetaArr = array(new ColumnMeta($type, "c_det"), new ColumnMeta($type, "c_rand", null, "randomized"));
$typeFull = "$dataType($m)";
echo "\nTesting $typeFull:\n";
//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);
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";
foreach ($pdoParamTypes as $pdoParamType) {
$det = "";
@ -36,14 +50,18 @@ try {
$stmt->bindColumn('c_rand', $rand, constant($pdoParamType));
$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 (!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 {
echo "****PDO param type $pdoParamType is compatible with encrypted $type****\n";
echo "c_det: $det\n";
echo "c_rand: $rand\n";
if (abs($det - $inputValues[0]) < $epsilon && abs($rand - $inputValues[1]) < $epsilon) {
echo "****Retrieving $typeFull as $pdoParamType is supported****\n";
} else {
echo "Retrieving $typeFull as $pdoParamType fails\n";
}
}
}
dropTable($conn, $tbname);
@ -56,41 +74,21 @@ try {
?>
--EXPECT--
Testing float(1):
****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
****Retrieving float(1) as PDO::PARAM_STR is supported****
****Retrieving float(1) as PDO::PARAM_LOB is supported****
Testing float(12):
****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
****Retrieving float(12) as PDO::PARAM_STR is supported****
****Retrieving float(12) as PDO::PARAM_LOB is supported****
Testing float(24):
****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
****Retrieving float(24) as PDO::PARAM_STR is supported****
****Retrieving float(24) as PDO::PARAM_LOB is supported****
Testing float(36):
****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.2233720368548004E+18
c_rand: -9.2233720368548004E+18
****Retrieving float(36) as PDO::PARAM_STR is supported****
****Retrieving float(36) as PDO::PARAM_LOB is supported****
Testing float(53):
****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.2233720368548004E+18
c_rand: -9.2233720368548004E+18
****Retrieving float(53) as PDO::PARAM_STR is supported****
****Retrieving float(53) as PDO::PARAM_LOB is supported****

View file

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

View file

@ -1,7 +1,12 @@
--TEST--
Test for inserting and retrieving encrypted data of numeric types
Test for retrieving encrypted data from numeric types columns using PDO::bindColumn
--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--
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
@ -10,19 +15,21 @@ require_once("MsCommon_mid-refactor.inc");
require_once("AEData.inc");
$dataTypes = array( "bit", "tinyint", "smallint", "int", "bigint", "real");
$epsilon = 1;
try {
$conn = connect("", array(), PDO::ERRMODE_SILENT);
foreach ($dataTypes as $dataType) {
echo "\nTesting $dataType:\n";
// create and populate table
$tbname = getTableName();
// create and populate table containing bit, tinyint, smallint, int, bigint, or real columns
$tbname = "test_" . $dataType;
$colMetaArr = array(new ColumnMeta($dataType, "c_det"), new ColumnMeta($dataType, "c_rand", null, "randomized"));
createTable($conn, $tbname, $colMetaArr);
$inputValues = array_slice(${explode("(", $dataType)[0] . "_params"}, 1, 2);
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";
foreach ($pdoParamTypes as $pdoParamType) {
$det = "";
@ -32,13 +39,48 @@ try {
$stmt->bindColumn('c_det', $det, constant($pdoParamType));
$stmt->bindColumn('c_rand', $rand, constant($pdoParamType));
$row = $stmt->fetch(PDO::FETCH_BOUND);
if ($row != false) {
if (is_null($det) || is_null($rand)) {
echo "PDO param type $pdoParamType is not compatible with encrypted $dataType\n";
// check the case when fetching as PDO::PARAM_NULL
// 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 {
echo "****PDO param type $pdoParamType is compatible with encrypted $dataType****\n";
echo "c_det: $det\n";
echo "c_rand: $rand\n";
if ($det == $inputValues[0] && $rand == $inputValues[1]) {
echo "****Retrieving $dataType as $pdoParamType is supported****\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--
Testing bit:
****PDO param type PDO::PARAM_BOOL is compatible with encrypted bit****
c_det: 1
c_rand: 0
PDO param type PDO::PARAM_NULL is not compatible with encrypted bit
****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
****Retrieving bit as PDO::PARAM_BOOL is supported****
****Retrieving bit as PDO::PARAM_INT is supported****
****Retrieving bit as PDO::PARAM_STR is supported****
****Retrieving bit as PDO::PARAM_LOB is supported****
Testing tinyint:
****PDO param type PDO::PARAM_BOOL is compatible with encrypted tinyint****
c_det: 0
c_rand: 255
PDO param type PDO::PARAM_NULL is not compatible with encrypted tinyint
****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
****Retrieving tinyint as PDO::PARAM_BOOL is supported****
****Retrieving tinyint as PDO::PARAM_INT is supported****
****Retrieving tinyint as PDO::PARAM_STR is supported****
****Retrieving tinyint as PDO::PARAM_LOB is supported****
Testing smallint:
****PDO param type PDO::PARAM_BOOL is compatible with encrypted smallint****
c_det: -32767
c_rand: 32767
PDO param type PDO::PARAM_NULL is not compatible with encrypted smallint
****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
****Retrieving smallint as PDO::PARAM_BOOL is supported****
****Retrieving smallint as PDO::PARAM_INT is supported****
****Retrieving smallint as PDO::PARAM_STR is supported****
****Retrieving smallint as PDO::PARAM_LOB is supported****
Testing int:
****PDO param type PDO::PARAM_BOOL is compatible with encrypted int****
c_det: -2147483647
c_rand: 2147483647
PDO param type PDO::PARAM_NULL is not compatible with encrypted int
****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
****Retrieving int as PDO::PARAM_BOOL is supported****
****Retrieving int as PDO::PARAM_INT is supported****
****Retrieving int as PDO::PARAM_STR is supported****
****Retrieving int as PDO::PARAM_LOB is supported****
Testing bigint:
PDO param type PDO::PARAM_BOOL is not compatible with encrypted bigint
PDO param type PDO::PARAM_NULL is not compatible with encrypted bigint
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
****Retrieving bigint as PDO::PARAM_STR is supported****
****Retrieving bigint as PDO::PARAM_LOB is supported****
Testing real:
****PDO param type PDO::PARAM_BOOL is compatible with encrypted real****
c_det: -2147
c_rand: 2147
PDO param type PDO::PARAM_NULL is not compatible with encrypted real
****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
****Retrieving real as PDO::PARAM_BOOL is supported****
****Retrieving real as PDO::PARAM_INT is supported****
****Retrieving real as PDO::PARAM_STR is supported****
****Retrieving real as PDO::PARAM_LOB is supported****

View file

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

View file

@ -1,7 +1,12 @@
--TEST--
Test for inserting and retrieving encrypted data of string types
Test for inserting encrypted data into char types columns with different sizes
--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--
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
@ -11,49 +16,59 @@ require_once("AEData.inc");
$dataTypes = array("char", "varchar", "varchar(max)");
$lengths = array(1, 8, 64, 512, 4096, 8000);
$encTypes = array("deterministic", "randomized");
try {
$conn = connect();
foreach ($dataTypes as $dataType) {
$maxtype = strpos($dataType, "(max)");
foreach ($lengths as $length) {
if ($maxtype !== false) {
$type = $dataType;
$maxcol = strpos($dataType, "(max)");
foreach ($lengths as $m) {
if ($maxcol !== false) {
$typeFull = $dataType;
} else {
$type = "$dataType($length)";
$typeFull = "$dataType($m)";
}
echo "\nTesting $type:\n";
echo "\nTesting $typeFull:\n";
foreach($encTypes as $encType) {
//create and populate table
$tbname = getTableName();
$colMetaArr = array(new ColumnMeta($type, "c1", null, $encType));
createTable($conn, $tbname, $colMetaArr);
$input = str_repeat("d", $length);
//create table containing char(m) or varchar(m) columns
$tbname = "test_" . str_replace(array('(', ')'), '', $dataType) . $m;
$colMetaArr = array(new ColumnMeta($typeFull, "c1", null, "randomized"));
createTable($conn, $tbname, $colMetaArr);
$input = str_repeat("d", $m);
// prepare statement for inserting into table
foreach ($pdoParamTypes as $pdoParamType) {
// insert a row
$r;
$stmt = insertRow($conn, $tbname, array( "c1" => new BindParamOp(1, $input, $pdoParamType)), "prepareBindParam", $r);
// insert by specifying PDO::PARAM_ types
foreach ($pdoParamTypes as $pdoParamType) {
$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) {
isIncompatibleTypesError($stmt, $type, $pdoParamType);
echo "Conversion from $pdoParamType to $typeFull should be supported\n";
} else {
$sql = "SELECT c1 FROM $tbname";
$stmt = $conn->query($sql);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if (strlen($row['c1']) == $length) {
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";
if (!is_null($row['c1'])) {
echo "Conversion from $pdoParamType to $typeFull should insert NULL\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);
@ -64,217 +79,109 @@ try {
?>
--EXPECT--
Testing char(1):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted char(1)****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted char(1)
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted char(1)****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted char(1)****
****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)****
****Conversion from PDO::PARAM_BOOL to char(1) is supported****
****Conversion from PDO::PARAM_INT to char(1) is supported****
****Conversion from PDO::PARAM_STR to char(1) is supported****
****Conversion from PDO::PARAM_LOB to char(1) is supported****
Testing char(8):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted char(8)****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted char(8)
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted char(8)****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted char(8)****
****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)****
****Conversion from PDO::PARAM_BOOL to char(8) is supported****
****Conversion from PDO::PARAM_INT to char(8) is supported****
****Conversion from PDO::PARAM_STR to char(8) is supported****
****Conversion from PDO::PARAM_LOB to char(8) is supported****
Testing char(64):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted char(64)****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted char(64)
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted char(64)****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted char(64)****
****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)****
****Conversion from PDO::PARAM_BOOL to char(64) is supported****
****Conversion from PDO::PARAM_INT to char(64) is supported****
****Conversion from PDO::PARAM_STR to char(64) is supported****
****Conversion from PDO::PARAM_LOB to char(64) is supported****
Testing char(512):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted char(512)****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted char(512)
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted char(512)****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted char(512)****
****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)****
****Conversion from PDO::PARAM_BOOL to char(512) is supported****
****Conversion from PDO::PARAM_INT to char(512) is supported****
****Conversion from PDO::PARAM_STR to char(512) is supported****
****Conversion from PDO::PARAM_LOB to char(512) is supported****
Testing char(4096):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted char(4096)****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted char(4096)
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted char(4096)****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted char(4096)****
****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)****
****Conversion from PDO::PARAM_BOOL to char(4096) is supported****
****Conversion from PDO::PARAM_INT to char(4096) is supported****
****Conversion from PDO::PARAM_STR to char(4096) is supported****
****Conversion from PDO::PARAM_LOB to char(4096) is supported****
Testing char(8000):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted char(8000)****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted char(8000)
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted char(8000)****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted char(8000)****
****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)****
****Conversion from PDO::PARAM_BOOL to char(8000) is supported****
****Conversion from PDO::PARAM_INT to char(8000) is supported****
****Conversion from PDO::PARAM_STR to char(8000) is supported****
****Conversion from PDO::PARAM_LOB to char(8000) is supported****
Testing varchar(1):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted varchar(1)****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted varchar(1)
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted varchar(1)****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted varchar(1)****
****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)****
****Conversion from PDO::PARAM_BOOL to varchar(1) is supported****
****Conversion from PDO::PARAM_INT to varchar(1) is supported****
****Conversion from PDO::PARAM_STR to varchar(1) is supported****
****Conversion from PDO::PARAM_LOB to varchar(1) is supported****
Testing varchar(8):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted varchar(8)****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted varchar(8)
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted varchar(8)****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted varchar(8)****
****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)****
****Conversion from PDO::PARAM_BOOL to varchar(8) is supported****
****Conversion from PDO::PARAM_INT to varchar(8) is supported****
****Conversion from PDO::PARAM_STR to varchar(8) is supported****
****Conversion from PDO::PARAM_LOB to varchar(8) is supported****
Testing varchar(64):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted varchar(64)****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted varchar(64)
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted varchar(64)****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted varchar(64)****
****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)****
****Conversion from PDO::PARAM_BOOL to varchar(64) is supported****
****Conversion from PDO::PARAM_INT to varchar(64) is supported****
****Conversion from PDO::PARAM_STR to varchar(64) is supported****
****Conversion from PDO::PARAM_LOB to varchar(64) is supported****
Testing varchar(512):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted varchar(512)****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted varchar(512)
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted varchar(512)****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted varchar(512)****
****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)****
****Conversion from PDO::PARAM_BOOL to varchar(512) is supported****
****Conversion from PDO::PARAM_INT to varchar(512) is supported****
****Conversion from PDO::PARAM_STR to varchar(512) is supported****
****Conversion from PDO::PARAM_LOB to varchar(512) is supported****
Testing varchar(4096):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted varchar(4096)****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted varchar(4096)
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted varchar(4096)****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted varchar(4096)****
****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)****
****Conversion from PDO::PARAM_BOOL to varchar(4096) is supported****
****Conversion from PDO::PARAM_INT to varchar(4096) is supported****
****Conversion from PDO::PARAM_STR to varchar(4096) is supported****
****Conversion from PDO::PARAM_LOB to varchar(4096) is supported****
Testing varchar(8000):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted varchar(8000)****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted varchar(8000)
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted varchar(8000)****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted varchar(8000)****
****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)****
****Conversion from PDO::PARAM_BOOL to varchar(8000) is supported****
****Conversion from PDO::PARAM_INT to varchar(8000) is supported****
****Conversion from PDO::PARAM_STR to varchar(8000) is supported****
****Conversion from PDO::PARAM_LOB to varchar(8000) is supported****
Testing varchar(max):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted varchar(max)****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted varchar(max)
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted varchar(max)****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted varchar(max)****
****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)****
****Conversion from PDO::PARAM_BOOL to varchar(max) is supported****
****Conversion from PDO::PARAM_INT to varchar(max) is supported****
****Conversion from PDO::PARAM_STR to varchar(max) is supported****
****Conversion from PDO::PARAM_LOB to varchar(max) is supported****
Testing varchar(max):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted varchar(max)****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted varchar(max)
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted varchar(max)****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted varchar(max)****
****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)****
****Conversion from PDO::PARAM_BOOL to varchar(max) is supported****
****Conversion from PDO::PARAM_INT to varchar(max) is supported****
****Conversion from PDO::PARAM_STR to varchar(max) is supported****
****Conversion from PDO::PARAM_LOB to varchar(max) is supported****
Testing varchar(max):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted varchar(max)****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted varchar(max)
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted varchar(max)****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted varchar(max)****
****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)****
****Conversion from PDO::PARAM_BOOL to varchar(max) is supported****
****Conversion from PDO::PARAM_INT to varchar(max) is supported****
****Conversion from PDO::PARAM_STR to varchar(max) is supported****
****Conversion from PDO::PARAM_LOB to varchar(max) is supported****
Testing varchar(max):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted varchar(max)****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted varchar(max)
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted varchar(max)****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted varchar(max)****
****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)****
****Conversion from PDO::PARAM_BOOL to varchar(max) is supported****
****Conversion from PDO::PARAM_INT to varchar(max) is supported****
****Conversion from PDO::PARAM_STR to varchar(max) is supported****
****Conversion from PDO::PARAM_LOB to varchar(max) is supported****
Testing varchar(max):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted varchar(max)****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted varchar(max)
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted varchar(max)****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted varchar(max)****
****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)****
****Conversion from PDO::PARAM_BOOL to varchar(max) is supported****
****Conversion from PDO::PARAM_INT to varchar(max) is supported****
****Conversion from PDO::PARAM_STR to varchar(max) is supported****
****Conversion from PDO::PARAM_LOB to varchar(max) is supported****
Testing varchar(max):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted varchar(max)****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted varchar(max)
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted varchar(max)****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted varchar(max)****
****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)****
****Conversion from PDO::PARAM_BOOL to varchar(max) is supported****
****Conversion from PDO::PARAM_INT to varchar(max) is supported****
****Conversion from PDO::PARAM_STR to varchar(max) is supported****
****Conversion from PDO::PARAM_LOB to varchar(max) is supported****

View file

@ -1,7 +1,12 @@
--TEST--
Test for inserting and retrieving encrypted data of datetime types
Test for inserting encrypted data into datetime types columns
--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--
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
@ -10,27 +15,47 @@ require_once("MsCommon_mid-refactor.inc");
require_once("AEData.inc");
$dataTypes = array( "date", "datetime", "smalldatetime");
try {
$conn = connect();
foreach ($dataTypes as $dataType) {
echo "\nTesting $dataType:\n";
// create table
$tbname = getTableName();
// create table containing date, datetime or smalldatetime columns
$tbname = "test_" . $dataType;
$colMetaArr = array( new ColumnMeta($dataType, "c_det"), new ColumnMeta($dataType, "c_rand", null, "randomized"));
createTable($conn, $tbname, $colMetaArr);
// prepare statement for inserting into table
// insert by specifying PDO::PARAM_ types
foreach ($pdoParamTypes as $pdoParamType) {
// insert a row
$inputValues = array_slice(${explode("(", $dataType)[0] . "_params"}, 1, 2);
$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 {
echo "****PDO param type $pdoParamType is compatible with encrypted $dataType****\n";
fetchAll($conn, $tbname);
$sql = "SELECT c_det, c_rand FROM $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");
}
@ -44,52 +69,19 @@ try {
?>
--EXPECT--
Testing date:
****PDO param type PDO::PARAM_BOOL is compatible with encrypted date****
c_det: 0001-01-01
c_rand: 9999-12-31
****PDO param type PDO::PARAM_NULL is compatible with encrypted date****
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
****Conversion from PDO::PARAM_BOOL to date is supported****
****Conversion from PDO::PARAM_INT to date is supported****
****Conversion from PDO::PARAM_STR to date is supported****
****Conversion from PDO::PARAM_LOB to date is supported****
Testing datetime:
****PDO param type PDO::PARAM_BOOL 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_NULL is compatible with encrypted datetime****
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
****Conversion from PDO::PARAM_BOOL to datetime is supported****
****Conversion from PDO::PARAM_INT to datetime is supported****
****Conversion from PDO::PARAM_STR to datetime is supported****
****Conversion from PDO::PARAM_LOB to datetime is supported****
Testing smalldatetime:
****PDO param type PDO::PARAM_BOOL 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_NULL is compatible with encrypted smalldatetime****
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
****Conversion from PDO::PARAM_BOOL to smalldatetime is supported****
****Conversion from PDO::PARAM_INT to smalldatetime is supported****
****Conversion from PDO::PARAM_STR to smalldatetime is supported****
****Conversion from PDO::PARAM_LOB to smalldatetime is supported****

View file

@ -1,7 +1,12 @@
--TEST--
Test for inserting and retrieving encrypted data of datetime types
Test for inserting encrypted data into datetime types with different precisions columns
--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--
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
@ -9,6 +14,20 @@ Use PDOstatement::bindParam with all PDO::PARAM_ types
require_once("MsCommon_mid-refactor.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");
$precisions = array(/*0,*/ 1, 2, 4, 7);
$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 {
$conn = connect("", array(), PDO::ERRMODE_SILENT);
foreach ($dataTypes as $dataType) {
foreach ($precisions as $precision) {
// change the input values depending on the precision
foreach ($precisions as $m) {
// add $m number of decimal digits to the some input values
$inputValues[0] = $inputValuesInit[$dataType][0];
$inputValues[1] = $inputValuesInit[$dataType][1];
if ($precision != 0) {
if ($m != 0) {
if ($dataType == "datetime2") {
$inputValues[1] .= "." . str_repeat("9", $precision);
$inputValues[1] .= "." . str_repeat("9", $m);
} else if ($dataType == "datetimeoffset") {
$inputPieces = explode(" ", $inputValues[1]);
$inputValues[1] = $inputPieces[0] . " " . $inputPieces[1] . "." . str_repeat("9", $precision) . " " . $inputPieces[2];
$dtoffsetPieces = explode(" ", $inputValues[1]);
$inputValues[1] = $dtoffsetPieces[0] . " " . $dtoffsetPieces[1] . "." . str_repeat("9", $m) . " " . $dtoffsetPieces[2];
} else if ($dataType == "time") {
$inputValues[0] .= "." . str_repeat("0", $precision);
$inputValues[1] .= "." . str_repeat("9", $precision);
$inputValues[0] .= "." . str_repeat("0", $m);
$inputValues[1] .= "." . str_repeat("9", $m);
}
}
$type = "$dataType($precision)";
echo "\nTesting $type:\n";
$typeFull = "$dataType($m)";
echo "\nTesting $typeFull:\n";
//create and populate table
$tbname = "test_datetime";
$colMetaArr = array(new ColumnMeta($type, "c_det"), new ColumnMeta($type, "c_rand", null, "randomized"));
//create table containing datetime2(m), datetimeoffset(m), or time(m) columns
$tbname = "test_" . $dataType . $m;
$colMetaArr = array(new ColumnMeta($typeFull, "c_det"), new ColumnMeta($typeFull, "c_rand", null, "randomized"));
createTable($conn, $tbname, $colMetaArr);
// prepare statement for inserting into table
// insert by specifying PDO::PARAM_ types
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);
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 {
echo "****PDO param type $pdoParamType is compatible with encrypted $dataType****\n";
fetchAll($conn, $tbname);
$sql = "SELECT c_det, c_rand FROM $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");
}
@ -64,205 +103,73 @@ try {
?>
--EXPECT--
Testing datetime2(1):
****PDO param type PDO::PARAM_BOOL 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_NULL is compatible with encrypted datetime2****
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
****Conversion from PDO::PARAM_BOOL to datetime2(1) is supported****
****Conversion from PDO::PARAM_INT to datetime2(1) is supported****
****Conversion from PDO::PARAM_STR to datetime2(1) is supported****
****Conversion from PDO::PARAM_LOB to datetime2(1) is supported****
Testing datetime2(2):
****PDO param type PDO::PARAM_BOOL 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_NULL is compatible with encrypted datetime2****
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
****Conversion from PDO::PARAM_BOOL to datetime2(2) is supported****
****Conversion from PDO::PARAM_INT to datetime2(2) is supported****
****Conversion from PDO::PARAM_STR to datetime2(2) is supported****
****Conversion from PDO::PARAM_LOB to datetime2(2) is supported****
Testing datetime2(4):
****PDO param type PDO::PARAM_BOOL 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_NULL is compatible with encrypted datetime2****
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
****Conversion from PDO::PARAM_BOOL to datetime2(4) is supported****
****Conversion from PDO::PARAM_INT to datetime2(4) is supported****
****Conversion from PDO::PARAM_STR to datetime2(4) is supported****
****Conversion from PDO::PARAM_LOB to datetime2(4) is supported****
Testing datetime2(7):
****PDO param type PDO::PARAM_BOOL 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_NULL is compatible with encrypted datetime2****
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
****Conversion from PDO::PARAM_BOOL to datetime2(7) is supported****
****Conversion from PDO::PARAM_INT to datetime2(7) is supported****
****Conversion from PDO::PARAM_STR to datetime2(7) is supported****
****Conversion from PDO::PARAM_LOB to datetime2(7) is supported****
Testing datetimeoffset(1):
****PDO param type PDO::PARAM_BOOL 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_NULL is compatible with encrypted datetimeoffset****
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
****Conversion from PDO::PARAM_BOOL to datetimeoffset(1) is supported****
****Conversion from PDO::PARAM_INT to datetimeoffset(1) is supported****
****Conversion from PDO::PARAM_STR to datetimeoffset(1) is supported****
****Conversion from PDO::PARAM_LOB to datetimeoffset(1) is supported****
Testing datetimeoffset(2):
****PDO param type PDO::PARAM_BOOL 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_NULL is compatible with encrypted datetimeoffset****
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
****Conversion from PDO::PARAM_BOOL to datetimeoffset(2) is supported****
****Conversion from PDO::PARAM_INT to datetimeoffset(2) is supported****
****Conversion from PDO::PARAM_STR to datetimeoffset(2) is supported****
****Conversion from PDO::PARAM_LOB to datetimeoffset(2) is supported****
Testing datetimeoffset(4):
****PDO param type PDO::PARAM_BOOL 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_NULL is compatible with encrypted datetimeoffset****
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
****Conversion from PDO::PARAM_BOOL to datetimeoffset(4) is supported****
****Conversion from PDO::PARAM_INT to datetimeoffset(4) is supported****
****Conversion from PDO::PARAM_STR to datetimeoffset(4) is supported****
****Conversion from PDO::PARAM_LOB to datetimeoffset(4) is supported****
Testing datetimeoffset(7):
****PDO param type PDO::PARAM_BOOL 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_NULL is compatible with encrypted datetimeoffset****
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
****Conversion from PDO::PARAM_BOOL to datetimeoffset(7) is supported****
****Conversion from PDO::PARAM_INT to datetimeoffset(7) is supported****
****Conversion from PDO::PARAM_STR to datetimeoffset(7) is supported****
****Conversion from PDO::PARAM_LOB to datetimeoffset(7) is supported****
Testing time(1):
****PDO param type PDO::PARAM_BOOL is compatible with encrypted time****
c_det: 00:00:00.0
c_rand: 23:59:59.9
****PDO param type PDO::PARAM_NULL is compatible with encrypted time****
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
****Conversion from PDO::PARAM_BOOL to time(1) is supported****
****Conversion from PDO::PARAM_INT to time(1) is supported****
****Conversion from PDO::PARAM_STR to time(1) is supported****
****Conversion from PDO::PARAM_LOB to time(1) is supported****
Testing time(2):
****PDO param type PDO::PARAM_BOOL is compatible with encrypted time****
c_det: 00:00:00.00
c_rand: 23:59:59.99
****PDO param type PDO::PARAM_NULL is compatible with encrypted time****
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
****Conversion from PDO::PARAM_BOOL to time(2) is supported****
****Conversion from PDO::PARAM_INT to time(2) is supported****
****Conversion from PDO::PARAM_STR to time(2) is supported****
****Conversion from PDO::PARAM_LOB to time(2) is supported****
Testing time(4):
****PDO param type PDO::PARAM_BOOL is compatible with encrypted time****
c_det: 00:00:00.0000
c_rand: 23:59:59.9999
****PDO param type PDO::PARAM_NULL is compatible with encrypted time****
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
****Conversion from PDO::PARAM_BOOL to time(4) is supported****
****Conversion from PDO::PARAM_INT to time(4) is supported****
****Conversion from PDO::PARAM_STR to time(4) is supported****
****Conversion from PDO::PARAM_LOB to time(4) is supported****
Testing time(7):
****PDO param type PDO::PARAM_BOOL is compatible with encrypted time****
c_det: 00:00:00.0000000
c_rand: 23:59:59.9999999
****PDO param type PDO::PARAM_NULL is compatible with encrypted time****
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
****Conversion from PDO::PARAM_BOOL to time(7) is supported****
****Conversion from PDO::PARAM_INT to time(7) is supported****
****Conversion from PDO::PARAM_STR to time(7) is supported****
****Conversion from PDO::PARAM_LOB to time(7) is supported****

View file

@ -1,7 +1,12 @@
--TEST--
Test for inserting and retrieving encrypted data of numeric types
Test for inserting encrypted data into float types columns
--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--
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
@ -12,29 +17,60 @@ require_once("AEData.inc");
$dataType = "float";
$bits = array(1, 12, 24, 36, 53);
$inputValues = array(9223372036854775808.9223372036854775808, -9223372036854775808.9223372036854775808);
$numint = 19;
try {
$conn = connect();
foreach ($bits as $bit) {
$type = "$dataType($bit)";
echo "\nTesting $type:\n";
foreach ($bits as $m) {
// compute the epsilon for comparing doubles
// 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
$tbname = "test_float1";
$colMetaArr = array(new ColumnMeta($type, "c_det"), new ColumnMeta($type, "c_rand", null, "randomized"));
$typeFull = "$dataType($m)";
echo "\nTesting $typeFull:\n";
//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);
// test each PDO::PARAM_ type
// insert by specifying PDO::PARAM_ types
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);
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 {
echo "****PDO param type $pdoParamType is compatible with encrypted $type****\n";
fetchAll($conn, $tbname);
$sql = "SELECT c_det, c_rand FROM $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");
}
dropTable($conn, $tbname);
@ -47,86 +83,31 @@ try {
?>
--EXPECT--
Testing float(1):
****PDO param type PDO::PARAM_BOOL is compatible with encrypted float(1)****
c_det: 9.223372E+18
c_rand: -9.223372E+18
****PDO param type PDO::PARAM_NULL is compatible with encrypted float(1)****
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
****Conversion from PDO::PARAM_BOOL to float(1) is supported****
****Conversion from PDO::PARAM_INT to float(1) is supported****
****Conversion from PDO::PARAM_STR to float(1) is supported****
****Conversion from PDO::PARAM_LOB to float(1) is supported****
Testing float(12):
****PDO param type PDO::PARAM_BOOL is compatible with encrypted float(12)****
c_det: 9.223372E+18
c_rand: -9.223372E+18
****PDO param type PDO::PARAM_NULL is compatible with encrypted float(12)****
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
****Conversion from PDO::PARAM_BOOL to float(12) is supported****
****Conversion from PDO::PARAM_INT to float(12) is supported****
****Conversion from PDO::PARAM_STR to float(12) is supported****
****Conversion from PDO::PARAM_LOB to float(12) is supported****
Testing float(24):
****PDO param type PDO::PARAM_BOOL is compatible with encrypted float(24)****
c_det: 9.223372E+18
c_rand: -9.223372E+18
****PDO param type PDO::PARAM_NULL is compatible with encrypted float(24)****
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
****Conversion from PDO::PARAM_BOOL to float(24) is supported****
****Conversion from PDO::PARAM_INT to float(24) is supported****
****Conversion from PDO::PARAM_STR to float(24) is supported****
****Conversion from PDO::PARAM_LOB to float(24) is supported****
Testing float(36):
****PDO param type PDO::PARAM_BOOL is compatible with encrypted float(36)****
c_det: 9.2233720368547758E+18
c_rand: -9.2233720368547758E+18
****PDO param type PDO::PARAM_NULL is compatible with encrypted float(36)****
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
****Conversion from PDO::PARAM_BOOL to float(36) is supported****
****Conversion from PDO::PARAM_INT to float(36) is supported****
****Conversion from PDO::PARAM_STR to float(36) is supported****
****Conversion from PDO::PARAM_LOB to float(36) is supported****
Testing float(53):
****PDO param type PDO::PARAM_BOOL is compatible with encrypted float(53)****
c_det: 9.2233720368547758E+18
c_rand: -9.2233720368547758E+18
****PDO param type PDO::PARAM_NULL is compatible with encrypted float(53)****
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
****Conversion from PDO::PARAM_BOOL to float(53) is supported****
****Conversion from PDO::PARAM_INT to float(53) is supported****
****Conversion from PDO::PARAM_STR to float(53) is supported****
****Conversion from PDO::PARAM_LOB to float(53) is supported****

View file

@ -1,7 +1,12 @@
--TEST--
Test for inserting and retrieving encrypted data of string types
Test for inserting encrypted data into nchar types columns with different sizes
--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--
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
@ -11,49 +16,59 @@ require_once("AEData.inc");
$dataTypes = array("nchar", "nvarchar", "nvarchar(max)");
$lengths = array(1, 8, 64, 512, 4000);
$encTypes = array("deterministic", "randomized");
try {
$conn = connect();
foreach ($dataTypes as $dataType) {
$maxtype = strpos($dataType, "(max)");
foreach ($lengths as $length) {
if ($maxtype !== false) {
$type = $dataType;
$maxcol = strpos($dataType, "(max)");
foreach ($lengths as $m) {
if ($maxcol !== false) {
$typeFull = $dataType;
} else {
$type = "$dataType($length)";
$typeFull = "$dataType($m)";
}
echo "\nTesting $type:\n";
echo "\nTesting $typeFull:\n";
foreach($encTypes as $encType) {
//create and populate table
$tbname = getTableName();
$colMetaArr = array(new ColumnMeta($type, "c1", null, $encType));
createTable($conn, $tbname, $colMetaArr);
$input = str_repeat("d", $length);
//create table containing nchar(m) or nvarchar(m) columns
$tbname = "test_" . str_replace(array('(', ')'), '', $dataType) . $m;
$colMetaArr = array(new ColumnMeta($typeFull, "c1"));
createTable($conn, $tbname, $colMetaArr);
$input = str_repeat("d", $m);
// prepare statement for inserting into table
foreach ($pdoParamTypes as $pdoParamType) {
// insert a row
$r;
$stmt = insertRow($conn, $tbname, array( "c1" => new BindParamOp(1, $input, $pdoParamType)), "prepareBindParam", $r);
// insert by specifying PDO::PARAM_ types
foreach ($pdoParamTypes as $pdoParamType) {
$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) {
isIncompatibleTypesError($stmt, $type, $pdoParamType);
echo "Conversion from $pdoParamType to $typeFull should be supported\n";
} else {
$sql = "SELECT c1 FROM $tbname";
$stmt = $conn->query($sql);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if (strlen($row['c1']) == $length) {
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";
if (!is_null($row['c1'])) {
echo "Conversion from $pdoParamType to $typeFull should insert NULL\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);
@ -64,181 +79,91 @@ try {
?>
--EXPECT--
Testing nchar(1):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted nchar(1)****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted nchar(1)
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted nchar(1)****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nchar(1)****
****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)****
****Conversion from PDO::PARAM_BOOL to nchar(1) is supported****
****Conversion from PDO::PARAM_INT to nchar(1) is supported****
****Conversion from PDO::PARAM_STR to nchar(1) is supported****
****Conversion from PDO::PARAM_LOB to nchar(1) is supported****
Testing nchar(8):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted nchar(8)****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted nchar(8)
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted nchar(8)****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nchar(8)****
****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)****
****Conversion from PDO::PARAM_BOOL to nchar(8) is supported****
****Conversion from PDO::PARAM_INT to nchar(8) is supported****
****Conversion from PDO::PARAM_STR to nchar(8) is supported****
****Conversion from PDO::PARAM_LOB to nchar(8) is supported****
Testing nchar(64):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted nchar(64)****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted nchar(64)
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted nchar(64)****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nchar(64)****
****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)****
****Conversion from PDO::PARAM_BOOL to nchar(64) is supported****
****Conversion from PDO::PARAM_INT to nchar(64) is supported****
****Conversion from PDO::PARAM_STR to nchar(64) is supported****
****Conversion from PDO::PARAM_LOB to nchar(64) is supported****
Testing nchar(512):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted nchar(512)****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted nchar(512)
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted nchar(512)****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nchar(512)****
****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)****
****Conversion from PDO::PARAM_BOOL to nchar(512) is supported****
****Conversion from PDO::PARAM_INT to nchar(512) is supported****
****Conversion from PDO::PARAM_STR to nchar(512) is supported****
****Conversion from PDO::PARAM_LOB to nchar(512) is supported****
Testing nchar(4000):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted nchar(4000)****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted nchar(4000)
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted nchar(4000)****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nchar(4000)****
****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)****
****Conversion from PDO::PARAM_BOOL to nchar(4000) is supported****
****Conversion from PDO::PARAM_INT to nchar(4000) is supported****
****Conversion from PDO::PARAM_STR to nchar(4000) is supported****
****Conversion from PDO::PARAM_LOB to nchar(4000) is supported****
Testing nvarchar(1):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted nvarchar(1)****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted nvarchar(1)
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted nvarchar(1)****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nvarchar(1)****
****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)****
****Conversion from PDO::PARAM_BOOL to nvarchar(1) is supported****
****Conversion from PDO::PARAM_INT to nvarchar(1) is supported****
****Conversion from PDO::PARAM_STR to nvarchar(1) is supported****
****Conversion from PDO::PARAM_LOB to nvarchar(1) is supported****
Testing nvarchar(8):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted nvarchar(8)****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted nvarchar(8)
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted nvarchar(8)****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nvarchar(8)****
****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)****
****Conversion from PDO::PARAM_BOOL to nvarchar(8) is supported****
****Conversion from PDO::PARAM_INT to nvarchar(8) is supported****
****Conversion from PDO::PARAM_STR to nvarchar(8) is supported****
****Conversion from PDO::PARAM_LOB to nvarchar(8) is supported****
Testing nvarchar(64):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted nvarchar(64)****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted nvarchar(64)
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted nvarchar(64)****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nvarchar(64)****
****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)****
****Conversion from PDO::PARAM_BOOL to nvarchar(64) is supported****
****Conversion from PDO::PARAM_INT to nvarchar(64) is supported****
****Conversion from PDO::PARAM_STR to nvarchar(64) is supported****
****Conversion from PDO::PARAM_LOB to nvarchar(64) is supported****
Testing nvarchar(512):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted nvarchar(512)****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted nvarchar(512)
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted nvarchar(512)****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nvarchar(512)****
****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)****
****Conversion from PDO::PARAM_BOOL to nvarchar(512) is supported****
****Conversion from PDO::PARAM_INT to nvarchar(512) is supported****
****Conversion from PDO::PARAM_STR to nvarchar(512) is supported****
****Conversion from PDO::PARAM_LOB to nvarchar(512) is supported****
Testing nvarchar(4000):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted nvarchar(4000)****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted nvarchar(4000)
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted nvarchar(4000)****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nvarchar(4000)****
****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)****
****Conversion from PDO::PARAM_BOOL to nvarchar(4000) is supported****
****Conversion from PDO::PARAM_INT to nvarchar(4000) is supported****
****Conversion from PDO::PARAM_STR to nvarchar(4000) is supported****
****Conversion from PDO::PARAM_LOB to nvarchar(4000) is supported****
Testing nvarchar(max):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted nvarchar(max)****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted nvarchar(max)
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted nvarchar(max)****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nvarchar(max)****
****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)****
****Conversion from PDO::PARAM_BOOL to nvarchar(max) is supported****
****Conversion from PDO::PARAM_INT to nvarchar(max) is supported****
****Conversion from PDO::PARAM_STR to nvarchar(max) is supported****
****Conversion from PDO::PARAM_LOB to nvarchar(max) is supported****
Testing nvarchar(max):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted nvarchar(max)****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted nvarchar(max)
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted nvarchar(max)****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nvarchar(max)****
****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)****
****Conversion from PDO::PARAM_BOOL to nvarchar(max) is supported****
****Conversion from PDO::PARAM_INT to nvarchar(max) is supported****
****Conversion from PDO::PARAM_STR to nvarchar(max) is supported****
****Conversion from PDO::PARAM_LOB to nvarchar(max) is supported****
Testing nvarchar(max):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted nvarchar(max)****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted nvarchar(max)
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted nvarchar(max)****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nvarchar(max)****
****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)****
****Conversion from PDO::PARAM_BOOL to nvarchar(max) is supported****
****Conversion from PDO::PARAM_INT to nvarchar(max) is supported****
****Conversion from PDO::PARAM_STR to nvarchar(max) is supported****
****Conversion from PDO::PARAM_LOB to nvarchar(max) is supported****
Testing nvarchar(max):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted nvarchar(max)****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted nvarchar(max)
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted nvarchar(max)****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nvarchar(max)****
****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)****
****Conversion from PDO::PARAM_BOOL to nvarchar(max) is supported****
****Conversion from PDO::PARAM_INT to nvarchar(max) is supported****
****Conversion from PDO::PARAM_STR to nvarchar(max) is supported****
****Conversion from PDO::PARAM_LOB to nvarchar(max) is supported****
Testing nvarchar(max):
****PDO param type PDO::PARAM_BOOL is compatible with deterministic encrypted nvarchar(max)****
PDO param type PDO::PARAM_NULL is incompatible with deterministic encrypted nvarchar(max)
****PDO param type PDO::PARAM_INT is compatible with deterministic encrypted nvarchar(max)****
****PDO param type PDO::PARAM_STR is compatible with deterministic encrypted nvarchar(max)****
****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)****
****Conversion from PDO::PARAM_BOOL to nvarchar(max) is supported****
****Conversion from PDO::PARAM_INT to nvarchar(max) is supported****
****Conversion from PDO::PARAM_STR to nvarchar(max) is supported****
****Conversion from PDO::PARAM_LOB to nvarchar(max) is supported****

View file

@ -1,35 +1,87 @@
--TEST--
Test for inserting and retrieving encrypted data of numeric types
Test for inserting encrypted data into numeric types columns
--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--
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
require_once("MsCommon_mid-refactor.inc");
require_once("AEData.inc");
$dataTypes = array( "bit", "tinyint", "smallint", "int", "bigint", "real" );
$epsilon = 1;
try {
$conn = connect();
foreach ($dataTypes as $dataType) {
echo "\nTesting $dataType:\n";
// create table
$tbname = getTableName();
// create table containing bit, tinyint, smallint, int, bigint, or real columns
$tbname = "test_" . $dataType;
$colMetaArr = array(new ColumnMeta($dataType, "c_det"), new ColumnMeta($dataType, "c_rand", null, "randomized"));
createTable($conn, $tbname, $colMetaArr);
// test each PDO::PARAM_ type
// insert by specifying PDO::PARAM_ types
foreach ($pdoParamTypes as $pdoParamType) {
// insert a row
$inputValues = array_slice(${explode("(", $dataType)[0] . "_params"}, 1, 2);
$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 {
echo "****PDO param type $pdoParamType is compatible with encrypted $dataType****\n";
fetchAll($conn, $tbname);
$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] && $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");
}
@ -43,103 +95,32 @@ try {
?>
--EXPECT--
Testing bit:
****PDO param type PDO::PARAM_BOOL is compatible with encrypted bit****
c_det: 1
c_rand: 0
****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
****Conversion from PDO::PARAM_INT to bit is supported****
****Conversion from PDO::PARAM_STR to bit is supported****
****Conversion from PDO::PARAM_LOB to bit is supported****
Testing tinyint:
****PDO param type PDO::PARAM_BOOL is compatible with encrypted tinyint****
c_det: 0
c_rand: 1
****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
****Conversion from PDO::PARAM_INT to tinyint is supported****
****Conversion from PDO::PARAM_STR to tinyint is supported****
****Conversion from PDO::PARAM_LOB to tinyint is supported****
Testing smallint:
****PDO param type PDO::PARAM_BOOL is compatible with encrypted smallint****
c_det: 1
c_rand: 1
****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
****Conversion from PDO::PARAM_INT to smallint is supported****
****Conversion from PDO::PARAM_STR to smallint is supported****
****Conversion from PDO::PARAM_LOB to smallint is supported****
Testing int:
****PDO param type PDO::PARAM_BOOL is compatible with encrypted int****
c_det: 1
c_rand: 1
****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
****Conversion from PDO::PARAM_INT to int is supported****
****Conversion from PDO::PARAM_STR to int is supported****
****Conversion from PDO::PARAM_LOB to int is supported****
Testing bigint:
****PDO param type PDO::PARAM_BOOL is compatible with encrypted bigint****
c_det: 1
c_rand: 1
****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
****Conversion from PDO::PARAM_INT to bigint is supported****
****Conversion from PDO::PARAM_STR to bigint is supported****
****Conversion from PDO::PARAM_LOB to bigint is supported****
Testing real:
****PDO param type PDO::PARAM_BOOL is compatible with encrypted real****
c_det: -2147.4829
c_rand: 2147.4829
****PDO param type PDO::PARAM_NULL is compatible with encrypted real****
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
****Conversion from PDO::PARAM_BOOL to real is supported****
****Conversion from PDO::PARAM_INT to real is supported****
****Conversion from PDO::PARAM_STR to real is supported****
****Conversion from PDO::PARAM_LOB to real is supported****