From c5d02cbeec57899b4452631aa85c96f571cbd832 Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Thu, 7 Dec 2017 14:10:10 -0800 Subject: [PATCH] apply review comments 2 --- .../pdo_sqlsrv/MsCommon_mid-refactor.inc | 2 +- .../pdo_sqlsrv/PDO38_FetchBound.phpt | 31 ++++++------------- .../pdo_sqlsrv/pdo_katmai_special_types.phpt | 1 + .../pdo_sqlsrv/pdo_param_output_variants.phpt | 29 ++++------------- .../pdo_simple_update_variants.phpt | 1 - ...dostatement_fetchmode_emulate_prepare.phpt | 5 ++- 6 files changed, 20 insertions(+), 49 deletions(-) diff --git a/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc b/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc index e9752379..27310ae9 100644 --- a/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc +++ b/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc @@ -185,7 +185,7 @@ class ColumnMeta $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 (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) { $cekName = getCekName(); if (stripos($this->dataType, "char") !== false) { diff --git a/test/functional/pdo_sqlsrv/PDO38_FetchBound.phpt b/test/functional/pdo_sqlsrv/PDO38_FetchBound.phpt index 26bf378a..db043fd7 100644 --- a/test/functional/pdo_sqlsrv/PDO38_FetchBound.phpt +++ b/test/functional/pdo_sqlsrv/PDO38_FetchBound.phpt @@ -69,14 +69,9 @@ try { $stmt1->bindColumn('idx', $idx); $stmt1->bindColumn('txt', $txt); $stmt1->execute(); - $boundCols = array(); while ($stmt1->fetch(PDO::FETCH_BOUND)) { - $boundCols[$idx] = $txt; + var_dump(array($idx=>$txt)); } - if (isColEncrypted()) { - ksort($boundCols); - } - var_dump($boundCols); echo "===ALONE===\n"; @@ -127,14 +122,9 @@ try { $stmt1->bindColumn('idx', $col); $stmt1->bindColumn('txt', $col); $stmt1->execute(); - $cols = array(); while ($stmt1->fetch(PDO::FETCH_BOUND)) { - array_push($cols, $col); + var_dump($col); } - if (isColEncrypted()) { - sort($cols); - } - var_dump($cols); // Cleanup dropTable($conn1, $tableName); @@ -159,11 +149,15 @@ array(3) { string(7) "String2" } ===WHILE=== -array(3) { +array(1) { [0]=> string(7) "String0" +} +array(1) { [1]=> string(7) "String1" +} +array(1) { [2]=> string(7) "String2" } @@ -236,11 +230,6 @@ bool(true) bool(true) string(1) "2" ===REBIND/CONFLICT=== -array(3) { - [0]=> - string(7) "String0" - [1]=> - string(7) "String1" - [2]=> - string(7) "String2" -} +string(7) "String0" +string(7) "String1" +string(7) "String2" diff --git a/test/functional/pdo_sqlsrv/pdo_katmai_special_types.phpt b/test/functional/pdo_sqlsrv/pdo_katmai_special_types.phpt index e342b88f..fe779745 100644 --- a/test/functional/pdo_sqlsrv/pdo_katmai_special_types.phpt +++ b/test/functional/pdo_sqlsrv/pdo_katmai_special_types.phpt @@ -106,6 +106,7 @@ function katmaiSparseChar($conn) if ($input !== trim($value1)) { echo "The value is unexpected!\n"; } + // trimming it required since SPARSE is not supported for encrypted columns if (trim($value1) !== trim($value2)) { echo "The values don't match!\n"; } diff --git a/test/functional/pdo_sqlsrv/pdo_param_output_variants.phpt b/test/functional/pdo_sqlsrv/pdo_param_output_variants.phpt index 439753dc..0f87fc3b 100644 --- a/test/functional/pdo_sqlsrv/pdo_param_output_variants.phpt +++ b/test/functional/pdo_sqlsrv/pdo_param_output_variants.phpt @@ -5,11 +5,9 @@ Since output param is not supported for sql_variant columns, this test verifies --FILE-- exec($spCode); @@ -17,7 +15,6 @@ function testReverse($conn) echo "Failed to create the reverse procedure\n"; echo $e->getMessage(); } - try { $stmt = $conn->prepare("{ CALL [$procName] (?) }"); $string = "123456789"; @@ -26,7 +23,7 @@ function testReverse($conn) // Connection with Column Encryption enabled works for non encrypted SQL_VARIANT // Since SQLDescribeParam is called 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 { echo "Does REVERSE work? $string \n"; @@ -35,13 +32,12 @@ function testReverse($conn) //echo "Failed when calling the reverse procedure\n"; $error = $e->getMessage(); 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 { echo "$error\n"; } } } - function createVariantTable($conn, $tableName) { try { @@ -50,7 +46,6 @@ function createVariantTable($conn, $tableName) echo "Failed to create a test table\n"; echo $e->getMessage(); } - $data = "This is to test if sql_variant works with output parameters"; if (!isColEncrypted()) { $tsql = "INSERT INTO [$tableName] ([c1_int], [c2_variant]) VALUES (1, ?)"; @@ -62,36 +57,29 @@ function createVariantTable($conn, $tableName) $intData = 1; $result = $stmt->execute(array($intData, $data)); } - if (! $result) { echo "Failed to insert data\n"; } } - function testOutputParam($conn, $tableName) { // First, create a temporary stored procedure $procName = getProcName('sqlVariant'); - $spArgs = "@p1 int, @p2 sql_variant OUTPUT"; $spCode = "SET @p2 = ( SELECT [c2_variant] FROM $tableName WHERE [c1_int] = @p1 )"; - $conn->exec("CREATE PROC [$procName] ($spArgs) AS BEGIN $spCode END"); - $callArgs = "?, ?"; - // Data to initialize $callResult variable. This variable should be different from // the inserted data in the table $initData = "A short text"; $callResult = $initData; - try { $stmt = $conn->prepare("{ CALL [$procName] ($callArgs)}"); $stmt->bindValue(1, 1); $stmt->bindParam(2, $callResult, PDO::PARAM_STR, 100); $stmt->execute(); 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 { echo "Does SELECT from table work? $callResult \n"; } @@ -101,26 +89,21 @@ function testOutputParam($conn, $tableName) } $error = $e->getMessage(); 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 { echo "$error\n"; } } } - try { // Connect $conn = connect(); - // Test with a simple stored procedure testReverse($conn); - // Now test with another stored procedure $tableName = getTableName(); createVariantTable($conn, $tableName); - testOutputParam($conn, $tableName); - $conn = null; } catch (Exception $e) { echo $e->getMessage(); @@ -128,5 +111,5 @@ try { ?> --EXPECT-- -Test input output parameter with SQL_VARIANT successfully. -Test output parameter with SQL_VARIANT successfully. +Testing input output parameter with SQL_VARIANT is successful. +Testing output parameter with SQL_VARIANT is successful. \ No newline at end of file diff --git a/test/functional/pdo_sqlsrv/pdo_simple_update_variants.phpt b/test/functional/pdo_sqlsrv/pdo_simple_update_variants.phpt index 3657eb40..866c5e2c 100644 --- a/test/functional/pdo_sqlsrv/pdo_simple_update_variants.phpt +++ b/test/functional/pdo_sqlsrv/pdo_simple_update_variants.phpt @@ -82,7 +82,6 @@ function fetchRows($conn, $tableName) $stmt = $conn->query($query); $stmt->setFetchMode(PDO::FETCH_CLASS, 'Food'); - $foodArray = array(); while ($food = $stmt->fetch()) { echo "ID: " . $food->id . " "; echo $food->getFood() . ", "; diff --git a/test/functional/pdo_sqlsrv/pdostatement_fetchmode_emulate_prepare.phpt b/test/functional/pdo_sqlsrv/pdostatement_fetchmode_emulate_prepare.phpt index f8d1e0b9..cccac782 100644 --- a/test/functional/pdo_sqlsrv/pdostatement_fetchmode_emulate_prepare.phpt +++ b/test/functional/pdo_sqlsrv/pdostatement_fetchmode_emulate_prepare.phpt @@ -1,7 +1,7 @@ --TEST-- PDO Fetch Mode Test with emulate prepare --DESCRIPTION-- -Basic verification for "PDOStatement::setFetchMode()�. +Basic verification for PDOStatement::setFetchMode. --ENV-- PHPT_EXEC=true --SKIPIF-- @@ -93,7 +93,6 @@ try { $assocArr['Label'] = $resultset[0]['Label']; $assocArr['Budget'] = $resultset[0]['Budget']; var_dump($assocArr); - //print "$resultset[1][1]\n"; print($resultset[1][1] . "\n"); print($resultset[4][3] . "\n"); print_r($resultset[3]); @@ -178,7 +177,7 @@ try { var_dump($metadata); // Cleanup - DropTable($conn1, $tableName); + dropTable($conn1, $tableName); unset($stmt1); unset($stmt2); unset($stmt3);