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 {
$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

View file

@ -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"));

View file

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

View file

@ -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();
}

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("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);

View file

@ -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();

View file

@ -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);

View file

@ -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

View file

@ -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--
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--

View file

@ -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--
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--

View file

@ -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);
}