iteration 2: apply review changes

This commit is contained in:
v-kaywon 2017-09-14 15:04:55 -07:00
parent 27b47665dd
commit ebdb18c837
29 changed files with 156 additions and 139 deletions

View file

@ -189,7 +189,7 @@ 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 $columnMetaAee : array of columnMeta objects, which contain metadata for one column
* @param array $columnMetaArr : array of columnMeta objects, which contain metadata for one column
*/
function create_table( $conn, $tbname, $columnMetaArr )
{
@ -325,13 +325,18 @@ function insert_row( $conn, $tbname, $inputs, &$r = null, $api = "query", $param
/**
* @param string $tbname : name of the table for an insert sql
* @param array $input : associative array containing a key value pair of column name and data to put into an insert sql string
* @param array $inputs : associative array containing a key value pair of column name and data to put into an insert sql string
* @return string a complete insert sql string
*/
function get_insertSql_complete( $tbname, $inputs )
{
$colStr = "INSERT INTO $tbname (";
$valStr = "VALUES (";
if ( empty( $inputs ))
{
echo "get_insertSql_complete: inputs for inserting a row cannot be empty.\n";
return;
}
foreach( $inputs as $key => $value )
{
$colStr .= $key . ", ";
@ -358,6 +363,11 @@ function get_insertSql_placeholders( $tbname, $inputs )
{
$colStr = "INSERT INTO $tbname (";
$valStr = "VALUES (";
if ( empty( $inputs ))
{
echo "get_insertSql_placeholders: inputs for inserting a row cannot be empty.\n";
return;
}
foreach( $inputs as $key => $value )
{
$colStr .= $key . ", ";
@ -388,6 +398,11 @@ function get_callProcSql_placeholders( $spname, $num )
*/
function get_seq_placeholders( $num )
{
if ( $num < 0 )
{
echo "get_seq_placeholders: num provided for creating a sequence of placeholders cannot be less than 0.\n";
return;
}
$placeholderStr = str_repeat( "?, ", $num );
$placeholderStr = rtrim( $placeholderStr, ", " );
return $placeholderStr;
@ -420,6 +435,19 @@ function fetch_all( $conn, $tbname ) {
}
/**
* @return bool false if $keystore specified in MsSetup.inc is none, otherwise return true
*/
function is_col_enc()
{
require 'MsSetup.inc';
if ( $keystore == "none" )
return false
else
return true;
}
// Create and insert
function create_and_insert_table1( $conn )
{
@ -1461,7 +1489,7 @@ function CreateUniqueIndexEx($conn, $tableName, $tableIndex, $colIndex)
function DropTable($conn, $tableName)
{
$tsql = "IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'" . $tableName . "') AND type in (N'U')) 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);

View file

@ -1,5 +1,5 @@
--TEST--
Test for inserting and retrieving encrypted datetime types data
Test for inserting and retrieving encrypted data of datetime types
No PDO::PARAM_ type specified when binding parameters
--SKIPIF--
@ -7,7 +7,6 @@ No PDO::PARAM_ type specified when binding parameters
<?php
include 'MsCommon.inc';
include 'AEData.inc';
include 'MsSetup.inc';
$dataTypes = array( "date", "datetime", "datetime2", "smalldatetime", "time", "datetimeoffset" );

View file

@ -1,5 +1,5 @@
--TEST--
Test for inserting and retrieving encrypted money types data
Test for inserting and retrieving encrypted data of money types
No PDO::PARAM_ tpe specified when binding parameters
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
@ -7,7 +7,6 @@ No PDO::PARAM_ tpe specified when binding parameters
<?php
include 'MsCommon.inc';
include 'AEData.inc';
include 'MsSetup.inc';
$dataTypes = array( "smallmoney", "money" );
@ -30,7 +29,7 @@ try
$r;
$stmt = insert_row( $conn, $tbname, array( $colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r );
if ( $keystore == "none" )
if ( !is_col_enc() )
{
if ( $r === false )
{
@ -66,7 +65,7 @@ try
}
}
if ( $success )
echo "Test successfully.\n";
echo "Test successfully done.\n";
DropTable( $conn, $tbname );
}
unset( $stmt );
@ -80,7 +79,7 @@ catch( PDOException $e )
--EXPECT--
Testing smallmoney:
Test successfully.
Test successfully done.
Testing money:
Test successfully.
Test successfully done.

View file

@ -1,5 +1,5 @@
--TEST--
Test for inserting and retrieving encrypted numeric types data
Test for inserting and retrieving encrypted data of numeric types
No PDO::PARAM_ tpe specified when binding parameters
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
@ -7,7 +7,6 @@ No PDO::PARAM_ tpe specified when binding parameters
<?php
include 'MsCommon.inc';
include 'AEData.inc';
include 'MsSetup.inc';
$dataTypes = array( "bit", "tinyint", "smallint", "int", "bigint", "decimal(18,5)", "numeric(10,5)", "float", "real" );

View file

@ -1,5 +1,5 @@
--TEST--
Test for inserting and retrieving encrypted datetime types data
Test for inserting and retrieving encrypted data of datetime types
Use PDOstatement::bindParam with all PDO::PARAM_ types
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
@ -7,7 +7,6 @@ Use PDOstatement::bindParam with all PDO::PARAM_ types
<?php
include 'MsCommon.inc';
include 'AEData.inc';
include 'MsSetup.inc';
$dataTypes = array( "date", "datetime", "datetime2", "smalldatetime", "time", "datetimeoffset" );

View file

@ -1,5 +1,5 @@
--TEST--
Test for inserting and retrieving encrypted money types data
Test for inserting and retrieving encrypted data of money types
Use PDOstatement::bindParam with all PDO::PARAM_ types
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
@ -7,7 +7,6 @@ Use PDOstatement::bindParam with all PDO::PARAM_ types
<?php
include 'MsCommon.inc';
include 'AEData.inc';
include 'MsSetup.inc';
$dataTypes = array( "smallmoney", "money" );
@ -33,7 +32,7 @@ try
$stmt = insert_row( $conn, $tbname, array( $colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r, "prepareBindParam", array( new bindParamOption( 1, $pdoParamType ), new bindParamOption( 2, $pdoParamType )));
if ( $keystore == "none" )
if ( !is_col_enc() )
{
if ( $r === false )
{
@ -73,7 +72,7 @@ try
$conn->query( "TRUNCATE TABLE $tbname" );
}
if ( $success )
echo "Test successfully.\n";
echo "Test successfully done.\n";
DropTable( $conn, $tbname );
}
unset( $stmt );
@ -87,7 +86,7 @@ catch( PDOException $e )
--EXPECT--
Testing smallmoney:
Test successfully.
Test successfully done.
Testing money:
Test successfully.
Test successfully done.

View file

@ -1,5 +1,5 @@
--TEST--
Test for inserting and retrieving encrypted numeric types data
Test for inserting and retrieving encrypted data of numeric types
Use PDOstatement::bindParam with all PDO::PARAM_ types
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
@ -7,7 +7,6 @@ Use PDOstatement::bindParam with all PDO::PARAM_ types
<?php
include 'MsCommon.inc';
include 'AEData.inc';
include 'MsSetup.inc';
$dataTypes = array( "bit", "tinyint", "smallint", "int", "decimal(18,5)", "numeric(10,5)", "float", "real" );

View file

@ -1,5 +1,5 @@
--TEST--
Test for inserting and retrieving encrypted string types data
Test for inserting and retrieving encrypted data of string types
Use PDOstatement::bindParam with all PDO::PARAM_ types
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
@ -7,7 +7,6 @@ Use PDOstatement::bindParam with all PDO::PARAM_ types
<?php
include 'MsCommon.inc';
include 'AEData.inc';
include 'MsSetup.inc';
$dataTypes = array( "char(5)", "varchar(max)", "nchar(5)", "nvarchar(max)" );

View file

@ -5,9 +5,7 @@ Retrieving SQL query contains encrypted filter
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
include 'MsSetup.inc';
include 'MsCommon.inc';
include 'AEData.inc';
try
{
@ -46,7 +44,7 @@ catch( PDOException $e )
// for AE only
echo "\nChecking ciphertext data:\n";
if ( $keystore != "none" )
if ( is_col_enc() )
{
try
{

View file

@ -4,9 +4,7 @@ Test for inserting encrypted fixed size types data and retrieve both encrypted a
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
include 'MsSetup.inc';
include 'MsCommon.inc';
include 'AEData.inc';
try
{
@ -48,7 +46,7 @@ catch( PDOException $e )
}
// for AE only
if ( $keystore != "none" )
if ( is_col_enc() )
{
try
{

View file

@ -4,9 +4,7 @@ Test for inserting encrypted nvarchar data of variable lengths and retrieving en
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
include 'MsSetup.inc';
include 'MsCommon.inc';
include 'AEData.inc';
$testPass = true;
try
@ -44,7 +42,7 @@ catch( PDOException $e )
}
// for AE only
if ( $keystore != "none" )
if ( is_col_enc() )
{
try
{

View file

@ -4,9 +4,7 @@ Test for inserting encrypted varchar data of variable lengths and retrieving enc
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
include 'MsSetup.inc';
include 'MsCommon.inc';
include 'AEData.inc';
$testPass = true;
try
@ -44,7 +42,7 @@ catch( PDOException $e )
}
// for AE only
if ( $keystore != "none" )
if ( is_col_enc() )
{
try
{

View file

@ -1,5 +1,5 @@
--TEST--
Test for inserting and retrieving encrypted string types data
Test for inserting and retrieving encrypted data of string types
No PDO::PARAM_ type specified when binding parameters
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
@ -7,7 +7,6 @@ No PDO::PARAM_ type specified when binding parameters
<?php
include 'MsCommon.inc';
include 'AEData.inc';
include 'MsSetup.inc';
$dataTypes = array( "char(5)", "varchar(max)", "nchar(5)", "nvarchar(max)" );

View file

@ -5,8 +5,6 @@ Test for binding output params for encrypted data for all types
--FILE--
<?php
include 'MsCommon.inc';
include 'MsSetup.inc';
include 'AEData.inc';
$conn = ae_connect();

View file

@ -86,7 +86,7 @@ function IsAEQualified($conn)
$server_ver = sqlsrv_server_info($conn)['SQLServerVersion'];
$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;
}
@ -223,6 +223,8 @@ function getCekName()
case "akv":
$cekName = 'AKVColumnKey';
break;
default:
echo "getCekName: Invalid keystore name.\n";
}
return $cekName;
}
@ -235,11 +237,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 );
}
@ -259,17 +261,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;
@ -293,14 +291,13 @@ 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 $columnMetaArr : array of columnMeta objects, which contain metadata for one column
*/
function create_table( $conn, $tbname, $columnMeta )
function create_table( $conn, $tbname, $columnMetaArr )
{
$dropSql = "IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'" . $tbname . "') AND type in (N'U')) DROP TABLE $tbname";
sqlsrv_query( $conn, $dropSql );
DropTable( $conn, $tbname );
$colDef = "";
foreach ( $columnMeta as $meta )
foreach ( $columnMetaArr as $meta )
{
$colDef = $colDef . $meta->getColDef() . ", ";
}
@ -374,11 +371,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 : SQLSRV API used for executing the insert query
* accepted values: "query", "queryParamsOp", "prepare", "prepareParamsOp"
* @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
@ -458,10 +455,17 @@ function get_insertSql_complete( $tbname, $inputs )
{
$colStr = "INSERT INTO $tbname (";
$valStr = "VALUES (";
if ( empty( $inputs ))
{
echo "get_insertSql_complete: inputs for inserting a row cannot be empty.\n";
return;
}
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 . ", ";
@ -475,13 +479,18 @@ function get_insertSql_complete( $tbname, $inputs )
/**
* @param string $tbname : name of the table for an insert sql
* @param array $input : associative array containing a key value pair of column name and data to put into an insert sql string
* @param array $inputs : associative array containing a key value pair of column name and data to put into an insert sql string
* @return string an insert sql string with "?" placeholders for all values
*/
function get_insertSql_placeholders( $tbname, $inputs )
{
$colStr = "INSERT INTO $tbname (";
$valStr = "VALUES (";
if ( empty( $inputs ))
{
echo "get_insertSql_placeholders: inputs for inserting a row cannot be empty.\n";
return;
}
foreach( $inputs as $key => $value )
{
$colStr .= $key . ", ";
@ -512,6 +521,11 @@ function get_callProcSql_placeholders( $spname, $num )
*/
function get_seq_placeholders( $num )
{
if ( $num < 0 )
{
echo "get_seq_placeholders: num provided for creating a sequence of placeholders cannot be less than 0.\n";
return;
}
$placeholderStr = str_repeat( "?, ", $num );
$placeholderStr = rtrim( $placeholderStr, ", " );
return $placeholderStr;
@ -523,7 +537,8 @@ function get_seq_placeholders( $num )
* @param resource $conn : connection resource
* @param string $tbname : name of the table to fetch from
*/
function fetch_all( $conn, $tbname ) {
function fetch_all( $conn, $tbname )
{
$sql = "SELECT * FROM $tbname";
$stmt = sqlsrv_query( $conn, $sql );
while ( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC ))
@ -533,9 +548,9 @@ function fetch_all( $conn, $tbname ) {
if ( is_object( $value ) )
{
print "$key:\n";
foreach ( $value as $k =>$value )
foreach ( $value as $k =>$v )
{
print ( " $k: $value\n" );
print ( " $k: $v\n" );
}
}
else
@ -545,6 +560,19 @@ function fetch_all( $conn, $tbname ) {
}
/**
* @return bool false if $keystore specified in MsSetup.inc is none, otherwise return true
*/
function is_col_enc()
{
require 'MsSetup.inc';
if ( $keystore == "none" )
return false
else
return true;
}
function GetTempTableName($table = '', $temporary = true)
{
// A temporary table name with the '#' prefix will be automatically
@ -1113,7 +1141,7 @@ function CreateUniqueIndexEx($conn, $tableName, $tableIndex, $colIndex)
function DropTable($conn, $tableName)
{
$stmt = sqlsrv_query($conn, "DROP TABLE [$tableName]");
$stmt = sqlsrv_query($conn, "IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'" . $tableName . "') AND type in (N'U')) DROP TABLE $tableName");
if ($stmt === false)
{
}

View file

@ -1,5 +1,5 @@
--TEST--
Test for inserting and retrieving encrypted datetime types data
Test for inserting and retrieving encrypted data of datetime types
Bind params using sqlsrv_prepare without any sql_type specified
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
@ -7,7 +7,6 @@ Bind params using sqlsrv_prepare without any sql_type specified
<?php
include 'MsCommon.inc';
include 'AEData.inc';
include 'MsSetup.inc';
$dataTypes = array( "date", "datetime", "datetime2", "smalldatetime", "time", "datetimeoffset" );
$conn = ae_connect();
@ -17,7 +16,7 @@ foreach ( $dataTypes as $dataType ) {
// 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

View file

@ -1,5 +1,5 @@
--TEST--
Test for inserting and retrieving encrypted money types data
Test for inserting and retrieving encrypted data of money types
Bind params using sqlsrv_prepare without any sql_type specified
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
@ -7,7 +7,6 @@ Bind params using sqlsrv_prepare without any sql_type specified
<?php
include 'MsCommon.inc';
include 'AEData.inc';
include 'MsSetup.inc';
$dataTypes = array( "smallmoney", "money" );
$conn = ae_connect();
@ -18,7 +17,7 @@ foreach ( $dataTypes as $dataType ) {
// 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
@ -26,7 +25,7 @@ foreach ( $dataTypes as $dataType ) {
$r;
$stmt = insert_row( $conn, $tbname, array( $colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r );
if ( $keystore == "none" )
if ( !is_col_enc() )
{
if ( $r === false )
{
@ -62,7 +61,7 @@ foreach ( $dataTypes as $dataType ) {
}
}
if ( $success )
echo "Test successfully.\n";
echo "Test successfully done.\n";
DropTable( $conn, $tbname );
}
sqlsrv_free_stmt( $stmt );
@ -71,7 +70,7 @@ sqlsrv_close( $conn );
--EXPECT--
Testing smallmoney:
Test successfully.
Test successfully done.
Testing money:
Test successfully.
Test successfully done.

View file

@ -1,5 +1,5 @@
--TEST--
Test for inserting and retrieving encrypted numeric types data
Test for inserting and retrieving encrypted data of numeric types
Bind params using sqlsrv_prepare without any sql_type specified
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
@ -7,7 +7,6 @@ Bind params using sqlsrv_prepare without any sql_type specified
<?php
include 'MsCommon.inc';
include 'AEData.inc';
include 'MsSetup.inc';
$dataTypes = array( "bit", "tinyint", "smallint", "int", "bigint", "decimal(18,5)", "numeric(10,5)", "float", "real" );
$conn = ae_connect();
@ -17,7 +16,7 @@ foreach ( $dataTypes as $dataType ) {
// 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

View file

@ -6,8 +6,6 @@ Retrieving SQL query contains encrypted filter
--FILE--
<?php
include 'MsCommon.inc';
include 'MsSetup.inc';
include 'AEData.inc';
$conn = ae_connect();
@ -47,7 +45,7 @@ sqlsrv_free_stmt( $stmt );
//for AE only
echo "\nChecking ciphertext data:\n";
if ( $keystore != "none" )
if ( is_col_enc() )
{
$conn1 = ae_connect( null, true );
$selectSql = "SELECT SSN, FirstName, LastName, BirthDate FROM $tbname";

View file

@ -5,8 +5,6 @@ Test for inserting encrypted fixed size types data and retrieve both encrypted a
--FILE--
<?php
include 'MsCommon.inc';
include 'MsSetup.inc';
include 'AEData.inc';
$conn = ae_connect();
$testPass = true;
@ -40,7 +38,7 @@ fetch_all( $conn, $tbname );
sqlsrv_free_stmt( $stmt );
// for AE only
if ( $keystore != "none" )
if ( is_col_enc() )
{
$conn1 = connect( null, true );

View file

@ -5,8 +5,6 @@ Test for inserting encrypted nvarchar data of variable lengths and retrieving en
--FILE--
<?php
include 'MsCommon.inc';
include 'MsSetup.inc';
include 'AEData.inc';
$conn = ae_connect();
$testPass = true;
@ -38,7 +36,7 @@ while ( $decrypted_row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC ))
sqlsrv_free_stmt( $stmt );
// for AE only
if ( $keystore != "none" )
if ( is_col_enc() )
{
$conn1 = ae_connect( null, true );
$stmt = sqlsrv_query( $conn1, $selectSql );

View file

@ -5,8 +5,6 @@ Test for inserting encrypted varchar data of variable lengths and retrieving enc
--FILE--
<?php
include 'MsCommon.inc';
include 'MsSetup.inc';
include 'AEData.inc';
$conn = ae_connect();
$testPass = true;
@ -38,7 +36,7 @@ while ( $decrypted_row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC ))
sqlsrv_free_stmt( $stmt );
// for AE only
if ( $keystore != "none" )
if ( is_col_enc() )
{
$conn1 = ae_connect( null, true );
$stmt = sqlsrv_query( $conn1, $selectSql );

View file

@ -1,5 +1,5 @@
--TEST--
Test for inserting and retrieving encrypted datetime types data
Test for inserting and retrieving encrypted data of datetime types
Bind params using sqlsrv_prepare with all sql_type
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
@ -7,7 +7,6 @@ Bind params using sqlsrv_prepare with all sql_type
<?php
include 'MsCommon.inc';
include 'AEData.inc';
include 'MsSetup.inc';
$dataTypes = array( "date", "datetime", "datetime2", "smalldatetime", "time", "datetimeoffset" );
$compatList = array( "date" => array( "SQLSRV_SQLTYPE_DATE", "SQLSRV_SQLTYPE_DATETIME", "SQLSRV_SQLTYPE_DATETIME2", "SQLSRV_SQLTYPE_DATETIMEOFFSET", "SQLSRV_SQLTYPE_NVARCHAR", "SQLSRV_SQLTYPE_SMALLDATETIME", "SQLSRV_SQLTYPE_VARCHAR"),
@ -25,7 +24,7 @@ foreach ( $dataTypes as $dataType ) {
// 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 SQLSRV_SQLTYPE_ constants
@ -38,7 +37,7 @@ foreach ( $dataTypes as $dataType ) {
$r;
$stmt = insert_row( $conn, $tbname, array( $colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r, "prepareParamsOp", $paramOp );
if ( $keystore == "none" )
if ( !is_col_enc() )
{
if ( $r === false )
{
@ -83,7 +82,7 @@ foreach ( $dataTypes as $dataType ) {
sqlsrv_query( $conn, "TRUNCATE TABLE $tbname" );
}
if ( $success )
echo "Test successfully.\n";
echo "Test successfully done.\n";
DropTable( $conn, $tbname );
}
sqlsrv_free_stmt( $stmt );
@ -92,19 +91,19 @@ sqlsrv_close( $conn );
--EXPECT--
Testing date:
Test successfully.
Test successfully done.
Testing datetime:
Test successfully.
Test successfully done.
Testing datetime2:
Test successfully.
Test successfully done.
Testing smalldatetime:
Test successfully.
Test successfully done.
Testing time:
Test successfully.
Test successfully done.
Testing datetimeoffset:
Test successfully.
Test successfully done.

View file

@ -1,5 +1,5 @@
--TEST--
Test for inserting and retrieving encrypted money types data
Test for inserting and retrieving encrypted data of money types
Bind params using sqlsrv_prepare with all sql_type
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
@ -7,7 +7,6 @@ Bind params using sqlsrv_prepare with all sql_type
<?php
include 'MsCommon.inc';
include 'AEData.inc';
include 'MsSetup.inc';
$dataTypes = array( "smallmoney", "money" );
$compatList = array( "smallmoney" => array( 'SQLSRV_SQLTYPE_CHAR', 'SQLSRV_SQLTYPE_DECIMAL', 'SQLSRV_SQLTYPE_FLOAT', 'SQLSRV_SQLTYPE_MONEY', 'SQLSRV_SQLTYPE_NCHAR', 'SQLSRV_SQLTYPE_NUMERIC', 'SQLSRV_SQLTYPE_NVARCHAR', 'SQLSRV_SQLTYPE_REAL', 'SQLSRV_SQLTYPE_SMALLMONEY', 'SQLSRV_SQLTYPE_VARCHAR' ),
@ -21,7 +20,7 @@ foreach ( $dataTypes as $dataType ) {
// 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 SQLSRV_SQLTYPE_ constants
@ -34,7 +33,7 @@ foreach ( $dataTypes as $dataType ) {
$r;
$stmt = insert_row( $conn, $tbname, array( $colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r, "prepareParamsOp", $paramOp );
if ( $keystore == "none" )
if ( !is_col_enc() )
{
if ( $r === false )
{
@ -62,7 +61,7 @@ foreach ( $dataTypes as $dataType ) {
sqlsrv_query( $conn, "TRUNCATE TABLE $tbname" );
}
if ( $success )
echo "Test successfully.\n";
echo "Test successfully done.\n";
DropTable( $conn, $tbname );
}
sqlsrv_free_stmt( $stmt );
@ -71,7 +70,7 @@ sqlsrv_close( $conn );
--EXPECT--
Testing smallmoney:
Test successfully.
Test successfully done.
Testing money:
Test successfully.
Test successfully done.

View file

@ -1,5 +1,5 @@
--TEST--
Test for inserting and retrieving encrypted numeric types data
Test for inserting and retrieving encrypted data of numeric types
Bind params using sqlsrv_prepare with all sql_type
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
@ -7,7 +7,6 @@ Bind params using sqlsrv_prepare with all sql_type
<?php
include 'MsCommon.inc';
include 'AEData.inc';
include 'MsSetup.inc';
$dataTypes = array( "bit", "tinyint", "smallint", "int", "bigint", "decimal(18,5)", "numeric(10,5)", "float", "real" );
$compatList = array( "bit" => array( "SQLSRV_SQLTYPE_BIGINT", "SQLSRV_SQLTYPE_BIT", "SQLSRV_SQLTYPE_CHAR", "SQLSRV_SQLTYPE_DECIMAL", "SQLSRV_SQLTYPE_FLOAT", "SQLSRV_SQLTYPE_INT", "SQLSRV_SQLTYPE_MONEY", "SQLSRV_SQLTYPE_NCHAR", "SQLSRV_SQLTYPE_NUMERIC", "SQLSRV_SQLTYPE_NVARCHAR", "SQLSRV_SQLTYPE_REAL", "SQLSRV_SQLTYPE_SMALLINT", "SQLSRV_SQLTYPE_SMALLMONEY", "SQLSRV_SQLTYPE_TINYINT", "SQLSRV_SQLTYPE_VARCHAR"),
@ -29,7 +28,7 @@ foreach ( $dataTypes as $dataType ) {
// 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 SQLSRV_SQLTYPE_ constants
@ -42,7 +41,7 @@ foreach ( $dataTypes as $dataType ) {
$r;
$stmt = insert_row( $conn, $tbname, array( $colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r, "prepareParamsOp", $paramOp );
if ( $keystore == "none" )
if ( !is_col_enc() )
{
if ( $r === false )
{
@ -96,7 +95,7 @@ foreach ( $dataTypes as $dataType ) {
sqlsrv_query( $conn, "TRUNCATE TABLE $tbname" );
}
if ( $success )
echo "Test successfully.\n";
echo "Test successfully done.\n";
DropTable( $conn, $tbname );
}
sqlsrv_free_stmt( $stmt );
@ -105,28 +104,28 @@ sqlsrv_close( $conn );
--EXPECT--
Testing bit:
Test successfully.
Test successfully done.
Testing tinyint:
Test successfully.
Test successfully done.
Testing smallint:
Test successfully.
Test successfully done.
Testing int:
Test successfully.
Test successfully done.
Testing bigint:
Test successfully.
Test successfully done.
Testing decimal(18,5):
Test successfully.
Test successfully done.
Testing numeric(10,5):
Test successfully.
Test successfully done.
Testing float:
Test successfully.
Test successfully done.
Testing real:
Test successfully.
Test successfully done.

View file

@ -1,5 +1,5 @@
--TEST--
Test for inserting and retrieving encrypted string types data
Test for inserting and retrieving encrypted data of string types
Bind params using sqlsrv_prepare with all sql_type
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
@ -7,7 +7,6 @@ Bind params using sqlsrv_prepare with all sql_type
<?php
include 'MsCommon.inc';
include 'AEData.inc';
include 'MsSetup.inc';
$dataTypes = array( "char(5)", "varchar(max)", "nchar(5)", "nvarchar(max)" );
$compatList = array( "char(5)" => array( "SQLSRV_SQLTYPE_CHAR", "SQLSRV_SQLTYPE_NCHAR", "SQLSRV_SQLTYPE_NVARCHAR", "SQLSRV_SQLTYPE_NTEXT", "SQLSRV_SQLTYPE_TEXT", "SQLSRV_SQLTYPE_VARCHAR"),
@ -23,7 +22,7 @@ foreach ( $dataTypes as $dataType ) {
// 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 SQLSRV_SQLTYPE_ constants
@ -38,7 +37,7 @@ foreach ( $dataTypes as $dataType ) {
if ( $r === false )
{
if ( $keystore == "none" )
if ( !is_col_enc() )
{
$isCompat = false;
foreach ( $compatList[$dataType] as $compatType )
@ -76,7 +75,7 @@ foreach ( $dataTypes as $dataType ) {
sqlsrv_query( $conn, "TRUNCATE TABLE $tbname" );
}
if ( $success )
echo "Test successfully.\n";
echo "Test successfully done.\n";
DropTable( $conn, $tbname );
}
sqlsrv_free_stmt( $stmt );
@ -85,13 +84,13 @@ sqlsrv_close( $conn );
--EXPECT--
Testing char(5):
Test successfully.
Test successfully done.
Testing varchar(max):
Test successfully.
Test successfully done.
Testing nchar(5):
Test successfully.
Test successfully done.
Testing nvarchar(max):
Test successfully.
Test successfully done.

View file

@ -1,5 +1,5 @@
--TEST--
Test for inserting and retrieving encrypted string types data
Test for inserting and retrieving encrypted data of string types
Bind params using sqlsrv_prepare without any sql_type specified
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
@ -7,7 +7,6 @@ Bind params using sqlsrv_prepare without any sql_type specified
<?php
include 'MsCommon.inc';
include 'AEData.inc';
include 'MsSetup.inc';
$dataTypes = array( "char(5)", "varchar(max)", "nchar(5)", "nvarchar(max)" );
$conn = ae_connect();
@ -17,8 +16,7 @@ foreach ( $dataTypes as $dataType ) {
// create table
$tbname = GetTempTableName( "", false );
$tbname = "test_numeric";
$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
@ -32,7 +30,7 @@ foreach ( $dataTypes as $dataType ) {
echo "****Encrypted default type is compatible with encrypted $dataType****\n";
fetch_all( $conn, $tbname );
}
//DropTable( $conn, $tbname );
DropTable( $conn, $tbname );
}
sqlsrv_free_stmt( $stmt );
sqlsrv_close( $conn );

View file

@ -5,8 +5,6 @@ Test for binding output parameter of encrypted values for a sample emplolyee tab
--FILE--
<?php
include 'MsCommon.inc';
include 'MsSetup.inc';
include 'AEData.inc';
$conn = ae_connect();

View file

@ -5,8 +5,6 @@ Test for binding output parameter of encrypted values for all types
--FILE--
<?php
include 'MsCommon.inc';
include 'MsSetup.inc';
include 'AEData.inc';
$conn = ae_connect();