php-sqlsrv/test/functional/sqlsrv/sqlsrv_ae_insert_datetime.phpt
2019-06-28 14:08:18 -07:00

83 lines
2.8 KiB
PHP

--TEST--
Test for inserting and retrieving encrypted data of datetime types
--DESCRIPTION--
Bind params using sqlsrv_prepare without any sql_type specified
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
require_once('MsCommon.inc');
require_once('AEData.inc');
date_default_timezone_set("Canada/Pacific");
$dataTypes = array( "date", "datetime", "datetime2", "smalldatetime", "time", "datetimeoffset" );
$conn = AE\connect();
foreach ($dataTypes as $dataType) {
echo "\nTesting $dataType: \n";
// create table
$tbname = GetTempTableName("", false);
$colMetaArr = array( new AE\ColumnMeta($dataType, "c_det"), new AE\ColumnMeta($dataType, "c_rand", null, false));
AE\createTable($conn, $tbname, $colMetaArr);
// insert a row
$inputValues = array_slice(${explode("(", $dataType)[0] . "_params"}, 1, 2);
$r;
$stmt = AE\insertRow($conn, $tbname, array( $colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r);
if ($r === false) {
is_incompatible_types_error($dataType, "default type");
} else {
echo "****Encrypted default type is compatible with encrypted $dataType****\n";
$sql = "SELECT * FROM $tbname";
$stmt = sqlsrv_query($conn, $sql);
$row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC);
foreach ($row as $key => $value) {
if ($dataType == "time") {
$t = $value->format('H:i:s');
print "$key: $t\n";
} else {
$t = date_format($value, "Y-m-d H:i:s.u");
$tz = $value->getTimezone()->getName();
print "$key: $t $tz\n";
}
}
}
dropTable($conn, $tbname);
}
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
?>
--EXPECT--
Testing date:
****Encrypted default type is compatible with encrypted date****
c_det: 0001-01-01 00:00:00.000000 Canada/Pacific
c_rand: 9999-12-31 00:00:00.000000 Canada/Pacific
Testing datetime:
****Encrypted default type is compatible with encrypted datetime****
c_det: 1753-01-01 00:00:00.000000 Canada/Pacific
c_rand: 9999-12-31 23:59:59.997000 Canada/Pacific
Testing datetime2:
****Encrypted default type is compatible with encrypted datetime2****
c_det: 0001-01-01 00:00:00.000000 Canada/Pacific
c_rand: 9999-12-31 23:59:59.123456 Canada/Pacific
Testing smalldatetime:
****Encrypted default type is compatible with encrypted smalldatetime****
c_det: 1900-01-01 00:00:00.000000 Canada/Pacific
c_rand: 2079-06-05 23:59:00.000000 Canada/Pacific
Testing time:
****Encrypted default type is compatible with encrypted time****
c_det: 00:00:00
c_rand: 23:59:59
Testing datetimeoffset:
****Encrypted default type is compatible with encrypted datetimeoffset****
c_det: 0001-01-01 00:00:00.000000 -14:00
c_rand: 9999-12-31 23:59:59.123456 +14:00