add tests for fetching with bindColumn
This commit is contained in:
parent
015be292d9
commit
5eaaa78292
|
@ -0,0 +1,128 @@
|
|||
--TEST--
|
||||
Test for inserting and retrieving encrypted data of numeric types
|
||||
--DESCRIPTION--
|
||||
Use PDOstatement::bindParam with all PDO::PARAM_ types
|
||||
--SKIPIF--
|
||||
<?php require('skipif_mid-refactor.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once("MsCommon_mid-refactor.inc");
|
||||
require_once("AEData.inc");
|
||||
|
||||
$dataTypes = array("binary", "varbinary", "varbinary(max)");
|
||||
$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;
|
||||
} else {
|
||||
$type = "$dataType($length)";
|
||||
}
|
||||
echo "\nTesting $type:\n";
|
||||
|
||||
//create and populate table
|
||||
$tbname = "test_binary";
|
||||
$colMetaArr = array(new ColumnMeta($type, "c_det"), new ColumnMeta($type, "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");
|
||||
|
||||
// fetch with PDO::bindColumn and PDO::FETCH_BOUND
|
||||
$query = "SELECT c_det, c_rand FROM $tbname";
|
||||
foreach ($pdoParamTypes as $pdoParamType) {
|
||||
$det = "";
|
||||
$rand = "";
|
||||
$stmt = $conn->prepare($query);
|
||||
$stmt->execute();
|
||||
$stmt->bindColumn('c_det', $det, constant($pdoParamType));
|
||||
$stmt->bindColumn('c_rand', $rand, constant($pdoParamType));
|
||||
$row = $stmt->fetch(PDO::FETCH_BOUND);
|
||||
|
||||
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";
|
||||
}
|
||||
} else {
|
||||
if (strlen($det) == $length && strlen($rand) == $length) {
|
||||
echo "****PDO param type $pdoParamType is compatible with encrypted $type****\n";
|
||||
} else {
|
||||
echo "Data corruption when fetching encrypted $type as PDO param type $pdoParamType\n";
|
||||
print_r($stmt->errorInfo());
|
||||
}
|
||||
}
|
||||
}
|
||||
dropTable($conn, $tbname);
|
||||
}
|
||||
}
|
||||
unset($stmt);
|
||||
unset($conn);
|
||||
} catch (PDOException $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
?>
|
||||
--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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
|
@ -0,0 +1,175 @@
|
|||
--TEST--
|
||||
Test for inserting and retrieving encrypted data of numeric types
|
||||
--DESCRIPTION--
|
||||
Use PDOstatement::bindParam with all PDO::PARAM_ types
|
||||
--SKIPIF--
|
||||
<?php require('skipif_mid-refactor.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once("MsCommon_mid-refactor.inc");
|
||||
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;
|
||||
} else {
|
||||
$type = "$dataType($length)";
|
||||
}
|
||||
echo "\nTesting $type:\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));
|
||||
|
||||
// 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";
|
||||
}
|
||||
} 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";
|
||||
}
|
||||
}
|
||||
}
|
||||
dropTable($conn, $tbname);
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($stmt);
|
||||
unset($conn);
|
||||
} catch (PDOException $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
?>
|
||||
--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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
|
@ -0,0 +1,77 @@
|
|||
--TEST--
|
||||
Test for inserting and retrieving encrypted data of datetime types
|
||||
--DESCRIPTION--
|
||||
Use PDOstatement::bindParam with all PDO::PARAM_ types
|
||||
--SKIPIF--
|
||||
<?php require('skipif_mid-refactor.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
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();
|
||||
$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
|
||||
$query = "SELECT c_det, c_rand FROM $tbname";
|
||||
foreach ($pdoParamTypes as $pdoParamType) {
|
||||
$det = "";
|
||||
$rand = "";
|
||||
$stmt = $conn->prepare($query);
|
||||
$stmt->execute();
|
||||
$stmt->bindColumn('c_det', $det, constant($pdoParamType));
|
||||
$stmt->bindColumn('c_rand', $rand, constant($pdoParamType));
|
||||
$row = $stmt->fetch(PDO::FETCH_BOUND);
|
||||
|
||||
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";
|
||||
}
|
||||
} else {
|
||||
echo "****PDO param type $pdoParamType is compatible with encrypted $dataType****\n";
|
||||
echo "c_det: $det\n";
|
||||
echo "c_rand: $rand\n";
|
||||
}
|
||||
}
|
||||
dropTable($conn, $tbname);
|
||||
}
|
||||
unset($stmt);
|
||||
unset($conn);
|
||||
} catch (PDOException $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
?>
|
||||
--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
|
||||
|
||||
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
|
||||
|
||||
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
|
|
@ -0,0 +1,170 @@
|
|||
--TEST--
|
||||
Test for inserting and retrieving encrypted data of numeric types
|
||||
--DESCRIPTION--
|
||||
Use PDOstatement::bindParam with all PDO::PARAM_ types
|
||||
--SKIPIF--
|
||||
<?php require('skipif_mid-refactor.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once("MsCommon_mid-refactor.inc");
|
||||
require_once("AEData.inc");
|
||||
|
||||
$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"),
|
||||
"datetimeoffset" => array("0001-01-01 00:00:00 -14:00", "9999-12-31 23:59:59 +14:00"),
|
||||
"time" => array("00:00:00", "23:59:59"));
|
||||
|
||||
try {
|
||||
$conn = connect("", array(), PDO::ERRMODE_SILENT);
|
||||
foreach ($dataTypes as $dataType) {
|
||||
foreach ($precisions as $precision) {
|
||||
// change the input values depending on the precision
|
||||
$inputValues[0] = $inputValuesInit[$dataType][0];
|
||||
$inputValues[1] = $inputValuesInit[$dataType][1];
|
||||
if ($precision != 0) {
|
||||
if ($dataType == "datetime2") {
|
||||
$inputValues[1] .= "." . str_repeat("9", $precision);
|
||||
} else if ($dataType == "datetimeoffset") {
|
||||
$inputPieces = explode(" ", $inputValues[1]);
|
||||
$inputValues[1] = $inputPieces[0] . " " . $inputPieces[1] . "." . str_repeat("9", $precision) . " " . $inputPieces[2];
|
||||
} else if ($dataType == "time") {
|
||||
$inputValues[0] .= "." . str_repeat("0", $precision);
|
||||
$inputValues[1] .= "." . str_repeat("9", $precision);
|
||||
}
|
||||
}
|
||||
$type = "$dataType($precision)";
|
||||
echo "\nTesting $type:\n";
|
||||
|
||||
//create and populate table
|
||||
$tbname = "test_datetime";
|
||||
$colMetaArr = array(new ColumnMeta($type, "c_det"), new ColumnMeta($type, "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
|
||||
$query = "SELECT c_det, c_rand FROM $tbname";
|
||||
foreach ($pdoParamTypes as $pdoParamType) {
|
||||
$det = "";
|
||||
$rand = "";
|
||||
$stmt = $conn->prepare($query);
|
||||
$stmt->execute();
|
||||
$stmt->bindColumn('c_det', $det, constant($pdoParamType));
|
||||
$stmt->bindColumn('c_rand', $rand, constant($pdoParamType));
|
||||
$row = $stmt->fetch(PDO::FETCH_BOUND);
|
||||
|
||||
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";
|
||||
}
|
||||
} else {
|
||||
echo "****PDO param type $pdoParamType is compatible with encrypted $type****\n";
|
||||
echo "c_det: $det\n";
|
||||
echo "c_rand: $rand\n";
|
||||
}
|
||||
}
|
||||
dropTable($conn, $tbname);
|
||||
}
|
||||
}
|
||||
unset($stmt);
|
||||
unset($conn);
|
||||
} catch (PDOException $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
?>
|
||||
--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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
|
@ -0,0 +1,233 @@
|
|||
--TEST--
|
||||
Test for inserting and retrieving encrypted data of numeric types
|
||||
--DESCRIPTION--
|
||||
Use PDOstatement::bindParam with all PDO::PARAM_ types
|
||||
--SKIPIF--
|
||||
<?php require('skipif_mid-refactor.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once("MsCommon_mid-refactor.inc");
|
||||
require_once("AEData.inc");
|
||||
|
||||
$dataTypes = array("decimal", "numeric");
|
||||
$precisions = array(1 => array(0, 1),
|
||||
4 => array(0, 1, 4),
|
||||
16 => array(0, 1, 4, 16),
|
||||
38 => array(0, 1, 4, 16, 38));
|
||||
$inputValuesInit = array(92233720368547758089223372036854775808, -92233720368547758089223372036854775808);
|
||||
$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);
|
||||
$inputValues = $inputValuesInit;
|
||||
foreach ($inputValues as &$inputValue) {
|
||||
$inputValue = $inputValue / pow(10, $precDiff);
|
||||
}
|
||||
// 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);
|
||||
} else {
|
||||
$numint = $precision - $scale;
|
||||
if ($numint < 14) {
|
||||
$epsilon = pow(10, (14 - $numint) * -1);
|
||||
} else {
|
||||
$epsilon = pow(10, $numint - 14);
|
||||
}
|
||||
}
|
||||
|
||||
$type = "$dataType($precision, $scale)";
|
||||
echo "\nTesting $type:\n";
|
||||
|
||||
//create and populate table
|
||||
$tbname = "test_decimal";
|
||||
$colMetaArr = array(new ColumnMeta($type, "c_det"), new ColumnMeta($type, "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
|
||||
$query = "SELECT c_det, c_rand FROM $tbname";
|
||||
foreach ($pdoParamTypes as $pdoParamType) {
|
||||
$det = "";
|
||||
$rand = "";
|
||||
$stmt = $conn->prepare($query);
|
||||
$stmt->execute();
|
||||
$stmt->bindColumn('c_det', $det, constant($pdoParamType));
|
||||
$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
|
||||
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";
|
||||
}
|
||||
} else {
|
||||
if (abs($det - $inputValues[0]) > $epsilon ||
|
||||
abs($rand - $inputValues[1]) > $epsilon) {
|
||||
echo "PDO param type $pdoParamType should be compatible with $type\n";
|
||||
} else {
|
||||
echo "****PDO param type $pdoParamType is compatible with $type****\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
dropTable($conn, $tbname);
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($stmt);
|
||||
unset($conn);
|
||||
} catch (PDOException $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
?>
|
||||
--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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
|
@ -0,0 +1,96 @@
|
|||
--TEST--
|
||||
Test for inserting and retrieving encrypted data of numeric types
|
||||
--DESCRIPTION--
|
||||
Use PDOstatement::bindParam with all PDO::PARAM_ types
|
||||
--SKIPIF--
|
||||
<?php require('skipif_mid-refactor.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once("MsCommon_mid-refactor.inc");
|
||||
require_once("AEData.inc");
|
||||
|
||||
$dataType = "float";
|
||||
$bits = array(1, 12, 24, 36, 53);
|
||||
$inputValues = array(9223372036854775808.9223372036854775808, -9223372036854775808.9223372036854775808);
|
||||
|
||||
try {
|
||||
$conn = connect("", array(), PDO::ERRMODE_SILENT);
|
||||
foreach ($bits as $bit) {
|
||||
$type = "$dataType($bit)";
|
||||
echo "\nTesting $type:\n";
|
||||
|
||||
//create and populate table
|
||||
$tbname = "test_float";
|
||||
$colMetaArr = array(new ColumnMeta($type, "c_det"), new ColumnMeta($type, "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
|
||||
$query = "SELECT c_det, c_rand FROM $tbname";
|
||||
foreach ($pdoParamTypes as $pdoParamType) {
|
||||
$det = "";
|
||||
$rand = "";
|
||||
$stmt = $conn->prepare($query);
|
||||
$stmt->execute();
|
||||
$stmt->bindColumn('c_det', $det, constant($pdoParamType));
|
||||
$stmt->bindColumn('c_rand', $rand, constant($pdoParamType));
|
||||
$row = $stmt->fetch(PDO::FETCH_BOUND);
|
||||
|
||||
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";
|
||||
}
|
||||
} else {
|
||||
echo "****PDO param type $pdoParamType is compatible with encrypted $type****\n";
|
||||
echo "c_det: $det\n";
|
||||
echo "c_rand: $rand\n";
|
||||
}
|
||||
}
|
||||
dropTable($conn, $tbname);
|
||||
}
|
||||
unset($stmt);
|
||||
unset($conn);
|
||||
} catch (PDOException $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
?>
|
||||
--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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
|
@ -0,0 +1,156 @@
|
|||
--TEST--
|
||||
Test for inserting and retrieving encrypted data of numeric types
|
||||
--DESCRIPTION--
|
||||
Use PDOstatement::bindParam with all PDO::PARAM_ types
|
||||
--SKIPIF--
|
||||
<?php require('skipif_mid-refactor.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once("MsCommon_mid-refactor.inc");
|
||||
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;
|
||||
} else {
|
||||
$type = "$dataType($length)";
|
||||
}
|
||||
echo "\nTesting $type:\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));
|
||||
|
||||
// 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";
|
||||
}
|
||||
} 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";
|
||||
}
|
||||
}
|
||||
}
|
||||
dropTable($conn, $tbname);
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($stmt);
|
||||
unset($conn);
|
||||
} catch (PDOException $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
?>
|
||||
--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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
||||
|
||||
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)****
|
|
@ -0,0 +1,138 @@
|
|||
--TEST--
|
||||
Test for inserting and retrieving encrypted data of numeric types
|
||||
--DESCRIPTION--
|
||||
Use PDOstatement::bindParam with all PDO::PARAM_ types
|
||||
--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");
|
||||
try {
|
||||
$conn = connect("", array(), PDO::ERRMODE_SILENT);
|
||||
foreach ($dataTypes as $dataType) {
|
||||
echo "\nTesting $dataType:\n";
|
||||
|
||||
// create and populate table
|
||||
$tbname = getTableName();
|
||||
$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
|
||||
$query = "SELECT c_det, c_rand FROM $tbname";
|
||||
foreach ($pdoParamTypes as $pdoParamType) {
|
||||
$det = "";
|
||||
$rand = "";
|
||||
$stmt = $conn->prepare($query);
|
||||
$stmt->execute();
|
||||
$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";
|
||||
} else {
|
||||
echo "****PDO param type $pdoParamType is compatible with encrypted $dataType****\n";
|
||||
echo "c_det: $det\n";
|
||||
echo "c_rand: $rand\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
dropTable($conn, $tbname);
|
||||
}
|
||||
unset($stmt);
|
||||
unset($conn);
|
||||
} catch (PDOException $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
?>
|
||||
--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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
Loading…
Reference in a new issue