iteration 1: apply review changes; fix expected outputs
This commit is contained in:
parent
8a512d8e97
commit
27b47665dd
|
@ -20,7 +20,7 @@ function IsAEQualified($conn)
|
|||
$server_ver = $conn->getAttribute(PDO::ATTR_SERVER_VERSION);
|
||||
$msodbcsql_maj = explode(".", $msodbcsql_ver)[0];
|
||||
$msodbcsql_min = explode(".", $msodbcsql_ver)[1];
|
||||
if ($msodbcsql_maj < 13 || explode('.', $server_ver)[0] < 13)
|
||||
if ($msodbcsql_maj < 17 || explode('.', $server_ver)[0] < 13)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
@ -121,6 +121,8 @@ function getCekName()
|
|||
case "akv":
|
||||
$cekName = 'AKVColumnKey';
|
||||
break;
|
||||
default:
|
||||
echo "getCekName: Invalid keystore name.\n";
|
||||
}
|
||||
return $cekName;
|
||||
}
|
||||
|
@ -133,11 +135,11 @@ class columnMeta {
|
|||
public $colName;
|
||||
public $dataType; //a string that includes the size of the type if necessary (e.g., decimal(10,5))
|
||||
public $encType; //randomized or deterministic; default is deterministic
|
||||
public $options; //a string that is empty by default (e.g. NOT NULL Identity (1,1) )
|
||||
public $options; //a string that is null by default (e.g. NOT NULL Identity (1,1) )
|
||||
|
||||
function __construct( $dataType, $colName = null, $options = null, $encType = "deterministic" )
|
||||
{
|
||||
if ( !$colName )
|
||||
if ( is_null( $colName ))
|
||||
{
|
||||
$this->colName = get_default_colname( $dataType );
|
||||
}
|
||||
|
@ -157,17 +159,13 @@ class columnMeta {
|
|||
require 'MsSetup.inc';
|
||||
$append = " ";
|
||||
|
||||
// an identity column is not encrypted because a select query with identity column as the where clause is often run and the user want to have to bind parameter every time
|
||||
if ( $keystore != "none" && stripos( $this->options, "identity" ) === false )
|
||||
{
|
||||
$cekName = getCekName();
|
||||
$encDet = "ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = $cekName) ";
|
||||
$encRand = "ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = $cekName) ";
|
||||
if ( stripos( $this->dataType, "char" ) !== false )
|
||||
$append .= "COLLATE Latin1_General_BIN2 ";
|
||||
if ( $this->encType == "deterministic" )
|
||||
$append .= $encDet;
|
||||
else
|
||||
$append .= $encRand;
|
||||
$append .= sprintf( "ENCRYPTED WITH (ENCRYPTION_TYPE = %s, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = $cekName) ", $this->encType );
|
||||
}
|
||||
$append .= $this->options;
|
||||
$colDef = "[" . $this->colName . "] " . $this->dataType . $append;
|
||||
|
@ -191,16 +189,15 @@ function get_default_colname( $dataType )
|
|||
* Create a table
|
||||
* @param object $conn : PDO connection object
|
||||
* @param string $tbname : name of the table to be created
|
||||
* @param array $columnMeta : array of columnMeta objects, which contain metadata for one column
|
||||
* @param array $columnMetaAee : array of columnMeta objects, which contain metadata for one column
|
||||
*/
|
||||
function create_table( $conn, $tbname, $columnMeta )
|
||||
function create_table( $conn, $tbname, $columnMetaArr )
|
||||
{
|
||||
try
|
||||
{
|
||||
$dropSql = "IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'" . $tbname . "') AND type in (N'U')) DROP TABLE $tbname";
|
||||
$conn->exec( $dropSql );
|
||||
DropTable( $conn, $tbname );
|
||||
$colDef = "";
|
||||
foreach ( $columnMeta as $meta )
|
||||
foreach ( $columnMetaArr as $meta )
|
||||
{
|
||||
$colDef = $colDef . $meta->getColDef() . ", ";
|
||||
}
|
||||
|
@ -244,11 +241,11 @@ class bindParamOption {
|
|||
|
||||
|
||||
/**
|
||||
* Create a row into a table
|
||||
* Insert a row into a table
|
||||
* @param object $conn : PDO connection object
|
||||
* @param string $tbname : name of the table to be created
|
||||
* @param string $tbname : name of the table for the row to be inserted
|
||||
* @param array $inputs : an associative array column name and its value
|
||||
* @param bool $r : if the row was successfully inserted
|
||||
* @param bool $r : true if the row was successfully inserted, otherwise false. Default value is null to make this parameter optional.
|
||||
* $param string $api : PDO_SQLSRV API used for executing the insert query
|
||||
* accepted values: "exec", "query", "prepare", "prepareBindParam"
|
||||
* @param array $paramOption : an array of bindParamOptions. Should only be provided if $api is "perpareWithParamOp", if provided, has to be in the same order as $inputs
|
||||
|
@ -338,7 +335,9 @@ function get_insertSql_complete( $tbname, $inputs )
|
|||
foreach( $inputs as $key => $value )
|
||||
{
|
||||
$colStr .= $key . ", ";
|
||||
if ( is_string( $value ))
|
||||
if ( is_null( $value ))
|
||||
echo "get_insertSql_complete: value provided for input $value is null.\n";
|
||||
elseif ( is_string( $value ))
|
||||
$valStr .= "'" . $value . "', ";
|
||||
else
|
||||
$valStr .= $value . ", ";
|
||||
|
@ -1462,7 +1461,7 @@ function CreateUniqueIndexEx($conn, $tableName, $tableIndex, $colIndex)
|
|||
|
||||
function DropTable($conn, $tableName)
|
||||
{
|
||||
$tsql = "DROP TABLE [$tableName]";
|
||||
$tsql = "IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'" . $tableName . "') AND type in (N'U')) DROP TABLE $tableName"
|
||||
if (IsPdoMode())
|
||||
{
|
||||
$mode = $conn->getAttribute(PDO::ATTR_ERRMODE);
|
||||
|
|
|
@ -14,14 +14,13 @@ $dataTypes = array( "date", "datetime", "datetime2", "smalldatetime", "time", "d
|
|||
try
|
||||
{
|
||||
$conn = ae_connect();
|
||||
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT );
|
||||
|
||||
foreach ( $dataTypes as $dataType ) {
|
||||
echo "\nTesting $dataType:\n";
|
||||
|
||||
// create table
|
||||
$tbname = GetTempTableName( "", false );
|
||||
$colMetaArr = array( new columnMeta( $dataType, "c_det" ), new columnMeta( $dataType, "c_rand" ));
|
||||
$colMetaArr = array( new columnMeta( $dataType, "c_det" ), new columnMeta( $dataType, "c_rand", null, "randomized" ));
|
||||
create_table( $conn, $tbname, $colMetaArr );
|
||||
|
||||
// insert a row
|
||||
|
|
|
@ -22,7 +22,7 @@ try
|
|||
|
||||
// create table
|
||||
$tbname = GetTempTableName( "", false );
|
||||
$colMetaArr = array( new columnMeta( $dataType, "c_det" ), new columnMeta( $dataType, "c_rand" ));
|
||||
$colMetaArr = array( new columnMeta( $dataType, "c_det" ), new columnMeta( $dataType, "c_rand", null, "randomized" ));
|
||||
create_table( $conn, $tbname, $colMetaArr );
|
||||
|
||||
// insert a row
|
||||
|
|
|
@ -14,14 +14,13 @@ $dataTypes = array( "bit", "tinyint", "smallint", "int", "bigint", "decimal(18,5
|
|||
try
|
||||
{
|
||||
$conn = ae_connect();
|
||||
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT );
|
||||
|
||||
foreach ( $dataTypes as $dataType ) {
|
||||
echo "\nTesting $dataType:\n";
|
||||
|
||||
// create table
|
||||
$tbname = GetTempTableName( "", false );
|
||||
$colMetaArr = array( new columnMeta( $dataType, "c_det" ), new columnMeta( $dataType, "c_rand" ));
|
||||
$colMetaArr = array( new columnMeta( $dataType, "c_det" ), new columnMeta( $dataType, "c_rand", null, "randomized" ));
|
||||
create_table( $conn, $tbname, $colMetaArr );
|
||||
|
||||
// insert a row
|
||||
|
|
|
@ -14,14 +14,13 @@ $dataTypes = array( "date", "datetime", "datetime2", "smalldatetime", "time", "d
|
|||
try
|
||||
{
|
||||
$conn = ae_connect();
|
||||
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT );
|
||||
|
||||
foreach ( $dataTypes as $dataType ) {
|
||||
echo "\nTesting $dataType:\n";
|
||||
|
||||
// create table
|
||||
$tbname = GetTempTableName( "", false );
|
||||
$colMetaArr = array( new columnMeta( $dataType, "c_det" ), new columnMeta( $dataType, "c_rand" ));
|
||||
$colMetaArr = array( new columnMeta( $dataType, "c_det" ), new columnMeta( $dataType, "c_rand", null, "randomized" ));
|
||||
create_table( $conn, $tbname, $colMetaArr );
|
||||
|
||||
// prepare statement for inserting into table
|
||||
|
@ -57,8 +56,8 @@ Testing 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:
|
||||
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
|
||||
|
@ -74,8 +73,8 @@ Testing 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:
|
||||
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
|
||||
|
@ -91,8 +90,8 @@ Testing 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:
|
||||
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
|
||||
|
@ -108,8 +107,8 @@ Testing 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:
|
||||
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
|
||||
|
@ -125,8 +124,8 @@ Testing 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:
|
||||
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
|
||||
|
@ -142,8 +141,8 @@ Testing 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:
|
||||
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
|
||||
|
|
|
@ -22,7 +22,7 @@ try
|
|||
|
||||
// create table
|
||||
$tbname = GetTempTableName( "", false );
|
||||
$colMetaArr = array( new columnMeta( $dataType, "c_det" ), new columnMeta( $dataType, "c_rand" ));
|
||||
$colMetaArr = array( new columnMeta( $dataType, "c_det" ), new columnMeta( $dataType, "c_rand", null, "randomized" ));
|
||||
create_table( $conn, $tbname, $colMetaArr );
|
||||
|
||||
// test each PDO::PARAM_ type
|
||||
|
|
|
@ -14,14 +14,13 @@ $dataTypes = array( "bit", "tinyint", "smallint", "int", "decimal(18,5)", "numer
|
|||
try
|
||||
{
|
||||
$conn = ae_connect();
|
||||
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT );
|
||||
|
||||
foreach ( $dataTypes as $dataType ) {
|
||||
echo "\nTesting $dataType:\n";
|
||||
|
||||
// create table
|
||||
$tbname = GetTempTableName( "", false );
|
||||
$colMetaArr = array( new columnMeta( $dataType, "c_det" ), new columnMeta( $dataType, "c_rand" ));
|
||||
$colMetaArr = array( new columnMeta( $dataType, "c_det" ), new columnMeta( $dataType, "c_rand", null, "randomized" ));
|
||||
create_table( $conn, $tbname, $colMetaArr );
|
||||
|
||||
// test each PDO::PARAM_ type
|
||||
|
|
|
@ -21,7 +21,7 @@ try
|
|||
|
||||
// create table
|
||||
$tbname = GetTempTableName( "", false );
|
||||
$colMetaArr = array( new columnMeta( $dataType, "c_det" ), new columnMeta( $dataType, "c_rand" ));
|
||||
$colMetaArr = array( new columnMeta( $dataType, "c_det" ), new columnMeta( $dataType, "c_rand", null, "randomized" ));
|
||||
create_table( $conn, $tbname, $colMetaArr );
|
||||
|
||||
// prepare statement for inserting into table
|
||||
|
@ -57,8 +57,8 @@ Testing char(5):
|
|||
c_det: -leng
|
||||
c_rand: th, n
|
||||
****PDO param type PDO::PARAM_NULL is compatible with encrypted char(5)****
|
||||
c_det:
|
||||
c_rand:
|
||||
c_det:
|
||||
c_rand:
|
||||
****PDO param type PDO::PARAM_INT is compatible with encrypted char(5)****
|
||||
c_det: -leng
|
||||
c_rand: th, n
|
||||
|
@ -74,8 +74,8 @@ Testing varchar(max):
|
|||
c_det: Use varchar(max) when the sizes of the column data entries vary considerably, and the size might exceed 8,000 bytes.
|
||||
c_rand: Each non-null varchar(max) or nvarchar(max) column requires 24 bytes of additional fixed allocation which counts against the 8,060 byte row limit during a sort operation.
|
||||
****PDO param type PDO::PARAM_NULL is compatible with encrypted varchar(max)****
|
||||
c_det:
|
||||
c_rand:
|
||||
c_det:
|
||||
c_rand:
|
||||
****PDO param type PDO::PARAM_INT is compatible with encrypted varchar(max)****
|
||||
c_det: Use varchar(max) when the sizes of the column data entries vary considerably, and the size might exceed 8,000 bytes.
|
||||
c_rand: Each non-null varchar(max) or nvarchar(max) column requires 24 bytes of additional fixed allocation which counts against the 8,060 byte row limit during a sort operation.
|
||||
|
@ -91,8 +91,8 @@ Testing nchar(5):
|
|||
c_det: -leng
|
||||
c_rand: th Un
|
||||
****PDO param type PDO::PARAM_NULL is compatible with encrypted nchar(5)****
|
||||
c_det:
|
||||
c_rand:
|
||||
c_det:
|
||||
c_rand:
|
||||
****PDO param type PDO::PARAM_INT is compatible with encrypted nchar(5)****
|
||||
c_det: -leng
|
||||
c_rand: th Un
|
||||
|
@ -108,8 +108,8 @@ Testing nvarchar(max):
|
|||
c_det: When prefixing a string constant with the letter N, the implicit conversion will result in a Unicode string if the constant to convert does not exceed the max length for a Unicode string data type (4,000).
|
||||
c_rand: Otherwise, the implicit conversion will result in a Unicode large-value (max).
|
||||
****PDO param type PDO::PARAM_NULL is compatible with encrypted nvarchar(max)****
|
||||
c_det:
|
||||
c_rand:
|
||||
c_det:
|
||||
c_rand:
|
||||
****PDO param type PDO::PARAM_INT is compatible with encrypted nvarchar(max)****
|
||||
c_det: When prefixing a string constant with the letter N, the implicit conversion will result in a Unicode string if the constant to convert does not exceed the max length for a Unicode string data type (4,000).
|
||||
c_rand: Otherwise, the implicit conversion will result in a Unicode large-value (max).
|
||||
|
|
|
@ -12,7 +12,6 @@ include 'AEData.inc';
|
|||
try
|
||||
{
|
||||
$conn = ae_connect();
|
||||
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT );
|
||||
|
||||
// Create the table
|
||||
$tbname = 'Patients';
|
||||
|
|
|
@ -11,7 +11,6 @@ include 'AEData.inc';
|
|||
try
|
||||
{
|
||||
$conn = ae_connect();
|
||||
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT );
|
||||
|
||||
// Create the table
|
||||
$tbname = 'FixedSizeAnalysis';
|
||||
|
|
|
@ -12,7 +12,6 @@ $testPass = true;
|
|||
try
|
||||
{
|
||||
$conn = ae_connect();
|
||||
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT );
|
||||
|
||||
// Create the table
|
||||
$tbname = 'NVarcharAnalysis';
|
||||
|
|
|
@ -12,7 +12,6 @@ $testPass = true;
|
|||
try
|
||||
{
|
||||
$conn = ae_connect();
|
||||
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT );
|
||||
|
||||
// Create the table
|
||||
$tbname = 'VarcharAnalysis';
|
||||
|
|
|
@ -14,15 +14,13 @@ $dataTypes = array( "char(5)", "varchar(max)", "nchar(5)", "nvarchar(max)" );
|
|||
try
|
||||
{
|
||||
$conn = ae_connect();
|
||||
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT );
|
||||
|
||||
foreach ( $dataTypes as $dataType ) {
|
||||
echo "\nTesting $dataType:\n";
|
||||
|
||||
// create table
|
||||
$tbname = GetTempTableName( "", false );
|
||||
$tbname = "teststring";
|
||||
$colMetaArr = array( new columnMeta( $dataType, "c_det" ), new columnMeta( $dataType, "c_rand" ));
|
||||
$colMetaArr = array( new columnMeta( $dataType, "c_det" ), new columnMeta( $dataType, "c_rand", null, "randomized" ));
|
||||
create_table( $conn, $tbname, $colMetaArr );
|
||||
|
||||
// insert a row
|
||||
|
@ -36,7 +34,7 @@ try
|
|||
echo "****Encrypted default type is compatible with encrypted $dataType****\n";
|
||||
fetch_all( $conn, $tbname );
|
||||
}
|
||||
//DropTable( $conn, $tbname );
|
||||
DropTable( $conn, $tbname );
|
||||
}
|
||||
unset( $stmt );
|
||||
unset( $conn );
|
||||
|
|
|
@ -9,7 +9,6 @@ include 'MsSetup.inc';
|
|||
include 'AEData.inc';
|
||||
|
||||
$conn = ae_connect();
|
||||
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT );
|
||||
|
||||
// Create the table
|
||||
$tbname = GetTempTableName( "", false );
|
||||
|
@ -157,7 +156,7 @@ numericOut: 21474\.83647
|
|||
floatOut: (9223372036\.8547993|9\.22337e\+009)
|
||||
realOut: (2147\.4829|2147\.48)
|
||||
dateOut: 9999-12-31
|
||||
datetimeOut: 9999-12-31 23:59:59\.997
|
||||
datetimeOut: (9999-12-31 23:59:59\.997|Dec 31 9999 11:59PM)
|
||||
datetime2Out: 9999-12-31 23:59:59\.9999999
|
||||
datetimeoffsetOut: 9999-12-31 23:59:59\.9999999 \+14:00
|
||||
timeOut: 23:59:59\.9999999
|
||||
|
|
|
@ -91,20 +91,20 @@ sqlsrv_close( $conn );
|
|||
?>
|
||||
--EXPECT--
|
||||
|
||||
Testing date:
|
||||
Testing date:
|
||||
Test successfully.
|
||||
|
||||
Testing datetime:
|
||||
Testing datetime:
|
||||
Test successfully.
|
||||
|
||||
Testing datetime2:
|
||||
Testing datetime2:
|
||||
Test successfully.
|
||||
|
||||
Testing smalldatetime:
|
||||
Testing smalldatetime:
|
||||
Test successfully.
|
||||
|
||||
Testing time:
|
||||
Testing time:
|
||||
Test successfully.
|
||||
|
||||
Testing datetimeoffset:
|
||||
Testing datetimeoffset:
|
||||
Test successfully.
|
Loading…
Reference in a new issue