From a60992f8a550ceaebe8f20a7e8dc4f49aa016b0a Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Fri, 3 Nov 2017 17:01:09 -0700 Subject: [PATCH] address review comments --- .../pdo_prepare_emulatePrepare_int.phpt | 5 +- .../pdo_prepare_emulatePrepare_unicode.phpt | 1 - .../pdo_sqlsrv/pdo_query_timeout.phpt | 6 +- .../pdo_statement_rowcount_query.phpt | 7 +- .../pdo_sqlsrv/pdostatement_bindColumn.phpt | 8 +- .../pdostatement_debugDumpParams.phpt | 2 +- .../pdo_sqlsrv/pdostatement_fetchColumn.phpt | 2 +- .../pdo_sqlsrv/pdostatement_fetch_style.phpt | 183 ++++++++---------- .../pdostatement_getColumnMeta.phpt | 4 +- ...tement_getColumnMeta_unicode_col_name.phpt | 4 +- .../pdo_sqlsrv/pdostatement_setFetchMode.phpt | 34 +--- 11 files changed, 110 insertions(+), 146 deletions(-) diff --git a/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_int.phpt b/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_int.phpt index 33bee845..8950e244 100644 --- a/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_int.phpt +++ b/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_int.phpt @@ -8,8 +8,7 @@ require_once('MsCommon_mid-refactor.inc'); try { $conn = connect(); - //$tableName = "fruit"; - $tableName = getTableName(); + $tableName = "fruit"; createTable($conn, $tableName, array("name" => "varchar(max)", "calories" => "int")); insertRow($conn, $tableName, array("name" => "apple", "calories" => 150)); @@ -42,7 +41,7 @@ try { if (!isColEncrypted()) { // without emulate prepare, binding PARAM_INT with SQLSRV_ENCODING_SYSTEM is not allowed - // thus these are not tested when Column Encryption is disabled + // thus the following will not be tested when Column Encryption is enabled $results = array(); //prepare with emulate prepare and encoding SQLSRV_ENCODING_SYSTEM diff --git a/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_unicode.phpt b/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_unicode.phpt index 834718fc..52559e4d 100644 --- a/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_unicode.phpt +++ b/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_unicode.phpt @@ -24,7 +24,6 @@ function prepareStmt($conn, $query, $prepareOptions = array(), $dataType = null, try { $conn = connect("", array(), PDO::ERRMODE_SILENT); - //$conn->setAttribute( PDO::SQLSRV_ATTR_QUERY_TIMEOUT, 1 ); $tableName = "users"; createTable($conn, $tableName, array("name" => "nvarchar(max)", "status" => "int", "age" => "int")); diff --git a/test/functional/pdo_sqlsrv/pdo_query_timeout.phpt b/test/functional/pdo_sqlsrv/pdo_query_timeout.phpt index 8e5e1ce4..a87a50f3 100644 --- a/test/functional/pdo_sqlsrv/pdo_query_timeout.phpt +++ b/test/functional/pdo_sqlsrv/pdo_query_timeout.phpt @@ -6,7 +6,7 @@ test query time out at the connection level and statement level getMessage(); } diff --git a/test/functional/pdo_sqlsrv/pdo_statement_rowcount_query.phpt b/test/functional/pdo_sqlsrv/pdo_statement_rowcount_query.phpt index 4ec2843d..d8217c70 100644 --- a/test/functional/pdo_sqlsrv/pdo_statement_rowcount_query.phpt +++ b/test/functional/pdo_sqlsrv/pdo_statement_rowcount_query.phpt @@ -35,18 +35,21 @@ function rowCountQuery($exec) function updateData($conn, $tableName, $value, $exec) { $newValue = $value * 100; - $query = "UPDATE $tableName SET c1_int = $newValue WHERE (c1_int = $value)"; $rowCount = 0; if (isColEncrypted()) { // need to bind parameters for updating encrypted columns $query = "UPDATE $tableName SET c1_int = ? WHERE (c1_int = ?)"; $stmt = $conn->prepare($query); + if ($rowCount > 0) { + echo "Number of rows affected prior to execution should be 0!\n"; + } $stmt->bindParam(1, $newValue); $stmt->bindParam(2, $value); $stmt->execute(); $rowCount = $stmt->rowCount(); } else { + $query = "UPDATE $tableName SET c1_int = $newValue WHERE (c1_int = $value)"; if ($exec) { $rowCount = $conn->exec($query); } else { @@ -147,7 +150,7 @@ function deleteData($conn, $tableName, $exec) echo "Starting test...\n"; try { rowCountQuery(true); - //rowCountQuery(false); + rowCountQuery(false); } catch (Exception $e) { echo $e->getMessage(); } diff --git a/test/functional/pdo_sqlsrv/pdostatement_bindColumn.phpt b/test/functional/pdo_sqlsrv/pdostatement_bindColumn.phpt index 89f5773f..ec4bcc7e 100644 --- a/test/functional/pdo_sqlsrv/pdostatement_bindColumn.phpt +++ b/test/functional/pdo_sqlsrv/pdostatement_bindColumn.phpt @@ -7,7 +7,7 @@ Test the bindColumn method using either by bind by column number or bind by colu require_once("MsCommon_mid-refactor.inc"); require_once("MsData_PDO_AllTypes.inc"); -function bindColumn_byName($db, $tbname) +function bindColumnByName($db, $tbname) { $stmt = $db->prepare("SELECT IntCol, CharCol, DateTimeCol FROM $tbname"); $stmt->execute(); @@ -20,7 +20,7 @@ function bindColumn_byName($db, $tbname) } } -function bindColumn_byNumber($db, $tbname) +function bindColumnByNumber($db, $tbname) { $stmt = $db->prepare("SELECT IntCol, CharCol, DateTimeCol FROM $tbname"); $stmt->execute(); @@ -38,9 +38,9 @@ try { $tbname = "PDO_MainTypes"; createAndInsertTableMainTypes($db, $tbname); echo "Bind Column by name :\n"; - bindColumn_byName($db, $tbname); + bindColumnByName($db, $tbname); echo "Bind Column by number :\n"; - bindColumn_byNumber($db, $tbname); + bindColumnByNumber($db, $tbname); dropTable($db, $tbname); unset($db); diff --git a/test/functional/pdo_sqlsrv/pdostatement_debugDumpParams.phpt b/test/functional/pdo_sqlsrv/pdostatement_debugDumpParams.phpt index 834a213e..64364ec3 100644 --- a/test/functional/pdo_sqlsrv/pdostatement_debugDumpParams.phpt +++ b/test/functional/pdo_sqlsrv/pdostatement_debugDumpParams.phpt @@ -14,7 +14,7 @@ try { createAndInsertTableAllTypes($db, $tbname); $bigint = 1; $string = "STRINGCOL1"; - $stmt = $db->prepare("SELECT IntCol FROM " . $tbname . " WHERE BigIntCol = :bigint AND CharCol = :string"); + $stmt = $db->prepare("SELECT IntCol FROM $tbname WHERE BigIntCol = :bigint AND CharCol = :string"); $stmt->bindValue(':bigint', $bigint, PDO::PARAM_INT); $stmt->bindValue(':string', $string, PDO::PARAM_STR); $stmt->execute(); diff --git a/test/functional/pdo_sqlsrv/pdostatement_fetchColumn.phpt b/test/functional/pdo_sqlsrv/pdostatement_fetchColumn.phpt index 344475f4..9df263c9 100644 --- a/test/functional/pdo_sqlsrv/pdostatement_fetchColumn.phpt +++ b/test/functional/pdo_sqlsrv/pdostatement_fetchColumn.phpt @@ -14,7 +14,7 @@ try { $stmt = $db->query("Select * from $tbname"); - // Fetch the first column from the next row in resultset. (This wud be first row since this is a first call to fetchcol) + // Fetch the first column from the next row in resultset. (This would be first row since this is a first call to fetchcol) $result = $stmt->fetchColumn(); var_dump($result); diff --git a/test/functional/pdo_sqlsrv/pdostatement_fetch_style.phpt b/test/functional/pdo_sqlsrv/pdostatement_fetch_style.phpt index e596327f..000931b6 100644 --- a/test/functional/pdo_sqlsrv/pdostatement_fetch_style.phpt +++ b/test/functional/pdo_sqlsrv/pdostatement_fetch_style.phpt @@ -7,100 +7,75 @@ Test the PDOStatement::fetch() method with different fetch styles. require_once("MsCommon_mid-refactor.inc"); require_once("MsData_PDO_AllTypes.inc"); -function fetchBoth($conn, $tbname) +function fetchWithStyle($conn, $tbname, $style) { - $stmt = $conn->query("Select * from $tbname"); - $result = $stmt->fetch(PDO::FETCH_BOTH); - var_dump($result); - $stmt->closeCursor(); -} - -function fetchAssoc($conn, $tbname) -{ - $stmt = $conn->query("Select * from $tbname"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); - $stmt->closeCursor(); -} - -function fetchLazy($conn, $tbname) -{ - $stmt = $conn->query("Select * from $tbname"); - $result = $stmt->fetch(PDO::FETCH_LAZY); - var_dump($result); - $stmt->closeCursor(); -} - -function fetchObj($conn, $tbname) -{ - $stmt = $conn->query("Select * from $tbname"); - $result = $stmt->fetch(PDO::FETCH_OBJ); - var_dump($result); - $stmt->closeCursor(); -} - -function fetchNum($conn, $tbname) -{ - $stmt = $conn->query("Select * from $tbname"); - $result = $stmt->fetch(PDO::FETCH_NUM); - var_dump($result); - $stmt->closeCursor(); -} - -function fetchBound($conn, $tbname) -{ - $stmt = $conn->query("Select * from $tbname"); - $stmt->bindColumn('IntCol', $IntCol); - $stmt->bindColumn('CharCol', $CharCol); - $stmt->bindColumn('NCharCol', $NCharCol); - $stmt->bindColumn('DateTimeCol', $DateTimeCol); - $stmt->bindColumn('VarcharCol', $VarcharCol); - $stmt->bindColumn('NVarCharCol', $NVarCharCol); - $stmt->bindColumn('FloatCol', $FloatCol); - $stmt->bindColumn('XmlCol', $XmlCol); - $result = $stmt->fetch(PDO::FETCH_BOUND); - if (!$result) { - die("Error in FETCH_BOUND\n"); - } - var_dump($IntCol); - var_dump($CharCol); - var_dump($NCharCol); - var_dump($DateTimeCol); - var_dump($VarcharCol); - var_dump($NVarCharCol); - var_dump($FloatCol); - var_dump($XmlCol); - $stmt->closeCursor(); -} - -function fetchClass($conn, $tbname) -{ - global $mainTypesClass; - $stmt = $conn->query("Select * from $tbname"); - $stmt->setFetchMode(PDO::FETCH_CLASS, $mainTypesClass); - $result = $stmt->fetch(PDO::FETCH_CLASS); - $result->dumpAll(); - $stmt->closeCursor(); -} - -function fetchInto($conn, $tbname) -{ - global $mainTypesClass; - $stmt = $conn->query("Select * from $tbname"); - $obj = new $mainTypesClass; - $stmt->setFetchMode(PDO::FETCH_INTO, $obj); - $result = $stmt->fetch(PDO::FETCH_INTO); - $obj->dumpAll(); - $stmt->closeCursor(); -} - -function fetchInvalid($conn, $tbname) -{ - $stmt = $conn->query("Select * from $tbname"); - try { - $result = $stmt->fetch(PDO::FETCH_UNKNOWN); - } catch (PDOException $err) { - print_r($err); + $stmt = $conn->query("SELECT * FROM $tbname"); + switch ($style) { + case PDO::FETCH_BOTH: + case PDO::FETCH_ASSOC: + case PDO::FETCH_LAZY: + case PDO::FETCH_OBJ: + case PDO::FETCH_NUM: + { + $result = $stmt->fetch($style); + var_dump($result); + unset($stmt); + break; + } + case PDO::FETCH_BOUND: + { + $stmt->bindColumn('IntCol', $IntCol); + $stmt->bindColumn('CharCol', $CharCol); + $stmt->bindColumn('NCharCol', $NCharCol); + $stmt->bindColumn('DateTimeCol', $DateTimeCol); + $stmt->bindColumn('VarcharCol', $VarcharCol); + $stmt->bindColumn('NVarCharCol', $NVarCharCol); + $stmt->bindColumn('FloatCol', $FloatCol); + $stmt->bindColumn('XmlCol', $XmlCol); + $result = $stmt->fetch($style); + if (!$result) { + die("Error in FETCH_BOUND\n"); + } + var_dump($IntCol); + var_dump($CharCol); + var_dump($NCharCol); + var_dump($DateTimeCol); + var_dump($VarcharCol); + var_dump($NVarCharCol); + var_dump($FloatCol); + var_dump($XmlCol); + unset($stmt); + break; + } + case PDO::FETCH_CLASS: + { + global $mainTypesClass; + $stmt->setFetchMode($style, $mainTypesClass); + $result = $stmt->fetch($style); + $result->dumpAll(); + unset($stmt); + break; + } + case PDO::FETCH_INTO: + { + global $mainTypesClass; + $obj = new $mainTypesClass; + $stmt->setFetchMode($style, $obj); + $result = $stmt->fetch($style); + $obj->dumpAll(); + unset($stmt); + break; + } + case "PDO::FETCH_INVALID": + { + try { + $result = $stmt->fetch(PDO::FETCH_UNKNOWN); + } catch (PDOException $err) { + print_r($err); + } + break; + } + } } @@ -109,23 +84,23 @@ try { $tbname = "PDO_MainTypes"; createAndInsertTableMainTypes($db, $tbname); echo "Test_1 : FETCH_BOTH :\n"; - fetchBoth($db, $tbname); + fetchWithStyle($db, $tbname, PDO::FETCH_BOTH); echo "Test_2 : FETCH_ASSOC :\n"; - fetchAssoc($db, $tbname); + fetchWithStyle($db, $tbname, PDO::FETCH_ASSOC); echo "Test_3 : FETCH_LAZY :\n"; - fetchLazy($db, $tbname); + fetchWithStyle($db, $tbname, PDO::FETCH_LAZY); echo "Test_4 : FETCH_OBJ :\n"; - fetchObj($db, $tbname); + fetchWithStyle($db, $tbname, PDO::FETCH_OBJ); echo "Test_5 : FETCH_NUM :\n"; - fetchNum($db, $tbname); + fetchWithStyle($db, $tbname, PDO::FETCH_NUM); echo "Test_6 : FETCH_BOUND :\n"; - fetchBound($db, $tbname); + fetchWithStyle($db, $tbname, PDO::FETCH_BOUND); echo "Test_7 : FETCH_CLASS :\n"; - fetchClass($db, $tbname); + fetchWithStyle($db, $tbname, PDO::FETCH_CLASS); echo "Test_8 : FETCH_INTO :\n"; - fetchInto($db, $tbname); + fetchWithStyle($db, $tbname, PDO::FETCH_INTO); echo "Test_9 : FETCH_INVALID :\n"; - fetchInvalid($db, $tbname); + fetchWithStyle($db, $tbname, "PDO::FETCH_INVALID"); dropTable($db, $tbname); unset($db); @@ -195,7 +170,7 @@ array(8) { Test_3 : FETCH_LAZY : object(PDORow)#%x (%x) { ["queryString"]=> - string(27) "Select * from PDO_MainTypes" + string(27) "SELECT * FROM PDO_MainTypes" ["IntCol"]=> string(1) "1" ["CharCol"]=> @@ -282,6 +257,6 @@ Test_9 : FETCH_INVALID : Fatal error: Uncaught Error: Undefined class constant 'FETCH_UNKNOWN' in %s:%x Stack trace: -#0 %s: fetchInvalid(Object(PDO), 'PDO_MainTypes') +#0 %s: fetchWithStyle(Object(PDO), 'PDO_MainTypes', 'PDO::FETCH_INVA...') #1 {main} thrown in %s on line %x diff --git a/test/functional/pdo_sqlsrv/pdostatement_getColumnMeta.phpt b/test/functional/pdo_sqlsrv/pdostatement_getColumnMeta.phpt index ea61164e..419f5a98 100644 --- a/test/functional/pdo_sqlsrv/pdostatement_getColumnMeta.phpt +++ b/test/functional/pdo_sqlsrv/pdostatement_getColumnMeta.phpt @@ -1,5 +1,7 @@ --TEST-- -Test the PDOStatement::getColumnMeta() method (Note: there could be an issue about using a non-existent column index --- doesn't give any error/output/warning). +Test the PDOStatement::getColumnMeta() method +--DESCRIPTION-- +there could be an issue about using a non-existent column index --- doesn't give any error/output/warning --SKIPIF-- --FILE-- diff --git a/test/functional/pdo_sqlsrv/pdostatement_getColumnMeta_unicode_col_name.phpt b/test/functional/pdo_sqlsrv/pdostatement_getColumnMeta_unicode_col_name.phpt index e60f80b0..bb01be10 100644 --- a/test/functional/pdo_sqlsrv/pdostatement_getColumnMeta_unicode_col_name.phpt +++ b/test/functional/pdo_sqlsrv/pdostatement_getColumnMeta_unicode_col_name.phpt @@ -1,5 +1,7 @@ --TEST-- -Test the PDOStatement::getColumnMeta() method for Unicode column names (Note: there could be an issue about using a non-existent column index --- doesn't give any error/output/warning). +Test the PDOStatement::getColumnMeta() method for Unicode column names +--DESCRIPTION-- +there could be an issue about using a non-existent column index --- doesn't give any error/output/warning --SKIPIF-- --FILE-- diff --git a/test/functional/pdo_sqlsrv/pdostatement_setFetchMode.phpt b/test/functional/pdo_sqlsrv/pdostatement_setFetchMode.phpt index 02ddb762..b7473211 100644 --- a/test/functional/pdo_sqlsrv/pdostatement_setFetchMode.phpt +++ b/test/functional/pdo_sqlsrv/pdostatement_setFetchMode.phpt @@ -11,31 +11,15 @@ try { $db = connect(); $tbname = "PDO_MainTypes"; createAndInsertTableMainTypes($db, $tbname); - $stmt = $db->query("SELECT * FROM $tbname"); - echo "Set Fetch Mode for PDO::FETCH_ASSOC\n"; - $stmt->setFetchMode(PDO::FETCH_ASSOC); - $result = $stmt->fetch(); - var_dump($result); - $stmt = $db->query("SELECT * FROM $tbname"); - echo "Set Fetch Mode for PDO::FETCH_NUM\n"; - $stmt->setFetchMode(PDO::FETCH_NUM); - $result = $stmt->fetch(); - var_dump($result); - $stmt = $db->query("SELECT * FROM $tbname"); - echo "Set Fetch Mode for PDO::FETCH_BOTH\n"; - $stmt->setFetchMode(PDO::FETCH_BOTH); - $result = $stmt->fetch(); - var_dump($result); - $stmt = $db->query("SELECT * FROM $tbname"); - echo "Set Fetch Mode for PDO::FETCH_LAZY\n"; - $stmt->setFetchMode(PDO::FETCH_LAZY); - $result = $stmt->fetch(); - var_dump($result); - $stmt = $db->query("SELECT * FROM $tbname"); - echo "Set Fetch Mode for PDO::FETCH_OBJ\n"; - $stmt->setFetchMode(PDO::FETCH_OBJ); - $result = $stmt->fetch(); - var_dump($result); + + $fetchModes = array("PDO::FETCH_ASSOC", "PDO::FETCH_NUM", "PDO::FETCH_BOTH", "PDO::FETCH_LAZY", "PDO::FETCH_OBJ"); + foreach ($fetchModes as $mode) { + $stmt = $db->query("SELECT * FROM $tbname"); + echo "Set Fetch Mode for $mode\n"; + $stmt->setFetchMode(constant($mode)); + $result = $stmt->fetch(); + var_dump($result); + } } catch (PDOException $e) { var_dump($e); }