address review comments

This commit is contained in:
v-kaywon 2017-11-03 17:01:09 -07:00
parent 0c74a27186
commit a60992f8a5
11 changed files with 110 additions and 146 deletions

View file

@ -8,8 +8,7 @@ require_once('MsCommon_mid-refactor.inc');
try { try {
$conn = connect(); $conn = connect();
//$tableName = "fruit"; $tableName = "fruit";
$tableName = getTableName();
createTable($conn, $tableName, array("name" => "varchar(max)", "calories" => "int")); createTable($conn, $tableName, array("name" => "varchar(max)", "calories" => "int"));
insertRow($conn, $tableName, array("name" => "apple", "calories" => 150)); insertRow($conn, $tableName, array("name" => "apple", "calories" => 150));
@ -42,7 +41,7 @@ try {
if (!isColEncrypted()) { if (!isColEncrypted()) {
// without emulate prepare, binding PARAM_INT with SQLSRV_ENCODING_SYSTEM is not allowed // 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(); $results = array();
//prepare with emulate prepare and encoding SQLSRV_ENCODING_SYSTEM //prepare with emulate prepare and encoding SQLSRV_ENCODING_SYSTEM

View file

@ -24,7 +24,6 @@ function prepareStmt($conn, $query, $prepareOptions = array(), $dataType = null,
try { try {
$conn = connect("", array(), PDO::ERRMODE_SILENT); $conn = connect("", array(), PDO::ERRMODE_SILENT);
//$conn->setAttribute( PDO::SQLSRV_ATTR_QUERY_TIMEOUT, 1 );
$tableName = "users"; $tableName = "users";
createTable($conn, $tableName, array("name" => "nvarchar(max)", "status" => "int", "age" => "int")); createTable($conn, $tableName, array("name" => "nvarchar(max)", "status" => "int", "age" => "int"));

View file

@ -6,7 +6,7 @@ test query time out at the connection level and statement level
<?php <?php
require_once("MsCommon_mid-refactor.inc"); require_once("MsCommon_mid-refactor.inc");
function QueryTimeout($connLevel) function queryTimeout($connLevel)
{ {
$conn = connect('', array(), PDO::ERRMODE_SILENT); $conn = connect('', array(), PDO::ERRMODE_SILENT);
@ -37,8 +37,8 @@ function QueryTimeout($connLevel)
echo "Starting test...\n"; echo "Starting test...\n";
try { try {
QueryTimeout(true); queryTimeout(true);
QueryTimeout(false); queryTimeout(false);
} catch (Exception $e) { } catch (Exception $e) {
echo $e->getMessage(); echo $e->getMessage();
} }

View file

@ -35,18 +35,21 @@ function rowCountQuery($exec)
function updateData($conn, $tableName, $value, $exec) function updateData($conn, $tableName, $value, $exec)
{ {
$newValue = $value * 100; $newValue = $value * 100;
$query = "UPDATE $tableName SET c1_int = $newValue WHERE (c1_int = $value)";
$rowCount = 0; $rowCount = 0;
if (isColEncrypted()) { if (isColEncrypted()) {
// need to bind parameters for updating encrypted columns // need to bind parameters for updating encrypted columns
$query = "UPDATE $tableName SET c1_int = ? WHERE (c1_int = ?)"; $query = "UPDATE $tableName SET c1_int = ? WHERE (c1_int = ?)";
$stmt = $conn->prepare($query); $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(1, $newValue);
$stmt->bindParam(2, $value); $stmt->bindParam(2, $value);
$stmt->execute(); $stmt->execute();
$rowCount = $stmt->rowCount(); $rowCount = $stmt->rowCount();
} else { } else {
$query = "UPDATE $tableName SET c1_int = $newValue WHERE (c1_int = $value)";
if ($exec) { if ($exec) {
$rowCount = $conn->exec($query); $rowCount = $conn->exec($query);
} else { } else {
@ -147,7 +150,7 @@ function deleteData($conn, $tableName, $exec)
echo "Starting test...\n"; echo "Starting test...\n";
try { try {
rowCountQuery(true); rowCountQuery(true);
//rowCountQuery(false); rowCountQuery(false);
} catch (Exception $e) { } catch (Exception $e) {
echo $e->getMessage(); echo $e->getMessage();
} }

View file

@ -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("MsCommon_mid-refactor.inc");
require_once("MsData_PDO_AllTypes.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 = $db->prepare("SELECT IntCol, CharCol, DateTimeCol FROM $tbname");
$stmt->execute(); $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 = $db->prepare("SELECT IntCol, CharCol, DateTimeCol FROM $tbname");
$stmt->execute(); $stmt->execute();
@ -38,9 +38,9 @@ try {
$tbname = "PDO_MainTypes"; $tbname = "PDO_MainTypes";
createAndInsertTableMainTypes($db, $tbname); createAndInsertTableMainTypes($db, $tbname);
echo "Bind Column by name :\n"; echo "Bind Column by name :\n";
bindColumn_byName($db, $tbname); bindColumnByName($db, $tbname);
echo "Bind Column by number :\n"; echo "Bind Column by number :\n";
bindColumn_byNumber($db, $tbname); bindColumnByNumber($db, $tbname);
dropTable($db, $tbname); dropTable($db, $tbname);
unset($db); unset($db);

View file

@ -14,7 +14,7 @@ try {
createAndInsertTableAllTypes($db, $tbname); createAndInsertTableAllTypes($db, $tbname);
$bigint = 1; $bigint = 1;
$string = "STRINGCOL1"; $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(':bigint', $bigint, PDO::PARAM_INT);
$stmt->bindValue(':string', $string, PDO::PARAM_STR); $stmt->bindValue(':string', $string, PDO::PARAM_STR);
$stmt->execute(); $stmt->execute();

View file

@ -14,7 +14,7 @@ try {
$stmt = $db->query("Select * from $tbname"); $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(); $result = $stmt->fetchColumn();
var_dump($result); var_dump($result);

View file

@ -7,100 +7,75 @@ Test the PDOStatement::fetch() method with different fetch styles.
require_once("MsCommon_mid-refactor.inc"); require_once("MsCommon_mid-refactor.inc");
require_once("MsData_PDO_AllTypes.inc"); require_once("MsData_PDO_AllTypes.inc");
function fetchBoth($conn, $tbname) function fetchWithStyle($conn, $tbname, $style)
{ {
$stmt = $conn->query("Select * from $tbname"); $stmt = $conn->query("SELECT * FROM $tbname");
$result = $stmt->fetch(PDO::FETCH_BOTH); switch ($style) {
var_dump($result); case PDO::FETCH_BOTH:
$stmt->closeCursor(); case PDO::FETCH_ASSOC:
} case PDO::FETCH_LAZY:
case PDO::FETCH_OBJ:
function fetchAssoc($conn, $tbname) case PDO::FETCH_NUM:
{ {
$stmt = $conn->query("Select * from $tbname"); $result = $stmt->fetch($style);
$result = $stmt->fetch(PDO::FETCH_ASSOC); var_dump($result);
var_dump($result); unset($stmt);
$stmt->closeCursor(); break;
} }
case PDO::FETCH_BOUND:
function fetchLazy($conn, $tbname) {
{ $stmt->bindColumn('IntCol', $IntCol);
$stmt = $conn->query("Select * from $tbname"); $stmt->bindColumn('CharCol', $CharCol);
$result = $stmt->fetch(PDO::FETCH_LAZY); $stmt->bindColumn('NCharCol', $NCharCol);
var_dump($result); $stmt->bindColumn('DateTimeCol', $DateTimeCol);
$stmt->closeCursor(); $stmt->bindColumn('VarcharCol', $VarcharCol);
} $stmt->bindColumn('NVarCharCol', $NVarCharCol);
$stmt->bindColumn('FloatCol', $FloatCol);
function fetchObj($conn, $tbname) $stmt->bindColumn('XmlCol', $XmlCol);
{ $result = $stmt->fetch($style);
$stmt = $conn->query("Select * from $tbname"); if (!$result) {
$result = $stmt->fetch(PDO::FETCH_OBJ); die("Error in FETCH_BOUND\n");
var_dump($result); }
$stmt->closeCursor(); var_dump($IntCol);
} var_dump($CharCol);
var_dump($NCharCol);
function fetchNum($conn, $tbname) var_dump($DateTimeCol);
{ var_dump($VarcharCol);
$stmt = $conn->query("Select * from $tbname"); var_dump($NVarCharCol);
$result = $stmt->fetch(PDO::FETCH_NUM); var_dump($FloatCol);
var_dump($result); var_dump($XmlCol);
$stmt->closeCursor(); unset($stmt);
} break;
}
function fetchBound($conn, $tbname) case PDO::FETCH_CLASS:
{ {
$stmt = $conn->query("Select * from $tbname"); global $mainTypesClass;
$stmt->bindColumn('IntCol', $IntCol); $stmt->setFetchMode($style, $mainTypesClass);
$stmt->bindColumn('CharCol', $CharCol); $result = $stmt->fetch($style);
$stmt->bindColumn('NCharCol', $NCharCol); $result->dumpAll();
$stmt->bindColumn('DateTimeCol', $DateTimeCol); unset($stmt);
$stmt->bindColumn('VarcharCol', $VarcharCol); break;
$stmt->bindColumn('NVarCharCol', $NVarCharCol); }
$stmt->bindColumn('FloatCol', $FloatCol); case PDO::FETCH_INTO:
$stmt->bindColumn('XmlCol', $XmlCol); {
$result = $stmt->fetch(PDO::FETCH_BOUND); global $mainTypesClass;
if (!$result) { $obj = new $mainTypesClass;
die("Error in FETCH_BOUND\n"); $stmt->setFetchMode($style, $obj);
} $result = $stmt->fetch($style);
var_dump($IntCol); $obj->dumpAll();
var_dump($CharCol); unset($stmt);
var_dump($NCharCol); break;
var_dump($DateTimeCol); }
var_dump($VarcharCol); case "PDO::FETCH_INVALID":
var_dump($NVarCharCol); {
var_dump($FloatCol); try {
var_dump($XmlCol); $result = $stmt->fetch(PDO::FETCH_UNKNOWN);
$stmt->closeCursor(); } catch (PDOException $err) {
} print_r($err);
}
function fetchClass($conn, $tbname) break;
{ }
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);
} }
} }
@ -109,23 +84,23 @@ try {
$tbname = "PDO_MainTypes"; $tbname = "PDO_MainTypes";
createAndInsertTableMainTypes($db, $tbname); createAndInsertTableMainTypes($db, $tbname);
echo "Test_1 : FETCH_BOTH :\n"; echo "Test_1 : FETCH_BOTH :\n";
fetchBoth($db, $tbname); fetchWithStyle($db, $tbname, PDO::FETCH_BOTH);
echo "Test_2 : FETCH_ASSOC :\n"; echo "Test_2 : FETCH_ASSOC :\n";
fetchAssoc($db, $tbname); fetchWithStyle($db, $tbname, PDO::FETCH_ASSOC);
echo "Test_3 : FETCH_LAZY :\n"; echo "Test_3 : FETCH_LAZY :\n";
fetchLazy($db, $tbname); fetchWithStyle($db, $tbname, PDO::FETCH_LAZY);
echo "Test_4 : FETCH_OBJ :\n"; echo "Test_4 : FETCH_OBJ :\n";
fetchObj($db, $tbname); fetchWithStyle($db, $tbname, PDO::FETCH_OBJ);
echo "Test_5 : FETCH_NUM :\n"; echo "Test_5 : FETCH_NUM :\n";
fetchNum($db, $tbname); fetchWithStyle($db, $tbname, PDO::FETCH_NUM);
echo "Test_6 : FETCH_BOUND :\n"; echo "Test_6 : FETCH_BOUND :\n";
fetchBound($db, $tbname); fetchWithStyle($db, $tbname, PDO::FETCH_BOUND);
echo "Test_7 : FETCH_CLASS :\n"; echo "Test_7 : FETCH_CLASS :\n";
fetchClass($db, $tbname); fetchWithStyle($db, $tbname, PDO::FETCH_CLASS);
echo "Test_8 : FETCH_INTO :\n"; echo "Test_8 : FETCH_INTO :\n";
fetchInto($db, $tbname); fetchWithStyle($db, $tbname, PDO::FETCH_INTO);
echo "Test_9 : FETCH_INVALID :\n"; echo "Test_9 : FETCH_INVALID :\n";
fetchInvalid($db, $tbname); fetchWithStyle($db, $tbname, "PDO::FETCH_INVALID");
dropTable($db, $tbname); dropTable($db, $tbname);
unset($db); unset($db);
@ -195,7 +170,7 @@ array(8) {
Test_3 : FETCH_LAZY : Test_3 : FETCH_LAZY :
object(PDORow)#%x (%x) { object(PDORow)#%x (%x) {
["queryString"]=> ["queryString"]=>
string(27) "Select * from PDO_MainTypes" string(27) "SELECT * FROM PDO_MainTypes"
["IntCol"]=> ["IntCol"]=>
string(1) "1" string(1) "1"
["CharCol"]=> ["CharCol"]=>
@ -282,6 +257,6 @@ Test_9 : FETCH_INVALID :
Fatal error: Uncaught Error: Undefined class constant 'FETCH_UNKNOWN' in %s:%x Fatal error: Uncaught Error: Undefined class constant 'FETCH_UNKNOWN' in %s:%x
Stack trace: Stack trace:
#0 %s: fetchInvalid(Object(PDO), 'PDO_MainTypes') #0 %s: fetchWithStyle(Object(PDO), 'PDO_MainTypes', 'PDO::FETCH_INVA...')
#1 {main} #1 {main}
thrown in %s on line %x thrown in %s on line %x

View file

@ -1,5 +1,7 @@
--TEST-- --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-- --SKIPIF--
<?php require('skipif_mid-refactor.inc'); ?> <?php require('skipif_mid-refactor.inc'); ?>
--FILE-- --FILE--

View file

@ -1,5 +1,7 @@
--TEST-- --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-- --SKIPIF--
<?php require('skipif_mid-refactor.inc'); ?> <?php require('skipif_mid-refactor.inc'); ?>
--FILE-- --FILE--

View file

@ -11,31 +11,15 @@ try {
$db = connect(); $db = connect();
$tbname = "PDO_MainTypes"; $tbname = "PDO_MainTypes";
createAndInsertTableMainTypes($db, $tbname); createAndInsertTableMainTypes($db, $tbname);
$stmt = $db->query("SELECT * FROM $tbname");
echo "Set Fetch Mode for PDO::FETCH_ASSOC\n"; $fetchModes = array("PDO::FETCH_ASSOC", "PDO::FETCH_NUM", "PDO::FETCH_BOTH", "PDO::FETCH_LAZY", "PDO::FETCH_OBJ");
$stmt->setFetchMode(PDO::FETCH_ASSOC); foreach ($fetchModes as $mode) {
$result = $stmt->fetch(); $stmt = $db->query("SELECT * FROM $tbname");
var_dump($result); echo "Set Fetch Mode for $mode\n";
$stmt = $db->query("SELECT * FROM $tbname"); $stmt->setFetchMode(constant($mode));
echo "Set Fetch Mode for PDO::FETCH_NUM\n"; $result = $stmt->fetch();
$stmt->setFetchMode(PDO::FETCH_NUM); var_dump($result);
$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);
} catch (PDOException $e) { } catch (PDOException $e) {
var_dump($e); var_dump($e);
} }