2017-09-14 02:46:44 +02:00
|
|
|
--TEST--
|
2018-03-03 01:34:47 +01:00
|
|
|
Test for inserting encrypted data into datetime types columns
|
2017-09-26 01:37:27 +02:00
|
|
|
--DESCRIPTION--
|
2018-03-03 01:34:47 +01:00
|
|
|
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
|
2017-09-14 02:46:44 +02:00
|
|
|
--SKIPIF--
|
2017-11-07 02:30:11 +01:00
|
|
|
<?php require('skipif_mid-refactor.inc'); ?>
|
2017-09-14 02:46:44 +02:00
|
|
|
--FILE--
|
|
|
|
<?php
|
2017-11-07 02:30:11 +01:00
|
|
|
require_once("MsCommon_mid-refactor.inc");
|
|
|
|
require_once("AEData.inc");
|
2017-09-14 02:46:44 +02:00
|
|
|
|
2018-02-27 00:56:05 +01:00
|
|
|
$dataTypes = array( "date", "datetime", "smalldatetime");
|
2018-03-03 01:34:47 +01:00
|
|
|
|
2017-11-07 02:30:11 +01:00
|
|
|
try {
|
|
|
|
$conn = connect();
|
|
|
|
foreach ($dataTypes as $dataType) {
|
2017-09-14 02:46:44 +02:00
|
|
|
echo "\nTesting $dataType:\n";
|
2017-11-07 02:30:11 +01:00
|
|
|
|
2018-03-03 01:34:47 +01:00
|
|
|
// create table containing date, datetime or smalldatetime columns
|
|
|
|
$tbname = "test_" . $dataType;
|
2017-11-07 02:30:11 +01:00
|
|
|
$colMetaArr = array( new ColumnMeta($dataType, "c_det"), new ColumnMeta($dataType, "c_rand", null, "randomized"));
|
|
|
|
createTable($conn, $tbname, $colMetaArr);
|
|
|
|
|
2018-03-03 01:34:47 +01:00
|
|
|
// insert by specifying PDO::PARAM_ types
|
2017-11-07 02:30:11 +01:00
|
|
|
foreach ($pdoParamTypes as $pdoParamType) {
|
|
|
|
$inputValues = array_slice(${explode("(", $dataType)[0] . "_params"}, 1, 2);
|
2017-09-14 02:46:44 +02:00
|
|
|
$r;
|
2017-11-07 02:30:11 +01:00
|
|
|
$stmt = insertRow($conn, $tbname, array( "c_det" => new BindParamOp(1, $inputValues[0], $pdoParamType), "c_rand" => new BindParamOp(2, $inputValues[1], $pdoParamType)), "prepareBindParam", $r);
|
2018-03-03 01:34:47 +01:00
|
|
|
|
|
|
|
// 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
|
2017-11-07 02:30:11 +01:00
|
|
|
} else {
|
2018-03-03 01:34:47 +01:00
|
|
|
$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";
|
|
|
|
}
|
2017-09-14 02:46:44 +02:00
|
|
|
}
|
2017-11-07 02:30:11 +01:00
|
|
|
$conn->query("TRUNCATE TABLE $tbname");
|
2017-09-14 02:46:44 +02:00
|
|
|
}
|
2017-11-07 02:30:11 +01:00
|
|
|
dropTable($conn, $tbname);
|
2017-09-14 02:46:44 +02:00
|
|
|
}
|
2017-11-07 02:30:11 +01:00
|
|
|
unset($stmt);
|
|
|
|
unset($conn);
|
|
|
|
} catch (PDOException $e) {
|
2017-09-14 02:46:44 +02:00
|
|
|
echo $e->getMessage();
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
--EXPECT--
|
|
|
|
Testing date:
|
2018-03-03 01:34:47 +01:00
|
|
|
****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****
|
2017-09-14 02:46:44 +02:00
|
|
|
|
|
|
|
Testing datetime:
|
2018-03-03 01:34:47 +01:00
|
|
|
****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****
|
2017-09-14 02:46:44 +02:00
|
|
|
|
|
|
|
Testing smalldatetime:
|
2018-03-03 01:34:47 +01: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****
|