From f3e31b834d39182bad26cceb5a599861ea375002 Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Thu, 30 Nov 2017 14:37:25 -0800 Subject: [PATCH 1/7] refactor PDO_SQLSRV bind param related tests --- .../pdo_sqlsrv/MsCommon_mid-refactor.inc | 4 +- .../pdo_sqlsrv/PDO100_InsertNulls.phpt | 123 ++++--- .../pdo_sqlsrv/PDO102_MaxOutputParams.phpt | 61 +--- .../pdo_sqlsrv/PDO32_StmtInterface.phpt | 67 ++-- .../pdo_sqlsrv/PDO38_FetchBound.phpt | 153 ++++----- .../functional/pdo_sqlsrv/PDO51_FetchLOB.phpt | 159 ++++----- .../pdo_sqlsrv/PDO61_BindColumn1.phpt | 201 ++++++----- .../pdo_sqlsrv/PDO62_BindColumn2.phpt | 131 ++++--- .../pdo_sqlsrv/PDO63_BindParam1.phpt | 79 ++--- .../pdo_sqlsrv/PDO64_BindParam2.phpt | 185 +++++----- .../pdo_sqlsrv/PDO65_BindValue1.phpt | 85 ++--- .../pdo_sqlsrv/PDO66_BindValue2.phpt | 278 +++++++-------- .../pdo_sqlsrv/PDO67_BindTruncation.phpt | 177 ++++------ ...ement_bindParam_inout_emulate_prepare.phpt | 36 +- ...ment_bindParam_output_emulate_prepare.phpt | 40 +-- .../pdo_fetch_variants_diff_styles.phpt | 286 ++++++++-------- .../pdo_sqlsrv/pdo_katmai_special_types.phpt | 233 +++++++------ .../pdo_param_output_select_variant.phpt | 109 +++--- .../pdo_sqlsrv/pdo_param_output_variants.phpt | 173 +++++----- .../pdo_sqlsrv/pdo_prepare_attribute.phpt | 68 ++-- .../pdo_simple_update_variants.phpt | 170 +++++----- .../pdo_utf8_stored_proc_unicode_chars.phpt | 96 +++--- .../pdostatement_bindcolumn_odd_types.phpt | 32 +- ...dostatement_fetchmode_emulate_prepare.phpt | 319 ++++++++++-------- .../test_encoding_UTF8_emulate_prepare.phpt | 159 ++++----- 25 files changed, 1576 insertions(+), 1848 deletions(-) diff --git a/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc b/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc index ca99ae8b..f235ef74 100644 --- a/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc +++ b/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc @@ -151,7 +151,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->isEncryptableType() && stripos($this->options, "identity") === false) { + if (isColEncrypted() && $this->isEncryptableType() && stripos($this->options, "identity") === false && stripos($this->options, "rowguidcol") === false) { $cekName = getCekName(); if (stripos($this->dataType, "char") !== false) { $append .= "COLLATE Latin1_General_BIN2 "; @@ -168,7 +168,7 @@ class ColumnMeta */ public function isEncryptableType() { - $unsupportedTypes = array("money", "smallmoney", "image", "ntext", "text", "xml", "sql_variant"); + $unsupportedTypes = array("money", "smallmoney", "image", "ntext", "text", "xml", "sql_variant", "timestamp", "geography", "geometry", "hierarchyid"); if (!$this->forceEncrypt && in_array(strtolower($this->dataType), $unsupportedTypes)) { return false; } else { diff --git a/test/functional/pdo_sqlsrv/PDO100_InsertNulls.phpt b/test/functional/pdo_sqlsrv/PDO100_InsertNulls.phpt index 0f3b1a52..b450e4bf 100644 --- a/test/functional/pdo_sqlsrv/PDO100_InsertNulls.phpt +++ b/test/functional/pdo_sqlsrv/PDO100_InsertNulls.phpt @@ -5,74 +5,82 @@ Test inserting nulls into nullable columns --ENV-- PHPT_EXEC=true --SKIPIF-- - + --FILE-- "int", + "c2_tinyint" => "tinyint", + "c3_smallint" => "smallint", + "c4_bigint" => "bigint", + "c5_bit" => "bit", + "c6_float" => "float", + "c7_real" => "real", + "c8_decimal" => "decimal(28,4)", + "c9_numeric" => "numeric(32,4)", + "c10_money" => "money", + "c11_smallmoney" => "smallmoney", + "c12_char" => "char(512)", + "c13_varchar" => "varchar(512)", + "c14_varchar_max" => "varchar(max)", + "c15_nchar" => "nchar(512)", + "c16_nvarchar" => "nvarchar(512)", + "c17_nvarchar_max" => "nvarchar(max)", + "c18_text" => "text", + "c19_ntext" => "ntext", + "c20_binary" => "binary(512)", + "c21_varbinary" => "varbinary(512)", + "c22_varbinary_max" => "varbinary(max)", + "c23_image" => "image", + "c24_uniqueidentifier" => "uniqueidentifier", + "c25_datetime" => "datetime", + "c26_smalldatetime" => "smalldatetime", + "c27_timestamp" => "timestamp", + "c28_xml" => "xml"); + createTable($conn, $tableName, $dataType); - $conn = Connect(); + $stmt = $conn->query("SELECT [TABLE_NAME],[COLUMN_NAME],[IS_NULLABLE] FROM [INFORMATION_SCHEMA].[COLUMNS] WHERE [TABLE_NAME] = '$tableName'"); - DropTable($conn, $tableName); - - CreateTable($conn, $tableName); - - $stmt = $conn->query(<<fetch(PDO::FETCH_ASSOC)) - { - Trace($row['COLUMN_NAME'] . ": " . $row['IS_NULLABLE'] . "\n"); - + while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $stmt2 = $conn->prepare("INSERT INTO [$tableName] ([" . $row['COLUMN_NAME'] . "]) VALUES (:p1)"); - if (strpos($row['COLUMN_NAME'], "timestamp") !== false) continue; + if (strpos($row['COLUMN_NAME'], "timestamp") !== false) { + continue; + } - if (($row['IS_NULLABLE'] == 'YES') && (strpos($row['COLUMN_NAME'], "binary") !== false)) - { - if ($bindType == PDO::PARAM_LOB) - { + if (($row['IS_NULLABLE'] == 'YES') && (strpos($row['COLUMN_NAME'], "binary") !== false)) { + if ($bindType == PDO::PARAM_LOB) { $stmt2->setAttribute(PDO::SQLSRV_ATTR_ENCODING, PDO::SQLSRV_ENCODING_BINARY); $stmt2->bindValue(":p1", null, $bindType); - } - else if ($bindType == PDO::PARAM_STR) - { + } elseif ($bindType == PDO::PARAM_STR) { $stmt2->bindParam(":p1", $outvar, $bindType, null, PDO::SQLSRV_ENCODING_BINARY); } - } - else - { + } else { $stmt2->bindParam(":p1", $outvar); } $stmt2->execute(); - if ($stmt2->errorCode() !== '00000') - { + if ($stmt2->errorCode() !== '00000') { print_r($stmt2->errorInfo()); - $failed = true; + $failed = true; } } - DropTable($conn, $tableName); - + dropTable($conn, $tableName); return($failed); } @@ -82,32 +90,19 @@ SQL // Repro // //-------------------------------------------------------------------- -function Repro() -{ - $failed = null; - - $testName = "PDO - Insert Nulls"; - - StartTest($testName); - - try - { - $failed |= InsertNullsTest(PDO::PARAM_LOB); - $failed |= InsertNullsTest(PDO::PARAM_STR); - } - catch (Exception $e) - { - echo $e->getMessage(); - } - - if ($failed) - FatalError("Possible Regression: Could not insert NULL"); - - EndTest($testName); +try { + $failed = false; + $failed |= insertNullsTest(PDO::PARAM_LOB); + $failed |= insertNullsTest(PDO::PARAM_STR); +} catch (Exception $e) { + echo $e->getMessage(); +} +if ($failed) { + FatalError("Possible Regression: Could not insert NULL"); +} else { + echo "Test 'PDO - Insert Nulls' completed successfully.\n"; } - -Repro(); ?> --EXPECT-- -Test "PDO - Insert Nulls" completed successfully. +Test 'PDO - Insert Nulls' completed successfully. diff --git a/test/functional/pdo_sqlsrv/PDO102_MaxOutputParams.phpt b/test/functional/pdo_sqlsrv/PDO102_MaxOutputParams.phpt index a80d84d0..67ef5cbf 100644 --- a/test/functional/pdo_sqlsrv/PDO102_MaxOutputParams.phpt +++ b/test/functional/pdo_sqlsrv/PDO102_MaxOutputParams.phpt @@ -5,50 +5,34 @@ Fetch data as VARCHAR(MAX) --ENV-- PHPT_EXEC=true --SKIPIF-- - + --FILE-- query("CREATE PROC [$procName] (@OUT varchar(80) output) AS BEGIN + SET NOCOUNT ON; select @OUT = '$expected'; return(0) END"); $sql = "execute EXEC_TEST ?"; - $stmt = $conn->prepare($sql); - - if ($length) - { - $stmt->bindParam(1, $outstr, PDO::PARAM_STR, 10); - } - else - { - $stmt->bindParam(1, $outstr, PDO::PARAM_STR, 3); - } - + $stmt->bindParam(1, $outstr, PDO::PARAM_STR, $length); $stmt->execute(); echo "Expected: $expected Received: $outstr\n"; - if ($outstr !== $expected) - { + if ($outstr !== $expected) { print_r($stmt->errorInfo()); + dropProc($conn, $procName); return(-1); } - + dropProc($conn, $procName); return(0); } @@ -57,26 +41,15 @@ function MaxOutputParamsTest($expected, $length) // Repro // //-------------------------------------------------------------------- -function Repro() -{ - $failed = null; +$failed = null; - $testName = "PDO - Max Output Params Test"; +$failed |= maxOutputParamsTest("abc", 3); +$failed |= maxOutputParamsTest("abc", 10); - StartTest($testName); - - $failed |= MaxOutputParamsTest("abc", null); - $failed |= MaxOutputParamsTest("abc", -1); - - if ($failed) - FatalError("Possible Regression: Value returned as VARCHAR(MAX) truncated"); - - EndTest($testName); +if ($failed) { + FatalError("Possible Regression: Value returned as VARCHAR(MAX) truncated"); } - -Repro(); ?> --EXPECT-- Expected: abc Received: abc Expected: abc Received: abc -Test "PDO - Max Output Params Test" completed successfully. diff --git a/test/functional/pdo_sqlsrv/PDO32_StmtInterface.phpt b/test/functional/pdo_sqlsrv/PDO32_StmtInterface.phpt index ac42caa6..06ca54d1 100644 --- a/test/functional/pdo_sqlsrv/PDO32_StmtInterface.phpt +++ b/test/functional/pdo_sqlsrv/PDO32_StmtInterface.phpt @@ -5,30 +5,26 @@ Verifies the compliance of the PDOStatement API Interface. --ENV-- PHPT_EXEC=true --SKIPIF-- - + --FILE-- "varchar(10)")); + $stmt1 = $conn1->query("SELECT * FROM [$tableName]"); - $testName = "PDOStatement - Interface"; - StartTest($testName); - - $conn1 = Connect(); - CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, val VARCHAR(10)", null); - $stmt1 = ExecuteQuery($conn1, "SELECT * FROM [$tableName]"); - - CheckInterface($stmt1); - $stmt1 = null; - $conn1 = null; - - EndTest($testName); + checkInterface($stmt1); + unset($stmt1); + unset($conn1); + echo "Test successfully completed\n"; +} catch (Exception $e) { + echo $e->getMessage(); } -function CheckInterface($stmt) +function checkInterface($stmt) { $expected = array( 'errorCode' => true, @@ -55,46 +51,21 @@ function CheckInterface($stmt) ); $classname = get_class($stmt); $methods = get_class_methods($classname); - foreach ($methods as $k => $method) - { - if (isset($expected[$method])) - { + foreach ($methods as $k => $method) { + if (isset($expected[$method])) { unset($expected[$method]); unset($methods[$k]); } } - if (!empty($expected)) - { + if (!empty($expected)) { printf("Dumping missing class methods\n"); var_dump($expected); } - if (!empty($methods)) - { + if (!empty($methods)) { printf("Found more methods than expected, dumping list\n"); var_dump($methods); } } - - -//-------------------------------------------------------------------- -// Repro -// -//-------------------------------------------------------------------- -function Repro() -{ - - try - { - StmtInfo(); - } - catch (Exception $e) - { - echo $e->getMessage(); - } -} - -Repro(); - ?> --EXPECT-- -Test "PDOStatement - Interface" completed successfully. \ No newline at end of file +Test successfully completed diff --git a/test/functional/pdo_sqlsrv/PDO38_FetchBound.phpt b/test/functional/pdo_sqlsrv/PDO38_FetchBound.phpt index 8f6c79d8..e241a8a3 100644 --- a/test/functional/pdo_sqlsrv/PDO38_FetchBound.phpt +++ b/test/functional/pdo_sqlsrv/PDO38_FetchBound.phpt @@ -5,33 +5,27 @@ Verification for "PDOStatenent::fetch(PDO::FETCH_BOUND)". --ENV-- PHPT_EXEC=true --SKIPIF-- - + --FILE-- "varchar(10)", "val2" => "varchar(16)")); + $data = array(array('10', 'Abc', 'zxy'), + array('20', 'Def', 'wvu'), + array('30', 'Ghi', 'tsr'), + array('40', 'Jkl', 'qpo'), + array('50', 'Mno', 'nml'), + array('60', 'Pqr', 'kji')); // Insert using question mark placeholders $stmt1 = PrepareQuery($conn1, "INSERT INTO [$tableName] VALUES(?, ?, ?)"); - foreach ($data as $row) - { + foreach ($data as $row) { $stmt1->execute($row); } unset($stmt1); @@ -40,37 +34,42 @@ function Fetch() $stmt2 = PrepareQuery($conn1, "SELECT COUNT(id) FROM [$tableName]"); $stmt2->execute(); $num = $stmt2->fetchColumn(); - echo 'There are ' . $num . " rows in the table.\n"; + echo "There are $num rows in the table.\n"; $stmt2->closeCursor(); // Insert using named parameters - $stmt1 = PrepareQuery($conn1, "INSERT INTO [$tableName] VALUES(:first, :second, :third)"); - foreach ($data as $row) - { + $stmt1 = $conn1->prepare("INSERT INTO [$tableName] VALUES(:first, :second, :third)"); + foreach ($data as $row) { $stmt1->execute(array(':first'=>($row[0] + 5), ':second'=>$row[1], ':third'=>$row[2])); } unset($stmt1); $stmt2->execute(); $num = $stmt2->fetchColumn(); - echo 'There are ' . $num . " rows in the table.\n"; + echo "There are $num rows in the table.\n"; - $dataCols = "idx, txt"; - CreateTableEx($conn1, $tableName, "idx int NOT NULL PRIMARY KEY, txt VARCHAR(20)", null); - InsertRowEx($conn1, $tableName, $dataCols, "0, 'String0'", null); - InsertRowEx($conn1, $tableName, $dataCols, "1, 'String1'", null); - InsertRowEx($conn1, $tableName, $dataCols, "2, 'String2'", null); + createTable($conn1, $tableName, array(new ColumnMeta("int", "idx", "NOT NULL PRIMARY KEY"), "txt" => "varchar(20)")); + insertRow($conn1, $tableName, array("idx" => 0, "txt" => 'String0')); + insertRow($conn1, $tableName, array("idx" => 1, "txt" => 'String1')); + insertRow($conn1, $tableName, array("idx" => 2, "txt" => 'String2')); // Testing with prepared query - $stmt1 = PrepareQuery($conn1, "SELECT COUNT(idx) FROM [$tableName]"); - + $stmt1 = $conn1->prepare("SELECT COUNT(idx) FROM [$tableName]"); $stmt1->execute(); var_dump($stmt1->fetchColumn()); unset($stmt1); - $stmt1 = PrepareQuery($conn1, "SELECT idx, txt FROM [$tableName] ORDER BY idx"); + if (!isColEncrypted()) { + $stmt1 = PrepareQuery($conn1, "SELECT idx, txt FROM [$tableName] ORDER BY idx"); + } else { + // ORDER BY does not work on encrypted columns + $stmt1 = PrepareQuery($conn1, "SELECT idx, txt FROM [$tableName]"); + } $stmt1->execute(); $data = $stmt1->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_UNIQUE); + if (isColEncrypted()) { + ksort($data); + } var_dump($data); echo "===WHILE===\n"; @@ -78,34 +77,35 @@ function Fetch() $stmt1->bindColumn('idx', $idx); $stmt1->bindColumn('txt', $txt); $stmt1->execute(); - while ($stmt1->fetch(PDO::FETCH_BOUND)) - { - var_dump(array($idx=>$txt)); + $boundCols = array(); + while ($stmt1->fetch(PDO::FETCH_BOUND)) { + $boundCols[$idx] = $txt; } + if (isColEncrypted()) { + ksort($boundCols); + } + var_dump($boundCols); echo "===ALONE===\n"; - $stmt2 = PrepareQuery($conn1, "SELECT txt FROM [$tableName] WHERE idx=:inp"); + $stmt2 = $conn1->prepare("SELECT txt FROM [$tableName] WHERE idx=:inp"); $stmt2->bindParam(':inp', $idx); // by foreign name - $stmt3 = PrepareQuery($conn1, "SELECT idx FROM [$tableName] WHERE txt=:txt"); + $stmt3 = $conn1->prepare("SELECT idx FROM [$tableName] WHERE txt=:txt"); $stmt3->bindParam(':txt', $txt); // using same name - foreach($data as $idx => $txt) - { + foreach ($data as $idx => $txt) { var_dump(array($idx=>$txt)); var_dump($stmt2->execute()); - if ($idx == 0) - { // bindColumn()s after execute() has been called at least once + if ($idx == 0) { // bindColumn()s after execute() has been called at least once $stmt2->bindColumn('txt', $col1); } var_dump($stmt2->fetch(PDO::FETCH_BOUND)); $stmt2->closeCursor(); var_dump($stmt3->execute()); - if ($idx == 0) - { // bindColumn()s after execute() has been called at least once + if ($idx == 0) { // bindColumn()s after execute() has been called at least once $stmt3->bindColumn('idx', $col2); } var_dump($stmt3->fetch(PDO::FETCH_BOUND)); @@ -117,8 +117,7 @@ function Fetch() echo "===REBIND/SAME===\n"; $stmt3->bindColumn('idx', $col1); - foreach($data as $idx => $txt) - { + foreach ($data as $idx => $txt) { var_dump(array($idx=>$txt)); var_dump($stmt2->execute()); var_dump($stmt2->fetch(PDO::FETCH_BOUND)); @@ -136,42 +135,24 @@ function Fetch() $stmt1->bindColumn('idx', $col1); $stmt1->bindColumn('txt', $col1); $stmt1->execute(); - while($stmt1->fetch(PDO::FETCH_BOUND)) - { - var_dump($col1); + $col1s = array(); + while ($stmt1->fetch(PDO::FETCH_BOUND)) { + array_push($col1s, $col1); } - + if (isColEncrypted()) { + sort($col1s); + } + var_dump($col1s); // Cleanup - DropTable($conn1, $tableName); - $stmt1 = null; - $stmt2 = null; - $stmt3 = null; - $conn1 = null; - - EndTest($testName); + dropTable($conn1, $tableName); + unset($stmt1); + unset($stmt2); + unset($stmt3); + unset($conn1); +} catch (Exception $e) { + echo $e->getMessage(); } - - -//-------------------------------------------------------------------- -// Repro -// -//-------------------------------------------------------------------- -function Repro() -{ - - try - { - Fetch(); - } - catch (Exception $e) - { - echo $e->getMessage(); - } -} - -Repro(); - ?> --EXPECT-- There are 6 rows in the table. @@ -186,15 +167,11 @@ array(3) { string(7) "String2" } ===WHILE=== -array(1) { +array(3) { [0]=> string(7) "String0" -} -array(1) { [1]=> string(7) "String1" -} -array(1) { [2]=> string(7) "String2" } @@ -267,7 +244,11 @@ bool(true) bool(true) string(1) "2" ===REBIND/CONFLICT=== -string(7) "String0" -string(7) "String1" -string(7) "String2" -Test "PDO Statement - Fetch Bound" completed successfully. \ No newline at end of file +array(3) { + [0]=> + string(7) "String0" + [1]=> + string(7) "String1" + [2]=> + string(7) "String2" +} diff --git a/test/functional/pdo_sqlsrv/PDO51_FetchLOB.phpt b/test/functional/pdo_sqlsrv/PDO51_FetchLOB.phpt index a433e04c..80719e45 100644 --- a/test/functional/pdo_sqlsrv/PDO51_FetchLOB.phpt +++ b/test/functional/pdo_sqlsrv/PDO51_FetchLOB.phpt @@ -5,119 +5,88 @@ Verification for LOB handling. --ENV-- PHPT_EXEC=true --SKIPIF-- - + --FILE-- getMessage(); } -function FetchLob($offset, $conn, $table, $sqlType, $data1, $data2) +function fetchLob($offset, $conn, $table, $sqlType, $data1, $data2) { - $id = NULL; - $label = NULL; + $id = null; + $label = null; - CreateTableEx($conn, $table, "id int NOT NULL PRIMARY KEY, label $sqlType", null); - InsertRowEx($conn, $table, "id, label", "$data1, '$data2'", null); + createTable($conn, $table, array(new ColumnMeta("int", "id", "NOT NULL PRIMARY KEY"), "label" => $sqlType)); + insertRow($conn, $table, array("id" => $data1, "label" => $data2)); - // Check data fetched with PDO::FETCH_BOUND - $stmt = ExecuteQuery($conn, "SELECT * FROM [$table]"); - if (!$stmt->bindColumn(1, $id, PDO::PARAM_INT)) - { - LogInfo($offset, "Cannot bind integer column"); - } - if (!$stmt->bindColumn(2, $label, PDO::PARAM_LOB)) - { - LogInfo($offset, "Cannot bind LOB column"); - } - if (!$stmt->fetch(PDO::FETCH_BOUND)) - { - LogInfo($offset, "Cannot fetch bound data"); - } - if ($id != $data1) - { - LogInfo($offset, "ID data corruption: [$id] instead of [$data1]"); - } - if ($label != $data2) - { - LogInfo($offset, "Label data corruption: [$label] instead of [$data2]"); - } - unset($stmt); - unset($label); + // Check data fetched with PDO::FETCH_BOUND + $stmt = $conn->query("SELECT * FROM [$table]"); + if (!$stmt->bindColumn(1, $id, PDO::PARAM_INT)) { + logInfo($offset, "Cannot bind integer column"); + } + if (!$stmt->bindColumn(2, $label, PDO::PARAM_LOB)) { + logInfo($offset, "Cannot bind LOB column"); + } + if (!$stmt->fetch(PDO::FETCH_BOUND)) { + logInfo($offset, "Cannot fetch bound data"); + } + if ($id != $data1) { + logInfo($offset, "ID data corruption: [$id] instead of [$data1]"); + } + if ($label != $data2) { + logInfo($offset, "Label data corruption: [$label] instead of [$data2]"); + } + unset($stmt); + unset($label); - // Check data fetched with PDO::FETCH_ASSOC - $stmt = ExecuteQuery($conn, "SELECT * FROM [$table]"); - $refData = $stmt->fetch(PDO::FETCH_ASSOC); - if ($refData['id'] != $data1) - { - $id = $refData['id']; - LogInfo($offset, "ID data corruption: [$id] instead of [$data1]"); - - } - if ($refData['label'] != $data2) - { - $label = $refData['label']; - LogInfo($offset, "Label data corruption: [$label] instead of [$data2]"); - } - unset($stmt); - unset($refData); + // Check data fetched with PDO::FETCH_ASSOC + $stmt = $conn->query("SELECT * FROM [$table]"); + $refData = $stmt->fetch(PDO::FETCH_ASSOC); + if ($refData['id'] != $data1) { + $id = $refData['id']; + logInfo($offset, "ID data corruption: [$id] instead of [$data1]"); + } + if ($refData['label'] != $data2) { + $label = $refData['label']; + logInfo($offset, "Label data corruption: [$label] instead of [$data2]"); + } + unset($stmt); + unset($refData); } -function LogInfo($offset, $msg) +function logInfo($offset, $msg) { - printf("[%03d] %s\n", $offset, $msg); + printf("[%03d] %s\n", $offset, $msg); } - -//-------------------------------------------------------------------- -// Repro -// -//-------------------------------------------------------------------- -function Repro() -{ - - try - { - LobTest(); - } - catch (Exception $e) - { - echo $e->getMessage(); - } -} - -Repro(); - ?> --EXPECT-- -Test "PDO Statement - Fetch LOB" completed successfully. \ No newline at end of file +Test "PDO Statement - Fetch LOB" completed successfully. diff --git a/test/functional/pdo_sqlsrv/PDO61_BindColumn1.phpt b/test/functional/pdo_sqlsrv/PDO61_BindColumn1.phpt index f760cea6..31976354 100644 --- a/test/functional/pdo_sqlsrv/PDO61_BindColumn1.phpt +++ b/test/functional/pdo_sqlsrv/PDO61_BindColumn1.phpt @@ -5,124 +5,124 @@ Verification for "PDOStatement::bindColumn". --ENV-- PHPT_EXEC=true --SKIPIF-- - + --FILE-- "varchar(20)")); + insertRow($conn1, $tableName, array("idx" => 0, "txt" => "String0")); + insertRow($conn1, $tableName, array("idx" => 1, "txt" => "String1")); + insertRow($conn1, $tableName, array("idx" => 2, "txt" => "String2")); + insertRow($conn1, $tableName, array("idx" => 3, "txt" => "String3")); - $conn1 = Connect(); + // Testing with prepared query + logInfo(1, "Testing fetchColumn() ..."); + $stmt1 = $conn1->query("SELECT COUNT(idx) FROM [$tableName]"); + var_dump($stmt1->fetchColumn()); + unset($stmt1); - // Prepare test table - $dataCols = "idx, txt"; - CreateTableEx($conn1, $tableName, "idx int NOT NULL PRIMARY KEY, txt VARCHAR(20)", null); - InsertRowEx($conn1, $tableName, $dataCols, "0, 'String0'", null); - InsertRowEx($conn1, $tableName, $dataCols, "1, 'String1'", null); - InsertRowEx($conn1, $tableName, $dataCols, "2, 'String2'", null); - InsertRowEx($conn1, $tableName, $dataCols, "3, 'String3'", null); + logInfo(2, "Testing fetchAll() ..."); + // ORDER BY doesn't work for encrypted columns + // need to fetch all rows first then sort and print + if (!isColEncrypted()) { + $stmt1 = $conn1->prepare("SELECT idx, txt FROM [$tableName] ORDER BY idx"); + } else { + $stmt1 = $conn1->prepare("SELECT idx, txt FROM [$tableName]"); + } + $stmt1->execute(); + $data = $stmt1->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_UNIQUE); + if (isColEncrypted()) { + sort($data); + } + var_dump($data); - // Testing with prepared query - LogInfo(1, "Testing fetchColumn() ..."); - $stmt1 = ExecuteQuery($conn1, "SELECT COUNT(idx) FROM [$tableName]"); - var_dump($stmt1->fetchColumn()); - unset($stmt1); + logInfo(3, "Testing bindColumn() ..."); + $stmt1->bindColumn('idx', $idx); + $stmt1->bindColumn('txt', $txt); + $stmt1->execute(); + $idxArray = array(); + $txtArray = array(); + while ($stmt1->fetch(PDO::FETCH_BOUND)) { + array_push($idxArray, $idx); + array_push($txtArray, $txt); + } + if (isColEncrypted()) { + sort($idxArray); + sort($txtArray); + } + for ($i = 0; $i < 4; $i++) { + var_dump(array($idxArray[$i] => $txtArray[$i])); + } - LogInfo(2, "Testing fetchAll() ..."); - $stmt1 = PrepareQuery($conn1, "SELECT idx, txt FROM [$tableName] ORDER BY idx"); - $stmt1->execute(); - $data = $stmt1->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_UNIQUE); - var_dump($data); + logInfo(4, "Testing bindColumn() with data check ..."); + $id = null; + $val = null; + $data = array(); + $index = 0; + if (!$stmt1->bindColumn(1, $id, PDO::PARAM_INT)) { + logError(5, "Cannot bind integer column", $stmt1); + } + if (!$stmt1->bindColumn(2, $val, PDO::PARAM_STR)) { + logError(5, "Cannot bind string column", $stmt1); + } + $stmt1->execute(); + while ($stmt1->fetch(PDO::FETCH_BOUND)) { + $data[] = array('id' => $id, 'val' => $val); + } + $sortedData = $data; + if (isColEncrypted()) { + sort($sortedData); + } + foreach ($sortedData as $d) { + printf( + "id = %s (%s) / val = %s (%s)\n", + var_export($d['id'], true), + gettype($d['id']), + var_export($d['val'], true), + gettype($d['val']) + ); + } - LogInfo(3, "Testing bindColumn() ..."); - $stmt1->bindColumn('idx', $idx); - $stmt1->bindColumn('txt', $txt); - $stmt1->execute(); - while ($stmt1->fetch(PDO::FETCH_BOUND)) - { - var_dump(array($idx=>$txt)); - } + unset($stmt1); + if (!isColEncrypted()) { + $stmt1 = $conn1->query("SELECT idx, txt FROM [$tableName] ORDER BY idx"); + } else { + $stmt1 = $conn1->query("SELECT idx, txt FROM [$tableName]"); + } + while ($row = $stmt1->fetch(PDO::FETCH_ASSOC)) { + if ($row['idx'] != $data[$index]['id']) { + logInfo(6, "Data corruption for integer column in row $index"); + } + if ($row['txt'] != $data[$index]['val']) { + logInfo(6, "Data corruption for string column in row $index"); + } + $index++; + } - LogInfo(4, "Testing bindColumn() with data check ..."); - $id = null; - $val = null; - $data = array(); - $index = 0; - if (!$stmt1->bindColumn(1, $id, PDO::PARAM_INT)) - { - LogError(5, "Cannot bind integer column", $stmt1); - } - if (!$stmt1->bindColumn(2, $val, PDO::PARAM_STR)) - { - LogError(5, "Cannot bind string column", $stmt1); - } - $stmt1->execute(); - while ($stmt1->fetch(PDO::FETCH_BOUND)) - { - $data[] = array('id' => $id, 'val' => $val); - printf("id = %s (%s) / val = %s (%s)\n", - var_export($id, true), gettype($id), - var_export($val, true), gettype($val)); - } - unset($stmt1); - $stmt1 = ExecuteQuery($conn1, "SELECT idx, txt FROM [$tableName] ORDER BY idx"); - while ($row = $stmt1->fetch(PDO::FETCH_ASSOC)) - { - if ($row['idx'] != $data[$index]['id']) - { - LogInfo(6, "Data corruption for integer column in row $index"); - } - if ($row['txt'] != $data[$index]['val']) - { - LogInfo(6, "Data corruption for string column in row $index"); - } - $index++; - } - - - // Cleanup - DropTable($conn1, $tableName); - $stmt1 = null; - $conn1 = null; - - EndTest($testName); + // Cleanup + dropTable($conn1, $tableName); + unset($stmt1); + unset($conn1); +} catch (Exception $e) { + echo $e->getMessage(); } -function LogInfo($offset, $msg) +function logInfo($offset, $msg) { - printf("[%03d] %s\n", $offset, $msg); + printf("[%03d] %s\n", $offset, $msg); } -function LogError($offset, $msg, &$obj) +function logError($offset, $msg, &$obj) { - printf("[%03d] %s: %s\n", $offset, $msg, $obj->errorCode); + printf("[%03d] %s: %s\n", $offset, $msg, $obj->errorCode); } - -//-------------------------------------------------------------------- -// Repro -// -//-------------------------------------------------------------------- -function Repro() -{ - - try - { - Fetch(); - } - catch (Exception $e) - { - echo $e->getMessage(); - } -} - -Repro(); - ?> --EXPECT-- [001] Testing fetchColumn() ... @@ -160,4 +160,3 @@ id = 0 (integer) / val = 'String0' (string) id = 1 (integer) / val = 'String1' (string) id = 2 (integer) / val = 'String2' (string) id = 3 (integer) / val = 'String3' (string) -Test "PDO Statement - Bind Column" completed successfully. \ No newline at end of file diff --git a/test/functional/pdo_sqlsrv/PDO62_BindColumn2.phpt b/test/functional/pdo_sqlsrv/PDO62_BindColumn2.phpt index 4b6688a9..abb2b62a 100644 --- a/test/functional/pdo_sqlsrv/PDO62_BindColumn2.phpt +++ b/test/functional/pdo_sqlsrv/PDO62_BindColumn2.phpt @@ -5,70 +5,81 @@ Verification for "PDOStatement::bindColumn()". --ENV-- PHPT_EXEC=true --SKIPIF-- - + --FILE-- "char(1)")); + insertRow($conn1, $tableName, array("id" => 1, "label" => "a")); + insertRow($conn1, $tableName, array("id" => 2, "label" => "b")); + insertRow($conn1, $tableName, array("id" => 3, "label" => "c")); + insertRow($conn1, $tableName, array("id" => 4, "label" => "d")); + insertRow($conn1, $tableName, array("id" => 5, "label" => "e")); + insertRow($conn1, $tableName, array("id" => 6, "label" => "f")); $rowCount = 3; $midRow = 4; // Check bind column - $tsql1 = "SELECT TOP($rowCount) id, label FROM [$tableName] ORDER BY id ASC"; - $data = BindColumn($conn1, $tsql1); - CheckBind($conn1, $tsql1, $data); + // order by does not work for encrypted columns + if (!isColEncrypted()) { + $tsql1 = "SELECT TOP($rowCount) id, label FROM [$tableName] ORDER BY id ASC"; + } else { + $tsql1 = "SELECT TOP($rowCount) id, label FROM [$tableName]"; + } + $data1 = bindColumn($conn1, $tsql1); + checkBind($conn1, $tsql1, $data1); - $tsql2 = "SELECT TOP($rowCount) id, label FROM (SELECT *, ROW_NUMBER() OVER(ORDER BY id ASC) as row FROM [$tableName]) [$tableName] WHERE row >= $midRow"; - $data = BindColumn($conn1, $tsql2); - CheckBind($conn1, $tsql2, $data); + if (!isColEncrypted()) { + $tsql2 = "SELECT TOP($rowCount) id, label FROM (SELECT *, ROW_NUMBER() OVER(ORDER BY id ASC) as row FROM [$tableName]) [$tableName] WHERE row >= $midRow"; + } else { + $tsql2 = "SELECT TOP($rowCount) id, label FROM (SELECT *, ROW_NUMBER() OVER(ORDER BY (SELECT 1)) as row FROM [$tableName]) [$tableName] WHERE row >= $midRow"; + } + $data2 = bindColumn($conn1, $tsql2); + checkBind($conn1, $tsql2, $data2); + + $data = array_merge($data1, $data2); + if (isColEncrypted()) { + sort($data); + } + foreach ($data as $d) { + printf( + "id = %s (%s) / label = %s (%s)\n", + var_export($d['id'], true), + gettype($d['id']), + var_export($d['label'], true), + gettype($d['label']) + ); + } // Cleanup - DropTable($conn1, $tableName); - $conn1 = null; - - EndTest($testName); + dropTable($conn1, $tableName); + unset($conn1); +} catch (Exception $e) { + echo $e->getMessage(); } -function BindColumn($conn, $tsql) +function bindColumn($conn, $tsql) { $id = null; $label = null; $data = array(); - $stmt = PrepareQuery($conn, $tsql); + $stmt = $conn->prepare($tsql); $stmt->execute(); - if (!$stmt->bindColumn(1, $id, PDO::PARAM_INT)) - { - LogInfo(1, "Cannot bind integer column"); + if (!$stmt->bindColumn(1, $id, PDO::PARAM_INT)) { + logInfo(1, "Cannot bind integer column"); } - if (!$stmt->bindColumn(2, $label, PDO::PARAM_STR)) - { - LogInfo(1, "Cannot bind string column"); + if (!$stmt->bindColumn(2, $label, PDO::PARAM_STR)) { + logInfo(1, "Cannot bind string column"); } - while ($stmt->fetch(PDO::FETCH_BOUND)) - { - printf("id = %s (%s) / label = %s (%s)\n", - var_export($id, true), gettype($id), - var_export($label, true), gettype($label)); + while ($stmt->fetch(PDO::FETCH_BOUND)) { $data[] = array('id' => $id, 'label' => $label); } unset($stmt); @@ -77,51 +88,28 @@ function BindColumn($conn, $tsql) } -function CheckBind($conn, $tsql, $data) +function checkBind($conn, $tsql, $data) { $index = 0; $stmt = ExecuteQuery($conn, $tsql); - while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) - { - if ($row['id'] != $data[$index]['id']) - { - LogInfo(2, "Fetch bound and fetch assoc differ - column 'id', row $index"); + while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { + if ($row['id'] != $data[$index]['id']) { + logInfo(2, "Fetch bound and fetch assoc differ - column 'id', row $index"); } - if ($row['label'] != $data[$index]['label']) - { - LogInfo(2, "Fetch bound and fetch assoc differ - column 'label', row $index"); + if ($row['label'] != $data[$index]['label']) { + logInfo(2, "Fetch bound and fetch assoc differ - column 'label', row $index"); } $index++; } unset($stmt); } -function LogInfo($offset, $msg) +function logInfo($offset, $msg) { printf("[%03d] %s\n", $offset, $msg); } - -//-------------------------------------------------------------------- -// Repro -// -//-------------------------------------------------------------------- -function Repro() -{ - - try - { - Bind(); - } - catch (Exception $e) - { - echo $e->getMessage(); - } -} - -Repro(); - ?> --EXPECT-- id = 1 (integer) / label = 'a' (string) @@ -130,4 +118,3 @@ id = 3 (integer) / label = 'c' (string) id = 4 (integer) / label = 'd' (string) id = 5 (integer) / label = 'e' (string) id = 6 (integer) / label = 'f' (string) -Test "PDO Statement - Bind Column" completed successfully. \ No newline at end of file diff --git a/test/functional/pdo_sqlsrv/PDO63_BindParam1.phpt b/test/functional/pdo_sqlsrv/PDO63_BindParam1.phpt index 54d22785..0dea0c44 100644 --- a/test/functional/pdo_sqlsrv/PDO63_BindParam1.phpt +++ b/test/functional/pdo_sqlsrv/PDO63_BindParam1.phpt @@ -5,39 +5,36 @@ Verification for "PDOStatement::bindParam()". --ENV-- PHPT_EXEC=true --SKIPIF-- - + --FILE-- exec( "CREATE CLUSTERED INDEX [idx_test_int] ON " . $tableName . "(id)" ); - + $tableName = "pdo_test_table"; + createTable($conn1, $tableName, array("id" => "int", "name" => "varchar(20)")); + $conn1->exec("CREATE CLUSTERED INDEX [idx_test_int] ON $tableName (id)"); // Insert test data - $stmt1 = PrepareQuery($conn1, "INSERT INTO [$tableName] ($dataCols) VALUES(0, :name)"); - $name = NULL; + if (isColEncrypted()) { + $stmt1 = $conn1->prepare("INSERT INTO [$tableName] ($dataCols) VALUES(:id, :name)"); + $id = 0; + $stmt1->bindParam(':id', $id); + } else { + $stmt1 = $conn1->prepare("INSERT INTO [$tableName] ($dataCols) VALUES(0, :name)"); + } + $name = null; $before_bind = $name; $stmt1->bindParam(':name', $name); // Check that bindParam does not modify parameter - if ($name !== $before_bind) - { + if ($name !== $before_bind) { echo "bind: fail\n"; - } - else - { + } else { echo "bind: success\n"; } @@ -45,41 +42,25 @@ function Bind() unset($stmt1); // Retrieve test data - $stmt1 = ExecuteQuery($conn1, "SELECT name FROM [$tableName] WHERE id = 0"); + if (isColEncrypted()) { + $stmt1 = $conn1->prepare("SELECT name FROM [$tableName] WHERE id = ?"); + $id = 0; + $stmt1->bindParam(1, $id); + $stmt1->execute(); + } else { + $stmt1 = $conn1->query("SELECT name FROM [$tableName] WHERE id = 0"); + } var_dump($stmt1->fetchColumn()); - // Cleanup - DropTable($conn1, $tableName); - $stmt1 = null; - $conn1 = null; - - EndTest($testName); + dropTable($conn1, $tableName); + unset($stmt1); + unset($conn1); +} catch (Exception $e) { + echo $e->getMessage(); } - - -//-------------------------------------------------------------------- -// Repro -// -//-------------------------------------------------------------------- -function Repro() -{ - - try - { - Bind(); - } - catch (Exception $e) - { - echo $e->getMessage(); - } -} - -Repro(); - ?> --EXPECT-- bind: success bool(true) NULL -Test "PDO Statement - Bind Param" completed successfully. \ No newline at end of file diff --git a/test/functional/pdo_sqlsrv/PDO64_BindParam2.phpt b/test/functional/pdo_sqlsrv/PDO64_BindParam2.phpt index a60dcbc5..d7b203ac 100644 --- a/test/functional/pdo_sqlsrv/PDO64_BindParam2.phpt +++ b/test/functional/pdo_sqlsrv/PDO64_BindParam2.phpt @@ -5,133 +5,115 @@ Verification for "PDOStatement::bindParam()". --ENV-- PHPT_EXEC=true --SKIPIF-- - + --FILE-- "char(1)")); + insertRow($conn1, $tableName, array("id" => 1, "label" => 'a')); + insertRow($conn1, $tableName, array("id" => 2, "label" => 'b')); + insertRow($conn1, $tableName, array("id" => 3, "label" => 'c')); + insertRow($conn1, $tableName, array("id" => 4, "label" => 'd')); + insertRow($conn1, $tableName, array("id" => 5, "label" => 'e')); + insertRow($conn1, $tableName, array("id" => 6, "label" => 'f')); - $conn1 = Connect(); + $id = null; + $label = null; - // Prepare test table - $dataCols = "id, label"; - CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, label CHAR(1)", null); - InsertRowEx($conn1, $tableName, $dataCols, "1, 'a'", null); - InsertRowEx($conn1, $tableName, $dataCols, "2, 'b'", null); - InsertRowEx($conn1, $tableName, $dataCols, "3, 'c'", null); - InsertRowEx($conn1, $tableName, $dataCols, "4, 'd'", null); - InsertRowEx($conn1, $tableName, $dataCols, "5, 'e'", null); - InsertRowEx($conn1, $tableName, $dataCols, "6, 'f'", null); + // Bind param @ SELECT + if (!isColEncrypted()) { + $tsql1 = "SELECT TOP(2) id, label FROM [$tableName] WHERE id > ? ORDER BY id ASC"; + $value1 = array(1 => 0); + } else { + $tsql1 = "SELECT id, label FROM $tableName WHERE id = ? OR id = ?"; + $value1 = array(1 => 1, 2 => 2); + } + $stmt1 = $conn1->prepare($tsql1); + bindParam(1, $stmt1, $value1); + execStmt(1, $stmt1); + bindColumn(1, $stmt1, $id, $label); + fetchBound($stmt1, $id, $label); + execStmt(1, $stmt1); + fetchBound($stmt1, $id, $label); + unset($stmt1); - $id = null; - $label = null; + // Bind param @ INSERT + if (!isColEncrypted()) { + $tsql2 = "INSERT INTO [$tableName](id, label) VALUES (100, ?)"; + $value2 = array(1 => null); + } else { + $tsql2 = "INSERT INTO [$tableName](id, label) VALUES (?, ?)"; + $value2 = array(1 => 100, 2 => null); + } + $stmt1 = $conn1->prepare($tsql2); + bindParam(2, $stmt1, $value2); + execStmt(2, $stmt1); + unset($stmt1); - // Bind param @ SELECT - $tsql1 = "SELECT TOP(2) id, label FROM [$tableName] WHERE id > ? ORDER BY id ASC"; - $value1 = 0; - $stmt1 = PrepareQuery($conn1, $tsql1); - BindParam(1, $stmt1, $value1); - ExecStmt(1, $stmt1); - BindColumn(1, $stmt1, $id, $label); - FetchBound($stmt1, $id, $label); - ExecStmt(1, $stmt1); - FetchBound($stmt1, $id, $label); - unset($stmt1); + // Check binding + $tsql3 = "SELECT id, NULL AS _label FROM [$tableName] WHERE label IS NULL"; + $stmt1 = $conn1->query($tsql3); + bindColumn(3, $stmt1, $id, $label); + fetchBound($stmt1, $id, $label); + unset($stmt1); - // Bind param @ INSERT - $tsql2 = "INSERT INTO [$tableName](id, label) VALUES (100, ?)"; - $value2 = null; - $stmt1 = PrepareQuery($conn1, $tsql2); - BindParam(2, $stmt1, $value2); - ExecStmt(2, $stmt1); - unset($stmt1); - - // Check binding - $tsql3 = "SELECT id, NULL AS _label FROM [$tableName] WHERE label IS NULL"; - $stmt1 = ExecuteQuery($conn1, $tsql3); - BindColumn(3, $stmt1, $id, $label); - FetchBound($stmt1, $id, $label); - unset($stmt1); - - // Cleanup - DropTable($conn1, $tableName); - $stmt1 = null; - $conn1 = null; - - EndTest($testName); + // Cleanup + dropTable($conn1, $tableName); + unset($stmt1); + unset($conn1); +} catch (Exception $e) { + echo $e->getMessage(); } -function BindParam($offset, $stmt, &$value) +function bindParam($offset, $stmt, $value) { - if (!$stmt->bindParam(1, $value)) - { - LogInfo($offset,"Cannot bind parameter"); - } + foreach ($value as $key => &$val) { + $stmt->bindParam($key, $val); + } } -function BindColumn($offset, $stmt, &$param1, &$param2) +function bindColumn($offset, $stmt, &$param1, &$param2) { - if (!$stmt->bindColumn(1, $param1, PDO::PARAM_INT)) - { - LogInfo($offset, "Cannot bind integer column"); - } - if (!$stmt->bindColumn(2, $param2, PDO::PARAM_STR)) - { - LogInfo($offset, "Cannot bind string column"); - } + if (!$stmt->bindColumn(1, $param1, PDO::PARAM_INT)) { + logInfo($offset, "Cannot bind integer column"); + } + if (!$stmt->bindColumn(2, $param2, PDO::PARAM_STR)) { + logInfo($offset, "Cannot bind string column"); + } } -function ExecStmt($offset, $stmt) +function execStmt($offset, $stmt) { - if (!$stmt->execute()) - { - LogInfo($offset, "Cannot execute statement"); - } + if (!$stmt->execute()) { + logInfo($offset, "Cannot execute statement"); + } } -function FetchBound($stmt, &$param1, &$param2) +function fetchBound($stmt, &$param1, &$param2) { - while ($stmt->fetch(PDO::FETCH_BOUND)) - { - printf("id = %s (%s) / label = %s (%s)\n", - var_export($param1, true), gettype($param1), - var_export($param2, true), gettype($param2)); - } + while ($stmt->fetch(PDO::FETCH_BOUND)) { + printf( + "id = %s (%s) / label = %s (%s)\n", + var_export($param1, true), + gettype($param1), + var_export($param2, true), + gettype($param2) + ); + } } - -function LogInfo($offset, $msg) +function logInfo($offset, $msg) { - printf("[%03d] %s\n", $offset, $msg); + printf("[%03d] %s\n", $offset, $msg); } - - -//-------------------------------------------------------------------- -// Repro -// -//-------------------------------------------------------------------- -function Repro() -{ - - try - { - Bind(); - } - catch (Exception $e) - { - echo $e->getMessage(); - } -} - -Repro(); - ?> --EXPECT-- id = 1 (integer) / label = 'a' (string) @@ -139,4 +121,3 @@ id = 2 (integer) / label = 'b' (string) id = 1 (integer) / label = 'a' (string) id = 2 (integer) / label = 'b' (string) id = 100 (integer) / label = NULL (NULL) -Test "PDO Statement - Bind Param" completed successfully. \ No newline at end of file diff --git a/test/functional/pdo_sqlsrv/PDO65_BindValue1.phpt b/test/functional/pdo_sqlsrv/PDO65_BindValue1.phpt index 9e96e4f6..7becaf0d 100644 --- a/test/functional/pdo_sqlsrv/PDO65_BindValue1.phpt +++ b/test/functional/pdo_sqlsrv/PDO65_BindValue1.phpt @@ -5,67 +5,47 @@ Verification for "PDOStatement::bindValue()". --ENV-- PHPT_EXEC=true --SKIPIF-- - + --FILE-- "varchar(10)", "val2" => "varchar(10)", "val3" => "varchar(10)")); + $data = array("one", "two", "three"); - $conn1 = Connect(); + // Insert test data + $i = 1; + if (!isColEncrypted()) { + $stmt1 = $conn1->prepare("INSERT INTO [$tableName] VALUES(1, ?, ?, ?)"); + } else { + $stmt1 = $conn1->prepare("INSERT INTO [$tableName] VALUES(?, ?, ?, ?)"); + $stmt1->bindValue(1, 1); + $i++; + } + foreach ($data as $v) { + $stmt1->bindValue($i, $v); + $i++; + } + $stmt1->execute(); + unset($stmt1); - // Prepare test table - CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, val1 VARCHAR(10), val2 VARCHAR(10), val3 VARCHAR(10)", null); - $data = array("one", "two", "three"); + // Retrieve test data + $stmt1 = $conn1->prepare("SELECT * FROM [$tableName]"); + $stmt1->execute(); + var_dump($stmt1->fetchAll(PDO::FETCH_ASSOC)); - // Insert test data - $stmt1 = PrepareQuery($conn1, "INSERT INTO [$tableName] VALUES(1, ?, ?, ?)"); - foreach ($data as $i => $v) - { - $stmt1->bindValue($i+1, $v); - } - $stmt1->execute(); - unset($stmt1); - - // Retrieve test data - $stmt1 = PrepareQuery($conn1, "SELECT * FROM [$tableName]"); - $stmt1->execute(); - var_dump($stmt1->fetchAll(PDO::FETCH_ASSOC)); - - - // Cleanup - DropTable($conn1, $tableName); - $stmt1 = null; - $conn1 = null; - - EndTest($testName); + // Cleanup + dropTable($conn1, $tableName); + unset($stmt1); + unset($conn1); +} catch (Exception $e) { + echo $e->getMessage(); } - -//-------------------------------------------------------------------- -// Repro -// -//-------------------------------------------------------------------- -function Repro() -{ - - try - { - Bind(); - } - catch (Exception $e) - { - echo $e->getMessage(); - } -} - -Repro(); - ?> --EXPECT-- array(1) { @@ -81,4 +61,3 @@ array(1) { string(5) "three" } } -Test "PDO Statement - Bind Value" completed successfully. \ No newline at end of file diff --git a/test/functional/pdo_sqlsrv/PDO66_BindValue2.phpt b/test/functional/pdo_sqlsrv/PDO66_BindValue2.phpt index 80ffea4c..1390fc39 100644 --- a/test/functional/pdo_sqlsrv/PDO66_BindValue2.phpt +++ b/test/functional/pdo_sqlsrv/PDO66_BindValue2.phpt @@ -5,184 +5,185 @@ Verification for "PDOStatement::bindValue()". --ENV-- PHPT_EXEC=true --SKIPIF-- - + --FILE-- "char(1)")); + insertRow($conn1, $tableName, array("id" => 1, "label" => "a")); + insertRow($conn1, $tableName, array("id" => 2, "label" => "b")); + insertRow($conn1, $tableName, array("id" => 3, "label" => "c")); + insertRow($conn1, $tableName, array("id" => 4, "label" => "d")); + insertRow($conn1, $tableName, array("id" => 5, "label" => "e")); + insertRow($conn1, $tableName, array("id" => 6, "label" => "f")); - $conn1 = Connect(); + $id = null; + $label = null; - // Prepare test table - $dataCols = "id, label"; - CreateTableEx($conn1, $tableName, "id int NOT NULL PRIMARY KEY, label CHAR(1)", null); - InsertRowEx($conn1, $tableName, $dataCols, "1, 'a'", null); - InsertRowEx($conn1, $tableName, $dataCols, "2, 'b'", null); - InsertRowEx($conn1, $tableName, $dataCols, "3, 'c'", null); - InsertRowEx($conn1, $tableName, $dataCols, "4, 'd'", null); - InsertRowEx($conn1, $tableName, $dataCols, "5, 'e'", null); - InsertRowEx($conn1, $tableName, $dataCols, "6, 'f'", null); + // Check different value bind modes + if (!isColEncrypted()) { + $tsql1 = "SELECT TOP(2) id, label FROM [$tableName] WHERE id > ? ORDER BY id ASC"; + } else { + $tsql1 = "SELECT id, label FROM [$tableName] WHERE id = ? OR id = ?"; + } + $stmt1 = $conn1->prepare($tsql1); - $id = null; - $label = null; + printf("Binding value and not variable...\n"); + if (!isColEncrypted()) { + bindValue(1, 1, $stmt1, 0); + } else { + bindValue(1, 1, $stmt1, 1); + bindValue(1, 2, $stmt1, 2); + } + execStmt(1, $stmt1); + bindColumn(1, $stmt1, $id, $label); + fetchBound($stmt1, $id, $label); - // Check different value bind modes - $tsql1 = "SELECT TOP(2) id, label FROM [$tableName] WHERE id > ? ORDER BY id ASC"; - $stmt1 = PrepareQuery($conn1, $tsql1); + printf("Binding variable...\n"); + $var1 = 0; + if (!isColEncrypted()) { + bindVar(2, 1, $stmt1, $var1); + } else { + $var11 = $var1 + 1; + $var12 = $var1 + 2; + bindVar(2, 1, $stmt1, $var11); + bindVar(2, 2, $stmt1, $var12); + } + execStmt(2, $stmt1); + bindColumn(2, $stmt1, $id, $label); + fetchBound($stmt1, $id, $label); - printf("Binding value and not variable...\n"); - BindValue(1, $stmt1, 0); - ExecStmt(1, $stmt1); - BindColumn(1, $stmt1, $id, $label); - FetchBound($stmt1, $id, $label); + printf("Binding variable which references another variable...\n"); + $var2 = 0; + $var_ref = &$var2; + if (!isColEncrypted()) { + bindVar(3, 1, $stmt1, $var_ref); + } else { + $var21 = $var2 + 1; + $var22 = $var2 + 2; + $var_ref1 = &$var21; + $var_ref2 = &$var22; + bindVar(3, 1, $stmt1, $var_ref1); + bindVar(3, 2, $stmt1, $var_ref2); + } + execStmt(3, $stmt1); + bindColumn(3, $stmt1, $id, $label); + fetchBound($stmt1, $id, $label); + unset($stmt1); - printf("Binding variable...\n"); - $var1 = 0; - BindVar(2, $stmt1, $var1); - ExecStmt(2, $stmt1); - BindColumn(2, $stmt1, $id, $label); - FetchBound($stmt1, $id, $label); + if (!isColEncrypted()) { + $tsql2 = "SELECT TOP(2) id, label FROM [$tableName] WHERE id > ? AND id <= ? ORDER BY id ASC"; + } else { + $tsql2 = "SELECT id, label FROM [$tableName] WHERE id = ? OR id = ?"; + } + $stmt1 = $conn1->prepare($tsql2); - printf("Binding variable which references another variable...\n"); - $var2 = 0; - $var_ref = &$var2; - BindVar(3, $stmt1, $var_ref); - ExecStmt(3, $stmt1); - BindColumn(3, $stmt1, $id, $label); - FetchBound($stmt1, $id, $label); + printf("Binding a variable and a value...\n"); + $var3 = 0; + if (isColEncrypted()) { + $var3++; + } + bindMixed(4, $stmt1, $var3, 2); + execStmt(4, $stmt1); + bindColumn(4, $stmt1, $id, $label); + fetchBound($stmt1, $id, $label); - unset($stmt1); + printf("Binding a variable to two placeholders and changing the variable value in between the binds...\n"); + $var4 = 0; + if (isColEncrypted()) { + $var4++; + } + $var5 = 2; + bindPlaceholder(5, $stmt1, $var4, $var5); + execStmt(5, $stmt1); + bindColumn(5, $stmt1, $id, $label); + fetchBound($stmt1, $id, $label); + unset($stmt1); - $tsql2 = "SELECT TOP(2) id, label FROM [$tableName] WHERE id > ? AND id <= ? ORDER BY id ASC"; - $stmt1 = PrepareQuery($conn1, $tsql2); - - printf("Binding a variable and a value...\n"); - $var3 = 0; - BindMixed(4, $stmt1, $var3, 2); - ExecStmt(4, $stmt1); - BindColumn(4, $stmt1, $id, $label); - FetchBound($stmt1, $id, $label); - - printf("Binding a variable to two placeholders and changing the variable value in between the binds...\n"); - $var4 = 0; - $var5 = 2; - BindPlaceholder(5, $stmt1, $var4, $var5); - ExecStmt(5, $stmt1); - BindColumn(5, $stmt1, $id, $label); - FetchBound($stmt1, $id, $label); - - unset($stmt1); - - // Cleanup - DropTable($conn1, $tableName); - $stmt1 = null; - $conn1 = null; - - EndTest($testName); + // Cleanup + dropTable($conn1, $tableName); + unset($stmt1); + unset($conn1); +} catch (Exception $e) { + echo $e->getMessage(); } -function BindValue($offset, $stmt, $value) +function bindValue($offset, $index, $stmt, $value) { - if (!$stmt->bindValue(1, $value)) - { - LogInfo($offset, "Cannot bind value"); - } + if (!$stmt->bindValue($index, $value)) { + logInfo($offset, "Cannot bind value"); + } } -function BindVar($offset, $stmt, &$var) +function bindVar($offset, $index, $stmt, &$var) { - if (!$stmt->bindValue(1, $var)) - { - LogInfo($offset, "Cannot bind variable"); - } + if (!$stmt->bindValue($index, $var)) { + logInfo($offset, "Cannot bind variable"); + } } -function BindMixed($offset, $stmt, &$var, $value) +function bindMixed($offset, $stmt, &$var, $value) { - if (!$stmt->bindValue(1, $var)) - { - LogInfo($offset, "Cannot bind variable"); - } - if (!$stmt->bindValue(2, $value)) - { - LogInfo($offset, "Cannot bind value"); - } + if (!$stmt->bindValue(1, $var)) { + logInfo($offset, "Cannot bind variable"); + } + if (!$stmt->bindValue(2, $value)) { + logInfo($offset, "Cannot bind value"); + } } -function BindPlaceholder($offset, $stmt, &$var1, &$var2) +function bindPlaceholder($offset, $stmt, &$var1, &$var2) { - if (!$stmt->bindValue(1, $var1)) - { - LogInfo($offset, "Cannot bind variable 1"); - } - if (!$stmt->bindValue(2, $var2)) - { - LogInfo($offset, "Cannot bind variable 2"); - } + if (!$stmt->bindValue(1, $var1)) { + logInfo($offset, "Cannot bind variable 1"); + } + if (!$stmt->bindValue(2, $var2)) { + logInfo($offset, "Cannot bind variable 2"); + } } -function BindColumn($offset, $stmt, &$param1, &$param2) +function bindColumn($offset, $stmt, &$param1, &$param2) { - if (!$stmt->bindColumn(1, $param1, PDO::PARAM_INT)) - { - LogInfo($offset, "Cannot bind integer column"); - } - if (!$stmt->bindColumn(2, $param2, PDO::PARAM_STR)) - { - LogInfo($offset, "Cannot bind string column"); - } + if (!$stmt->bindColumn(1, $param1, PDO::PARAM_INT)) { + logInfo($offset, "Cannot bind integer column"); + } + if (!$stmt->bindColumn(2, $param2, PDO::PARAM_STR)) { + logInfo($offset, "Cannot bind string column"); + } } -function ExecStmt($offset, $stmt) +function execStmt($offset, $stmt) { - if (!$stmt->execute()) - { - LogInfo($offset, "Cannot execute statement"); - } + if (!$stmt->execute()) { + logInfo($offset, "Cannot execute statement"); + } } -function FetchBound($stmt, &$param1, &$param2) +function fetchBound($stmt, &$param1, &$param2) { - while ($stmt->fetch(PDO::FETCH_BOUND)) - { - printf("id = %s (%s) / label = %s (%s)\n", - var_export($param1, true), gettype($param1), - var_export($param2, true), gettype($param2)); - } + while ($stmt->fetch(PDO::FETCH_BOUND)) { + printf( + "id = %s (%s) / label = %s (%s)\n", + var_export($param1, true), + gettype($param1), + var_export($param2, true), + gettype($param2) + ); + } } -function LogInfo($offset, $msg) +function logInfo($offset, $msg) { - printf("[%03d] %s\n", $offset, $msg); + printf("[%03d] %s\n", $offset, $msg); } - -//-------------------------------------------------------------------- -// Repro -// -//-------------------------------------------------------------------- -function Repro() -{ - - try - { - Bind(); - } - catch (Exception $e) - { - echo $e->getMessage(); - } -} - -Repro(); - ?> --EXPECT-- Binding value and not variable... @@ -200,4 +201,3 @@ id = 2 (integer) / label = 'b' (string) Binding a variable to two placeholders and changing the variable value in between the binds... id = 1 (integer) / label = 'a' (string) id = 2 (integer) / label = 'b' (string) -Test "PDO Statement - Bind Value" completed successfully. \ No newline at end of file diff --git a/test/functional/pdo_sqlsrv/PDO67_BindTruncation.phpt b/test/functional/pdo_sqlsrv/PDO67_BindTruncation.phpt index b4dd7dce..5969ab37 100644 --- a/test/functional/pdo_sqlsrv/PDO67_BindTruncation.phpt +++ b/test/functional/pdo_sqlsrv/PDO67_BindTruncation.phpt @@ -5,137 +5,106 @@ Verification for "PDOStatement::bindParam()". --ENV-- PHPT_EXEC=true --SKIPIF-- - + --FILE-- "int", "value" => "char(32)")); + $conn1->exec("CREATE CLUSTERED INDEX [idx_test_int] ON $tableName (id)"); + $tsql1 = "SET IDENTITY_INSERT [$tableName] ON"; + $tsql2 = "INSERT INTO [$tableName] (id, class, value) VALUES(:id, :class, :value)"; + $tsql3 = "SET IDENTITY_INSERT [$tableName] OFF"; + $tsql4 = "SELECT id, value FROM [$tableName]"; - $conn1 = Connect(); + $id = 0; + $class = 0; + $value = ''; - // Prepare test table - CreateTableEx($conn1, $tableName, "id INT IDENTITY NOT NULL, class INT, value CHAR(32)", null); - $conn1->exec( "CREATE CLUSTERED INDEX [idx_test_int] ON " . $tableName . "(id)" ); - $tsql1 = "SET IDENTITY_INSERT [$tableName] ON"; - $tsql2 = "INSERT INTO [$tableName] (id, class, value) VALUES(:id, :class, :value)"; - $tsql3 = "SET IDENTITY_INSERT [$tableName] OFF"; - $tsql4 = "SELECT id, value FROM [$tableName]"; + // Prepare insert query$ + $stmt1 = $conn1->prepare("$tsql1; $tsql2; $tsql3;"); + bindParam(1, $stmt1, ':id', $id); + bindParam(2, $stmt1, ':class', $class); + bindParam(3, $stmt1, ':value', $value); + + // Insert test rows + $id = 1; + $class = 4; + $value = '2011'; + execStmt(1, $stmt1); - - $id = 0; - $class = 0; - $value = ''; + $id = 2; + $class = 5; + $value = 'Sat, 20 Mar 10 21:29:13 -0600'; + execStmt(2, $stmt1); - // Prepare insert query - $stmt1 = PrepareQuery($conn1, "$tsql1; $tsql2; $tsql3;"); - BindParam(1, $stmt1, ':id', $id); - BindParam(2, $stmt1, ':class', $class); - BindParam(3, $stmt1, ':value', $value); + $id = 3; + $class = 6; + $value = 'Fri, 07 May 10 11:35:32 -0600'; + execStmt(3, $stmt1); - // Insert test rows - $id = 1; - $class = 4; - $value = '2011'; - ExecStmt(1, $stmt1); + unset($stmt1); - $id = 2; - $class = 5; - $value = 'Sat, 20 Mar 10 21:29:13 -0600'; - ExecStmt(2, $stmt1); + // Check data + $id = 0; + $value = ''; + $stmt2 = $conn1->query($tsql4); + bindColumn(1, $stmt2, $id, $value); + while ($stmt2->fetch(PDO::FETCH_BOUND)) { + printf( + "id = %s (%s) / value = %s (%s)\n", + var_export($id, true), + gettype($id), + var_export($value, true), + gettype($value) + ); + } + unset($stmt2); - $id = 3; - $class = 6; - $value = 'Fri, 07 May 10 11:35:32 -0600'; - ExecStmt(3, $stmt1); - - unset($stmt1); - $stmt1 = null; - - // Check data - $id = 0; - $value = ''; - $stmt2 = ExecuteQuery($conn1, $tsql4); - BindColumn(1, $stmt2, $id, $value); - while ($stmt2->fetch(PDO::FETCH_BOUND)) - { - printf("id = %s (%s) / value = %s (%s)\n", - var_export($id, true), gettype($id), - var_export($value, true), gettype($value)); - } - unset($stmt2); - $stmt2 = null; - - // Cleanup - DropTable($conn1, $tableName); - $stmt1 = null; - $conn1 = null; - - EndTest($testName); + // Cleanup + dropTable($conn1, $tableName); + unset($stmt1); + unset($conn1); +} catch (Exception $e) { + echo $e->getMessage(); } -function BindParam($offset, $stmt, $param, &$value) +function bindParam($offset, $stmt, $param, &$value) { - if (!$stmt->bindParam($param, $value)) - { - LogInfo($offset,"Cannot bind parameter $param"); - } + if (!$stmt->bindParam($param, $value)) { + LogInfo($offset, "Cannot bind parameter $param"); + } } -function BindColumn($offset, $stmt, &$param1, &$param2) +function bindColumn($offset, $stmt, &$param1, &$param2) { - if (!$stmt->bindColumn(1, $param1, PDO::PARAM_INT)) - { - LogInfo($offset, "Cannot bind integer column"); - } - if (!$stmt->bindColumn(2, $param2, PDO::PARAM_STR)) - { - LogInfo($offset, "Cannot bind string column"); - } + if (!$stmt->bindColumn(1, $param1, PDO::PARAM_INT)) { + LogInfo($offset, "Cannot bind integer column"); + } + if (!$stmt->bindColumn(2, $param2, PDO::PARAM_STR)) { + LogInfo($offset, "Cannot bind string column"); + } } -function ExecStmt($offset, $stmt) +function execStmt($offset, $stmt) { - if (!$stmt->execute()) - { - LogInfo($offset, "Cannot execute statement"); - var_dump($stmt->errorInfo()); - } + if (!$stmt->execute()) { + LogInfo($offset, "Cannot execute statement"); + var_dump($stmt->errorInfo()); + } } function LogInfo($offset, $msg) { - printf("[%03d] %s\n", $offset, $msg); + printf("[%03d] %s\n", $offset, $msg); } - - -//-------------------------------------------------------------------- -// Repro -// -//-------------------------------------------------------------------- -function Repro() -{ - - try - { - Bind(); - } - catch (Exception $e) - { - echo $e->getMessage(); - } -} - -Repro(); - ?> --EXPECT-- id = 1 (integer) / value = '2011 ' (string) id = 2 (integer) / value = 'Sat, 20 Mar 10 21:29:13 -0600 ' (string) id = 3 (integer) / value = 'Fri, 07 May 10 11:35:32 -0600 ' (string) -Test "PDO Statement - Bind Param Truncation" completed successfully. \ No newline at end of file diff --git a/test/functional/pdo_sqlsrv/pdoStatement_bindParam_inout_emulate_prepare.phpt b/test/functional/pdo_sqlsrv/pdoStatement_bindParam_inout_emulate_prepare.phpt index fabf870f..1ddd0eea 100644 --- a/test/functional/pdo_sqlsrv/pdoStatement_bindParam_inout_emulate_prepare.phpt +++ b/test/functional/pdo_sqlsrv/pdoStatement_bindParam_inout_emulate_prepare.phpt @@ -1,30 +1,36 @@ --TEST-- Tests error returned when binding input/output parameter with emulate prepare --SKIPIF-- - + --FILE-- setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $dbh = connect(); - $dbh->query("IF OBJECT_ID('sp_ReverseString', 'P') IS NOT NULL DROP PROCEDURE sp_ReverseString"); - $dbh->query("CREATE PROCEDURE sp_ReverseString @String as VARCHAR(2048) OUTPUT as SELECT @String = REVERSE(@String)"); - $stmt = $dbh->prepare("EXEC sp_ReverseString ?", array(PDO::ATTR_EMULATE_PREPARES => true)); + $procName = 'sp_ReverseString'; + dropProc($dbh, $procName); + $dbh->query("CREATE PROCEDURE $procName @String as VARCHAR(2048) OUTPUT as SELECT @String = REVERSE(@String)"); + $stmt = $dbh->prepare("EXEC $procName ?", array(PDO::ATTR_EMULATE_PREPARES => true)); $string = "123456789"; $stmt->bindParam(1, $string, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT, 2048); $stmt->execute(); - print "Result: ".$string; + print "Result: $string"; //free the statement and connection - $stmt = null; - $dbh = null; -} -catch(PDOException $e) { - print("Error: " . $e->getMessage() . "\n"); + dropProc($dbh, $procName); + unset($stmt); + unset($dbh); +} catch (PDOException $e) { + $error = $e->getMessage(); + $pass = !isColEncrypted() && $error === "SQLSTATE[IMSSP]: Statement with emulate prepare on does not support output or input_output parameters."; + $pass |= isColEncrypted() && ($error === "SQLSTATE[IMSSP]: Connection with Column Encryption enabled do no support PDO::ATTR_EMULATE_PREPARES with binding parameters."); + if (!$pass) { + print("Error: " . $error . "\n"); + } else { + print("Test successfully done\n"); + } } ?> --EXPECT-- -Error: SQLSTATE[IMSSP]: Statement with emulate prepare on does not support output or input_output parameters. \ No newline at end of file +Test successfully done diff --git a/test/functional/pdo_sqlsrv/pdoStatement_bindParam_output_emulate_prepare.phpt b/test/functional/pdo_sqlsrv/pdoStatement_bindParam_output_emulate_prepare.phpt index 94773069..3a6f6ece 100644 --- a/test/functional/pdo_sqlsrv/pdoStatement_bindParam_output_emulate_prepare.phpt +++ b/test/functional/pdo_sqlsrv/pdoStatement_bindParam_output_emulate_prepare.phpt @@ -1,52 +1,48 @@ --TEST-- Tests error returned when binding output parameter with emulate prepare --SKIPIF-- - + --FILE-- setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $conn = connect(); $count = 0; - + $query = "select ? = count(* ) from cd_info"; $stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true)); - $stmt->bindParam( 1, $count, PDO::PARAM_STR, 10 ); + $stmt->bindParam(1, $count, PDO::PARAM_STR, 10); $stmt->execute(); echo "Result: ".$count."\n"; - + $query = "select bigint_type, int_type, money_type from [test_types] where int_type < 0"; $stmt1 = $conn->prepare($query); $stmt1->execute(); - $row = $stmt1->fetch( PDO::FETCH_ASSOC ); - print_r($row); + $row = $stmt1->fetch(PDO::FETCH_ASSOC); + print_r($row); $int = 0; $bigint = 100; $query = "select ? = bigint_type, ? = int_type, ? = money_type from [test_types] where int_type < 0"; $stmt2 = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true)); - $stmt2->bindparam( 1, $bigint, PDO::PARAM_STR, 256 ); - $stmt2->bindParam( 2, $int, PDO::PARAM_INT, 4 ); - $stmt2->bindParam( 3, $money, PDO::PARAM_STR, 1024 ); + $stmt2->bindparam(1, $bigint, PDO::PARAM_STR, 256); + $stmt2->bindParam(2, $int, PDO::PARAM_INT, 4); + $stmt2->bindParam(3, $money, PDO::PARAM_STR, 1024); $stmt2->execute(); echo "Big integer: ".$bigint."\n"; echo "Integer: ".$int."\n"; echo "Money: ".$money."\n"; - + //free the statement and connection - $stmt = null; - $stmt1 = null; - $stmt2 = null; - $conn = null; - -} -catch(PDOException $e) { + unset($stmt); + unset($stmt1); + unset($stmt2); + unset($conn); +} catch (PDOException $e) { print("Error: " . $e->getMessage() . "\n"); } ?> --EXPECT-- -Error: SQLSTATE[IMSSP]: Statement with emulate prepare on does not support output or input_output parameters. \ No newline at end of file +Error: SQLSTATE[IMSSP]: Statement with emulate prepare on does not support output or input_output parameters. diff --git a/test/functional/pdo_sqlsrv/pdo_fetch_variants_diff_styles.phpt b/test/functional/pdo_sqlsrv/pdo_fetch_variants_diff_styles.phpt index 2aacac59..311538ab 100644 --- a/test/functional/pdo_sqlsrv/pdo_fetch_variants_diff_styles.phpt +++ b/test/functional/pdo_sqlsrv/pdo_fetch_variants_diff_styles.phpt @@ -13,114 +13,127 @@ hierarchyid geometry datetimeoffset User-defined types +--SKIPIF-- + --FILE-- exec("CREATE TABLE $tableName ([c1_int] sql_variant, [c2_tinyint] sql_variant, [c3_smallint] sql_variant, [c4_bigint] sql_variant, [c5_bit] sql_variant, [c6_float] sql_variant, [c7_real] sql_variant, [c8_decimal] sql_variant, [c9_numeric] sql_variant, [c10_money] sql_variant, [c11_smallmoney] sql_variant, [c12_char] sql_variant, [c13_varchar] sql_variant, [c14_nchar] sql_variant, [c15_nvarchar] sql_variant, [c16_binary] sql_variant, [c17_varbinary] sql_variant, [c18_uniqueidentifier] sql_variant, [c19_datetime] sql_variant, [c20_smalldatetime] sql_variant, [c21_time] sql_variant, [c22_date] sql_variant, [c23_datetime2] sql_variant)"); - } - catch (Exception $e) - { + try { + $colArr = array("c1_int" => "sql_variant", + "c2_tinyint" => "sql_variant", + "c3_smallint" => "sql_variant", + "c4_bigint" => "sql_variant", + "c5_bit" => "sql_variant", + "c6_float" => "sql_variant", + "c7_real" => "sql_variant", + "c8_decimal" => "sql_variant", + "c9_numeric" => "sql_variant", + "c10_money" => "sql_variant", + "c11_smallmoney" => "sql_variant", + "c12_char" => "sql_variant", + "c13_varchar" => "sql_variant", + "c14_nchar" => "sql_variant", + "c15_nvarchar" => "sql_variant", + "c16_binary" => "sql_variant", + "c17_varbinary" => "sql_variant", + "c18_uniqueidentifier" => "sql_variant", + "c19_datetime" => "sql_variant", + "c20_smalldatetime" => "sql_variant", + "c21_time" => "sql_variant", + "c22_date" => "sql_variant", + "c23_datetime2" => "sql_variant"); + createTable($conn, $tableName, $colArr); + } catch (Exception $e) { echo "Failed to create a test table\n"; echo $e->getMessage(); - } + } } -function InsertData($conn, $tableName, $numRows) +function insertData($conn, $tableName, $numRows) { - try - { - for ($i = 1; $i <= $numRows; $i++) - { - $stmt = $conn->query(GetQuery($tableName, $i)); - } - } - catch (Exception $e) - { + try { + for ($i = 1; $i <= $numRows; $i++) { + $stmt = $conn->query(getQuery($tableName, $i)); + } + } catch (Exception $e) { echo "Failed to populate the test table\n"; echo $e->getMessage(); - } + } } -function Fetch_BoundMixed($conn, $tableName, $numRows) +function fetchBoundMixed($conn, $tableName, $numRows) { - $query = "SELECT * FROM $tableName ORDER BY c1_int"; - - $stmt = $conn->query($query); - $numCols = $stmt->columnCount(); + $query = "SELECT * FROM $tableName ORDER BY c1_int"; + + $stmt = $conn->query($query); + $numCols = $stmt->columnCount(); $cols = array_fill(0, 23, null); - $stmt->bindColumn('c1_int', $cols[0]); - $stmt->bindColumn('c2_tinyint', $cols[1]); - $stmt->bindColumn(3, $cols[2]); - $stmt->bindColumn(4, $cols[3]); - $stmt->bindColumn(5, $cols[4]); - $stmt->bindColumn(6, $cols[5]); - $stmt->bindColumn(7, $cols[6]); - $stmt->bindColumn(8, $cols[7]); - $stmt->bindColumn('c9_numeric', $cols[8]); - $stmt->bindColumn('c10_money', $cols[9]); - $stmt->bindColumn('c11_smallmoney', $cols[10]); - $stmt->bindColumn('c12_char', $cols[11]); - $stmt->bindColumn(13, $cols[12]); - $stmt->bindColumn(14, $cols[13]); - $stmt->bindColumn('c15_nvarchar', $cols[14]); - $stmt->bindColumn('c16_binary', $cols[15]); - $stmt->bindColumn(17, $cols[16]); - $stmt->bindColumn('c18_uniqueidentifier', $cols[17]); - $stmt->bindColumn(19, $cols[18]); - $stmt->bindColumn(20, $cols[19]); - $stmt->bindColumn(21, $cols[20]); - $stmt->bindColumn(22, $cols[21]); - $stmt->bindColumn('c23_datetime2', $cols[22]); + $stmt->bindColumn('c1_int', $cols[0]); + $stmt->bindColumn('c2_tinyint', $cols[1]); + $stmt->bindColumn(3, $cols[2]); + $stmt->bindColumn(4, $cols[3]); + $stmt->bindColumn(5, $cols[4]); + $stmt->bindColumn(6, $cols[5]); + $stmt->bindColumn(7, $cols[6]); + $stmt->bindColumn(8, $cols[7]); + $stmt->bindColumn('c9_numeric', $cols[8]); + $stmt->bindColumn('c10_money', $cols[9]); + $stmt->bindColumn('c11_smallmoney', $cols[10]); + $stmt->bindColumn('c12_char', $cols[11]); + $stmt->bindColumn(13, $cols[12]); + $stmt->bindColumn(14, $cols[13]); + $stmt->bindColumn('c15_nvarchar', $cols[14]); + $stmt->bindColumn('c16_binary', $cols[15]); + $stmt->bindColumn(17, $cols[16]); + $stmt->bindColumn('c18_uniqueidentifier', $cols[17]); + $stmt->bindColumn(19, $cols[18]); + $stmt->bindColumn(20, $cols[19]); + $stmt->bindColumn(21, $cols[20]); + $stmt->bindColumn(22, $cols[21]); + $stmt->bindColumn('c23_datetime2', $cols[22]); $stmt2 = $conn->query($query); - - // compare data values + + // compare data values $row = 1; - while ($result = $stmt->fetch(PDO::FETCH_BOUND)) - { + while ($result = $stmt->fetch(PDO::FETCH_BOUND)) { echo "Comparing data in row $row\n"; - + $obj = $stmt2->fetch(PDO::FETCH_LAZY); - if (! $obj) + if (! $obj) { echo "Failed to fetch data as object\n"; - + } + $j = 0; - foreach ($cols as $value1) - { + foreach ($cols as $value1) { $col = $j+1; - $value2 = GetValueFromObject($obj, $col); - DoValuesMatched($value1, $value2, $row, $col); - + $value2 = getValueFromObject($obj, $col); + doValuesMatched($value1, $value2, $row, $col); + $j++; } - + $row++; } - + $noActualRows = $row - 1; - if ($noActualRows != $numRows) - { + if ($noActualRows != $numRows) { echo "Number of Actual Rows $noActualRows is unexpected!\n"; } - - $stmt = null; - $stmt2 = null; - + + unset($stmt); + unset($stmt2); + return $numCols; } -function GetValueFromObject($obj, $col) +function getValueFromObject($obj, $col) { - switch ($col) - { + switch ($col) { case 1: return $obj->c1_int; case 2: return $obj->c2_tinyint; case 3: return $obj->c3_smallint; @@ -145,99 +158,88 @@ function GetValueFromObject($obj, $col) case 22: return $obj->c22_date; case 23: return $obj->c23_datetime2; default: return null; - } + } } -function DoValuesMatched($value1, $value2, $row, $col) +function doValuesMatched($value1, $value2, $row, $col) { $matched = ($value1 === $value2); - if (! $matched) - { + if (! $matched) { echo "Values from row $row and column $col do not matched\n"; echo "One is $value1 but the other is $value2\n"; - } + } } -function Fetch_Columns($conn, $tableName, $numRows, $numCols) +function fetchColumns($conn, $tableName, $numRows, $numCols) { - try - { - // insert column data from a row of the original table - $stmtOriginal = $conn->prepare("SELECT * FROM $tableName WHERE c1_int = :row"); - - for ($i = 1; $i <= $numRows; $i++) - { + try { + // insert column data from a row of the original table + $stmtOriginal = $conn->prepare("SELECT * FROM $tableName WHERE c1_int = :row"); + + for ($i = 1; $i <= $numRows; $i++) { $c1_int = $i; - - echo "Insert all columns from row $c1_int into one column of type sql_variant\n"; + + echo "Insert all columns from row $c1_int into one column of type sql_variant\n"; $stmtOriginal->bindValue(':row', $c1_int, PDO::PARAM_INT); // create another temporary test table $name = 'row' . $c1_int; - $tmpTable = GetTempTableName($name); - $conn->exec("CREATE TABLE $tmpTable ([id] int identity(1, 1), [value] sql_variant)"); - + $tmpTable = getTableName($name); + createTable($conn, $tmpTable, array(new ColumnMeta("int", "id", "identity(1, 1)"), "value" => "sql_variant")); + // change $c1_int now should not affect the results $c1_int = 'DummyValue'; - + $stmtTmp = $conn->prepare("INSERT INTO $tmpTable ([value]) VALUES (?)"); - for ($j = 0; $j < $numCols; $j++) - { + for ($j = 0; $j < $numCols; $j++) { $stmtOriginal->execute(); $value = $stmtOriginal->fetchColumn($j); - + // insert this value into the only column in the new table - $stmtTmp->bindParam($j + 1, $value, PDO::PARAM_STR); + $stmtTmp->bindParam(1, $value, PDO::PARAM_STR); $res = $stmtTmp->execute(); - if (! $res) + if (! $res) { echo "Failed to insert data from column ". $j +1 ."\n"; - + } } // now select them all and compare $stmtTmp = $conn->query("SELECT value FROM $tmpTable ORDER BY [id]"); $metadata = $stmtTmp->getColumnMeta(0); var_dump($metadata['sqlsrv:decl_type']); - + $results = $stmtTmp->fetchAll(PDO::FETCH_COLUMN); - + $stmtOriginal->execute(); $arrays = $stmtOriginal->fetchAll(PDO::FETCH_ASSOC); $columns = $arrays[0]; // only the first set is needed - + $j = 0; - foreach ($columns as $column) - { - if ($j == 0) - { + foreach ($columns as $column) { + if ($j == 0) { $val = sprintf('%d', $i); - DoValuesMatched($results[$j], $val, $i, $j+1); - } - else - { - DoValuesMatched($results[$j], $column, $i, $j+1); + doValuesMatched($results[$j], $val, $i, $j+1); + } else { + doValuesMatched($results[$j], $column, $i, $j+1); } $j++; } - - $stmtTmp = null; + + unset($stmtTmp); } - } - catch (Exception $e) - { + } catch (Exception $e) { echo "Failed in creating a table with a single column of sql_variant\n"; echo $e->getMessage(); } - - $stmtOriginal = null; + + unset($stmtOriginal); } -function GetQuery($tableName, $index) +function getQuery($tableName, $index) { $query = ""; - switch ($index) - { + switch ($index) { case 1: $query = "INSERT INTO $tableName ([c1_int], [c2_tinyint], [c3_smallint], [c4_bigint], [c5_bit], [c6_float], [c7_real], [c8_decimal], [c9_numeric], [c10_money], [c11_smallmoney], [c12_char], [c13_varchar], [c14_nchar], [c15_nvarchar], [c16_binary], [c17_varbinary], [c18_uniqueidentifier], [c19_datetime], [c20_smalldatetime], [c21_time], [c22_date], [c23_datetime2]) VALUES ((1), (110), (-28270), (804279686), (0), (0), (null), (-100000000000000000000000), (0.6685), (0.2997), (0.5352), ('äðubý/ö*bUah¢AoÖrZÃ_oßoüöÐ>ßÄßUAüîÖh_u*uh.uå:,öî@UCO,<¢<:Ö@>+ß,ªåÜbrª¢öãäo,ü£/b,|ýãý~öߣîUö_¢ªðu.+ýÃhAaäzvzrb£ßAÃhö,ö.aöü/Z+Ã.uvUo~v:+u_ýý©z¢ª|U/îã<©|vý+bÐÄЩoðbbüðb_~*î..üÐÃz,äAðß~Ö¢Äå~ð.£_ßzãÖv~¢£Oå*@|UozU©Ð+ãÄÐ,*Z/vA>ªOÄ,¢bhý/ÖÖuäAoü.a@@ßaðvbaߣ@v,ub+Oä@oBBÖöAüßö|Ö~hhvbuäo/<Ã+£¢Ã¢ß>'), ('Z:Uî/ÜãýüÄzãüvä/Ühý£||ãoå,ªÜ©uÖ_.>ßýbåää|üð/ý.BO:ZCu©ß<£ªãÄ@ýß©vöß:>:ä+åvCBª£.o>Z/*,B_å~AO,rO+åÖZ£>rö¢Ð~ðuö_Ðä'), (N''), (N'ZªC|©v¢Äß~Uh¢£o>ªvª,~Öß@@Oß*BOOöA_¢AªðßäªåaB~ÖABhbääbCÃ_Ü¢A>>vª¢,zBBahåÃ>ÐÜÃÖÐðÜhÄrb*zåðãbUýåZ,*v,ÄU£öbýoO,**ýßbÃv+Üb|Zb:OUöîåßO*:/,'), (0xF502D70F2F74A32894021775707AEE3D8601A0E601FF565636A220DBFE213F3B143FA70B33712EC31501D0202A6125E5EA13FCD7F33991F6AC80D88D53C82A73C3DB6130D3E20914D2DDD1002E352BD57D3AF1EA246748DBADB05FB398A16F4DD75D5D4F00F4120709E704166891C77755030F18D63F4F5C9386822283567B316D8328D0D8DCD58828E9E13C6232731CE9E85D95915676980E01BB7A), (0xB36CD3A8E468F69E792D86F0ED5E12F9611266399BF8E6A0160D90C2D6205B1638642DD08F898EB3F249E4670A66883AFB075A670CB6E9BA853292D7D834C758D270B889304269D884B24751147E95B08456C6CFC6F40A817B734A5CF7B6DBBD818C959AADFF09B99D82E2596F97A6079CE153816DF892DE65370DBDF80DE0CDD689D087E9FB03844C0D314311B012E3CC43BF15635A4F88FAB63475F14CC090A11583E5C61E1DA1DECE3460C64ECDB4252AF0B54DCB697C39488D33C68D93004CA1A2FC2D2C1DAD251E379525EFC1ACE98050C75B0B42D6AB06AB7E91EADA503B331325ABD186F80C42902F94D4564986E14A463DCBA5415ECC5026809E1C3A43E65AF1DC9C0017F957BA187B1341D6AF61F8AFA09412), ('00000000-0000-0000-0000-000000000000'), ('2819-01-08 00:12:52.445'), ('2079-06-06 23:59:00'), ('03:46:33.6181920'), ('2148-04-25'), ('0269-03-15 01:59:43.6050438'))"; break; @@ -250,47 +252,29 @@ function GetQuery($tableName, $index) return $query; } -function RunTest() -{ - StartTest("pdo_fetch_variants_diff_styles"); - try - { - include("MsSetup.inc"); +try { + // Connect + $conn = connect(); + $tableName = getTableName(); + createTestTable($conn, $tableName); - // Connect - $conn = new PDO( "sqlsrv:server=$server;Database=$databaseName", $uid, $pwd); - $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); + $numRows = 2; + insertData($conn, $tableName, $numRows); - $tableName = GetTempTableName(); - CreateTestTable($conn, $tableName); - - $numRows = 2; - InsertData($conn, $tableName, $numRows); - - $numCols = Fetch_BoundMixed($conn, $tableName, $numRows); - Fetch_Columns($conn, $tableName, $numRows, $numCols); + $numCols = fetchBoundMixed($conn, $tableName, $numRows); + fetchColumns($conn, $tableName, $numRows, $numCols); - $conn = null; - } - catch (Exception $e) - { - echo $e->getMessage(); - } - echo "\nDone\n"; - EndTest("pdo_fetch_variants_diff_styles"); + dropTable($conn, $tableName); + unset($conn); +} catch (Exception $e) { + echo $e->getMessage(); } -RunTest(); - ?> --EXPECT-- - Comparing data in row 1 Comparing data in row 2 Insert all columns from row 1 into one column of type sql_variant string(11) "sql_variant" Insert all columns from row 2 into one column of type sql_variant string(11) "sql_variant" - -Done -Test "pdo_fetch_variants_diff_styles" completed successfully. \ No newline at end of file diff --git a/test/functional/pdo_sqlsrv/pdo_katmai_special_types.phpt b/test/functional/pdo_sqlsrv/pdo_katmai_special_types.phpt index 17ccd16b..aaa4237a 100644 --- a/test/functional/pdo_sqlsrv/pdo_katmai_special_types.phpt +++ b/test/functional/pdo_sqlsrv/pdo_katmai_special_types.phpt @@ -1,147 +1,173 @@ --TEST-- Test various Katmai types, like geography, geometry, hierarchy, sparse, etc. and fetch them back as strings --SKIPIF-- - + --FILE-- exec("CREATE TABLE $tableName ([c1_time] time, [c2_date] date, [c3_datetimeoffset] datetimeoffset, [c4_geography] geography, [c5_geometry] geometry, [c6_hierarchyid] hierarchyid, [c7_uniqueidentifier] uniqueidentifier ROWGUIDCOL NOT NULL UNIQUE DEFAULT NEWID())"); - $stmt = null; - - $query = "INSERT INTO $tableName ([c1_time], [c2_date], [c3_datetimeoffset], [c4_geography], [c5_geometry], [c6_hierarchyid], [c7_uniqueidentifier]) VALUES (('03:32:25.5643401'), ('1439-01-10'), ('0221-01-12 06:39:07.0620256+00:00'), ('POINT(27.91 -76.74)'), ('LINESTRING(30.50 -0.66, 31.03 -0.38)'), ('/1/3/'), ('5a1a88f7-3749-46a3-8a7a-efae73efe88f'))"; - $stmt = $conn->query($query); - $stmt = null; - - echo "\nShowing results of Katmai basic fields\n"; - - $stmt = $conn->query("SELECT * FROM $tableName"); - $numFields = $stmt->columnCount(); - $cols = array_fill(0, $numFields, ""); - - for ($i = 0; $i < $numFields; $i++) - { - $stmt->bindColumn($i+1, $cols[$i]); - } - - $stmt->fetch(PDO::FETCH_BOUND); - for ($i = 0; $i < $numFields; $i++) - { - $value = $cols[$i]; - if ($i >= 3) - { - if ($value != null) - $value = bin2hex($value); + $tableName = getTableName(); + $dataTypes = array("c1_time" => "time", + "c2_date" => "date", + "c3_datetimeoffset" => "datetimeoffset", + "c4_geography" => "geography", + "c5_geometry" => "geometry", + "c6_hierarchyid" => "hierarchyid", + new ColumnMeta("uniqueidentifier", "c7_uniqueidentifier", "ROWGUIDCOL NOT NULL UNIQUE DEFAULT NEWID()")); + $data = array("c1_time" => '03:32:25.5643401', + "c2_date" => '1439-01-10', + "c3_datetimeoffset" => '0221-01-12 06:39:07.0620256+00:00', + "c4_geography" => 'POINT(27.91 -76.74)', + "c5_geometry" => 'LINESTRING(30.50 -0.66, 31.03 -0.38)', + "c6_hierarchyid" => '/1/3/', + "c7_uniqueidentifier" => '5a1a88f7-3749-46a3-8a7a-efae73efe88f'); + $expOutput = array("c1_time" => '03:32:25.5643401', + "c2_date" => '1439-01-10', + "c3_datetimeoffset" => '0221-01-12 06:39:07.0620256 +00:00', + "c4_geography" => 'e6100000010c8fc2f5285c2f53c0295c8fc2f5e83b40', + "c5_geometry" => '0000000001140000000000803e401f85eb51b81ee5bf48e17a14ae073f4052b81e85eb51d8bf', + "c6_hierarchyid" => '5bc0', + "c7_uniqueidentifier" => '35413141383846372d333734392d343641332d384137412d454641453733454645383846'); + if (isColEncrypted()) { + $toRemove = array("c4_geography", "c5_geometry", "c6_hierarchyid"); + foreach ($toRemove as $key) { + unset($dataTypes[$key]); + unset($data[$key]); + unset($expOutput[$key]); } + } + $expOutput = array_values($expOutput); + createTable($conn, $tableName, $dataTypes); + insertRow($conn, $tableName, $data); + echo "\nComparing results of Katmai basic fields\n"; - var_dump($value); - } + $stmt = $conn->query("SELECT * FROM $tableName"); + $numFields = $stmt->columnCount(); + $cols = array_fill(0, $numFields, ""); + + for ($i = 0; $i < $numFields; $i++) { + $stmt->bindColumn($i+1, $cols[$i]); + } + + $stmt->fetch(PDO::FETCH_BOUND); + for ($i = 0; $i < $numFields; $i++) { + $value = $cols[$i]; + if ($i >= 3) { + if ($value != null) { + $value = bin2hex($value); + } + } + if ($value !== $expOutput[$i]) { + echo "Unexpected output retrieved.\n"; + var_dump($value); + } + } + dropTable($conn, $tableName); } -function Katmai_SparseChar($conn) +function katmaiSparseChar($conn) { - $tableName = GetTempTableName(); - - $stmt = $conn->exec("CREATE TABLE $tableName (c1 int, c2 char(512) SPARSE NULL, c3 varchar(512) SPARSE NULL, c4 varchar(max) SPARSE NULL, c5 nchar(512) SPARSE NULL, c6 nvarchar(512) SPARSE NULL, c7 nvarchar(max) SPARSE NULL)"); - $stmt = null; + $tableName = getTableName(); + + // Sparse column set is not supported for Always Encrypted + $options = ""; + if (!isColEncrypted()) { + $options = "SPARSE NULL"; + } + $dataTypes = array("c1" => "int", + new ColumnMeta("char(512)", "c2", $options), + new ColumnMeta("char(512)", "c3", $options), + new ColumnMeta("varchar(max)", "c4", $options), + new ColumnMeta("nchar(512)", "c5", $options), + new ColumnMeta("nvarchar(512)", "c6", $options), + new ColumnMeta("nvarchar(max)", "c7", $options)); + createTable($conn, $tableName, $dataTypes); $input = "The quick brown fox jumps over the lazy dog"; - $stmt = $conn->query("INSERT INTO $tableName (c1, c2, c5) VALUES(1, 'The quick brown fox jumps over the lazy dog', 'The quick brown fox jumps over the lazy dog')"); - $stmt = null; - $stmt = $conn->query("INSERT INTO $tableName (c1, c3, c6) VALUES(2, 'The quick brown fox jumps over the lazy dog', 'The quick brown fox jumps over the lazy dog')"); - $stmt = null; - $stmt = $conn->query("INSERT INTO $tableName (c1, c4, c7) VALUES(3, 'The quick brown fox jumps over the lazy dog', 'The quick brown fox jumps over the lazy dog')"); - $stmt = null; - + insertRow($conn, $tableName, array("c1" => 1, "c2" => $input, "c5" => $input)); + insertRow($conn, $tableName, array("c1" => 2, "c3" => $input, "c6" => $input)); + insertRow($conn, $tableName, array("c1" => 3, "c4" => $input, "c7" => $input)); + echo "\nComparing results of Katmai sparse fields\n"; - $stmt = $conn->query("SELECT * FROM $tableName"); - - while ($row = $stmt->fetch(PDO::FETCH_NUM)) - { + $stmt = $conn->query("SELECT * FROM $tableName"); + + while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $fld1 = $row[0]; $fld2 = $fld1 + 3; - + $value1 = $row[$fld1]; $value2 = $row[$fld2]; - if ($input !== trim($value1)) - { + if ($input !== trim($value1)) { echo "The value is unexpected!\n"; } - if ($value1 !== $value2) - { + if (trim($value1) !== trim($value2)) { echo "The values don't match!\n"; } } + dropTable($conn, $tableName); } -function Katmai_SparseNumeric($conn) +function katmaiSparseNumeric($conn) { - $tableName = GetTempTableName(); - - $stmt = $conn->exec("CREATE TABLE $tableName (c1 int, c2 int SPARSE NULL, c3 tinyint SPARSE NULL, c4 smallint SPARSE NULL, c5 bigint SPARSE NULL, c6 bit SPARSE NULL, c7 float SPARSE NULL, c8 real SPARSE NULL, c9 decimal(28,4) SPARSE NULL, c10 numeric(32,4) SPARSE NULL)"); - - $stmt = $conn->query("INSERT INTO $tableName (c1, c2, c3, c4, c5, c6, c7, c8, c9, c10) VALUES(1, '1', '1', '1', '1', '1', '1', '1', '1', '1')"); - $stmt = null; - + $tableName = getTableName(); + + // Sparse column set is not supported for Always Encrypted + $options = ""; + if (!isColEncrypted()) { + $options = "SPARSE NULL"; + } + + $dataTypes = array("c1" => "int", + new ColumnMeta("int", "c2", $options), + new ColumnMeta("tinyint", "c3", $options), + new ColumnMeta("smallint", "c4", $options), + new ColumnMeta("bigint", "c5", $options), + new ColumnMeta("bit", "c6", $options), + new ColumnMeta("float", "c7", $options), + new ColumnMeta("real", "c8", $options), + new ColumnMeta("decimal(28,4)", "c9", $options), + new ColumnMeta("numeric(32,4)", "c10", $options)); + createTable($conn, $tableName, $dataTypes); + + $data = array("c1" => 1); + for ($i = 1; $i < 10; $i++) { + $colName = "c" . strval($i+1); + $data[$colName] = '1'; + } + insertRow($conn, $tableName, $data); + echo "\nShowing results of Katmai sparse numeric fields\n"; - $stmt = $conn->query("SELECT * FROM $tableName"); - $row = $stmt->fetch(PDO::FETCH_NUM); - foreach ($row as $value) - { + $stmt = $conn->query("SELECT * FROM $tableName"); + $row = $stmt->fetch(PDO::FETCH_NUM); + foreach ($row as $value) { var_dump($value); - } + } + dropTable($conn, $tableName); } //-------------------------------------------------------------------- // Repro // //-------------------------------------------------------------------- -function Repro() -{ - StartTest("pdo_katmai_special_types"); - echo "\nStarting test...\n"; - try - { - include("MsSetup.inc"); - set_time_limit(0); - - $conn = new PDO( "sqlsrv:server=$server;database=$databaseName", $uid, $pwd); - - Katmai_Basic_Types($conn); - Katmai_SparseChar($conn); - Katmai_SparseNumeric($conn); +try { + $conn = connect(); - $conn = null; - } - catch (Exception $e) - { - echo $e->getMessage(); - } - echo "\nDone\n"; - - EndTest("pdo_katmai_special_types"); + katmaiBasicTypes($conn); + katmaiSparseChar($conn); + katmaiSparseNumeric($conn); + + unset($conn); +} catch (Exception $e) { + echo $e->getMessage(); } -Repro(); - ?> --EXPECT-- - -Starting test... -Showing results of Katmai basic fields -string(16) "03:32:25.5643401" -string(10) "1439-01-10" -string(34) "0221-01-12 06:39:07.0620256 +00:00" -string(44) "e6100000010c8fc2f5285c2f53c0295c8fc2f5e83b40" -string(76) "0000000001140000000000803e401f85eb51b81ee5bf48e17a14ae073f4052b81e85eb51d8bf" -string(4) "5bc0" -string(72) "35413141383846372d333734392d343641332d384137412d454641453733454645383846" +Comparing results of Katmai basic fields Comparing results of Katmai sparse fields @@ -156,6 +182,3 @@ string(3) "1.0" string(3) "1.0" string(6) "1.0000" string(6) "1.0000" - -Done -Test "pdo_katmai_special_types" completed successfully. \ No newline at end of file diff --git a/test/functional/pdo_sqlsrv/pdo_param_output_select_variant.phpt b/test/functional/pdo_sqlsrv/pdo_param_output_select_variant.phpt index 9c3dfff3..94ce1812 100644 --- a/test/functional/pdo_sqlsrv/pdo_param_output_select_variant.phpt +++ b/test/functional/pdo_sqlsrv/pdo_param_output_select_variant.phpt @@ -1,85 +1,76 @@ --TEST-- -Test sql_variant as an output parameter +Test sql_variant as an output parameter --DESCRIPTION-- -Since output param is not supported for sql_variant columns, this test verifies a proper error message is returned +Since output param is not supported for sql_variant columns, this test verifies a proper error message is returned +--SKIPIF-- + --FILE-- prepare("SELECT ? = COUNT(* ) FROM $tableName"); - $stmt->bindParam( 1, $count, PDO::PARAM_INT, 4 ); - $stmt->execute(); - echo "Number of rows: $count\n"; + $stmt = $conn->prepare("SELECT ? = COUNT(* ) FROM $tableName"); + $stmt->bindParam(1, $count, PDO::PARAM_INT, 4); + $stmt->execute(); + echo "Number of rows: $count\n"; $value = 'xx'; - - $stmt = $conn->prepare("SELECT ? = c2_variant FROM $tableName"); - $stmt->bindParam( 1, $value, PDO::PARAM_STR, 50 ); - $stmt->execute(); - echo "Variant column: $value\n\n"; - + + $stmt = $conn->prepare("SELECT ? = c2_variant FROM $tableName"); + $stmt->bindParam(1, $value, PDO::PARAM_STR, 50); + $stmt->execute(); + echo "Variant column: $value\n\n"; } -function CreateVariantTable($conn, $tableName) +function createVariantTable($conn, $tableName) { - try - { - $stmt = $conn->exec("CREATE TABLE [$tableName] ([c1_int] int, [c2_variant] sql_variant)"); - } - catch (Exception $e) - { + try { + createTable($conn, $tableName, array("c1_int" => "int", "c2_variant" => "sql_variant")); + } catch (Exception $e) { echo "Failed to create a test table\n"; echo $e->getMessage(); - } + } - $tsql = "INSERT INTO [$tableName] ([c1_int], [c2_variant]) VALUES (1, ?)"; - $data = "This is to test if sql_variant works with output parameters"; - - $stmt = $conn->prepare($tsql); - $result = $stmt->execute(array($data)); - if (! $result) + if (!isColEncrypted()) { + $tsql = "INSERT INTO [$tableName] ([c1_int], [c2_variant]) VALUES (1, ?)"; + $stmt = $conn->prepare($tsql); + $result = $stmt->execute(array($data)); + } else { + $tsql = "INSERT INTO [$tableName] ([c1_int], [c2_variant]) VALUES (?, ?)"; + $stmt = $conn->prepare($tsql); + $intData = 1; + $result = $stmt->execute(array($intData, $data)); + } + + if (! $result) { echo "Failed to insert data\n"; + } } -function RunTest() -{ - StartTest("pdo_param_output_select_variant"); - try - { - include("MsSetup.inc"); - // Connect - $conn = new PDO( "sqlsrv:server=$server;Database=$databaseName", $uid, $pwd); - $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); - echo "\n"; +try { + // Connect + $conn = connect(); - // Now test with another stored procedure - $tableName = GetTempTableName(); - CreateVariantTable($conn, $tableName); + // Now test with another stored procedure + $tableName = getTableName(); + createVariantTable($conn, $tableName); - // Test a simple select to get output - TestSimpleSelect($conn, $tableName); - - $conn = null; - } - catch (Exception $e) - { - echo $e->getMessage(); - } - echo "\nDone\n"; - EndTest("pdo_param_output_select_variant"); + // Test a simple select to get output + testSimpleSelect($conn, $tableName); + + dropTable($conn, $tableName); + unset($conn); +} catch (Exception $e) { + echo $e->getMessage(); } - -RunTest(); +echo "\nDone\n"; ?> ---EXPECTREGEX-- - +--EXPECT-- Number of rows: 1 -SQLSTATE\[42000\]: \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]\[SQL Server\]Implicit conversion from data type sql_variant to nvarchar\(max\) is not allowed. Use the CONVERT function to run this query. +SQLSTATE[42000]: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Implicit conversion from data type sql_variant to nvarchar(max) is not allowed. Use the CONVERT function to run this query. Done -Test \"pdo_param_output_select_variant\" completed successfully\. diff --git a/test/functional/pdo_sqlsrv/pdo_param_output_variants.phpt b/test/functional/pdo_sqlsrv/pdo_param_output_variants.phpt index 0749c1e1..50a9e8c3 100644 --- a/test/functional/pdo_sqlsrv/pdo_param_output_variants.phpt +++ b/test/functional/pdo_sqlsrv/pdo_param_output_variants.phpt @@ -1,75 +1,81 @@ --TEST-- Test parametrized insert and sql_variant as an output parameter. --DESCRIPTION-- -Since output param is not supported for sql_variant columns, this test verifies a proper error message is returned +Since output param is not supported for sql_variant columns, this test verifies a proper error message is returned --FILE-- exec($spCode); - } - catch (Exception $e) - { + $conn->exec($spCode); + } catch (Exception $e) { echo "Failed to create the reverse procedure\n"; echo $e->getMessage(); - } - - try - { - $stmt = $conn->prepare("{ CALL [$procName] (?) }"); - $string = "123456789"; - $stmt->bindParam(1, $string, PDO::PARAM_STR, 30); - $stmt->execute(); - echo "Does REVERSE work? $string \n"; } - catch (Exception $e) - { + + try { + $stmt = $conn->prepare("{ CALL [$procName] (?) }"); + $string = "123456789"; + $stmt->bindParam(1, $string, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT, 30); + $stmt->execute(); + // 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"; + } else { + echo "Does REVERSE work? $string \n"; + } + } catch (Exception $e) { //echo "Failed when calling the reverse procedure\n"; - echo $e->getMessage(); - echo "\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"; + } else { + echo "$error\n"; + } + } } -function CreateVariantTable($conn, $tableName) +function createVariantTable($conn, $tableName) { - try - { - $stmt = $conn->exec("CREATE TABLE [$tableName] ([c1_int] int, [c2_variant] sql_variant)"); - } - catch (Exception $e) - { + try { + createTable($conn, $tableName, array("c1_int" => "int", "c2_variant" => "sql_variant")); + } catch (Exception $e) { echo "Failed to create a test table\n"; echo $e->getMessage(); - } + } - $tsql = "INSERT INTO [$tableName] ([c1_int], [c2_variant]) VALUES (1, ?)"; - $data = "This is to test if sql_variant works with output parameters"; - - $stmt = $conn->prepare($tsql); - $result = $stmt->execute(array($data)); - if (! $result) + if (!isColEncrypted()) { + $tsql = "INSERT INTO [$tableName] ([c1_int], [c2_variant]) VALUES (1, ?)"; + $stmt = $conn->prepare($tsql); + $result = $stmt->execute(array($data)); + } else { + $tsql = "INSERT INTO [$tableName] ([c1_int], [c2_variant]) VALUES (?, ?)"; + $stmt = $conn->prepare($tsql); + $intData = 1; + $result = $stmt->execute(array($intData, $data)); + } + + if (! $result) { echo "Failed to insert data\n"; + } } -function TestOutputParam($conn, $tableName) +function testOutputParam($conn, $tableName) { // First, create a temporary stored procedure - $procName = GetTempProcName('sqlVariant'); - + $procName = getProcName('sqlVariant'); + $spArgs = "@p1 int, @p2 sql_variant OUTPUT"; $spCode = "SET @p2 = ( SELECT [c2_variant] FROM $tableName WHERE [c1_int] = @p1 )"; - - $stmt = $conn->exec("CREATE PROC [$procName] ($spArgs) AS BEGIN $spCode END"); - $stmt = null; + + $conn->exec("CREATE PROC [$procName] ($spArgs) AS BEGIN $spCode END"); $callArgs = "?, ?"; @@ -78,63 +84,48 @@ function TestOutputParam($conn, $tableName) $initData = "A short text"; $callResult = $initData; - try - { + try { $stmt = $conn->prepare("{ CALL [$procName] ($callArgs)}"); $stmt->bindValue(1, 1); $stmt->bindParam(2, $callResult, PDO::PARAM_STR, 100); $stmt->execute(); - - - } - catch (Exception $e) - { - if(!strcmp($initData, $callResult)) - { + if (isColEncrypted() && $callResult === "This is to test if sql_variant works with output parameters") { + echo "Test output parameter with SQL_VARIANT successfully.\n"; + } else { + echo "Does SELECT from table work? $callResult \n"; + } + } catch (Exception $e) { + if (!strcmp($initData, $callResult)) { echo "initialized data and result should be the same"; } - echo $e->getMessage(); - echo "\n"; - } + $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"; + } else { + echo "$error\n"; + } + } } -function RunTest() -{ - StartTest("pdo_param_output_variants"); - try - { - include("MsSetup.inc"); - // Connect - $conn = new PDO( "sqlsrv:server=$server;Database=$databaseName", $uid, $pwd); - $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); - echo "\n"; +try { + // Connect + $conn = connect(); - // Test with a simple stored procedure - TestReverse($conn); - - // Now test with another stored procedure - $tableName = GetTempTableName(); - CreateVariantTable($conn, $tableName); + // Test with a simple stored procedure + testReverse($conn); - TestOutputParam($conn, $tableName); - - $conn = null; - } - catch (Exception $e) - { - echo $e->getMessage(); - } - echo "\nDone\n"; - EndTest("pdo_param_output_variants"); + // Now test with another stored procedure + $tableName = getTableName(); + createVariantTable($conn, $tableName); + + testOutputParam($conn, $tableName); + + $conn = null; +} catch (Exception $e) { + echo $e->getMessage(); } -RunTest(); - ?> --EXPECTREGEX-- - -SQLSTATE\[22018\]: \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]\[SQL Server\]Operand type clash: nvarchar\(max\) is incompatible with sql_variant -SQLSTATE\[22018\]: \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]\[SQL Server\]Operand type clash: nvarchar\(max\) is incompatible with sql_variant - -Done -Test \"pdo_param_output_variants\" completed successfully\. +Test input output parameter with SQL_VARIANT successfully. +Test output parameter with SQL_VARIANT successfully. diff --git a/test/functional/pdo_sqlsrv/pdo_prepare_attribute.phpt b/test/functional/pdo_sqlsrv/pdo_prepare_attribute.phpt index 6d4422be..ef702bf6 100644 --- a/test/functional/pdo_sqlsrv/pdo_prepare_attribute.phpt +++ b/test/functional/pdo_sqlsrv/pdo_prepare_attribute.phpt @@ -3,76 +3,62 @@ Test PDO::prepare() with PDO::ATTR_EMULATE_PREPARES. --ENV-- PHPT_EXEC=true --SKIPIF-- - + --FILE-- setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); - // retrieve correct results -$s = $db->prepare( "SELECT '' + TITLE FROM cd_info GROUP BY '' + TITLE" ); - +$s = $db->prepare("SELECT '' + TITLE FROM cd_info GROUP BY '' + TITLE"); $s->execute(); $titles = array(); - -while( $r = $s->fetch()) { - - $titles[] = $r[0]; +while ($r = $s->fetch()) { + $titles[] = $r[0]; } $exception_thrown = false; try { + $s = $db->prepare('SELECT :prefix + TITLE FROM cd_info GROUP BY :prefix + TITLE'); + $s->bindValue(':prefix', ""); + $s->execute(); -$s = $db->prepare( 'SELECT :prefix + TITLE FROM cd_info GROUP BY :prefix + TITLE' ); - -$s->bindValue( ':prefix', "" ); - -$s->execute(); - -while( $r = $s->fetch()) { - - print_r( $r ); -} - -} -catch ( PDOException $e ) { - + while ($r = $s->fetch()) { + print_r($r); + } +} catch (PDOException $e) { $exception_thrown = true; } -if( !$exception_thrown ) { - - die( "Exception not thrown\nTest failed\n" ); +if (!$exception_thrown) { + die("Exception not thrown\nTest failed\n"); } -$s = $db->prepare( "SELECT :prefix + TITLE FROM cd_info GROUP BY :prefix + TITLE", - array( PDO::ATTR_EMULATE_PREPARES => true )); - -$s->bindValue( ':prefix', "" ); +// Column encryption is not supported by emulate prepared statement +$option[PDO::ATTR_EMULATE_PREPARES] = true; +if (isColEncrypted()) { + $option[PDO::ATTR_EMULATE_PREPARES] = false; +} +$s = $db->prepare("SELECT :prefix + TITLE FROM cd_info GROUP BY :prefix + TITLE", $option); +$s->bindValue(':prefix', ""); $s->execute(); $param_titles = array(); - -while( $r = $s->fetch()) { - - $param_titles[] = $r[0]; +while ($r = $s->fetch()) { + $param_titles[] = $r[0]; } -if ( $titles === $param_titles ) { +if ($titles === $param_titles) { echo "Test succeeded\n"; -} -else { - +} else { echo "Test failed\n"; - print_r( $titles ); - print_r( $param_titles ); + print_r($titles); + print_r($param_titles); } ?> diff --git a/test/functional/pdo_sqlsrv/pdo_simple_update_variants.phpt b/test/functional/pdo_sqlsrv/pdo_simple_update_variants.phpt index c0ace417..b289a38f 100644 --- a/test/functional/pdo_sqlsrv/pdo_simple_update_variants.phpt +++ b/test/functional/pdo_sqlsrv/pdo_simple_update_variants.phpt @@ -2,149 +2,143 @@ Test simple insert and update sql_variants using parameters of some different data categorys --DESCRIPTION-- ORDER BY should work with sql_variants +--SKIPIF-- + --FILE-- food; } - function getcategory() + public function getcategory() { return $this->category; - } + } } -function CreateVariantTable($conn, $tableName) +function createVariantTable($conn, $tableName) { - try - { - $stmt = $conn->exec("CREATE TABLE $tableName ([id] sql_variant, [food] sql_variant, [category] sql_variant)"); - } - catch (Exception $e) - { + try { + createTable($conn, $tableName, array("id" => "sql_variant", "food" => "sql_variant", "category" => "sql_variant")); + } catch (Exception $e) { echo "Failed to create a test table\n"; echo $e->getMessage(); - } + } } -function InsertData($conn, $tableName, $id, $food, $category) +function insertData($conn, $tableName, $id, $food, $category) { - try - { + try { $query = "INSERT $tableName ([id], [food], [category]) VALUES (:id, :food, :category)"; $stmt = $conn->prepare($query); $stmt->bindValue(':id', $id); $stmt->bindValue(':food', $food); $stmt->bindValue(':category', $category); - - $result = $stmt->execute(); - if ($result) - echo "\nAdded $food in $category with ID $id."; - } - catch (Exception $e) - { + + $result = $stmt->execute(); + if ($result) { + echo "Added $food in $category with ID $id.\n"; + } + } catch (Exception $e) { echo "Failed to insert food $food\n"; echo $e->getMessage(); - } + } } -function UpdateID($conn, $tableName, $id, $food, $category) +function updateID($conn, $tableName, $id, $food, $category) { $query = "UPDATE $tableName SET id = ? WHERE food = ? AND category = ?"; $stmt = $conn->prepare($query); $result = $stmt->execute(array($id, $food, $category)); - - if ($result) - echo "\nFood $food now updated with new id $id."; - else - echo "Failed to update ID.\n"; + + if ($result) { + echo "Food $food now updated with new id $id.\n"; + } else { + echo "Failed to update ID.\n"; + } } -function UpdateFood($conn, $tableName, $id, $food, $category) +function updateFood($conn, $tableName, $id, $food, $category) { $query = "UPDATE $tableName SET food = ? WHERE id = ? AND category = ?"; $stmt = $conn->prepare($query); $result = $stmt->execute(array($food, $id, $category)); - - if ($result) - echo "\nCategory $category now updated with $food."; - else - echo "Failed to update food.\n"; + + if ($result) { + echo "Category $category now updated with $food.\n"; + } else { + echo "Failed to update food.\n"; + } } -function FetchRows($conn, $tableName) +function fetchRows($conn, $tableName) { - $query = "SELECT * FROM $tableName ORDER BY id"; - - $stmt = $conn->query($query); + if (!isColEncrypted()) { + $query = "SELECT * FROM $tableName ORDER BY id"; + } else { + $query = "SELECT * FROM $tableName"; + } + $stmt = $conn->query($query); $stmt->setFetchMode(PDO::FETCH_CLASS, 'Food'); - while ($food = $stmt->fetch()) - { - echo "\nID: " . $food->id . " "; + $foodArray = array(); + while ($food = $stmt->fetch()) { + array_push($foodArray, $food); + } + if (isColEncrypted()) { + sort($foodArray); + } + foreach ($foodArray as $food) { + echo "ID: " . $food->id . " "; echo $food->getFood() . ", "; - echo $food->getcategory(); + echo $food->getcategory() . "\n"; } - - $stmt = null; + unset($stmt); } -function RunTest() -{ - StartTest("pdo_simple_update_variants"); - try - { - include("MsSetup.inc"); - // Connect - $conn = new PDO( "sqlsrv:server=$server;Database=$databaseName", $uid, $pwd); - $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); - $tableName = GetTempTableName(); - CreateVariantTable($conn, $tableName); - - // Add three kinds of foods - InsertData($conn, $tableName, 1, 'Milk', 'Diary Products'); - InsertData($conn, $tableName, 3, 'Chicken', 'Meat'); - InsertData($conn, $tableName, 5, 'Blueberry', 'Fruits'); - - FetchRows($conn, $tableName); - - UpdateID($conn, $tableName, 4, 'Milk', 'Diary Products'); +try { + // Connect + $conn = connect(); - FetchRows($conn, $tableName); - - UpdateFood($conn, $tableName, 4, 'Cheese', 'Diary Products'); + $tableName = getTableName(); + createVariantTable($conn, $tableName); - FetchRows($conn, $tableName); + // Add three kinds of foods + insertData($conn, $tableName, 1, 'Milk', 'Diary Products'); + insertData($conn, $tableName, 3, 'Chicken', 'Meat'); + insertData($conn, $tableName, 5, 'Blueberry', 'Fruits'); - // Add three kinds of foods - InsertData($conn, $tableName, 6, 'Salmon', 'Fish'); - InsertData($conn, $tableName, 2, 'Broccoli', 'Vegetables'); - - FetchRows($conn, $tableName); - - $conn = null; - } - catch (Exception $e) - { - echo $e->getMessage(); - } - echo "\nDone\n"; - EndTest("pdo_simple_update_variants"); + fetchRows($conn, $tableName); + + updateID($conn, $tableName, 4, 'Milk', 'Diary Products'); + + fetchRows($conn, $tableName); + + updateFood($conn, $tableName, 4, 'Cheese', 'Diary Products'); + + fetchRows($conn, $tableName); + + // Add three kinds of foods + insertData($conn, $tableName, 6, 'Salmon', 'Fish'); + insertData($conn, $tableName, 2, 'Broccoli', 'Vegetables'); + + fetchRows($conn, $tableName); + + dropTable($conn, $tableName); + unset($conn); +} catch (Exception $e) { + echo $e->getMessage(); } -RunTest(); - ?> --EXPECT-- -  Added Milk in Diary Products with ID 1. Added Chicken in Meat with ID 3. Added Blueberry in Fruits with ID 5. @@ -166,5 +160,3 @@ ID: 3 Chicken, Meat ID: 4 Cheese, Diary Products ID: 5 Blueberry, Fruits ID: 6 Salmon, Fish -Done -Test "pdo_simple_update_variants" completed successfully. \ No newline at end of file diff --git a/test/functional/pdo_sqlsrv/pdo_utf8_stored_proc_unicode_chars.phpt b/test/functional/pdo_sqlsrv/pdo_utf8_stored_proc_unicode_chars.phpt index 3fd9216d..dabc69c2 100644 --- a/test/functional/pdo_sqlsrv/pdo_utf8_stored_proc_unicode_chars.phpt +++ b/test/functional/pdo_sqlsrv/pdo_utf8_stored_proc_unicode_chars.phpt @@ -1,104 +1,90 @@ --TEST-- call a stored procedure with unicode input to get output back as unicode; also test with xml data --SKIPIF-- - + --FILE-- exec("CREATE PROC $procName (@p1 XML, @p2 CHAR(512) OUTPUT) AS BEGIN SELECT @p2 = CONVERT(CHAR(512), @p1) END"); - + $stmt = $conn->prepare("{CALL $procName (?, ?)}"); $stmt->bindValue(1, $inValue1); $stmt->bindParam(2, $outValue1, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT, 512); $stmt->execute(); - + var_dump(trim($outValue1)); - - $stmt = null; + + dropProc($conn, $procName); + unset($conn); } -function StoredProc_Surrogate($conn) +function storedProcSurrogate($conn) { $inValue1 = pack('H*', 'F2948080EFBFBDEFBFBDF48FBA83EFBFBDEFBFBDEFBFBDEFBFBDEFBFBDF48FB080EFBFBDEFBFBDEFBFBDF392A683EFBFBDF090808BF0908080F0908A83EFBFBDEFBFBDEFBFBDF48FBFBFEFBFBDEFBFBDF090808BF0908683EFBFBDF48FBFBFF2948880EFBFBDF0A08FBFEFBFBDF392A880F0A08A83F294808BF0908880EFBFBDEFBFBDEFBFBDEFBFBDF48FB080F48FB683EFBFBDF0908080EFBFBDF392AA83F48FB683EFBFBDF2948080F2948A83EFBFBDF0A08080F392A880EFBFBDF2948FBFEFBFBDEFBFBDEFBFBDEFBFBDF48FB683EFBFBDEFBFBDEFBFBDF48FBFBFF0908080EFBFBDEFBFBDEFBFBDEFBFBDF48FBFBFEFBFBDF48FB880F0908683F392A080F0908FBFEFBFBDEFBFBDEFBFBDEFBFBDEFBFBDF2948FBFEFBFBDF0908683EFBFBDF0A08A83F48FBA83EFBFBDF48FB08B'); $outValue1 = "TEST"; - - $procName = GetTempProcName(); + + $procName = getProcName(); $stmt = $conn->exec("CREATE PROC $procName (@p1 NVARCHAR(1000), @p2 NVARCHAR(1000) OUTPUT) AS BEGIN SELECT @p2 = CONVERT(NVARCHAR(1000), @p1) END"); - + $stmt = $conn->prepare("{CALL $procName (?, ?)}"); $stmt->bindValue(1, $inValue1); $stmt->bindParam(2, $outValue1, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT, 1000); $stmt->execute(); - - var_dump ($outValue1 === $inValue1); - - $stmt = null; + + var_dump($outValue1 === $inValue1); + + dropProc($conn, $procName); + unset($stmt); } -function StoredProc_Unicode($conn) +function storedProcUnicode($conn) { $inValue1 = pack('H*', 'E9AA8CE597BFE382A1E38381C3BDD086C39FD086C3B6C39CE3838FC3BDE8A1A4C3B6E38390C3A4C3B0C2AAE78687C3B0E2808DE6B490C4B1E385AFE382BFE9B797E9B797D79CC39FC383DAAFE382B0E597BFE382BDE382B0E58080D187C3BCE382BCE385AFD290E78687E38381C3AEE382BCE9B797E2808CC3BB69E888B3D790D291E382AFD0A7E58080C39CE69B82D291C384C3BDD196E3839DE8A1A4C3AEE382BCC3BCE8A1A4E382BFD290E2808FE38380C4B0D187C3A5E3839DE382BDE382AFC396E382B0E382BFC3B6C396D0A7E385B0E3838FC3A3C2AAD990D187C3B6C3BBC384C3B0C390D18FE382BEC4B0E382BCD086C39FE3838FE4BE83E382BCC384E382BDD79CC3BCC39FE382BFE382BCE2808DE58080E58081D196C384D794D794C3B6D18FC3AEC3B6DA98E69B82E6B490C3AEE382BEDAAFD290'); $outValue1 = "TEST"; - - $procName = GetTempProcName(); + + $procName = getProcName(); $stmt = $conn->exec("CREATE PROC $procName (@p1 NVARCHAR(MAX), @p2 NCHAR(1024) OUTPUT) AS BEGIN SELECT @p2 = CONVERT(NCHAR(1024), @p1) END"); - + $stmt = $conn->prepare("{CALL $procName (?, ?)}"); $stmt->bindValue(1, $inValue1); $stmt->bindParam(2, $outValue1, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT, 1500); $stmt->execute(); - + $outValue1 = trim($outValue1); - var_dump ($outValue1 === $inValue1); - - $stmt = null; + var_dump($outValue1 === $inValue1); + + dropProc($conn, $procName); + unset($stmt); } -function RunTest() -{ - StartTest("pdo_utf8_stored_proc_unicode_chars"); - echo "\nStarting test...\n"; - try - { - include("MsSetup.inc"); - set_time_limit(0); - - $conn = new PDO( "sqlsrv:server=$server;database=$databaseName", $uid, $pwd); - - StoredProc_Xml($conn); - StoredProc_Surrogate($conn); - StoredProc_Unicode($conn); +echo "Starting test...\n"; +try { + set_time_limit(0); + $conn = connect(); - $conn = null; - } - catch (Exception $e) - { - echo $e->getMessage(); - } - echo "\nDone\n"; - EndTest("pdo_utf8_stored_proc_unicode_chars"); + storedProcXml($conn); + storedProcSurrogate($conn); + storedProcUnicode($conn); + + unset($conn); +} catch (Exception $e) { + echo $e->getMessage(); } - -RunTest(); - +echo "Done\n"; ?> --EXPECT-- - Starting test... string(47) "Je préfère l'été" bool(true) bool(true) - Done -Test "pdo_utf8_stored_proc_unicode_chars" completed successfully. - diff --git a/test/functional/pdo_sqlsrv/pdostatement_bindcolumn_odd_types.phpt b/test/functional/pdo_sqlsrv/pdostatement_bindcolumn_odd_types.phpt index ad310f59..8980282f 100644 --- a/test/functional/pdo_sqlsrv/pdostatement_bindcolumn_odd_types.phpt +++ b/test/functional/pdo_sqlsrv/pdostatement_bindcolumn_odd_types.phpt @@ -1,43 +1,37 @@ --TEST-- Test the bindColumn method using PDO::PARAM_NULL and PDO::PARAM_STMT --SKIPIF-- - + --FILE-- "int", "CharCol" => "nvarchar(20)")); + insertRow($conn, $tbname, array("IntCol" => 10, "CharCol" => "ten")); -try -{ - $conn = new PDO( "sqlsrv:Server=$server; database = $databaseName ", $uid, $pwd); - $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); - $conn->exec("IF OBJECT_ID('table1', 'U') IS NOT NULL DROP TABLE table1"); - $conn->exec("CREATE TABLE table1(IntCol INT, CharCol NVARCHAR(20)) "); - $conn->exec("INSERT INTO table1 (IntCol, CharCol) VALUES (10, 'ten')"); - $stmt = $conn->prepare("SELECT IntCol FROM table1"); $stmt->execute(); - + // PARAM_NULL returns null $stmt->bindColumn('IntCol', $intCol, PDO::PARAM_NULL); $row = $stmt->fetch(PDO::FETCH_BOUND); - if ($intCol == NULL) { + if ($intCol == null) { echo "intCol is NULL\n"; } else { echo "intCol should have been NULL\n"; } - + $stmt = $conn->prepare("SELECT CharCol FROM table1"); $stmt->execute(); - + // PARAM_STMT is not supported and should throw an exception $stmt->bindColumn('CharCol', $charCol, PDO::PARAM_STMT); $row = $stmt->fetch(PDO::FETCH_BOUND); echo "PARAM_STMT should have thrown an exception\n"; - -} -catch (PDOException $e) -{ +} catch (PDOException $e) { print_r($e->errorInfo[2]); echo "\n"; } @@ -45,4 +39,4 @@ catch (PDOException $e) ?> --EXPECT-- intCol is NULL -PDO::PARAM_STMT is not a supported parameter type. \ No newline at end of file +PDO::PARAM_STMT is not a supported parameter type. diff --git a/test/functional/pdo_sqlsrv/pdostatement_fetchmode_emulate_prepare.phpt b/test/functional/pdo_sqlsrv/pdostatement_fetchmode_emulate_prepare.phpt index f1b0e7a8..e7da69c6 100644 --- a/test/functional/pdo_sqlsrv/pdostatement_fetchmode_emulate_prepare.phpt +++ b/test/functional/pdo_sqlsrv/pdostatement_fetchmode_emulate_prepare.phpt @@ -1,167 +1,193 @@ --TEST-- -PDO Fetch Mode Test with emulate prepare +PDO Fetch Mode Test with emulate prepare --DESCRIPTION-- -Basic verification for "PDOStatement::setFetchMode(). +Basic verification for "PDOStatement::setFetchMode()�. --ENV-- PHPT_EXEC=true --SKIPIF-- - + --FILE-- setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); + // Prepare test table + $tableName = "pdo_test_table"; + createTable($conn1, $tableName, array(new ColumnMeta("int", "ID", "NOT NULL PRIMARY KEY"), "Policy" => "varchar(2)", "Label" => "varchar(10)", "Budget" => "money")); - // Prepare test table - CreateTableEx($conn1, $tableName, "ID int NOT NULL PRIMARY KEY, Policy VARCHAR(2), Label VARCHAR(10), Budget MONEY", null); + try { + $res = $conn1->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); + if ($res) { + echo "setAttribute should have failed.\n\n"; + } + } catch (Exception $e) { + echo $e->getMessage() . "\n"; + } - try { - $res = $conn1->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); - if ($res) - { - echo "setAttribute should have failed.\n\n"; - } - } - catch (Exception $e) - { - echo $e->getMessage(); - } + try { + $query = "SELECT * FROM [$tableName]"; + $stmt = $conn1->query($query); + $stmt->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); + } catch (Exception $e) { + echo $e->getMessage(); + } - echo "\n"; - - try { - $query = "SELECT * FROM [$tableName]"; - $stmt = $conn1->query($query); - $stmt->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); - } - catch (Exception $e) - { - echo $e->getMessage(); - } + echo "\nStart inserting data...\n"; + $dataCols = "ID, Policy, Label"; + $query = "INSERT INTO [$tableName](ID, Policy, Label, Budget) VALUES (?, ?, ?, ?)"; + $stmtOptions = array(PDO::ATTR_EMULATE_PREPARES => false); + $stmt = $conn1->prepare($query, $stmtOptions); + for ($i = 1; $i <= 2; $i++) { + $pol = chr(64+$i); + $grp = "Group " . $i; + $budget = $i * 1000 + $i * 15; + $stmt->execute(array( $i, $pol, $grp, $budget )); + } - echo "\nStart inserting data...\n"; - $dataCols = "ID, Policy, Label"; - $query = "INSERT INTO [$tableName](ID, Policy, Label, Budget) VALUES (?, ?, ?, ?)"; - $stmt = $conn1->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true)); - $stmt = $conn1->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => false)); - for ($i = 1; $i <= 2; $i++) - { - $pol = chr(64+$i); - $grp = "Group " . $i; - $budget = $i * 1000 + $i * 15; - $stmt->execute( array( $i, $pol, $grp, $budget ) ); - } + $query1 = "INSERT INTO [$tableName](ID, Policy, Label, Budget) VALUES (:col1, :col2, :col3, :col4)"; + if (!isColEncrypted()) { + $stmtOptions[PDO::ATTR_EMULATE_PREPARES] = true; + } + $stmt = $conn1->prepare($query1, $stmtOptions); + for ($i = 3; $i <= 5; $i++) { + $pol = chr(64+$i); + $grp = "Group " . $i; + $budget = $i * 1000 + $i * 15; + $stmt->execute(array( ':col1' => $i, ':col2' => $pol, ':col3' => $grp, ':col4' => $budget )); + } + echo "....Done....\n"; + echo "Now selecting....\n"; + $tsql = "SELECT * FROM [$tableName]"; + $stmtOptions[PDO::ATTR_CURSOR] = PDO::CURSOR_SCROLL; + if (isColEncrypted()) { + $stmtOptions[PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE] = PDO::SQLSRV_CURSOR_BUFFERED; + } + $stmt1 = $conn1->prepare($tsql, $stmtOptions); + $stmt1->execute(); + // The row order in the resultset when the column is encrypted (which is dependent on the encrytion key used) + // is different from the order when the column is not enabled + // To make this test work, if the column is encrypted, fetch all then find the corresponding row + if (!isColEncrypted()) { + var_dump($stmt1->fetch(PDO::FETCH_ASSOC)); + $row = $stmt1->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_NEXT); + print "$row[1]\n"; + $row = $stmt1->fetch(PDO::FETCH_LAZY, PDO::FETCH_ORI_LAST); + print "$row[3]\n"; + $row = $stmt1->fetch(PDO::FETCH_BOTH, PDO::FETCH_ORI_PRIOR); + print_r($row); + } else { + $resultset = []; + // fetch first two rows + array_push($resultset, $stmt1->fetch(PDO::FETCH_BOTH)); + array_push($resultset, $stmt1->fetch(PDO::FETCH_BOTH, PDO::FETCH_ORI_NEXT)); + // fetch last three rows + array_push($resultset, $stmt1->fetch(PDO::FETCH_BOTH, PDO::FETCH_ORI_LAST)); + array_push($resultset, $stmt1->fetch(PDO::FETCH_BOTH, PDO::FETCH_ORI_PRIOR)); + array_push($resultset, $stmt1->fetch(PDO::FETCH_BOTH, PDO::FETCH_ORI_PRIOR)); + // sort and print + sort($resultset); + $assocArr['ID'] = $resultset[0]['ID']; + $assocArr['Policy'] = $resultset[0]['Policy']; + $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]); + } - $query1 = "INSERT INTO [$tableName](ID, Policy, Label, Budget) VALUES (:col1, :col2, :col3, :col4)"; - $stmt = $conn1->prepare($query1, array(PDO::ATTR_EMULATE_PREPARES => true)); - for ($i = 3; $i <= 5; $i++) - { - $pol = chr(64+$i); - $grp = "Group " . $i; - $budget = $i * 1000 + $i * 15; - $stmt->execute( array( ':col1' => $i, ':col2' => $pol, ':col3' => $grp, ':col4' => $budget ) ); - } - echo "....Done....\n"; - echo "Now selecting....\n"; - $tsql = "SELECT * FROM [$tableName]"; - $stmt1 = $conn1->prepare($tsql, array(PDO::ATTR_EMULATE_PREPARES => false)); - $stmt1 = $conn1->prepare($tsql, array(PDO::ATTR_EMULATE_PREPARES => true, PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL)); - $stmt1->execute(); - var_dump($stmt1->fetch( PDO::FETCH_ASSOC )); - $row = $stmt1->fetch( PDO::FETCH_NUM, PDO::FETCH_ORI_NEXT ); - print "$row[1]\n"; - $row = $stmt1->fetch( PDO::FETCH_LAZY, PDO::FETCH_ORI_LAST ); - print "$row[3]\n"; - $row = $stmt1->fetch( PDO::FETCH_BOTH, PDO::FETCH_ORI_PRIOR ); - print_r($row); + echo "\nFirst two groups or Budget > 4000....\n"; + unset($stmtOptions[PDO::ATTR_CURSOR]); + if (!isColEncrypted()) { + $tsql = "SELECT * FROM [$tableName] WHERE ID <= :id OR Budget > :budget"; + $stmt2 = $conn1->prepare($tsql, $stmtOptions); + $budget = 4000; + $id = 2; + $stmt2->bindParam(':id', $id); + $stmt2->bindParam(':budget', $budget); + $stmt2->execute(); + while ($result = $stmt2->fetchObject()) { + print_r($result); + } + } else { + // more and less than operators do not work for encrypted columns + $tsql = "SELECT * FROM [$tableName] WHERE NOT ID = :id"; + unset($stmtOptions[PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE]); + $stmt2 = $conn1->prepare($tsql, $stmtOptions); + $id = 3; + $stmt2->bindParam(':id', $id); + $stmt2->execute(); + // again need to fetch all, sort, then print + $resultset = array(); + while ($result = $stmt2->fetchObject()) { + array_push($resultset, $result); + } + sort($resultset); + foreach ($resultset as $r) { + print_r($r); + } + } - echo "\nFirst two groups or Budget > 4000....\n"; - $tsql = "SELECT * FROM [$tableName] WHERE ID <= :id OR Budget > :budget"; - $stmt2 = $conn1->prepare($tsql, array(PDO::ATTR_EMULATE_PREPARES => true)); - $budget = 4000; - $id = 2; - $stmt2->bindParam(':id', $id); - $stmt2->bindParam(':budget', $budget); - $stmt2->execute(); - while ( $result = $stmt2->fetchObject() ){ - print_r($result); - echo "\n"; - } - - echo "\nSelect Policy = 'A'....\n"; - $tsql = "SELECT * FROM [$tableName] WHERE Policy = ?"; - $stmt3 = $conn1->prepare($tsql, array(PDO::ATTR_EMULATE_PREPARES => true)); - $pol = 'A'; - $stmt3->bindValue(1, $pol); - $id = 'C'; - $stmt3->execute(); - while ( $row = $stmt3->fetch( PDO::FETCH_ASSOC ) ){ - print_r($row); - echo "\n"; - } - - echo "\nSelect id > 2....\n"; - $tsql = "SELECT Policy, Label, Budget FROM [$tableName] WHERE ID > 2"; - $stmt4 = $conn1->prepare($tsql, array(PDO::ATTR_EMULATE_PREPARES => true)); - $stmt4->execute(); - $stmt4->bindColumn('Policy', $policy); - $stmt4->bindColumn('Budget', $budget); - while ( $row = $stmt4->fetch( PDO::FETCH_BOUND ) ){ - echo "Policy: $policy\tBudget: $budget\n"; - } + echo "\nSelect Policy = 'A'....\n"; + $tsql = "SELECT * FROM [$tableName] WHERE Policy = ?"; + $stmt3 = $conn1->prepare($tsql, $stmtOptions); + $pol = 'A'; + $stmt3->bindValue(1, $pol); + $id = 'C'; + $stmt3->execute(); + while ($row = $stmt3->fetch(PDO::FETCH_ASSOC)) { + print_r($row); + echo "\n"; + } - echo "\nBudget Metadata....\n"; - $metadata = $stmt4->getColumnMeta(2); - var_dump($metadata); + echo "\nSelect id > 2....\n"; + if (!isColEncrypted()) { + $tsql = "SELECT Policy, Label, Budget FROM [$tableName] WHERE ID > 2"; + $stmt4 = $conn1->prepare($tsql, $stmtOptions); + } else { + $tsql = "SELECT Policy, Label, Budget FROM [$tableName] WHERE NOT ID = ? AND NOT ID = ?"; + $stmt4 = $conn1->prepare($tsql, $stmtOptions); + $id1 = 1; + $id2 = 2; + $stmt4->bindParam(1, $id1); + $stmt4->bindParam(2, $id2); + } + $stmt4->execute(); + $stmt4->bindColumn('Policy', $policy); + $stmt4->bindColumn('Budget', $budget); + $policyArr = array(); + $budgetArr = array(); + while ($row = $stmt4->fetch(PDO::FETCH_BOUND)) { + //echo "Policy: $policy\tBudget: $budget\n"; + array_push($policyArr, $policy); + array_push($budgetArr, $budget); + } + if (isColEncrypted()) { + sort($policyArr); + sort($budgetArr); + } + for ($i = 0; $i < 3; $i++) { + echo "Policy: $policyArr[$i]\tBudget: $budgetArr[$i]\n"; + } - // Cleanup - DropTable($conn1, $tableName); - $stmt1 = null; - $stmt2 = null; - $stmt3 = null; - $stmt4 = null; - $conn1 = null; + echo "\nBudget Metadata....\n"; + $metadata = $stmt4->getColumnMeta(2); + var_dump($metadata); - EndTest($testName); + // Cleanup + DropTable($conn1, $tableName); + unset($stmt1); + unset($stmt2); + unset($stmt3); + unset($stmt4); + unset($conn1); +} catch (Exception $e) { + echo $e->getMessage(); } -class Test -{ - function __construct($name = 'N/A') - { - echo __METHOD__ . "($name)\n"; - } -} - - -//-------------------------------------------------------------------- -// Repro -// -//-------------------------------------------------------------------- -function Repro() -{ - - try - { - FetchMode(); - } - catch (Exception $e) - { - echo $e->getMessage(); - } -} - -Repro(); - ?> --EXPECT-- SQLSTATE[IMSSP]: The given attribute is only supported on the PDOStatement object. @@ -201,7 +227,6 @@ stdClass Object [Label] => Group 1 [Budget] => 1015.0000 ) - stdClass Object ( [ID] => 2 @@ -209,7 +234,6 @@ stdClass Object [Label] => Group 2 [Budget] => 2030.0000 ) - stdClass Object ( [ID] => 4 @@ -217,7 +241,6 @@ stdClass Object [Label] => Group 4 [Budget] => 4060.0000 ) - stdClass Object ( [ID] => 5 @@ -226,7 +249,6 @@ stdClass Object [Budget] => 5075.0000 ) - Select Policy = 'A'.... Array ( @@ -261,4 +283,3 @@ array(8) { ["precision"]=> int(4) } -Test "PDO Statement - Set Fetch Mode" completed successfully. \ No newline at end of file diff --git a/test/functional/pdo_sqlsrv/test_encoding_UTF8_emulate_prepare.phpt b/test/functional/pdo_sqlsrv/test_encoding_UTF8_emulate_prepare.phpt index 1d3d7eff..e9137afe 100644 --- a/test/functional/pdo_sqlsrv/test_encoding_UTF8_emulate_prepare.phpt +++ b/test/functional/pdo_sqlsrv/test_encoding_UTF8_emulate_prepare.phpt @@ -1,113 +1,86 @@ --TEST-- Test UTF8 Encoding with emulate prepare --SKIPIF-- - + --FILE-- setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); - $conn->setAttribute( PDO::SQLSRV_ATTR_ENCODING, PDO::SQLSRV_ENCODING_SYSTEM); - $stmt1 = $conn->query("IF OBJECT_ID('Table_UTF', 'U') IS NOT NULL DROP TABLE [Table_UTF]"); - $stmt1 = null; + $conn = connect(); + $conn->setAttribute(PDO::SQLSRV_ATTR_ENCODING, PDO::SQLSRV_ENCODING_SYSTEM); - $stmt2 = $conn->query("CREATE TABLE [Table_UTF] ([c1_int] int PRIMARY KEY, [c2_char] char(512))"); - $stmt2 = null; + $tbname = "Table_UTF"; + createTable($conn, $tbname, array(new ColumnMeta("int", "c1_int", "PRIMARY KEY"), "c2_char" => "char(512)")); - $stmt3 = $conn->prepare("INSERT INTO [Table_UTF] (c1_int, c2_char) VALUES (:var1, :var2)"); - $stmt3->setAttribute(constant('PDO::SQLSRV_ATTR_ENCODING'), PDO::SQLSRV_ENCODING_UTF8); - $stmt3->bindParam(2, $inValue1); - $stmt3->bindValue(1, 1); - $stmt3->execute(); - $stmt3->bindValue(1, 2); - $stmt3->execute(); - $stmt3->bindValue(1, 3); - $stmt3->execute(); - $stmt3->bindValue(1, 4); - $stmt3->execute(); - $stmt3->bindValue(1, 5); - $stmt3->execute(); - $stmt3 = null; - - $stmt4 = $conn->prepare("SELECT * FROM [Table_UTF]"); - $stmt4->setAttribute(constant('PDO::SQLSRV_ATTR_ENCODING'), PDO::SQLSRV_ENCODING_UTF8); - $outValue1 = null; - $stmt4->execute(); - $row1 = $stmt4->fetch(); - $count1 = count($row1); - echo ("Number of rows: $count1\n"); - $v0 = $row1[0]; - $outValue1 = $row1[1]; - if (strncmp($inValue1, $outValue1, $inValueLen) == 0) { - echo "outValue is the same as inValue.\n"; - } - $outValue1 = null; - - $value1 = $stmt4->fetchcolumn(1); - $outValue1 = $value1; - if (strncmp($inValue1, $outValue1, $inValueLen) == 0) { - echo "outValue is the same as inValue.\n"; - } - $outvalue1 = null; - - $value2 = $stmt4->fetchColumn(1); - $outValue1 = $value2; - if (strncmp($inValue1, $outValue1, $inValueLen) == 0) { - echo "outValue is the same as inValue.\n"; - } - $outValue1 = null; - - $value3 = $stmt4->fetchColumn(1); - $outValue1 = $value3; - if (strncmp($inValue1, $outValue1, $inValueLen) == 0) { - echo "outValue is the same as inValue.\n"; - } - $outValue1 = null; - - $value4 = $stmt4->fetchColumn(1); - $outValue1 = $value4; - if (strncmp($inValue1, $outValue1, $inValueLen) == 0) { - echo "outValue is the same as inValue.\n"; - } - $stmt4 = null; - - $stmt5 = $conn->prepare( "SELECT ? = c2_char FROM [Table_UTF]", array(PDO::ATTR_EMULATE_PREPARES => true) ); - $stmt5->setAttribute(constant('PDO::SQLSRV_ATTR_ENCODING'), PDO::SQLSRV_ENCODING_UTF8); - $outValue1 = "hello"; - $stmt5->bindParam( 1, $outValue1, PDO::PARAM_STR, 1024); - $stmt5->execute(); - if (strncmp($inValue1, $outValue1, $inValueLen) == 0) { - echo "outValue is the same as inValue.\n"; - } else { - echo "outValue is $outValue1\n"; - } - $stmt5 = null; + $stmt3 = $conn->prepare("INSERT INTO [Table_UTF] (c1_int, c2_char) VALUES (:var1, :var2)"); + $stmt3->setAttribute(PDO::SQLSRV_ATTR_ENCODING, PDO::SQLSRV_ENCODING_UTF8); + $stmt3->bindParam(2, $inValue1); + $stmt3->bindValue(1, 1); + $stmt3->execute(); + $stmt3->bindValue(1, 2); + $stmt3->execute(); + $stmt3->bindValue(1, 3); + $stmt3->execute(); + $stmt3->bindValue(1, 4); + $stmt3->execute(); + $stmt3->bindValue(1, 5); + $stmt3->execute(); + unset($stmt3); - $stmt6 = $conn->query("DROP TABLE [Table_UTF]"); - $stmt6 = null; - - $conn = null; -} -catch (PDOexception $e){ - print_r( ($e->errorInfo)[2] ); + $stmt4 = $conn->prepare("SELECT * FROM $tbname"); + $stmt4->setAttribute(PDO::SQLSRV_ATTR_ENCODING, PDO::SQLSRV_ENCODING_UTF8); + $outValue1 = null; + $stmt4->execute(); + $row1 = $stmt4->fetch(PDO::FETCH_NUM); + $count1 = count($row1); + echo("Number of columns: $count1\n"); + $v0 = $row1[0]; + $outValue1 = $row1[1]; + if (strncmp($inValue1, $outValue1, $inValueLen) == 0) { + echo "outValue is the same as inValue.\n"; + } + + for ($i = 0; $i < 4; $i++) { + $outValue1 = $stmt4->fetchColumn(1); + if (strncmp($inValue1, $outValue1, $inValueLen) == 0) { + echo "outValue is the same as inValue.\n"; + } + } + unset($stmt4); + + $option; + if (!isColEncrypted()) { + $option[PDO::ATTR_EMULATE_PREPARES] = true; + } else { + $option[PDO::ATTR_EMULATE_PREPARES] = false; + } + $stmt5 = $conn->prepare("SELECT ? = c2_char FROM $tbname", $option); + $stmt5->setAttribute(PDO::SQLSRV_ATTR_ENCODING, PDO::SQLSRV_ENCODING_UTF8); + $outValue1 = "hello"; + $stmt5->bindParam(1, $outValue1, PDO::PARAM_STR, 1024); + $stmt5->execute(); + if (strncmp($inValue1, $outValue1, $inValueLen) == 0) { + echo "outValue is the same as inValue.\n"; + } else { + echo "outValue is $outValue1\n"; + } + unset($stmt5); + dropTable($conn, $tbname); + unset($conn); +} catch (PDOexception $e) { + print_r(($e->errorInfo)[2]); echo "\n"; } ?> --EXPECT-- -Number of rows: 4 +Number of columns: 2 outValue is the same as inValue. outValue is the same as inValue. outValue is the same as inValue. outValue is the same as inValue. outValue is the same as inValue. Statement with emulate prepare on does not support output or input_output parameters. - - - - From 3b65f26776f433108a25704c2ac01e7be7fd9a54 Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Thu, 30 Nov 2017 16:26:39 -0800 Subject: [PATCH 2/7] fix line endings --- test/functional/pdo_sqlsrv/PDO51_FetchLOB.phpt | 2 +- test/functional/pdo_sqlsrv/PDO65_BindValue1.phpt | 1 + .../pdo_sqlsrv/pdo_katmai_special_types.phpt | 13 +++++-------- .../pdo_sqlsrv/pdo_param_output_select_variant.phpt | 6 +++--- .../pdo_sqlsrv/pdo_param_output_variants.phpt | 7 ++++--- .../pdo_sqlsrv/pdo_simple_update_variants.phpt | 2 +- 6 files changed, 15 insertions(+), 16 deletions(-) diff --git a/test/functional/pdo_sqlsrv/PDO51_FetchLOB.phpt b/test/functional/pdo_sqlsrv/PDO51_FetchLOB.phpt index 80719e45..e26f73e7 100644 --- a/test/functional/pdo_sqlsrv/PDO51_FetchLOB.phpt +++ b/test/functional/pdo_sqlsrv/PDO51_FetchLOB.phpt @@ -89,4 +89,4 @@ function logInfo($offset, $msg) ?> --EXPECT-- -Test "PDO Statement - Fetch LOB" completed successfully. +Test 'PDO Statement - Fetch LOB' completed successfully. diff --git a/test/functional/pdo_sqlsrv/PDO65_BindValue1.phpt b/test/functional/pdo_sqlsrv/PDO65_BindValue1.phpt index 7becaf0d..7e1914ec 100644 --- a/test/functional/pdo_sqlsrv/PDO65_BindValue1.phpt +++ b/test/functional/pdo_sqlsrv/PDO65_BindValue1.phpt @@ -14,6 +14,7 @@ try { $conn1 = connect(); // Prepare test table + $tableName = "pdo_test_table"; createTable($conn1, $tableName, array(new ColumnMeta("int", "id", "NOT NULL PRIMARY KEY"), "val1" => "varchar(10)", "val2" => "varchar(10)", "val3" => "varchar(10)")); $data = array("one", "two", "three"); diff --git a/test/functional/pdo_sqlsrv/pdo_katmai_special_types.phpt b/test/functional/pdo_sqlsrv/pdo_katmai_special_types.phpt index aaa4237a..082017df 100644 --- a/test/functional/pdo_sqlsrv/pdo_katmai_special_types.phpt +++ b/test/functional/pdo_sqlsrv/pdo_katmai_special_types.phpt @@ -41,7 +41,7 @@ function katmaiBasicTypes($conn) $expOutput = array_values($expOutput); createTable($conn, $tableName, $dataTypes); insertRow($conn, $tableName, $data); - echo "\nComparing results of Katmai basic fields\n"; + echo "Comparing results of Katmai basic fields\n"; $stmt = $conn->query("SELECT * FROM $tableName"); $numFields = $stmt->columnCount(); @@ -90,7 +90,7 @@ function katmaiSparseChar($conn) insertRow($conn, $tableName, array("c1" => 2, "c3" => $input, "c6" => $input)); insertRow($conn, $tableName, array("c1" => 3, "c4" => $input, "c7" => $input)); - echo "\nComparing results of Katmai sparse fields\n"; + echo "Comparing results of Katmai sparse fields\n"; $stmt = $conn->query("SELECT * FROM $tableName"); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { @@ -139,7 +139,7 @@ function katmaiSparseNumeric($conn) } insertRow($conn, $tableName, $data); - echo "\nShowing results of Katmai sparse numeric fields\n"; + echo "Showing results of Katmai sparse numeric fields\n"; $stmt = $conn->query("SELECT * FROM $tableName"); $row = $stmt->fetch(PDO::FETCH_NUM); foreach ($row as $value) { @@ -163,14 +163,11 @@ try { } catch (Exception $e) { echo $e->getMessage(); } - ?> + --EXPECT-- - -Comparing results of Katmai basic fields - +Comparing results of Katmai basic fields Comparing results of Katmai sparse fields - Showing results of Katmai sparse numeric fields string(1) "1" string(1) "1" diff --git a/test/functional/pdo_sqlsrv/pdo_param_output_select_variant.phpt b/test/functional/pdo_sqlsrv/pdo_param_output_select_variant.phpt index 94ce1812..c8205af5 100644 --- a/test/functional/pdo_sqlsrv/pdo_param_output_select_variant.phpt +++ b/test/functional/pdo_sqlsrv/pdo_param_output_select_variant.phpt @@ -70,7 +70,7 @@ try { echo "\nDone\n"; ?> ---EXPECT-- -Number of rows: 1 -SQLSTATE[42000]: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Implicit conversion from data type sql_variant to nvarchar(max) is not allowed. Use the CONVERT function to run this query. +--EXPECTREGEX-- +Number of rows: 1 +SQLSTATE\[42000\]: \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]\[SQL Server\]Implicit conversion from data type sql_variant to nvarchar\(max\) is not allowed. Use the CONVERT function to run this query. Done diff --git a/test/functional/pdo_sqlsrv/pdo_param_output_variants.phpt b/test/functional/pdo_sqlsrv/pdo_param_output_variants.phpt index 50a9e8c3..439753dc 100644 --- a/test/functional/pdo_sqlsrv/pdo_param_output_variants.phpt +++ b/test/functional/pdo_sqlsrv/pdo_param_output_variants.phpt @@ -27,6 +27,7 @@ function testReverse($conn) // Since SQLDescribeParam is called if (isColEncrypted() && $string === "987654321") { echo "Test input output parameter with SQL_VARIANT successfully.\n"; + } else { echo "Does REVERSE work? $string \n"; } @@ -124,8 +125,8 @@ try { } catch (Exception $e) { echo $e->getMessage(); } - ?> ---EXPECTREGEX-- -Test input output parameter with SQL_VARIANT successfully. + +--EXPECT-- +Test input output parameter with SQL_VARIANT successfully. Test output parameter with SQL_VARIANT successfully. diff --git a/test/functional/pdo_sqlsrv/pdo_simple_update_variants.phpt b/test/functional/pdo_sqlsrv/pdo_simple_update_variants.phpt index b289a38f..cb3d9917 100644 --- a/test/functional/pdo_sqlsrv/pdo_simple_update_variants.phpt +++ b/test/functional/pdo_sqlsrv/pdo_simple_update_variants.phpt @@ -139,7 +139,7 @@ try { ?> --EXPECT-- -Added Milk in Diary Products with ID 1. +Added Milk in Diary Products with ID 1. Added Chicken in Meat with ID 3. Added Blueberry in Fruits with ID 5. ID: 1 Milk, Diary Products From 8297fce1b96606bc9a085a550173b69c94552de9 Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Tue, 5 Dec 2017 16:32:18 -0800 Subject: [PATCH 3/7] apply review comments --- .../pdo_sqlsrv/PDO100_InsertNulls.phpt | 10 +++--- .../pdo_sqlsrv/PDO102_MaxOutputParams.phpt | 11 +++---- .../pdo_sqlsrv/PDO38_FetchBound.phpt | 33 ++++++++++--------- ...ement_bindParam_inout_emulate_prepare.phpt | 4 +-- .../pdo_sqlsrv/pdo_prepare_attribute.phpt | 2 +- ...dostatement_fetchmode_emulate_prepare.phpt | 2 +- .../test_encoding_UTF8_emulate_prepare.phpt | 2 +- 7 files changed, 32 insertions(+), 32 deletions(-) diff --git a/test/functional/pdo_sqlsrv/PDO100_InsertNulls.phpt b/test/functional/pdo_sqlsrv/PDO100_InsertNulls.phpt index b450e4bf..97d712e7 100644 --- a/test/functional/pdo_sqlsrv/PDO100_InsertNulls.phpt +++ b/test/functional/pdo_sqlsrv/PDO100_InsertNulls.phpt @@ -14,10 +14,10 @@ function insertNullsTest($bindType) { $outvar = null; $failed = false; - $conn =connect(); + $conn = connect(); $tableName = "pdo_test_table"; - $dataType = array("c1_int" => "int", + $dataTypes = array("c1_int" => "int", "c2_tinyint" => "tinyint", "c3_smallint" => "smallint", "c4_bigint" => "bigint", @@ -45,12 +45,12 @@ function insertNullsTest($bindType) "c26_smalldatetime" => "smalldatetime", "c27_timestamp" => "timestamp", "c28_xml" => "xml"); - createTable($conn, $tableName, $dataType); + createTable($conn, $tableName, $dataTypes); $stmt = $conn->query("SELECT [TABLE_NAME],[COLUMN_NAME],[IS_NULLABLE] FROM [INFORMATION_SCHEMA].[COLUMNS] WHERE [TABLE_NAME] = '$tableName'"); if ($stmt === false) { - FatalError("Could not query for column information on table $tableName"); + fatalError("Could not query for column information on table $tableName"); } while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { @@ -98,7 +98,7 @@ try { echo $e->getMessage(); } if ($failed) { - FatalError("Possible Regression: Could not insert NULL"); + fatalError("Possible Regression: Could not insert NULL"); } else { echo "Test 'PDO - Insert Nulls' completed successfully.\n"; } diff --git a/test/functional/pdo_sqlsrv/PDO102_MaxOutputParams.phpt b/test/functional/pdo_sqlsrv/PDO102_MaxOutputParams.phpt index 67ef5cbf..721c66b9 100644 --- a/test/functional/pdo_sqlsrv/PDO102_MaxOutputParams.phpt +++ b/test/functional/pdo_sqlsrv/PDO102_MaxOutputParams.phpt @@ -27,13 +27,12 @@ function maxOutputParamsTest($expected, $length) echo "Expected: $expected Received: $outstr\n"; + $failed = false; if ($outstr !== $expected) { print_r($stmt->errorInfo()); - dropProc($conn, $procName); - return(-1); + $failed = true; } - dropProc($conn, $procName); - return(0); + return $failed; } @@ -41,13 +40,13 @@ function maxOutputParamsTest($expected, $length) // Repro // //-------------------------------------------------------------------- -$failed = null; +$failed = false; $failed |= maxOutputParamsTest("abc", 3); $failed |= maxOutputParamsTest("abc", 10); if ($failed) { - FatalError("Possible Regression: Value returned as VARCHAR(MAX) truncated"); + fatalError("Possible Regression: Value returned as VARCHAR(MAX) truncated"); } ?> --EXPECT-- diff --git a/test/functional/pdo_sqlsrv/PDO38_FetchBound.phpt b/test/functional/pdo_sqlsrv/PDO38_FetchBound.phpt index e241a8a3..2885916a 100644 --- a/test/functional/pdo_sqlsrv/PDO38_FetchBound.phpt +++ b/test/functional/pdo_sqlsrv/PDO38_FetchBound.phpt @@ -24,14 +24,14 @@ try { array('60', 'Pqr', 'kji')); // Insert using question mark placeholders - $stmt1 = PrepareQuery($conn1, "INSERT INTO [$tableName] VALUES(?, ?, ?)"); + $stmt1 = $conn1->prepare("INSERT INTO [$tableName] VALUES(?, ?, ?)"); foreach ($data as $row) { $stmt1->execute($row); } unset($stmt1); // Count inserted rows - $stmt2 = PrepareQuery($conn1, "SELECT COUNT(id) FROM [$tableName]"); + $stmt2 = $conn1->prepare("SELECT COUNT(id) FROM [$tableName]"); $stmt2->execute(); $num = $stmt2->fetchColumn(); echo "There are $num rows in the table.\n"; @@ -60,13 +60,14 @@ try { unset($stmt1); if (!isColEncrypted()) { - $stmt1 = PrepareQuery($conn1, "SELECT idx, txt FROM [$tableName] ORDER BY idx"); + $stmt1 = $conn1->prepare("SELECT idx, txt FROM [$tableName] ORDER BY idx"); } else { // ORDER BY does not work on encrypted columns - $stmt1 = PrepareQuery($conn1, "SELECT idx, txt FROM [$tableName]"); + $stmt1 = $conn1->prepare("SELECT idx, txt FROM [$tableName]"); } $stmt1->execute(); $data = $stmt1->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_UNIQUE); + // needs to order the result set manually as ORDER BY does not work properly on encrypted columns if (isColEncrypted()) { ksort($data); } @@ -99,50 +100,50 @@ try { var_dump($stmt2->execute()); if ($idx == 0) { // bindColumn()s after execute() has been called at least once - $stmt2->bindColumn('txt', $col1); + $stmt2->bindColumn('txt', $txtCol); } var_dump($stmt2->fetch(PDO::FETCH_BOUND)); $stmt2->closeCursor(); var_dump($stmt3->execute()); if ($idx == 0) { // bindColumn()s after execute() has been called at least once - $stmt3->bindColumn('idx', $col2); + $stmt3->bindColumn('idx', $idxCol); } var_dump($stmt3->fetch(PDO::FETCH_BOUND)); $stmt3->closeCursor(); - var_dump(array($col2=>$col1)); + var_dump(array($idxCol=>$txtCol)); } echo "===REBIND/SAME===\n"; - $stmt3->bindColumn('idx', $col1); + $stmt3->bindColumn('idx', $idxCol); foreach ($data as $idx => $txt) { var_dump(array($idx=>$txt)); var_dump($stmt2->execute()); var_dump($stmt2->fetch(PDO::FETCH_BOUND)); $stmt2->closeCursor(); - var_dump($col1); + var_dump($idxCol); var_dump($stmt3->execute()); var_dump($stmt3->fetch(PDO::FETCH_BOUND)); $stmt3->closeCursor(); - var_dump($col1); + var_dump($idxCol); } echo "===REBIND/CONFLICT===\n"; - $stmt1->bindColumn('idx', $col1); - $stmt1->bindColumn('txt', $col1); + $stmt1->bindColumn('idx', $col); + $stmt1->bindColumn('txt', $col); $stmt1->execute(); - $col1s = array(); + $cols = array(); while ($stmt1->fetch(PDO::FETCH_BOUND)) { - array_push($col1s, $col1); + array_push($cols, $col); } if (isColEncrypted()) { - sort($col1s); + sort($cols); } - var_dump($col1s); + var_dump($cols); // Cleanup dropTable($conn1, $tableName); diff --git a/test/functional/pdo_sqlsrv/pdoStatement_bindParam_inout_emulate_prepare.phpt b/test/functional/pdo_sqlsrv/pdoStatement_bindParam_inout_emulate_prepare.phpt index 1ddd0eea..677ebe14 100644 --- a/test/functional/pdo_sqlsrv/pdoStatement_bindParam_inout_emulate_prepare.phpt +++ b/test/functional/pdo_sqlsrv/pdoStatement_bindParam_inout_emulate_prepare.phpt @@ -23,8 +23,8 @@ try { unset($dbh); } catch (PDOException $e) { $error = $e->getMessage(); - $pass = !isColEncrypted() && $error === "SQLSTATE[IMSSP]: Statement with emulate prepare on does not support output or input_output parameters."; - $pass |= isColEncrypted() && ($error === "SQLSTATE[IMSSP]: Connection with Column Encryption enabled do no support PDO::ATTR_EMULATE_PREPARES with binding parameters."); + $pass = !isAEConnected() && $error === "SQLSTATE[IMSSP]: Statement with emulate prepare on does not support output or input_output parameters."; + $pass |= isAEConnected() && ($error === "SQLSTATE[IMSSP]: Parameterized statement with attribute PDO::ATTR_EMULATE_PREPARES is not supported in a Column Encryption enabled Connection."); if (!$pass) { print("Error: " . $error . "\n"); } else { diff --git a/test/functional/pdo_sqlsrv/pdo_prepare_attribute.phpt b/test/functional/pdo_sqlsrv/pdo_prepare_attribute.phpt index ef702bf6..6f4b5f45 100644 --- a/test/functional/pdo_sqlsrv/pdo_prepare_attribute.phpt +++ b/test/functional/pdo_sqlsrv/pdo_prepare_attribute.phpt @@ -40,7 +40,7 @@ if (!$exception_thrown) { // Column encryption is not supported by emulate prepared statement $option[PDO::ATTR_EMULATE_PREPARES] = true; -if (isColEncrypted()) { +if (isAEConnected()) { $option[PDO::ATTR_EMULATE_PREPARES] = false; } diff --git a/test/functional/pdo_sqlsrv/pdostatement_fetchmode_emulate_prepare.phpt b/test/functional/pdo_sqlsrv/pdostatement_fetchmode_emulate_prepare.phpt index e7da69c6..f8d1e0b9 100644 --- a/test/functional/pdo_sqlsrv/pdostatement_fetchmode_emulate_prepare.phpt +++ b/test/functional/pdo_sqlsrv/pdostatement_fetchmode_emulate_prepare.phpt @@ -47,7 +47,7 @@ try { } $query1 = "INSERT INTO [$tableName](ID, Policy, Label, Budget) VALUES (:col1, :col2, :col3, :col4)"; - if (!isColEncrypted()) { + if (!isAEConnected()) { $stmtOptions[PDO::ATTR_EMULATE_PREPARES] = true; } $stmt = $conn1->prepare($query1, $stmtOptions); diff --git a/test/functional/pdo_sqlsrv/test_encoding_UTF8_emulate_prepare.phpt b/test/functional/pdo_sqlsrv/test_encoding_UTF8_emulate_prepare.phpt index e9137afe..0b790437 100644 --- a/test/functional/pdo_sqlsrv/test_encoding_UTF8_emulate_prepare.phpt +++ b/test/functional/pdo_sqlsrv/test_encoding_UTF8_emulate_prepare.phpt @@ -53,7 +53,7 @@ try { unset($stmt4); $option; - if (!isColEncrypted()) { + if (!isAEConnected()) { $option[PDO::ATTR_EMULATE_PREPARES] = true; } else { $option[PDO::ATTR_EMULATE_PREPARES] = false; From 9196c557f82649889c175dd2e7c8d0e13eabe666 Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Tue, 5 Dec 2017 16:34:18 -0800 Subject: [PATCH 4/7] update MsCommon_mid-refactor.inc to not require AE_Ksp --- .../pdo_sqlsrv/MsCommon_mid-refactor.inc | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc b/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc index f235ef74..35a175c7 100644 --- a/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc +++ b/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc @@ -13,6 +13,10 @@ // to be runnable from the MSSQL teams' internal proprietary test running system // +const KSP_NAME = 'MyCustomKSPName'; +const ENCRYPT_KEY = 'LPKCWVD07N3RG98J0MBLG4H2'; +const KSP_TEST_TABLE = 'CustomKSPTestTable'; + function isAEQualified($conn) { $msodbcsql_ver = $conn->getAttribute(PDO::ATTR_CLIENT_VERSION)["DriverVer"]; @@ -81,8 +85,9 @@ function getDSN($sqlsrvserver, $database, $keywords = '', $disableCE = false) $dsn .= "ColumnEncryption=Enabled;"; } if ($keystore == "ksp" && !$disableCE) { - require('AE_Ksp.inc'); $ksp_path = getKSPPath(); + $ksp_name = KSP_NAME; + $encrypt_key = ENCRYPT_KEY; $dsn .= "CEKeystoreProvider=$ksp_path;CEKeystoreName=$ksp_name;CEKeystoreEncryptKey=$encrypt_key;"; } if ($keywords) { @@ -118,6 +123,27 @@ function getCekName() return $cekName; } +/** + * @return the path to the KSP dll/so file + */ +function getKSPpath() +{ + $name = 'myKSP'; + + $dir_name = realpath(dirname(__FILE__)); + $ksp = $dir_name . DIRECTORY_SEPARATOR . $name; + if ( strtoupper( substr( php_uname( 's' ), 0, 3 ) ) == 'WIN' ) { + $arch = 'x64'; + if ( PHP_INT_SIZE == 4 ) // running 32 bit + $arch = ''; + $ksp .= $arch . '.dll'; + } + else + $ksp .= '.so'; + + return $ksp; +} + /** * class for encapsulating column metadata needed for creating a table @@ -523,6 +549,13 @@ function isColEncrypted() } } + +function isAEConnected() +{ + require('MsSetup.inc'); + return $keystore != "none"; +} + function teardown() { // TBD From 98d7307860df92bacfcb81bc6a70b1c6dfc1a369 Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Wed, 6 Dec 2017 11:54:10 -0800 Subject: [PATCH 5/7] do not encrypt column needed for ORDER BY clause --- .../pdo_sqlsrv/MsCommon_mid-refactor.inc | 19 +++++-- .../pdo_sqlsrv/PDO38_FetchBound.phpt | 23 +++----- .../pdo_sqlsrv/PDO61_BindColumn1.phpt | 49 +++-------------- .../pdo_sqlsrv/PDO62_BindColumn2.phpt | 40 ++++---------- .../pdo_sqlsrv/PDO64_BindParam2.phpt | 26 +++------ .../pdo_sqlsrv/PDO66_BindValue2.phpt | 55 ++++--------------- .../pdo_sqlsrv/pdo_katmai_special_types.phpt | 3 + .../pdo_simple_update_variants.phpt | 14 +---- 8 files changed, 62 insertions(+), 167 deletions(-) diff --git a/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc b/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc index 35a175c7..e9752379 100644 --- a/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc +++ b/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc @@ -153,10 +153,10 @@ class ColumnMeta public $dataType; //a string that includes the size of the type if necessary (e.g., decimal(10,5)) public $colName; //column name public $options; //a string that is null by default (e.g. NOT NULL Identity (1,1) ) - public $encType; //randomized or deterministic; default is deterministic - public $forceEncrypt; //force encryption on a datatype no supported by Column Encrypton + public $encType; //randomized, deterministic, or normal; default is null + public $forceEncrypt; //force encryption on a datatype not supported by Column Encrypton - public function __construct($dataType, $colName = null, $options = null, $encType = "deterministic", $forceEncrypt = false) + public function __construct($dataType, $colName = null, $options = null, $encType = null, $forceEncrypt = false) { if (is_null($colName)) { $this->colName = getDefaultColName($dataType); @@ -165,6 +165,15 @@ class ColumnMeta } $this->dataType = $dataType; $this->options = $options; + if (is_null($encType)) { + if (isColEncrypted()) { + $this->encType = "deterministic"; + } else { + $this->encType = "normal"; + } + } else { + $this->encType = $encType; + } $this->encType = $encType; $this->forceEncrypt = $forceEncrypt; } @@ -173,11 +182,11 @@ class ColumnMeta */ public function getColDef() { - //return getColDef($this->colName, $this->dataType, $this->options, $this->encType); $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->isEncryptableType() && stripos($this->options, "identity") === false && stripos($this->options, "rowguidcol") === false) { + if (isColEncrypted() && ($this->encType == "deterministic" || $this->encType == "ramdomized") && $this->isEncryptableType() + && stripos($this->options, "identity") === false && stripos($this->options, "rowguidcol") === false) { $cekName = getCekName(); if (stripos($this->dataType, "char") !== false) { $append .= "COLLATE Latin1_General_BIN2 "; diff --git a/test/functional/pdo_sqlsrv/PDO38_FetchBound.phpt b/test/functional/pdo_sqlsrv/PDO38_FetchBound.phpt index 2885916a..26bf378a 100644 --- a/test/functional/pdo_sqlsrv/PDO38_FetchBound.phpt +++ b/test/functional/pdo_sqlsrv/PDO38_FetchBound.phpt @@ -48,7 +48,7 @@ try { $num = $stmt2->fetchColumn(); echo "There are $num rows in the table.\n"; - createTable($conn1, $tableName, array(new ColumnMeta("int", "idx", "NOT NULL PRIMARY KEY"), "txt" => "varchar(20)")); + createTable($conn1, $tableName, array(new ColumnMeta("int", "idx", "NOT NULL PRIMARY KEY", "normal"), "txt" => "varchar(20)")); insertRow($conn1, $tableName, array("idx" => 0, "txt" => 'String0')); insertRow($conn1, $tableName, array("idx" => 1, "txt" => 'String1')); insertRow($conn1, $tableName, array("idx" => 2, "txt" => 'String2')); @@ -59,18 +59,9 @@ try { var_dump($stmt1->fetchColumn()); unset($stmt1); - if (!isColEncrypted()) { - $stmt1 = $conn1->prepare("SELECT idx, txt FROM [$tableName] ORDER BY idx"); - } else { - // ORDER BY does not work on encrypted columns - $stmt1 = $conn1->prepare("SELECT idx, txt FROM [$tableName]"); - } + $stmt1 = $conn1->prepare("SELECT idx, txt FROM [$tableName] ORDER BY idx"); $stmt1->execute(); $data = $stmt1->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_UNIQUE); - // needs to order the result set manually as ORDER BY does not work properly on encrypted columns - if (isColEncrypted()) { - ksort($data); - } var_dump($data); echo "===WHILE===\n"; @@ -100,7 +91,7 @@ try { var_dump($stmt2->execute()); if ($idx == 0) { // bindColumn()s after execute() has been called at least once - $stmt2->bindColumn('txt', $txtCol); + $stmt2->bindColumn('txt', $col); } var_dump($stmt2->fetch(PDO::FETCH_BOUND)); $stmt2->closeCursor(); @@ -112,23 +103,23 @@ try { var_dump($stmt3->fetch(PDO::FETCH_BOUND)); $stmt3->closeCursor(); - var_dump(array($idxCol=>$txtCol)); + var_dump(array($idxCol=>$col)); } echo "===REBIND/SAME===\n"; - $stmt3->bindColumn('idx', $idxCol); + $stmt3->bindColumn('idx', $col); foreach ($data as $idx => $txt) { var_dump(array($idx=>$txt)); var_dump($stmt2->execute()); var_dump($stmt2->fetch(PDO::FETCH_BOUND)); $stmt2->closeCursor(); - var_dump($idxCol); + var_dump($col); var_dump($stmt3->execute()); var_dump($stmt3->fetch(PDO::FETCH_BOUND)); $stmt3->closeCursor(); - var_dump($idxCol); + var_dump($col); } echo "===REBIND/CONFLICT===\n"; diff --git a/test/functional/pdo_sqlsrv/PDO61_BindColumn1.phpt b/test/functional/pdo_sqlsrv/PDO61_BindColumn1.phpt index 31976354..e70a514d 100644 --- a/test/functional/pdo_sqlsrv/PDO61_BindColumn1.phpt +++ b/test/functional/pdo_sqlsrv/PDO61_BindColumn1.phpt @@ -15,7 +15,7 @@ try { // Prepare test table $tableName = "pdo_test_table"; - createTable($conn1, $tableName, array(new ColumnMeta("int", "idx", "NOT NULL PRIMARY KEY"), "txt" => "varchar(20)")); + createTable($conn1, $tableName, array(new ColumnMeta("int", "idx", "NOT NULL PRIMARY KEY", "normal"), "txt" => "varchar(20)")); insertRow($conn1, $tableName, array("idx" => 0, "txt" => "String0")); insertRow($conn1, $tableName, array("idx" => 1, "txt" => "String1")); insertRow($conn1, $tableName, array("idx" => 2, "txt" => "String2")); @@ -28,36 +28,17 @@ try { unset($stmt1); logInfo(2, "Testing fetchAll() ..."); - // ORDER BY doesn't work for encrypted columns - // need to fetch all rows first then sort and print - if (!isColEncrypted()) { - $stmt1 = $conn1->prepare("SELECT idx, txt FROM [$tableName] ORDER BY idx"); - } else { - $stmt1 = $conn1->prepare("SELECT idx, txt FROM [$tableName]"); - } + $stmt1 = $conn1->prepare("SELECT idx, txt FROM [$tableName] ORDER BY idx"); $stmt1->execute(); $data = $stmt1->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_UNIQUE); - if (isColEncrypted()) { - sort($data); - } var_dump($data); logInfo(3, "Testing bindColumn() ..."); $stmt1->bindColumn('idx', $idx); $stmt1->bindColumn('txt', $txt); $stmt1->execute(); - $idxArray = array(); - $txtArray = array(); while ($stmt1->fetch(PDO::FETCH_BOUND)) { - array_push($idxArray, $idx); - array_push($txtArray, $txt); - } - if (isColEncrypted()) { - sort($idxArray); - sort($txtArray); - } - for ($i = 0; $i < 4; $i++) { - var_dump(array($idxArray[$i] => $txtArray[$i])); + var_dump(array($idx=>$txt)); } logInfo(4, "Testing bindColumn() with data check ..."); @@ -74,27 +55,13 @@ try { $stmt1->execute(); while ($stmt1->fetch(PDO::FETCH_BOUND)) { $data[] = array('id' => $id, 'val' => $val); + printf("id = %s (%s) / val = %s (%s)\n", + var_export($id, true), gettype($id), + var_export($val, true), gettype($val)); } - $sortedData = $data; - if (isColEncrypted()) { - sort($sortedData); - } - foreach ($sortedData as $d) { - printf( - "id = %s (%s) / val = %s (%s)\n", - var_export($d['id'], true), - gettype($d['id']), - var_export($d['val'], true), - gettype($d['val']) - ); - } - unset($stmt1); - if (!isColEncrypted()) { - $stmt1 = $conn1->query("SELECT idx, txt FROM [$tableName] ORDER BY idx"); - } else { - $stmt1 = $conn1->query("SELECT idx, txt FROM [$tableName]"); - } + + $stmt1 = $conn1->query("SELECT idx, txt FROM [$tableName] ORDER BY idx"); while ($row = $stmt1->fetch(PDO::FETCH_ASSOC)) { if ($row['idx'] != $data[$index]['id']) { logInfo(6, "Data corruption for integer column in row $index"); diff --git a/test/functional/pdo_sqlsrv/PDO62_BindColumn2.phpt b/test/functional/pdo_sqlsrv/PDO62_BindColumn2.phpt index abb2b62a..acb5e9b6 100644 --- a/test/functional/pdo_sqlsrv/PDO62_BindColumn2.phpt +++ b/test/functional/pdo_sqlsrv/PDO62_BindColumn2.phpt @@ -15,7 +15,7 @@ try { // Prepare test table $tableName = "pdo_test_table"; - createTable($conn1, $tableName, array(new ColumnMeta("int", "id", "NOT NULL PRIMARY KEY"), "label" => "char(1)")); + createTable($conn1, $tableName, array(new ColumnMeta("int", "id", "NOT NULL PRIMARY KEY", "normal"), "label" => "char(1)")); insertRow($conn1, $tableName, array("id" => 1, "label" => "a")); insertRow($conn1, $tableName, array("id" => 2, "label" => "b")); insertRow($conn1, $tableName, array("id" => 3, "label" => "c")); @@ -27,36 +27,13 @@ try { $midRow = 4; // Check bind column - // order by does not work for encrypted columns - if (!isColEncrypted()) { - $tsql1 = "SELECT TOP($rowCount) id, label FROM [$tableName] ORDER BY id ASC"; - } else { - $tsql1 = "SELECT TOP($rowCount) id, label FROM [$tableName]"; - } - $data1 = bindColumn($conn1, $tsql1); - checkBind($conn1, $tsql1, $data1); + $tsql1 = "SELECT TOP($rowCount) id, label FROM [$tableName] ORDER BY id ASC"; + $data = bindColumn($conn1, $tsql1); + checkBind($conn1, $tsql1, $data); - if (!isColEncrypted()) { - $tsql2 = "SELECT TOP($rowCount) id, label FROM (SELECT *, ROW_NUMBER() OVER(ORDER BY id ASC) as row FROM [$tableName]) [$tableName] WHERE row >= $midRow"; - } else { - $tsql2 = "SELECT TOP($rowCount) id, label FROM (SELECT *, ROW_NUMBER() OVER(ORDER BY (SELECT 1)) as row FROM [$tableName]) [$tableName] WHERE row >= $midRow"; - } - $data2 = bindColumn($conn1, $tsql2); - checkBind($conn1, $tsql2, $data2); - - $data = array_merge($data1, $data2); - if (isColEncrypted()) { - sort($data); - } - foreach ($data as $d) { - printf( - "id = %s (%s) / label = %s (%s)\n", - var_export($d['id'], true), - gettype($d['id']), - var_export($d['label'], true), - gettype($d['label']) - ); - } + $tsql2 = "SELECT TOP($rowCount) id, label FROM (SELECT *, ROW_NUMBER() OVER(ORDER BY id ASC) as row FROM [$tableName]) [$tableName] WHERE row >= $midRow"; + $data = bindColumn($conn1, $tsql2); + checkBind($conn1, $tsql2, $data); // Cleanup dropTable($conn1, $tableName); @@ -80,6 +57,9 @@ function bindColumn($conn, $tsql) logInfo(1, "Cannot bind string column"); } while ($stmt->fetch(PDO::FETCH_BOUND)) { + printf("id = %s (%s) / label = %s (%s)\n", + var_export($id, true), gettype($id), + var_export($label, true), gettype($label)); $data[] = array('id' => $id, 'label' => $label); } unset($stmt); diff --git a/test/functional/pdo_sqlsrv/PDO64_BindParam2.phpt b/test/functional/pdo_sqlsrv/PDO64_BindParam2.phpt index d7b203ac..f6fbde34 100644 --- a/test/functional/pdo_sqlsrv/PDO64_BindParam2.phpt +++ b/test/functional/pdo_sqlsrv/PDO64_BindParam2.phpt @@ -16,7 +16,7 @@ try { // Prepare test table $dataCols = "id, label"; $tableName = "pdo_test_table"; - createTable($conn1, $tableName, array(new ColumnMeta("int", "id", "NOT NULL PRIMARY KEY"), "label" => "char(1)")); + createTable($conn1, $tableName, array(new ColumnMeta("int", "id", "NOT NULL PRIMARY KEY", "normal"), "label" => "char(1)")); insertRow($conn1, $tableName, array("id" => 1, "label" => 'a')); insertRow($conn1, $tableName, array("id" => 2, "label" => 'b')); insertRow($conn1, $tableName, array("id" => 3, "label" => 'c')); @@ -28,13 +28,8 @@ try { $label = null; // Bind param @ SELECT - if (!isColEncrypted()) { - $tsql1 = "SELECT TOP(2) id, label FROM [$tableName] WHERE id > ? ORDER BY id ASC"; - $value1 = array(1 => 0); - } else { - $tsql1 = "SELECT id, label FROM $tableName WHERE id = ? OR id = ?"; - $value1 = array(1 => 1, 2 => 2); - } + $tsql1 = "SELECT TOP(2) id, label FROM [$tableName] WHERE id > ? ORDER BY id ASC"; + $value1 = 0; $stmt1 = $conn1->prepare($tsql1); bindParam(1, $stmt1, $value1); execStmt(1, $stmt1); @@ -45,13 +40,8 @@ try { unset($stmt1); // Bind param @ INSERT - if (!isColEncrypted()) { - $tsql2 = "INSERT INTO [$tableName](id, label) VALUES (100, ?)"; - $value2 = array(1 => null); - } else { - $tsql2 = "INSERT INTO [$tableName](id, label) VALUES (?, ?)"; - $value2 = array(1 => 100, 2 => null); - } + $tsql2 = "INSERT INTO [$tableName](id, label) VALUES (100, ?)"; + $value2 = null; $stmt1 = $conn1->prepare($tsql2); bindParam(2, $stmt1, $value2); execStmt(2, $stmt1); @@ -72,10 +62,10 @@ try { echo $e->getMessage(); } -function bindParam($offset, $stmt, $value) +function bindParam($offset, $stmt, &$value) { - foreach ($value as $key => &$val) { - $stmt->bindParam($key, $val); + if (!$stmt->bindParam(1, $value)) { + logInfo($offset,"Cannot bind parameter"); } } diff --git a/test/functional/pdo_sqlsrv/PDO66_BindValue2.phpt b/test/functional/pdo_sqlsrv/PDO66_BindValue2.phpt index 1390fc39..75fee971 100644 --- a/test/functional/pdo_sqlsrv/PDO66_BindValue2.phpt +++ b/test/functional/pdo_sqlsrv/PDO66_BindValue2.phpt @@ -15,7 +15,7 @@ try { // Prepare test table $tableName = "pdo_test_table"; - createTable($conn1, $tableName, array(new ColumnMeta("int", "id", "NOT NULL PRIMARY KEY"), "label" => "char(1)")); + createTable($conn1, $tableName, array(new ColumnMeta("int", "id", "NOT NULL PRIMARY KEY", "normal"), "label" => "char(1)")); insertRow($conn1, $tableName, array("id" => 1, "label" => "a")); insertRow($conn1, $tableName, array("id" => 2, "label" => "b")); insertRow($conn1, $tableName, array("id" => 3, "label" => "c")); @@ -27,34 +27,18 @@ try { $label = null; // Check different value bind modes - if (!isColEncrypted()) { - $tsql1 = "SELECT TOP(2) id, label FROM [$tableName] WHERE id > ? ORDER BY id ASC"; - } else { - $tsql1 = "SELECT id, label FROM [$tableName] WHERE id = ? OR id = ?"; - } + $tsql1 = "SELECT TOP(2) id, label FROM [$tableName] WHERE id > ? ORDER BY id ASC"; $stmt1 = $conn1->prepare($tsql1); printf("Binding value and not variable...\n"); - if (!isColEncrypted()) { - bindValue(1, 1, $stmt1, 0); - } else { - bindValue(1, 1, $stmt1, 1); - bindValue(1, 2, $stmt1, 2); - } + bindValue(1, $stmt1, 0); execStmt(1, $stmt1); bindColumn(1, $stmt1, $id, $label); fetchBound($stmt1, $id, $label); printf("Binding variable...\n"); $var1 = 0; - if (!isColEncrypted()) { - bindVar(2, 1, $stmt1, $var1); - } else { - $var11 = $var1 + 1; - $var12 = $var1 + 2; - bindVar(2, 1, $stmt1, $var11); - bindVar(2, 2, $stmt1, $var12); - } + bindVar(2, $stmt1, $var1); execStmt(2, $stmt1); bindColumn(2, $stmt1, $id, $label); fetchBound($stmt1, $id, $label); @@ -62,33 +46,17 @@ try { printf("Binding variable which references another variable...\n"); $var2 = 0; $var_ref = &$var2; - if (!isColEncrypted()) { - bindVar(3, 1, $stmt1, $var_ref); - } else { - $var21 = $var2 + 1; - $var22 = $var2 + 2; - $var_ref1 = &$var21; - $var_ref2 = &$var22; - bindVar(3, 1, $stmt1, $var_ref1); - bindVar(3, 2, $stmt1, $var_ref2); - } + bindVar(3, $stmt1, $var_ref); execStmt(3, $stmt1); bindColumn(3, $stmt1, $id, $label); fetchBound($stmt1, $id, $label); unset($stmt1); - if (!isColEncrypted()) { - $tsql2 = "SELECT TOP(2) id, label FROM [$tableName] WHERE id > ? AND id <= ? ORDER BY id ASC"; - } else { - $tsql2 = "SELECT id, label FROM [$tableName] WHERE id = ? OR id = ?"; - } + $tsql2 = "SELECT TOP(2) id, label FROM [$tableName] WHERE id > ? AND id <= ? ORDER BY id ASC"; $stmt1 = $conn1->prepare($tsql2); printf("Binding a variable and a value...\n"); $var3 = 0; - if (isColEncrypted()) { - $var3++; - } bindMixed(4, $stmt1, $var3, 2); execStmt(4, $stmt1); bindColumn(4, $stmt1, $id, $label); @@ -96,9 +64,6 @@ try { printf("Binding a variable to two placeholders and changing the variable value in between the binds...\n"); $var4 = 0; - if (isColEncrypted()) { - $var4++; - } $var5 = 2; bindPlaceholder(5, $stmt1, $var4, $var5); execStmt(5, $stmt1); @@ -114,16 +79,16 @@ try { echo $e->getMessage(); } -function bindValue($offset, $index, $stmt, $value) +function bindValue($offset, $stmt, $value) { - if (!$stmt->bindValue($index, $value)) { + if (!$stmt->bindValue(1, $value)) { logInfo($offset, "Cannot bind value"); } } -function bindVar($offset, $index, $stmt, &$var) +function bindVar($offset, $stmt, &$var) { - if (!$stmt->bindValue($index, $var)) { + if (!$stmt->bindValue(1, $var)) { logInfo($offset, "Cannot bind variable"); } } diff --git a/test/functional/pdo_sqlsrv/pdo_katmai_special_types.phpt b/test/functional/pdo_sqlsrv/pdo_katmai_special_types.phpt index 082017df..e342b88f 100644 --- a/test/functional/pdo_sqlsrv/pdo_katmai_special_types.phpt +++ b/test/functional/pdo_sqlsrv/pdo_katmai_special_types.phpt @@ -30,7 +30,10 @@ function katmaiBasicTypes($conn) "c5_geometry" => '0000000001140000000000803e401f85eb51b81ee5bf48e17a14ae073f4052b81e85eb51d8bf', "c6_hierarchyid" => '5bc0', "c7_uniqueidentifier" => '35413141383846372d333734392d343641332d384137412d454641453733454645383846'); + if (isColEncrypted()) { + // remove these types from tests because these types require direct query for the data to be inserted + // and the insertRow common function uses bind parameters to insertion when column encryption is enabled $toRemove = array("c4_geography", "c5_geometry", "c6_hierarchyid"); foreach ($toRemove as $key) { unset($dataTypes[$key]); diff --git a/test/functional/pdo_sqlsrv/pdo_simple_update_variants.phpt b/test/functional/pdo_sqlsrv/pdo_simple_update_variants.phpt index cb3d9917..3657eb40 100644 --- a/test/functional/pdo_sqlsrv/pdo_simple_update_variants.phpt +++ b/test/functional/pdo_sqlsrv/pdo_simple_update_variants.phpt @@ -78,23 +78,13 @@ function updateFood($conn, $tableName, $id, $food, $category) function fetchRows($conn, $tableName) { - if (!isColEncrypted()) { - $query = "SELECT * FROM $tableName ORDER BY id"; - } else { - $query = "SELECT * FROM $tableName"; - } + $query = "SELECT * FROM $tableName ORDER BY id"; $stmt = $conn->query($query); $stmt->setFetchMode(PDO::FETCH_CLASS, 'Food'); $foodArray = array(); while ($food = $stmt->fetch()) { - array_push($foodArray, $food); - } - if (isColEncrypted()) { - sort($foodArray); - } - foreach ($foodArray as $food) { - echo "ID: " . $food->id . " "; + echo "ID: " . $food->id . " "; echo $food->getFood() . ", "; echo $food->getcategory() . "\n"; } From c5d02cbeec57899b4452631aa85c96f571cbd832 Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Thu, 7 Dec 2017 14:10:10 -0800 Subject: [PATCH 6/7] 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); From b808f3bd870de04143bbf192d15e0a2db00b832c Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Fri, 8 Dec 2017 12:11:53 -0800 Subject: [PATCH 7/7] change normal encryption to none encryption --- test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc | 4 ++-- test/functional/pdo_sqlsrv/PDO38_FetchBound.phpt | 2 +- test/functional/pdo_sqlsrv/PDO61_BindColumn1.phpt | 2 +- test/functional/pdo_sqlsrv/PDO62_BindColumn2.phpt | 2 +- test/functional/pdo_sqlsrv/PDO64_BindParam2.phpt | 2 +- test/functional/pdo_sqlsrv/PDO66_BindValue2.phpt | 2 +- test/functional/pdo_sqlsrv/pdo_katmai_special_types.phpt | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc b/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc index 27310ae9..bca30945 100644 --- a/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc +++ b/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc @@ -153,7 +153,7 @@ class ColumnMeta public $dataType; //a string that includes the size of the type if necessary (e.g., decimal(10,5)) public $colName; //column name public $options; //a string that is null by default (e.g. NOT NULL Identity (1,1) ) - public $encType; //randomized, deterministic, or normal; default is null + public $encType; //randomized, deterministic, or none; default is null public $forceEncrypt; //force encryption on a datatype not supported by Column Encrypton public function __construct($dataType, $colName = null, $options = null, $encType = null, $forceEncrypt = false) @@ -169,7 +169,7 @@ class ColumnMeta if (isColEncrypted()) { $this->encType = "deterministic"; } else { - $this->encType = "normal"; + $this->encType = "none"; } } else { $this->encType = $encType; diff --git a/test/functional/pdo_sqlsrv/PDO38_FetchBound.phpt b/test/functional/pdo_sqlsrv/PDO38_FetchBound.phpt index db043fd7..e5366c35 100644 --- a/test/functional/pdo_sqlsrv/PDO38_FetchBound.phpt +++ b/test/functional/pdo_sqlsrv/PDO38_FetchBound.phpt @@ -48,7 +48,7 @@ try { $num = $stmt2->fetchColumn(); echo "There are $num rows in the table.\n"; - createTable($conn1, $tableName, array(new ColumnMeta("int", "idx", "NOT NULL PRIMARY KEY", "normal"), "txt" => "varchar(20)")); + createTable($conn1, $tableName, array(new ColumnMeta("int", "idx", "NOT NULL PRIMARY KEY", "none"), "txt" => "varchar(20)")); insertRow($conn1, $tableName, array("idx" => 0, "txt" => 'String0')); insertRow($conn1, $tableName, array("idx" => 1, "txt" => 'String1')); insertRow($conn1, $tableName, array("idx" => 2, "txt" => 'String2')); diff --git a/test/functional/pdo_sqlsrv/PDO61_BindColumn1.phpt b/test/functional/pdo_sqlsrv/PDO61_BindColumn1.phpt index e70a514d..1d773a3f 100644 --- a/test/functional/pdo_sqlsrv/PDO61_BindColumn1.phpt +++ b/test/functional/pdo_sqlsrv/PDO61_BindColumn1.phpt @@ -15,7 +15,7 @@ try { // Prepare test table $tableName = "pdo_test_table"; - createTable($conn1, $tableName, array(new ColumnMeta("int", "idx", "NOT NULL PRIMARY KEY", "normal"), "txt" => "varchar(20)")); + createTable($conn1, $tableName, array(new ColumnMeta("int", "idx", "NOT NULL PRIMARY KEY", "none"), "txt" => "varchar(20)")); insertRow($conn1, $tableName, array("idx" => 0, "txt" => "String0")); insertRow($conn1, $tableName, array("idx" => 1, "txt" => "String1")); insertRow($conn1, $tableName, array("idx" => 2, "txt" => "String2")); diff --git a/test/functional/pdo_sqlsrv/PDO62_BindColumn2.phpt b/test/functional/pdo_sqlsrv/PDO62_BindColumn2.phpt index acb5e9b6..9e39ca3c 100644 --- a/test/functional/pdo_sqlsrv/PDO62_BindColumn2.phpt +++ b/test/functional/pdo_sqlsrv/PDO62_BindColumn2.phpt @@ -15,7 +15,7 @@ try { // Prepare test table $tableName = "pdo_test_table"; - createTable($conn1, $tableName, array(new ColumnMeta("int", "id", "NOT NULL PRIMARY KEY", "normal"), "label" => "char(1)")); + createTable($conn1, $tableName, array(new ColumnMeta("int", "id", "NOT NULL PRIMARY KEY", "none"), "label" => "char(1)")); insertRow($conn1, $tableName, array("id" => 1, "label" => "a")); insertRow($conn1, $tableName, array("id" => 2, "label" => "b")); insertRow($conn1, $tableName, array("id" => 3, "label" => "c")); diff --git a/test/functional/pdo_sqlsrv/PDO64_BindParam2.phpt b/test/functional/pdo_sqlsrv/PDO64_BindParam2.phpt index f6fbde34..3801bf7f 100644 --- a/test/functional/pdo_sqlsrv/PDO64_BindParam2.phpt +++ b/test/functional/pdo_sqlsrv/PDO64_BindParam2.phpt @@ -16,7 +16,7 @@ try { // Prepare test table $dataCols = "id, label"; $tableName = "pdo_test_table"; - createTable($conn1, $tableName, array(new ColumnMeta("int", "id", "NOT NULL PRIMARY KEY", "normal"), "label" => "char(1)")); + createTable($conn1, $tableName, array(new ColumnMeta("int", "id", "NOT NULL PRIMARY KEY", "none"), "label" => "char(1)")); insertRow($conn1, $tableName, array("id" => 1, "label" => 'a')); insertRow($conn1, $tableName, array("id" => 2, "label" => 'b')); insertRow($conn1, $tableName, array("id" => 3, "label" => 'c')); diff --git a/test/functional/pdo_sqlsrv/PDO66_BindValue2.phpt b/test/functional/pdo_sqlsrv/PDO66_BindValue2.phpt index 75fee971..71a885a7 100644 --- a/test/functional/pdo_sqlsrv/PDO66_BindValue2.phpt +++ b/test/functional/pdo_sqlsrv/PDO66_BindValue2.phpt @@ -15,7 +15,7 @@ try { // Prepare test table $tableName = "pdo_test_table"; - createTable($conn1, $tableName, array(new ColumnMeta("int", "id", "NOT NULL PRIMARY KEY", "normal"), "label" => "char(1)")); + createTable($conn1, $tableName, array(new ColumnMeta("int", "id", "NOT NULL PRIMARY KEY", "none"), "label" => "char(1)")); insertRow($conn1, $tableName, array("id" => 1, "label" => "a")); insertRow($conn1, $tableName, array("id" => 2, "label" => "b")); insertRow($conn1, $tableName, array("id" => 3, "label" => "c")); diff --git a/test/functional/pdo_sqlsrv/pdo_katmai_special_types.phpt b/test/functional/pdo_sqlsrv/pdo_katmai_special_types.phpt index fe779745..fc6ff687 100644 --- a/test/functional/pdo_sqlsrv/pdo_katmai_special_types.phpt +++ b/test/functional/pdo_sqlsrv/pdo_katmai_special_types.phpt @@ -106,7 +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 + // trimming is required since SPARSE is not supported for encrypted columns if (trim($value1) !== trim($value2)) { echo "The values don't match!\n"; }