apply review comments 2
This commit is contained in:
parent
98d7307860
commit
c5d02cbeec
|
@ -185,7 +185,7 @@ class ColumnMeta
|
||||||
$append = " ";
|
$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
|
// 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 (isColEncrypted() && ($this->encType == "deterministic" || $this->encType == "ramdomized") && $this->isEncryptableType()
|
if (isColEncrypted() && ($this->encType == "deterministic" || $this->encType == "randomized") && $this->isEncryptableType()
|
||||||
&& stripos($this->options, "identity") === false && stripos($this->options, "rowguidcol") === false) {
|
&& stripos($this->options, "identity") === false && stripos($this->options, "rowguidcol") === false) {
|
||||||
$cekName = getCekName();
|
$cekName = getCekName();
|
||||||
if (stripos($this->dataType, "char") !== false) {
|
if (stripos($this->dataType, "char") !== false) {
|
||||||
|
|
|
@ -69,14 +69,9 @@ try {
|
||||||
$stmt1->bindColumn('idx', $idx);
|
$stmt1->bindColumn('idx', $idx);
|
||||||
$stmt1->bindColumn('txt', $txt);
|
$stmt1->bindColumn('txt', $txt);
|
||||||
$stmt1->execute();
|
$stmt1->execute();
|
||||||
$boundCols = array();
|
|
||||||
while ($stmt1->fetch(PDO::FETCH_BOUND)) {
|
while ($stmt1->fetch(PDO::FETCH_BOUND)) {
|
||||||
$boundCols[$idx] = $txt;
|
var_dump(array($idx=>$txt));
|
||||||
}
|
}
|
||||||
if (isColEncrypted()) {
|
|
||||||
ksort($boundCols);
|
|
||||||
}
|
|
||||||
var_dump($boundCols);
|
|
||||||
|
|
||||||
echo "===ALONE===\n";
|
echo "===ALONE===\n";
|
||||||
|
|
||||||
|
@ -127,14 +122,9 @@ try {
|
||||||
$stmt1->bindColumn('idx', $col);
|
$stmt1->bindColumn('idx', $col);
|
||||||
$stmt1->bindColumn('txt', $col);
|
$stmt1->bindColumn('txt', $col);
|
||||||
$stmt1->execute();
|
$stmt1->execute();
|
||||||
$cols = array();
|
|
||||||
while ($stmt1->fetch(PDO::FETCH_BOUND)) {
|
while ($stmt1->fetch(PDO::FETCH_BOUND)) {
|
||||||
array_push($cols, $col);
|
var_dump($col);
|
||||||
}
|
}
|
||||||
if (isColEncrypted()) {
|
|
||||||
sort($cols);
|
|
||||||
}
|
|
||||||
var_dump($cols);
|
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
dropTable($conn1, $tableName);
|
dropTable($conn1, $tableName);
|
||||||
|
@ -159,11 +149,15 @@ array(3) {
|
||||||
string(7) "String2"
|
string(7) "String2"
|
||||||
}
|
}
|
||||||
===WHILE===
|
===WHILE===
|
||||||
array(3) {
|
array(1) {
|
||||||
[0]=>
|
[0]=>
|
||||||
string(7) "String0"
|
string(7) "String0"
|
||||||
|
}
|
||||||
|
array(1) {
|
||||||
[1]=>
|
[1]=>
|
||||||
string(7) "String1"
|
string(7) "String1"
|
||||||
|
}
|
||||||
|
array(1) {
|
||||||
[2]=>
|
[2]=>
|
||||||
string(7) "String2"
|
string(7) "String2"
|
||||||
}
|
}
|
||||||
|
@ -236,11 +230,6 @@ bool(true)
|
||||||
bool(true)
|
bool(true)
|
||||||
string(1) "2"
|
string(1) "2"
|
||||||
===REBIND/CONFLICT===
|
===REBIND/CONFLICT===
|
||||||
array(3) {
|
string(7) "String0"
|
||||||
[0]=>
|
string(7) "String1"
|
||||||
string(7) "String0"
|
string(7) "String2"
|
||||||
[1]=>
|
|
||||||
string(7) "String1"
|
|
||||||
[2]=>
|
|
||||||
string(7) "String2"
|
|
||||||
}
|
|
||||||
|
|
|
@ -106,6 +106,7 @@ function katmaiSparseChar($conn)
|
||||||
if ($input !== trim($value1)) {
|
if ($input !== trim($value1)) {
|
||||||
echo "The value is unexpected!\n";
|
echo "The value is unexpected!\n";
|
||||||
}
|
}
|
||||||
|
// trimming it required since SPARSE is not supported for encrypted columns
|
||||||
if (trim($value1) !== trim($value2)) {
|
if (trim($value1) !== trim($value2)) {
|
||||||
echo "The values don't match!\n";
|
echo "The values don't match!\n";
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,11 +5,9 @@ Since output param is not supported for sql_variant columns, this test verifies
|
||||||
--FILE--
|
--FILE--
|
||||||
<?php
|
<?php
|
||||||
require_once("MsCommon_mid-refactor.inc");
|
require_once("MsCommon_mid-refactor.inc");
|
||||||
|
|
||||||
function testReverse($conn)
|
function testReverse($conn)
|
||||||
{
|
{
|
||||||
$procName = getProcName('sqlReverse');
|
$procName = getProcName('sqlReverse');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$spCode = "CREATE PROC [$procName] @string AS SQL_VARIANT OUTPUT as SELECT @string = REVERSE(CAST(@string AS varchar(30)))";
|
$spCode = "CREATE PROC [$procName] @string AS SQL_VARIANT OUTPUT as SELECT @string = REVERSE(CAST(@string AS varchar(30)))";
|
||||||
$conn->exec($spCode);
|
$conn->exec($spCode);
|
||||||
|
@ -17,7 +15,6 @@ function testReverse($conn)
|
||||||
echo "Failed to create the reverse procedure\n";
|
echo "Failed to create the reverse procedure\n";
|
||||||
echo $e->getMessage();
|
echo $e->getMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$stmt = $conn->prepare("{ CALL [$procName] (?) }");
|
$stmt = $conn->prepare("{ CALL [$procName] (?) }");
|
||||||
$string = "123456789";
|
$string = "123456789";
|
||||||
|
@ -26,7 +23,7 @@ function testReverse($conn)
|
||||||
// Connection with Column Encryption enabled works for non encrypted SQL_VARIANT
|
// Connection with Column Encryption enabled works for non encrypted SQL_VARIANT
|
||||||
// Since SQLDescribeParam is called
|
// Since SQLDescribeParam is called
|
||||||
if (isColEncrypted() && $string === "987654321") {
|
if (isColEncrypted() && $string === "987654321") {
|
||||||
echo "Test input output parameter with SQL_VARIANT successfully.\n";
|
echo "Testing input output parameter with SQL_VARIANT is successful.\n";
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
echo "Does REVERSE work? $string \n";
|
echo "Does REVERSE work? $string \n";
|
||||||
|
@ -35,13 +32,12 @@ function testReverse($conn)
|
||||||
//echo "Failed when calling the reverse procedure\n";
|
//echo "Failed when calling the reverse procedure\n";
|
||||||
$error = $e->getMessage();
|
$error = $e->getMessage();
|
||||||
if (!isColEncrypted() && strpos($error, "Implicit conversion from data type sql_variant to nvarchar is not allowed.") !== false) {
|
if (!isColEncrypted() && strpos($error, "Implicit conversion from data type sql_variant to nvarchar is not allowed.") !== false) {
|
||||||
echo "Test input output parameter with SQL_VARIANT successfully.\n";
|
echo "Testing input output parameter with SQL_VARIANT is successful.\n";
|
||||||
} else {
|
} else {
|
||||||
echo "$error\n";
|
echo "$error\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function createVariantTable($conn, $tableName)
|
function createVariantTable($conn, $tableName)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
@ -50,7 +46,6 @@ function createVariantTable($conn, $tableName)
|
||||||
echo "Failed to create a test table\n";
|
echo "Failed to create a test table\n";
|
||||||
echo $e->getMessage();
|
echo $e->getMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = "This is to test if sql_variant works with output parameters";
|
$data = "This is to test if sql_variant works with output parameters";
|
||||||
if (!isColEncrypted()) {
|
if (!isColEncrypted()) {
|
||||||
$tsql = "INSERT INTO [$tableName] ([c1_int], [c2_variant]) VALUES (1, ?)";
|
$tsql = "INSERT INTO [$tableName] ([c1_int], [c2_variant]) VALUES (1, ?)";
|
||||||
|
@ -62,36 +57,29 @@ function createVariantTable($conn, $tableName)
|
||||||
$intData = 1;
|
$intData = 1;
|
||||||
$result = $stmt->execute(array($intData, $data));
|
$result = $stmt->execute(array($intData, $data));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $result) {
|
if (! $result) {
|
||||||
echo "Failed to insert data\n";
|
echo "Failed to insert data\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function testOutputParam($conn, $tableName)
|
function testOutputParam($conn, $tableName)
|
||||||
{
|
{
|
||||||
// First, create a temporary stored procedure
|
// First, create a temporary stored procedure
|
||||||
$procName = getProcName('sqlVariant');
|
$procName = getProcName('sqlVariant');
|
||||||
|
|
||||||
$spArgs = "@p1 int, @p2 sql_variant OUTPUT";
|
$spArgs = "@p1 int, @p2 sql_variant OUTPUT";
|
||||||
$spCode = "SET @p2 = ( SELECT [c2_variant] FROM $tableName WHERE [c1_int] = @p1 )";
|
$spCode = "SET @p2 = ( SELECT [c2_variant] FROM $tableName WHERE [c1_int] = @p1 )";
|
||||||
|
|
||||||
$conn->exec("CREATE PROC [$procName] ($spArgs) AS BEGIN $spCode END");
|
$conn->exec("CREATE PROC [$procName] ($spArgs) AS BEGIN $spCode END");
|
||||||
|
|
||||||
$callArgs = "?, ?";
|
$callArgs = "?, ?";
|
||||||
|
|
||||||
// Data to initialize $callResult variable. This variable should be different from
|
// Data to initialize $callResult variable. This variable should be different from
|
||||||
// the inserted data in the table
|
// the inserted data in the table
|
||||||
$initData = "A short text";
|
$initData = "A short text";
|
||||||
$callResult = $initData;
|
$callResult = $initData;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$stmt = $conn->prepare("{ CALL [$procName] ($callArgs)}");
|
$stmt = $conn->prepare("{ CALL [$procName] ($callArgs)}");
|
||||||
$stmt->bindValue(1, 1);
|
$stmt->bindValue(1, 1);
|
||||||
$stmt->bindParam(2, $callResult, PDO::PARAM_STR, 100);
|
$stmt->bindParam(2, $callResult, PDO::PARAM_STR, 100);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
if (isColEncrypted() && $callResult === "This is to test if sql_variant works with output parameters") {
|
if (isColEncrypted() && $callResult === "This is to test if sql_variant works with output parameters") {
|
||||||
echo "Test output parameter with SQL_VARIANT successfully.\n";
|
echo "Testing output parameter with SQL_VARIANT is successful.\n";
|
||||||
} else {
|
} else {
|
||||||
echo "Does SELECT from table work? $callResult \n";
|
echo "Does SELECT from table work? $callResult \n";
|
||||||
}
|
}
|
||||||
|
@ -101,26 +89,21 @@ function testOutputParam($conn, $tableName)
|
||||||
}
|
}
|
||||||
$error = $e->getMessage();
|
$error = $e->getMessage();
|
||||||
if (!isColEncrypted() && strpos($error, "Operand type clash: nvarchar(max) is incompatible with sql_variant") !== false) {
|
if (!isColEncrypted() && strpos($error, "Operand type clash: nvarchar(max) is incompatible with sql_variant") !== false) {
|
||||||
echo "Test output parameter with SQL_VARIANT successfully.\n";
|
echo "Testing output parameter with SQL_VARIANT is successful.\n";
|
||||||
} else {
|
} else {
|
||||||
echo "$error\n";
|
echo "$error\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Connect
|
// Connect
|
||||||
$conn = connect();
|
$conn = connect();
|
||||||
|
|
||||||
// Test with a simple stored procedure
|
// Test with a simple stored procedure
|
||||||
testReverse($conn);
|
testReverse($conn);
|
||||||
|
|
||||||
// Now test with another stored procedure
|
// Now test with another stored procedure
|
||||||
$tableName = getTableName();
|
$tableName = getTableName();
|
||||||
createVariantTable($conn, $tableName);
|
createVariantTable($conn, $tableName);
|
||||||
|
|
||||||
testOutputParam($conn, $tableName);
|
testOutputParam($conn, $tableName);
|
||||||
|
|
||||||
$conn = null;
|
$conn = null;
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
echo $e->getMessage();
|
echo $e->getMessage();
|
||||||
|
@ -128,5 +111,5 @@ try {
|
||||||
?>
|
?>
|
||||||
|
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
Test input output parameter with SQL_VARIANT successfully.
|
Testing input output parameter with SQL_VARIANT is successful.
|
||||||
Test output parameter with SQL_VARIANT successfully.
|
Testing output parameter with SQL_VARIANT is successful.
|
|
@ -82,7 +82,6 @@ function fetchRows($conn, $tableName)
|
||||||
$stmt = $conn->query($query);
|
$stmt = $conn->query($query);
|
||||||
|
|
||||||
$stmt->setFetchMode(PDO::FETCH_CLASS, 'Food');
|
$stmt->setFetchMode(PDO::FETCH_CLASS, 'Food');
|
||||||
$foodArray = array();
|
|
||||||
while ($food = $stmt->fetch()) {
|
while ($food = $stmt->fetch()) {
|
||||||
echo "ID: " . $food->id . " ";
|
echo "ID: " . $food->id . " ";
|
||||||
echo $food->getFood() . ", ";
|
echo $food->getFood() . ", ";
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
--TEST--
|
--TEST--
|
||||||
PDO Fetch Mode Test with emulate prepare
|
PDO Fetch Mode Test with emulate prepare
|
||||||
--DESCRIPTION--
|
--DESCRIPTION--
|
||||||
Basic verification for "PDOStatement::setFetchMode()<29>.
|
Basic verification for PDOStatement::setFetchMode.
|
||||||
--ENV--
|
--ENV--
|
||||||
PHPT_EXEC=true
|
PHPT_EXEC=true
|
||||||
--SKIPIF--
|
--SKIPIF--
|
||||||
|
@ -93,7 +93,6 @@ try {
|
||||||
$assocArr['Label'] = $resultset[0]['Label'];
|
$assocArr['Label'] = $resultset[0]['Label'];
|
||||||
$assocArr['Budget'] = $resultset[0]['Budget'];
|
$assocArr['Budget'] = $resultset[0]['Budget'];
|
||||||
var_dump($assocArr);
|
var_dump($assocArr);
|
||||||
//print "$resultset[1][1]\n";
|
|
||||||
print($resultset[1][1] . "\n");
|
print($resultset[1][1] . "\n");
|
||||||
print($resultset[4][3] . "\n");
|
print($resultset[4][3] . "\n");
|
||||||
print_r($resultset[3]);
|
print_r($resultset[3]);
|
||||||
|
@ -178,7 +177,7 @@ try {
|
||||||
var_dump($metadata);
|
var_dump($metadata);
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
DropTable($conn1, $tableName);
|
dropTable($conn1, $tableName);
|
||||||
unset($stmt1);
|
unset($stmt1);
|
||||||
unset($stmt2);
|
unset($stmt2);
|
||||||
unset($stmt3);
|
unset($stmt3);
|
||||||
|
|
Loading…
Reference in a new issue