Modified files as per review comments
This commit is contained in:
parent
41eec918c9
commit
1daa4f0623
|
@ -31,7 +31,7 @@ this test is very similar to test_scrollable.phpt... might consider removing thi
|
||||||
$options = array('Scrollable' => 'static');
|
$options = array('Scrollable' => 'static');
|
||||||
}
|
}
|
||||||
|
|
||||||
$stmt = AE\executeQueryEx($conn, $query, $options);
|
$stmt = sqlsrv_query($conn, $query, array(), $options);
|
||||||
$rows = sqlsrv_has_rows($stmt);
|
$rows = sqlsrv_has_rows($stmt);
|
||||||
if ($rows != false) {
|
if ($rows != false) {
|
||||||
fatalError("Should be no rows present");
|
fatalError("Should be no rows present");
|
||||||
|
@ -46,7 +46,7 @@ this test is very similar to test_scrollable.phpt... might consider removing thi
|
||||||
print_r(sqlsrv_errors(), true);
|
print_r(sqlsrv_errors(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$stmt = AE\selectFromTable($conn, $tableName);
|
$stmt = sqlsrv_query($conn, $query);
|
||||||
$rows = sqlsrv_has_rows($stmt);
|
$rows = sqlsrv_has_rows($stmt);
|
||||||
if ($rows != false) {
|
if ($rows != false) {
|
||||||
fatalError("Should be no rows present");
|
fatalError("Should be no rows present");
|
||||||
|
|
|
@ -74,10 +74,10 @@ class ColumnMeta
|
||||||
// https://docs.microsoft.com/en-us/sql/relational-databases/security/encryption/always-encrypted-database-engine
|
// https://docs.microsoft.com/en-us/sql/relational-databases/security/encryption/always-encrypted-database-engine
|
||||||
|
|
||||||
$unsupported = array("xml", "timestamp", "image", "ntext", "text", "sql_variant", "hierarchyid", "geography", "geometry", "alias");
|
$unsupported = array("xml", "timestamp", "image", "ntext", "text", "sql_variant", "hierarchyid", "geography", "geometry", "alias");
|
||||||
|
|
||||||
if (stripos($this->options, "identity") !== false) {
|
if (stripos($this->options, "identity") !== false) {
|
||||||
$this->encryptable = false;
|
$this->encryptable = false;
|
||||||
} elseif (in_array(strtolower($this->dataType), $unsupported)) {
|
} elseif (in_array(strtolower($this->dataType), $unsupported)) {
|
||||||
$this->encryptable = false;
|
$this->encryptable = false;
|
||||||
} else {
|
} else {
|
||||||
$this->encryptable = true;
|
$this->encryptable = true;
|
||||||
|
@ -222,17 +222,19 @@ function getKSPpath()
|
||||||
|
|
||||||
$dir_name = realpath(dirname(__FILE__));
|
$dir_name = realpath(dirname(__FILE__));
|
||||||
$ksp = $dir_name . DIRECTORY_SEPARATOR . $name;
|
$ksp = $dir_name . DIRECTORY_SEPARATOR . $name;
|
||||||
if ( strtoupper( substr( php_uname( 's' ), 0, 3 ) ) == 'WIN' ) {
|
if (strtoupper(substr(php_uname('s'), 0, 3)) == 'WIN') {
|
||||||
$arch = 'x64';
|
$arch = 'x64';
|
||||||
if ( PHP_INT_SIZE == 4 ) // running 32 bit
|
if (PHP_INT_SIZE == 4) {
|
||||||
|
// running 32 bit
|
||||||
$arch = '';
|
$arch = '';
|
||||||
|
}
|
||||||
$ksp .= $arch . '.dll';
|
$ksp .= $arch . '.dll';
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
$ksp .= '.so';
|
$ksp .= '.so';
|
||||||
|
}
|
||||||
|
|
||||||
return $ksp;
|
return $ksp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string default column name when a name is not provided in the ColumnMeta class
|
* @return string default column name when a name is not provided in the ColumnMeta class
|
||||||
|
@ -429,7 +431,7 @@ function insertRow($conn, $tbname, $inputs, &$r = null, $api = INSERT_QUERY)
|
||||||
$stmt = sqlsrv_prepare($conn, $insertSql);
|
$stmt = sqlsrv_prepare($conn, $insertSql);
|
||||||
if ($stmt) {
|
if ($stmt) {
|
||||||
$r = sqlsrv_execute($stmt);
|
$r = sqlsrv_execute($stmt);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -443,20 +445,20 @@ function insertRow($conn, $tbname, $inputs, &$r = null, $api = INSERT_QUERY)
|
||||||
array_push($params, $inputs[$key]);
|
array_push($params, $inputs[$key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// use prepare for inserts when AE is enabled
|
// use prepare for inserts when AE is enabled
|
||||||
if (isColEncrypted() || $api == INSERT_PREPARE_PARAMS) {
|
if (isColEncrypted() || $api == INSERT_PREPARE_PARAMS) {
|
||||||
$stmt = sqlsrv_prepare($conn, $insertSql, $params);
|
$stmt = sqlsrv_prepare($conn, $insertSql, $params);
|
||||||
if ($stmt) {
|
if ($stmt) {
|
||||||
$r = sqlsrv_execute($stmt);
|
$r = sqlsrv_execute($stmt);
|
||||||
} else {
|
} else {
|
||||||
fatalError("insertRow: failed to prepare insert query!");
|
fatalError("insertRow: failed to prepare insert query!");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$stmt = sqlsrv_query($conn, $insertSql, $params);
|
$stmt = sqlsrv_query($conn, $insertSql, $params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $stmt;
|
return $stmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -501,18 +503,19 @@ function executeQuery($conn, $sql, $conds = null, $values = null, $options = nul
|
||||||
$sql = $sql . " WHERE $clause ";
|
$sql = $sql . " WHERE $clause ";
|
||||||
} elseif (!empty($conds)) {
|
} elseif (!empty($conds)) {
|
||||||
$sql = $sql . " WHERE $conds ";
|
$sql = $sql . " WHERE $conds ";
|
||||||
}
|
}
|
||||||
|
|
||||||
$stmt = sqlsrv_query($conn, $sql, null, $options);
|
$stmt = sqlsrv_query($conn, $sql, null, $options);
|
||||||
} else {
|
} else {
|
||||||
// with AE enabled, use sqlsrv_prepare() in case there are
|
// with AE enabled, use sqlsrv_prepare() in case there are
|
||||||
// fields with unlimited size
|
// fields with unlimited size
|
||||||
if (empty($conds) || empty($values)) {
|
if (empty($conds)) {
|
||||||
$stmt = sqlsrv_prepare($conn, $sql, null, $options);
|
$stmt = sqlsrv_prepare($conn, $sql, null, $options);
|
||||||
} else {
|
} else {
|
||||||
$sql = $sql . " WHERE $conds ";
|
$sql = $sql . " WHERE $conds ";
|
||||||
|
// pass $values to sqlsrv_prepare whether the array is null, empty or filled
|
||||||
$stmt = sqlsrv_prepare($conn, $sql, $values, $options);
|
$stmt = sqlsrv_prepare($conn, $sql, $values, $options);
|
||||||
}
|
}
|
||||||
if ($stmt) {
|
if ($stmt) {
|
||||||
$r = sqlsrv_execute($stmt);
|
$r = sqlsrv_execute($stmt);
|
||||||
if (!$r) {
|
if (!$r) {
|
||||||
|
@ -681,7 +684,7 @@ function insertTestRow($conn, $tbname, $index)
|
||||||
if (empty($inputArray)) {
|
if (empty($inputArray)) {
|
||||||
fatalError("getInsertSqlComplete: inputs for inserting a row cannot be empty");
|
fatalError("getInsertSqlComplete: inputs for inserting a row cannot be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = null;
|
$result = null;
|
||||||
if (isColEncrypted()) {
|
if (isColEncrypted()) {
|
||||||
$stmt = insertRow($conn, $tbname, $inputArray, $result);
|
$stmt = insertRow($conn, $tbname, $inputArray, $result);
|
||||||
|
@ -693,14 +696,14 @@ function insertTestRow($conn, $tbname, $index)
|
||||||
$col = 1;
|
$col = 1;
|
||||||
foreach ($inputArray as $key => $value) {
|
foreach ($inputArray as $key => $value) {
|
||||||
$colStr .= $key . ", ";
|
$colStr .= $key . ", ";
|
||||||
|
|
||||||
if (is_array($value)) {
|
if (is_array($value)) {
|
||||||
$value = $value[0];
|
$value = $value[0];
|
||||||
// this might be an input to a decimal, a numeric or a binary field
|
// this might be an input to a decimal, a numeric or a binary field
|
||||||
if (isBinary($col)) {
|
if (isBinary($col)) {
|
||||||
$value = "0x" . $value; // annotate the input string as a hex string
|
$value = "0x" . $value; // annotate the input string as a hex string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is_null($value)) {
|
if (is_null($value)) {
|
||||||
$valStr .= "null, ";
|
$valStr .= "null, ";
|
||||||
} elseif (is_string($value) && !isBinary($col)) {
|
} elseif (is_string($value) && !isBinary($col)) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
if(! extension_loaded( "sqlsrv" ) )
|
if (!extension_loaded("sqlsrv"))
|
||||||
die( "skip extension not loaded" );
|
die("skip extension not loaded");
|
||||||
|
|
||||||
require_once('MsCommon.inc');
|
require_once('MsCommon.inc');
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ Fetch data from a prepopulated test table given a custom keystore provider
|
||||||
|
|
||||||
require_once('MsHelper.inc');
|
require_once('MsHelper.inc');
|
||||||
$conn = AE\connect(array('ReturnDatesAsStrings'=>true));
|
$conn = AE\connect(array('ReturnDatesAsStrings'=>true));
|
||||||
if($conn === false) {
|
if ($conn === false) {
|
||||||
echo "Failed to connect.\n";
|
echo "Failed to connect.\n";
|
||||||
print_r(sqlsrv_errors());
|
print_r(sqlsrv_errors());
|
||||||
} else {
|
} else {
|
||||||
|
@ -19,7 +19,7 @@ Fetch data from a prepopulated test table given a custom keystore provider
|
||||||
$ksp_test_table = AE\KSP_TEST_TABLE;
|
$ksp_test_table = AE\KSP_TEST_TABLE;
|
||||||
$tsql = "SELECT * FROM $ksp_test_table";
|
$tsql = "SELECT * FROM $ksp_test_table";
|
||||||
$stmt = sqlsrv_prepare($conn, $tsql);
|
$stmt = sqlsrv_prepare($conn, $tsql);
|
||||||
if (! sqlsrv_execute($stmt)) {
|
if (!sqlsrv_execute($stmt)) {
|
||||||
echo "Failed to fetch data.\n";
|
echo "Failed to fetch data.\n";
|
||||||
print_r(sqlsrv_errors());
|
print_r(sqlsrv_errors());
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ Fetch encrypted data from a prepopulated test table given a custom keystore prov
|
||||||
|
|
||||||
require_once('MsHelper.inc');
|
require_once('MsHelper.inc');
|
||||||
$conn = AE\connect(array('ReturnDatesAsStrings'=>true));
|
$conn = AE\connect(array('ReturnDatesAsStrings'=>true));
|
||||||
if($conn === false) {
|
if ($conn === false) {
|
||||||
fatalError("Failed to connect.\n");
|
fatalError("Failed to connect.\n");
|
||||||
} else {
|
} else {
|
||||||
echo "Connected successfully with ColumnEncryption disabled.\n";
|
echo "Connected successfully with ColumnEncryption disabled.\n";
|
||||||
|
|
|
@ -8,7 +8,7 @@ Connect using a custom keystore provider with some required inputs missing
|
||||||
function connect($server, $connectionInfo)
|
function connect($server, $connectionInfo)
|
||||||
{
|
{
|
||||||
$conn = sqlsrv_connect($server, $connectionInfo);
|
$conn = sqlsrv_connect($server, $connectionInfo);
|
||||||
if($conn === false) {
|
if ($conn === false) {
|
||||||
echo "Failed to connect.\n";
|
echo "Failed to connect.\n";
|
||||||
$errors = sqlsrv_errors();
|
$errors = sqlsrv_errors();
|
||||||
foreach ($errors[0] as $key => $error) {
|
foreach ($errors[0] as $key => $error) {
|
||||||
|
@ -31,20 +31,20 @@ Connect using a custom keystore provider with some required inputs missing
|
||||||
$ksp_name = AE\KSP_NAME;
|
$ksp_name = AE\KSP_NAME;
|
||||||
$encrypt_key = AE\ENCRYPT_KEY;
|
$encrypt_key = AE\ENCRYPT_KEY;
|
||||||
|
|
||||||
echo("Connecting... with column encryption\n");
|
echo "Connecting... with column encryption\n";
|
||||||
$connectionInfo = array("Database"=>$databaseName, "UID"=>$uid, "PWD"=>$pwd,
|
$connectionInfo = array("Database"=>$databaseName, "UID"=>$uid, "PWD"=>$pwd,
|
||||||
"ColumnEncryption"=>"enabled");
|
"ColumnEncryption"=>"enabled");
|
||||||
|
|
||||||
connect($server, $connectionInfo);
|
connect($server, $connectionInfo);
|
||||||
|
|
||||||
echo("Connecting... with an invalid input to CEKeystoreProvider\n");
|
echo "Connecting... with an invalid input to CEKeystoreProvider\n";
|
||||||
$connectionInfo = array("Database"=>$databaseName, "UID"=>$uid, "PWD"=>$pwd,
|
$connectionInfo = array("Database"=>$databaseName, "UID"=>$uid, "PWD"=>$pwd,
|
||||||
"ColumnEncryption"=>"enabled",
|
"ColumnEncryption"=>"enabled",
|
||||||
"CEKeystoreProvider"=>1);
|
"CEKeystoreProvider"=>1);
|
||||||
|
|
||||||
connect($server, $connectionInfo);
|
connect($server, $connectionInfo);
|
||||||
|
|
||||||
echo("Connecting... with an empty path\n");
|
echo "Connecting... with an empty path\n";
|
||||||
$connectionInfo = array("Database"=>$databaseName, "UID"=>$uid, "PWD"=>$pwd,
|
$connectionInfo = array("Database"=>$databaseName, "UID"=>$uid, "PWD"=>$pwd,
|
||||||
"ColumnEncryption"=>"enabled",
|
"ColumnEncryption"=>"enabled",
|
||||||
"CEKeystoreProvider"=>"",
|
"CEKeystoreProvider"=>"",
|
||||||
|
@ -53,7 +53,7 @@ Connect using a custom keystore provider with some required inputs missing
|
||||||
|
|
||||||
connect($server, $connectionInfo);
|
connect($server, $connectionInfo);
|
||||||
|
|
||||||
echo("Connecting... without a name\n");
|
echo "Connecting... without a name\n";
|
||||||
$connectionInfo = array("Database"=>$databaseName, "UID"=>$uid, "PWD"=>$pwd,
|
$connectionInfo = array("Database"=>$databaseName, "UID"=>$uid, "PWD"=>$pwd,
|
||||||
"ColumnEncryption"=>"enabled",
|
"ColumnEncryption"=>"enabled",
|
||||||
"CEKeystoreProvider"=>$ksp_path,
|
"CEKeystoreProvider"=>$ksp_path,
|
||||||
|
@ -61,7 +61,7 @@ Connect using a custom keystore provider with some required inputs missing
|
||||||
|
|
||||||
connect($server, $connectionInfo);
|
connect($server, $connectionInfo);
|
||||||
|
|
||||||
echo("Connecting... with an empty name\n");
|
echo "Connecting... with an empty name\n";
|
||||||
$connectionInfo = array("Database"=>$databaseName, "UID"=>$uid, "PWD"=>$pwd,
|
$connectionInfo = array("Database"=>$databaseName, "UID"=>$uid, "PWD"=>$pwd,
|
||||||
"ColumnEncryption"=>"enabled",
|
"ColumnEncryption"=>"enabled",
|
||||||
"CEKeystoreProvider"=>$ksp_path,
|
"CEKeystoreProvider"=>$ksp_path,
|
||||||
|
@ -70,7 +70,7 @@ Connect using a custom keystore provider with some required inputs missing
|
||||||
|
|
||||||
connect($server, $connectionInfo);
|
connect($server, $connectionInfo);
|
||||||
|
|
||||||
echo("Connecting... without a key\n");
|
echo "Connecting... without a key\n";
|
||||||
$connectionInfo = array("Database"=>$databaseName, "UID"=>$uid, "PWD"=>$pwd,
|
$connectionInfo = array("Database"=>$databaseName, "UID"=>$uid, "PWD"=>$pwd,
|
||||||
"ColumnEncryption"=>"enabled",
|
"ColumnEncryption"=>"enabled",
|
||||||
"CEKeystoreProvider"=>$ksp_path,
|
"CEKeystoreProvider"=>$ksp_path,
|
||||||
|
@ -78,7 +78,7 @@ Connect using a custom keystore provider with some required inputs missing
|
||||||
|
|
||||||
connect($server, $connectionInfo);
|
connect($server, $connectionInfo);
|
||||||
|
|
||||||
echo("Connecting... with all required inputs\n");
|
echo "Connecting... with all required inputs\n";
|
||||||
$connectionInfo = array("Database"=>$databaseName, "UID"=>$uid, "PWD"=>$pwd,
|
$connectionInfo = array("Database"=>$databaseName, "UID"=>$uid, "PWD"=>$pwd,
|
||||||
"ColumnEncryption"=>"enabled",
|
"ColumnEncryption"=>"enabled",
|
||||||
"CEKeystoreProvider"=>$ksp_path,
|
"CEKeystoreProvider"=>$ksp_path,
|
||||||
|
|
|
@ -4,7 +4,7 @@ Test simple insert, fetch and update with ColumnEncryption enabled and a custome
|
||||||
<?php require('skipif_not_ksp.inc'); ?>
|
<?php require('skipif_not_ksp.inc'); ?>
|
||||||
--FILE--
|
--FILE--
|
||||||
<?php
|
<?php
|
||||||
function CreatePatientsTable()
|
function createPatientsTable()
|
||||||
{
|
{
|
||||||
global $conn;
|
global $conn;
|
||||||
$tableName = 'Patients';
|
$tableName = 'Patients';
|
||||||
|
@ -82,13 +82,13 @@ Test simple insert, fetch and update with ColumnEncryption enabled and a custome
|
||||||
|
|
||||||
require_once('MsHelper.inc');
|
require_once('MsHelper.inc');
|
||||||
$conn = AE\connect(array('ReturnDatesAsStrings'=>true));
|
$conn = AE\connect(array('ReturnDatesAsStrings'=>true));
|
||||||
if($conn === false) {
|
if ($conn === false) {
|
||||||
fatalError( "Failed to connect.\n");
|
fatalError( "Failed to connect.\n");
|
||||||
} else {
|
} else {
|
||||||
echo "Connected successfully with ColumnEncryption enabled.\n";
|
echo "Connected successfully with ColumnEncryption enabled.\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
$tableName = CreatePatientsTable();
|
$tableName = createPatientsTable();
|
||||||
|
|
||||||
insertData('748-68-0245', 'Jeannette', 'McDonald', '2002-11-28');
|
insertData('748-68-0245', 'Jeannette', 'McDonald', '2002-11-28');
|
||||||
insertData('795-73-9838', 'John', 'Doe', '2001-05-29');
|
insertData('795-73-9838', 'John', 'Doe', '2001-05-29');
|
||||||
|
@ -103,7 +103,7 @@ Test simple insert, fetch and update with ColumnEncryption enabled and a custome
|
||||||
array('Chang', null, null, SQLSRV_SQLTYPE_NVARCHAR(50)),
|
array('Chang', null, null, SQLSRV_SQLTYPE_NVARCHAR(50)),
|
||||||
array('456-12-5486', null, null, SQLSRV_SQLTYPE_CHAR(11)));
|
array('456-12-5486', null, null, SQLSRV_SQLTYPE_CHAR(11)));
|
||||||
|
|
||||||
$tsql = "UPDATE Patients SET BirthDate = ?, LastName = ? WHERE SSN = ?";
|
$tsql = "UPDATE $tableName SET BirthDate = ?, LastName = ? WHERE SSN = ?";
|
||||||
$stmt = sqlsrv_query($conn, $tsql, $params);
|
$stmt = sqlsrv_query($conn, $tsql, $params);
|
||||||
|
|
||||||
if (!$stmt) {
|
if (!$stmt) {
|
||||||
|
@ -112,7 +112,7 @@ Test simple insert, fetch and update with ColumnEncryption enabled and a custome
|
||||||
|
|
||||||
echo "Update his birthdate too...\n";
|
echo "Update his birthdate too...\n";
|
||||||
$params = array(array('456-12-5486', null, null, SQLSRV_SQLTYPE_CHAR(11)));
|
$params = array(array('456-12-5486', null, null, SQLSRV_SQLTYPE_CHAR(11)));
|
||||||
$tsql = "SELECT SSN, FirstName, LastName, BirthDate FROM Patients WHERE SSN = ?";
|
$tsql = "SELECT SSN, FirstName, LastName, BirthDate FROM $tableName WHERE SSN = ?";
|
||||||
$stmt = sqlsrv_query($conn, $tsql, $params);
|
$stmt = sqlsrv_query($conn, $tsql, $params);
|
||||||
if (!$stmt) {
|
if (!$stmt) {
|
||||||
fatalError("Failed to select with a WHERE clause\n");
|
fatalError("Failed to select with a WHERE clause\n");
|
||||||
|
@ -128,7 +128,7 @@ Test simple insert, fetch and update with ColumnEncryption enabled and a custome
|
||||||
///////////////////////////////////////////
|
///////////////////////////////////////////
|
||||||
$procName = '#phpAEProc1';
|
$procName = '#phpAEProc1';
|
||||||
$spArgs = "@p1 INT, @p2 DATE OUTPUT";
|
$spArgs = "@p1 INT, @p2 DATE OUTPUT";
|
||||||
$spCode = "SET @p2 = (SELECT [BirthDate] FROM Patients WHERE [PatientId] = @p1)";
|
$spCode = "SET @p2 = (SELECT [BirthDate] FROM $tableName WHERE [PatientId] = @p1)";
|
||||||
$stmt = sqlsrv_query($conn, "CREATE PROC [$procName] ($spArgs) AS BEGIN $spCode END");
|
$stmt = sqlsrv_query($conn, "CREATE PROC [$procName] ($spArgs) AS BEGIN $spCode END");
|
||||||
sqlsrv_free_stmt($stmt);
|
sqlsrv_free_stmt($stmt);
|
||||||
|
|
||||||
|
@ -147,7 +147,7 @@ Test simple insert, fetch and update with ColumnEncryption enabled and a custome
|
||||||
///////////////////////////////////////////
|
///////////////////////////////////////////
|
||||||
$procName = '#phpAEProc2';
|
$procName = '#phpAEProc2';
|
||||||
$spArgs = "@p1 INT, @p2 CHAR(11) OUTPUT";
|
$spArgs = "@p1 INT, @p2 CHAR(11) OUTPUT";
|
||||||
$spCode = "SET @p2 = (SELECT [SSN] FROM Patients WHERE [PatientId] = @p1)";
|
$spCode = "SET @p2 = (SELECT [SSN] FROM $tableName WHERE [PatientId] = @p1)";
|
||||||
$stmt = sqlsrv_query($conn, "CREATE PROC [$procName] ($spArgs) AS BEGIN $spCode END");
|
$stmt = sqlsrv_query($conn, "CREATE PROC [$procName] ($spArgs) AS BEGIN $spCode END");
|
||||||
sqlsrv_free_stmt($stmt);
|
sqlsrv_free_stmt($stmt);
|
||||||
|
|
||||||
|
|
|
@ -1,118 +1,96 @@
|
||||||
--TEST--
|
--TEST--
|
||||||
Test using sqlserv_query for binding parameters with ColumnEncryption enabled and a custome keystore provider
|
Test using sqlsrv_query for binding parameters with column encryption and a custom keystore provider
|
||||||
--SKIPIF--
|
--SKIPIF--
|
||||||
<?php require('skipif_not_ksp.inc'); ?>
|
<?php require('skipif_not_ksp.inc'); ?>
|
||||||
--FILE--
|
--FILE--
|
||||||
<?php
|
<?php
|
||||||
function CreatePatientsTable()
|
function createPatientsTable()
|
||||||
{
|
{
|
||||||
global $conn;
|
global $conn;
|
||||||
$tablename = 'Patients';
|
$tableName = 'Patients';
|
||||||
|
|
||||||
$stmt = sqlsrv_query( $conn, "IF OBJECT_ID('$tablename', 'U') IS NOT NULL DROP TABLE $tablename" );
|
|
||||||
sqlsrv_free_stmt( $stmt );
|
|
||||||
|
|
||||||
$tsql = "CREATE TABLE $tablename (
|
$columns = array(new AE\ColumnMeta('int', 'PatientId', 'IDENTITY(1,1) NOT NULL'),
|
||||||
[PatientId] [int] IDENTITY(1,1) NOT NULL,
|
new AE\ColumnMeta('char(11)', 'SSN'),
|
||||||
[SSN] [char](11) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = CustomCEK, ENCRYPTION_TYPE = Deterministic, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256') NOT NULL,
|
new AE\ColumnMeta('nvarchar(50)', 'FirstName'),
|
||||||
[FirstName] [nvarchar](50) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = CustomCEK, ENCRYPTION_TYPE = Deterministic, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256') NULL,
|
new AE\ColumnMeta('nvarchar(50)', 'LastName'),
|
||||||
[LastName] [nvarchar](50) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = CustomCEK, ENCRYPTION_TYPE = Deterministic, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256') NULL,
|
new AE\ColumnMeta('date', 'BirthDate'));
|
||||||
[BirthDate] [date] ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = CustomCEK, ENCRYPTION_TYPE = Randomized, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256') NOT NULL)";
|
$stmt = AE\createTable($conn, $tableName, $columns);
|
||||||
|
if (!$stmt) {
|
||||||
$stmt = sqlsrv_query( $conn, $tsql );
|
fatalError("Failed to create test table!\n");
|
||||||
if (! $stmt )
|
|
||||||
{
|
|
||||||
echo "Failed to create test table!\n";
|
|
||||||
die( print_r( sqlsrv_errors(), true ));
|
|
||||||
}
|
}
|
||||||
|
return $tableName;
|
||||||
return $tablename;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function SelectData()
|
|
||||||
{
|
|
||||||
global $conn, $tablename;
|
|
||||||
|
|
||||||
$stmt = sqlsrv_query($conn, "SELECT * FROM $tablename");
|
|
||||||
|
|
||||||
while ($obj = sqlsrv_fetch_object( $stmt ))
|
function selectData()
|
||||||
{
|
{
|
||||||
|
global $conn, $tableName;
|
||||||
|
|
||||||
|
$stmt = sqlsrv_query($conn, "SELECT * FROM $tableName");
|
||||||
|
|
||||||
|
while ($obj = sqlsrv_fetch_object($stmt)) {
|
||||||
echo $obj->PatientId . "\n";
|
echo $obj->PatientId . "\n";
|
||||||
echo $obj->SSN . "\n";
|
echo $obj->SSN . "\n";
|
||||||
echo $obj->FirstName . "\n";
|
echo $obj->FirstName . "\n";
|
||||||
echo $obj->LastName . "\n";
|
echo $obj->LastName . "\n";
|
||||||
echo $obj->BirthDate . "\n\n";
|
echo $obj->BirthDate . "\n\n";
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function PrintError()
|
|
||||||
{
|
|
||||||
$errors = sqlsrv_errors();
|
|
||||||
foreach ( $errors as $error )
|
|
||||||
{
|
|
||||||
echo " SQLSTATE: " . $error['SQLSTATE'] . "\n";
|
|
||||||
echo " code: " . $error['code'] . "\n";
|
|
||||||
echo " message: " . $error['message'] . "\n\n";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlsrv_configure( 'WarningsReturnAsErrors', 1 );
|
|
||||||
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
|
|
||||||
|
|
||||||
require_once( 'MsSetup.inc' );
|
function printError()
|
||||||
require_once( 'AE_Ksp.inc' );
|
|
||||||
|
|
||||||
$ksp_path = getKSPpath();
|
|
||||||
|
|
||||||
$connectionInfo = array( "Database"=>$databaseName, "UID"=>$uid, "PWD"=>$pwd,
|
|
||||||
"ReturnDatesAsStrings"=>true, "ColumnEncryption"=>'Enabled',
|
|
||||||
"CEKeystoreProvider"=>$ksp_path,
|
|
||||||
"CEKeystoreName"=>$ksp_name,
|
|
||||||
"CEKeystoreEncryptKey"=>$encrypt_key);
|
|
||||||
|
|
||||||
$conn = sqlsrv_connect( $server, $connectionInfo );
|
|
||||||
if( $conn === false )
|
|
||||||
{
|
{
|
||||||
echo "Failed to connect.\n";
|
$errors = sqlsrv_errors();
|
||||||
PrintError();
|
foreach ($errors as $error) {
|
||||||
|
echo " SQLSTATE: " . $error['SQLSTATE'] . "\n";
|
||||||
|
echo " code: " . $error['code'] . "\n";
|
||||||
|
echo " message: " . $error['message'] . "\n\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
sqlsrv_configure('WarningsReturnAsErrors', 1);
|
||||||
|
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
|
||||||
|
|
||||||
|
require_once('MsHelper.inc');
|
||||||
|
$conn = AE\connect(array('ReturnDatesAsStrings'=>true));
|
||||||
|
|
||||||
|
if ($conn === false) {
|
||||||
|
echo "Failed to connect.\n";
|
||||||
|
printError();
|
||||||
|
} else {
|
||||||
echo "Connected successfully with ColumnEncryption enabled.\n\n";
|
echo "Connected successfully with ColumnEncryption enabled.\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
$tablename = CreatePatientsTable();
|
$tableName = createPatientsTable();
|
||||||
|
|
||||||
$tsql = "INSERT INTO $tablename (SSN, FirstName, LastName, BirthDate) VALUES (?, ?, ?, ?)";
|
$tsql = "INSERT INTO $tableName (SSN, FirstName, LastName, BirthDate) VALUES (?, ?, ?, ?)";
|
||||||
$inputs = array( '748-68-0245', 'Jeannette', 'McDonald', '2002-11-28' );
|
$inputs = array('748-68-0245', 'Jeannette', 'McDonald', '2002-11-28');
|
||||||
|
|
||||||
//expects an error in Column Encryption enabled connection
|
// expects an error in Column Encryption enabled connection
|
||||||
print_r( "Using sqlsrv_query and binding parameters with literal values:\n" );
|
print_r("Using sqlsrv_query and binding parameters with literal values:\n");
|
||||||
$stmt = sqlsrv_query( $conn, $tsql, $inputs );
|
$stmt = sqlsrv_query($conn, $tsql, $inputs);
|
||||||
if ( !$stmt)
|
if (!$stmt) {
|
||||||
PrintError();
|
printError();
|
||||||
|
}
|
||||||
//expects an error in Column Encryption enabled connection
|
|
||||||
print_r( "Using sqlsrv_query and binding parameters with parameter arrays and no sqltypes provided:\n" );
|
// expects an error in Column Encryption enabled connection
|
||||||
$stmt = sqlsrv_query( $conn, $tsql, array( array( $inputs[0], SQLSRV_PARAM_IN ),
|
print_r("Using sqlsrv_query and binding parameters with parameter arrays and no sqltypes provided:\n");
|
||||||
array( $inputs[1], SQLSRV_PARAM_IN ),
|
$stmt = sqlsrv_query($conn, $tsql, array(array($inputs[0], SQLSRV_PARAM_IN),
|
||||||
array( $inputs[2], SQLSRV_PARAM_IN ),
|
array($inputs[1], SQLSRV_PARAM_IN),
|
||||||
array( $inputs[3], SQLSRV_PARAM_IN )));
|
array($inputs[2], SQLSRV_PARAM_IN),
|
||||||
if ( !$stmt)
|
array($inputs[3], SQLSRV_PARAM_IN)));
|
||||||
PrintError();
|
if (!$stmt) {
|
||||||
|
printError();
|
||||||
//no error is expected
|
}
|
||||||
print_r( "Using sqlsrv_query and binding parameters with parameter arrays and sqltypes provided:\n" );
|
// no error is expected
|
||||||
$stmt = sqlsrv_query( $conn, $tsql, array( array( $inputs[0], null, null, SQLSRV_SQLTYPE_CHAR(11) ),
|
print_r("Using sqlsrv_query and binding parameters with parameter arrays and sqltypes provided:\n");
|
||||||
array( $inputs[1], null, null, SQLSRV_SQLTYPE_NVARCHAR(50) ),
|
$stmt = sqlsrv_query($conn, $tsql, array(array($inputs[0], null, null, SQLSRV_SQLTYPE_CHAR(11)),
|
||||||
array( $inputs[2], null, null, SQLSRV_SQLTYPE_NVARCHAR(50) ),
|
array($inputs[1], null, null, SQLSRV_SQLTYPE_NVARCHAR(50)),
|
||||||
array( $inputs[3], null, null, SQLSRV_SQLTYPE_DATE ) ));
|
array($inputs[2], null, null, SQLSRV_SQLTYPE_NVARCHAR(50)),
|
||||||
if ( !$stmt)
|
array($inputs[3], null, null, SQLSRV_SQLTYPE_DATE)));
|
||||||
PrintError();
|
if (!$stmt) {
|
||||||
|
printError();
|
||||||
SelectData();
|
}
|
||||||
|
selectData();
|
||||||
|
|
||||||
echo "Done\n";
|
echo "Done\n";
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
|
|
Loading…
Reference in a new issue