php-sqlsrv/test/functional/pdo_sqlsrv/pdo_ae_bindColumn_pdoparam_datetime.phpt

82 lines
3.6 KiB
Plaintext
Raw Normal View History

2018-02-27 22:38:49 +01:00
--TEST--
2018-03-03 01:34:47 +01:00
Test for retrieving encrypted data from datetime types columns using PDO::bindColumn
2018-02-27 22:38:49 +01:00
--DESCRIPTION--
2018-03-03 01:34:47 +01:00
Test conversion from datetime types column to output of PDO::PARAM types
2018-03-13 20:50:20 +01:00
With or without Always Encrypted, conversion works if:
2018-03-03 01:34:47 +01:00
1. From any datetime type column to PDO::PARAM_STR
2. From any datetime type column to PDO::PARAM_LOB
2018-02-27 22:38:49 +01:00
--SKIPIF--
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
require_once("MsCommon_mid-refactor.inc");
require_once("AEData.inc");
$dataTypes = array("date", "datetime", "smalldatetime");
2018-03-03 01:34:47 +01:00
2018-02-27 22:38:49 +01:00
try {
$conn = connect("", array(), PDO::ERRMODE_SILENT);
foreach ($dataTypes as $dataType) {
echo "\nTesting $dataType:\n";
2018-03-03 01:34:47 +01:00
// create and populate table containing date, datetime or smalldatetime columns
$tbname = "test_" . $dataType;
2018-02-27 22:38:49 +01:00
$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]));
2018-03-03 01:34:47 +01:00
// fetch by specifying PDO::PARAM_ types with PDO::bindColumn
2018-02-27 22:38:49 +01:00
$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);
2018-03-03 01:34:47 +01:00
// check the case when fetching as PDO::PARAM_BOOL, PDO::PARAM_NULL or PDO::PARAM_INT
2018-03-13 20:50:20 +01:00
// with or without AE: should not work
2018-02-27 22:38:49 +01:00
if ($pdoParamType == "PDO::PARAM_BOOL" || $pdoParamType == "PDO::PARAM_NULL" || $pdoParamType == "PDO::PARAM_INT") {
if (!is_null($det) || !is_null($rand)) {
2018-03-03 01:34:47 +01:00
echo "Retrieving $dataType data as $pdoParamType should not be supported\n";
2018-02-27 22:38:49 +01:00
}
2018-03-03 01:34:47 +01:00
// check the case when fetching as PDO::PARAM_STR or PDO::PARAM_LOB
2018-03-14 00:15:42 +01:00
// only check if input values are part of fetched values because some input values do not contain any deicmal places, the value retrieved however has 3 decimal places if the type is a datetime
2018-03-03 01:34:47 +01:00
// with or without AE: should work
2018-02-27 22:38:49 +01:00
} else {
2021-07-29 00:45:04 +02:00
if (PHP_VERSION_ID >= 80100 && $pdoParamType == "PDO::PARAM_LOB") {
// Starting with PHP 8.1 fetching as PDO::PARAM_LOB will return a resource obj
$det = fread($det, 8192);
$rand = fread($rand, 8192);
}
2018-03-03 01:34:47 +01:00
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";
}
2018-02-27 22:38:49 +01:00
}
}
2018-03-03 01:34:47 +01:00
// cleanup
2018-02-27 22:38:49 +01:00
dropTable($conn, $tbname);
}
unset($stmt);
unset($conn);
} catch (PDOException $e) {
echo $e->getMessage();
}
?>
--EXPECT--
Testing date:
2018-03-03 01:34:47 +01:00
****Retrieving date as PDO::PARAM_STR is supported****
****Retrieving date as PDO::PARAM_LOB is supported****
2018-02-27 22:38:49 +01:00
Testing datetime:
2018-03-03 01:34:47 +01:00
****Retrieving datetime as PDO::PARAM_STR is supported****
****Retrieving datetime as PDO::PARAM_LOB is supported****
2018-02-27 22:38:49 +01:00
Testing smalldatetime:
2018-03-03 01:34:47 +01:00
****Retrieving smalldatetime as PDO::PARAM_STR is supported****
****Retrieving smalldatetime as PDO::PARAM_LOB is supported****