From 50d3c19c4709ab54417158fcdd2850da1303ccfe Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Wed, 1 Nov 2017 17:09:58 -0700 Subject: [PATCH 01/16] refactor PDO tests with client buffer or table with all datatypes --- .../pdo_sqlsrv/MsCommon_mid-refactor.inc | 9 +- .../pdo_sqlsrv/MsData_PDO_AllTypes.inc | 227 ++++++++ test/functional/pdo_sqlsrv/PDO11_Drivers.phpt | 55 +- test/functional/pdo_sqlsrv/PDO12_Info.phpt | 49 +- .../pdo_sqlsrv/PDO21_Connection.phpt | 65 +-- .../pdo_sqlsrv/PDO24_ErrorCode.phpt | 73 +-- .../pdo_sqlsrv/PDO25_ErrorInfo.phpt | 115 ++-- test/functional/pdo_sqlsrv/break_pdo.php | 57 +- test/functional/pdo_sqlsrv/pdo_TNIR.phpt | 21 +- .../pdo_sqlsrv/pdo_bigint_outparam.phpt | 1 + .../pdo_sqlsrv/pdo_bool_outparam.phpt | 1 + .../pdo_sqlsrv/pdo_connection_resiliency.phpt | 204 ++++---- test/functional/pdo_sqlsrv/pdo_error.phpt | 29 +- .../pdo_sqlsrv/pdo_insertDataType.phpt | 85 +-- test/functional/pdo_sqlsrv/pdo_prepare.phpt | 64 +-- .../pdo_prepare_emulatePrepare_float.phpt | 129 ++--- .../pdo_prepare_emulatePrepare_int.phpt | 140 +++-- .../pdo_prepare_emulatePrepare_money.phpt | 128 ++--- .../pdo_prepare_emulatePrepare_unicode.phpt | 161 +++--- .../pdo_prepare_invalid_cursor.phpt | 33 +- .../pdo_prepare_invalid_encoding.phpt | 28 +- .../pdo_prepare_invalid_option_key.phpt | 25 +- ...pdo_prepare_invalid_scrollable_cursor.phpt | 30 +- .../pdo_sqlsrv/pdo_prepare_options.phpt | 30 +- test/functional/pdo_sqlsrv/pdo_query.phpt | 113 ++-- .../pdo_sqlsrv/pdo_query_timeout.phpt | 107 ++-- test/functional/pdo_sqlsrv/pdo_quote.phpt | 18 +- .../pdo_sqlsrv/pdo_set_attr_invalid.phpt | 30 +- .../pdo_set_attr_invalid_encoding.phpt | 30 +- .../pdo_statement_rowcount_query.phpt | 212 ++++---- .../pdo_stored_proc_fetch_datatypes.phpt | 367 +++++++------ .../pdo_sqlsrv/pdo_testDataType.phpt | 494 ------------------ .../pdo_sqlsrv/pdo_transaction.phpt | 76 ++- .../pdo_sqlsrv/pdo_transactions.phpt | 94 ++-- test/functional/pdo_sqlsrv/pdo_utf8_conn.phpt | 27 +- .../pdo_sqlsrv/pdostatement_Buffqry.phpt | 322 ++++++------ .../pdo_sqlsrv/pdostatement_GetDataType.phpt | 419 ++++++++------- .../pdo_sqlsrv/pdostatement_bindColumn.phpt | 45 +- .../pdo_sqlsrv/pdostatement_bindParam.phpt | 217 ++++---- .../pdo_sqlsrv/pdostatement_bindValue.phpt | 23 +- .../pdo_sqlsrv/pdostatement_closeCursor.phpt | 29 +- .../pdo_sqlsrv/pdostatement_columnCount.phpt | 31 +- .../pdostatement_debugDumpParams.phpt | 24 +- .../pdo_sqlsrv/pdostatement_error.phpt | 27 +- .../pdo_sqlsrv/pdostatement_execute.phpt | 62 ++- .../pdo_sqlsrv/pdostatement_fetchAll.phpt | Bin 17857 -> 17989 bytes .../pdo_sqlsrv/pdostatement_fetchColumn.phpt | 64 +-- .../pdo_sqlsrv/pdostatement_fetchObject.phpt | Bin 3678 -> 3978 bytes .../pdo_sqlsrv/pdostatement_fetch_style.phpt | 116 ++-- .../pdostatement_getColumnMeta.phpt | 89 ++-- ...tement_getColumnMeta_unicode_col_name.phpt | 165 +++--- .../pdo_sqlsrv/pdostatement_nextRowset.phpt | Bin 10443 -> 10845 bytes .../pdo_sqlsrv/pdostatement_setFetchMode.phpt | 48 +- 53 files changed, 2218 insertions(+), 2790 deletions(-) create mode 100644 test/functional/pdo_sqlsrv/MsData_PDO_AllTypes.inc delete mode 100644 test/functional/pdo_sqlsrv/pdo_testDataType.phpt diff --git a/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc b/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc index 6158e870..37fdb775 100644 --- a/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc +++ b/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc @@ -183,9 +183,10 @@ function getDefaultColName($dataType) * @param array $inputs : an associative array column name and its value; value may be a literal value or a ColumnMeta object * @param bool $disableCE : flag for disabling column encryption even when keystore is NOT none * for creating table with datatypes not support for encryption + * @param string $tableOption : table options appended to the end of a create table statement * @return int reporting the number of rows affected (should always be 0 for creating table) */ -function createTable($conn, $tbname, $columnMetaArr, $disableCE = false) +function createTable($conn, $tbname, $columnMetaArr, $tableOption = '', $disableCE = false) { try { dropTable($conn, $tbname); @@ -202,7 +203,7 @@ function createTable($conn, $tbname, $columnMetaArr, $disableCE = false) } } $colDef = rtrim($colDef, ", "); - $createSql = "CREATE TABLE $tbname ($colDef)"; + $createSql = "CREATE TABLE $tbname ($colDef) $tableOption"; $numRows = $conn->exec($createSql); return $numRows; } catch (PDOException $e) { @@ -234,7 +235,7 @@ class BindParamOp if (in_array($pdoType, $pdoParams)) { $this->pdoType = $pdoType; } else { - prinft("BindParamOp construct: The pdoType provided must be one of PDO::PARAM_BOOL, PDO::PARAM_NULL, PDO::PARAM_INT, PDO::PARAM_STR, or PDO::PARAM_LOB.\n"); + printf("BindParamOp construct: The pdoType provided must be one of PDO::PARAM_BOOL, PDO::PARAM_NULL, PDO::PARAM_INT, PDO::PARAM_STR, or PDO::PARAM_LOB.\n"); exit; } @@ -1366,7 +1367,7 @@ function CreateTableEx($conn, $tableName, $dataType) { Trace("Creating table $tableName ..."); $tsql = "CREATE TABLE [$tableName] ($dataType)"; - DropTable($conn, $tableName); + dropTable($conn, $tableName); if (IsPdoMode()) { $outcome = $conn->exec($tsql); diff --git a/test/functional/pdo_sqlsrv/MsData_PDO_AllTypes.inc b/test/functional/pdo_sqlsrv/MsData_PDO_AllTypes.inc new file mode 100644 index 00000000..0c20ff18 --- /dev/null +++ b/test/functional/pdo_sqlsrv/MsData_PDO_AllTypes.inc @@ -0,0 +1,227 @@ + 1 " . $large_string . "", " 2 " . $large_string . ""); + +$null_col = 'null'; + +$mainTypesClass = 'PDO_MainTypesClass'; +class PDO_MainTypesClass +{ + public $IntCol; + public $CharCol; + public $NCharCol; + public $DateTimeCol; + public $VarcharCol; + public $NVarCharCol; + public $FloatCol; + public $XmlCol; + + public function dumpAll() + { + var_dump($this->IntCol); + var_dump($this->CharCol); + var_dump($this->NCharCol); + var_dump($this->DateTimeCol); + var_dump($this->VarcharCol); + var_dump($this->NVarCharCol); + var_dump($this->FloatCol); + var_dump($this->XmlCol); + } +} + +function createTableMainTypes($conn, $tbname) +{ + try { + require_once("MsCommon_mid-refactor.inc"); + if (isColEncrypted()) { + $xmlType = "nvarchar(max)"; + } else { + $xmlType = "xml"; + } + $columnMetaArr = array("IntCol" => "int", + "CharCol" => "char(10)", + "NCharCol" => "nchar(10)", + "DateTimeCol" => "datetime", + "VarcharCol" => "varchar(50)", + "NVarCharCol" => "nvarchar(50)", + "FloatCol" => "float", + "XmlCol" => $xmlType); + createTable($conn, $tbname, $columnMetaArr, "ON [PRIMARY]"); + } catch (Exception $e) { + var_dump($e); + exit; + } +} + +function insertIntoTableMainTypes($conn, $tbname, $rownum) +{ + try { + require_once("MsCommon_mid-refactor.inc"); + global $string_col, $date_col, $large_string_col, $xml_col, $binary_col, $int_col, $decimal_col, $guid_col, $datetime_col, $datetime2_col, $dtoffset_col, $smalldt_col, $timeCol; + + $inputs = array("IntCol" => $int_col[$rownum], + "CharCol" => $string_col[$rownum], + "NCharCol" => $string_col[$rownum], + "DateTimeCol" => $datetime_col[$rownum], + "VarcharCol" => $string_col[$rownum], + "NVarCharCol" => $string_col[$rownum], + "FloatCol" => $decimal_col[$rownum], + "XmlCol" => $xml_col[$rownum]); + $stmt = insertRow($conn, $tbname, $inputs, "prepareBindParam"); + } catch (Exception $e) { + var_dump($e); + exit; + } +} + +function createAndInsertTableMainTypes($conn, $tbname, $rows = array(0, 1)) +{ + createTableMainTypes($conn, $tbname); + foreach ($rows as $rownum) { + insertIntoTableMainTypes($conn, $tbname, $rownum); + } +} + +function createTableAllTypes($conn, $tbname) +{ + try { + require_once("MsCommon_mid-refactor.inc"); + + if (isColEncrypted()) { + $moneyType = "decimal(19,4)"; + $smallmoneyType = "decimal(10,4)"; + $imageType = "varbinary(max)"; + $ntextType = "nvarchar(max)"; + $textType = "varchar(max)"; + $xmlType = "nvarchar(max)"; + } else { + $moneyType = "money"; + $smallmoneyType = "smallmoney"; + $imageType = "image"; + $ntextType = "ntext"; + $textType = "text"; + $xmlType = "xml"; + } + + $columnMetaArr = array("BigIntCol" => "bigint", + "BinaryCol" => "binary(5)", + "BitCol" => "bit", + "CharCol" => "char(10)", + "DateCol" => "date", + "DateTimeCol" => "datetime", + "DateTime2Col" => "datetime2(7)", + "DTOffsetCol" => "datetimeoffset(7)", + "DecimalCol" => "decimal(18,0)", + "FloatCol" => "float", + "ImageCol" => $imageType, + "IntCol" => "int", + "MoneyCol" => $moneyType, + "NCharCol" => "nchar(10)", + "NTextCol" => $ntextType, + "NumCol" => "numeric(18,0)", + "NVarCharCol" => "nvarchar(50)", + "NVarCharMaxCol" => "nvarchar(max)", + "RealCol" => "real", + "SmallDTCol" => "smalldatetime", + "SmallIntCol" => "smallint", + "SmallMoneyCol" => $smallmoneyType, + "TextCol" => $textType, + "TimeCol" => "time(7)", + "TinyIntCol" => "tinyint", + "Guidcol" => "uniqueidentifier", + "VarbinaryCol" => "varbinary(50)", + "VarbinaryMaxCol" => "varbinary(max)", + "VarcharCol" => "varchar(50)", + "VarcharMaxCol" => "varchar(max)", + "XmlCol" => $xmlType); + createTable($conn, $tbname, $columnMetaArr, "ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]"); + } catch (Exception $e) { + var_dump($e); + exit; + } +} + +function insertIntoTableAllTypes($conn, $tbname, $rownum) +{ + try { + require_once("MsCommon_mid-refactor.inc"); + global $string_col, $date_col, $large_string_col, $xml_col, $binary_col, $int_col, $decimal_col, $guid_col, $datetime_col, $datetime2_col, $dtoffset_col, $smalldt_col, $timeCol; + + $inputs = array("BigIntCol" => $int_col[$rownum], + "BinaryCol" => new BindParamOp(2, $binary_col[$rownum], "PDO::PARAM_LOB", 0, "PDO::SQLSRV_ENCODING_BINARY"), + "BitCol" => 0, + "CharCol" => $string_col[$rownum], + "DateCol" => $date_col[$rownum], + "DateTimeCol" => $datetime_col[$rownum], + "DateTime2Col" => $datetime2_col[$rownum], + "DTOffsetCol" => $dtoffset_col[$rownum], + "DecimalCol" => $decimal_col[$rownum], + "FloatCol" => $decimal_col[$rownum], + "ImageCol" => new BindParamOp(11, $binary_col[$rownum], "PDO::PARAM_LOB", 0, "PDO::SQLSRV_ENCODING_BINARY"), + "IntCol" => $int_col[$rownum], + "MoneyCol" => $decimal_col[$rownum], + "NCharCol" => $string_col[$rownum], + "NTextCol" => $large_string_col[$rownum], + "NumCol" => $int_col[$rownum], + "NVarCharCol" => $string_col[$rownum], + "NVarCharMaxCol" => $large_string_col[$rownum], + "RealCol" => $decimal_col[$rownum], + "SmallDTCol" => $smalldt_col[$rownum], + "SmallIntCol" => $int_col[$rownum], + "SmallMoneyCol" => $decimal_col[$rownum], + "TextCol" => $large_string_col[$rownum], + "TimeCol" => $timeCol[$rownum], + "TinyIntCol" => $int_col[$rownum], + "Guidcol" => $guid_col[$rownum], + "VarbinaryCol" => new BindParamOp(27, $binary_col[$rownum], "PDO::PARAM_LOB", 0, "PDO::SQLSRV_ENCODING_BINARY"), + "VarbinaryMaxCol" => new BindParamOp(28, $binary_col[$rownum], "PDO::PARAM_LOB", 0, "PDO::SQLSRV_ENCODING_BINARY"), + "VarcharCol" => $string_col[$rownum], + "VarcharMaxCol" => $large_string_col[$rownum], + "XmlCol" => $xml_col[$rownum]); + $stmt = insertRow($conn, $tbname, $inputs, "prepareBindParam"); + } catch (Exception $e) { + var_dump($e); + exit; + } +} + +function createAndInsertTableAllTypes($conn, $tbname, $rows = array(0)) +{ + createTableAllTypes($conn, $tbname); + foreach ($rows as $rownum) { + insertIntoTableAllTypes($conn, $tbname, $rownum); + } +} diff --git a/test/functional/pdo_sqlsrv/PDO11_Drivers.phpt b/test/functional/pdo_sqlsrv/PDO11_Drivers.phpt index c6b557c0..5353a5f3 100644 --- a/test/functional/pdo_sqlsrv/PDO11_Drivers.phpt +++ b/test/functional/pdo_sqlsrv/PDO11_Drivers.phpt @@ -1,60 +1,23 @@ --TEST-- PDO Drivers Info Test --DESCRIPTION-- -Verifies the functionality of "PDO:getAvailableDrivers()”. +Verifies the functionality of "PDO:getAvailableDrivers()�. --ENV-- PHPT_EXEC=true --SKIPIF-- - + --FILE-- getMessage(); } - - - -//-------------------------------------------------------------------- -// Repro -// -//-------------------------------------------------------------------- -function Repro() -{ - - try - { - DriversInfo(); - } - catch (Exception $e) - { - echo $e->getMessage(); - } -} - -Repro(); - ?> --EXPECT-- -Test "PDO - Drivers" completed successfully. \ No newline at end of file +Done diff --git a/test/functional/pdo_sqlsrv/PDO12_Info.phpt b/test/functional/pdo_sqlsrv/PDO12_Info.phpt index b8f17e65..dd9acb16 100644 --- a/test/functional/pdo_sqlsrv/PDO12_Info.phpt +++ b/test/functional/pdo_sqlsrv/PDO12_Info.phpt @@ -5,57 +5,26 @@ Verifies the functionality of PDO with phpinfo(). --ENV-- PHPT_EXEC=true --SKIPIF-- - + --FILE-- enabled") === false) - { + if (stristr($info, "PDO support => enabled") === false) { printf("PDO is not enabled\n"); - } - else if (stristr($info, "pdo_sqlsrv support => enabled") === false) - { + } elseif (stristr($info, "pdo_sqlsrv support => enabled") === false) { printf("Cannot find PDO driver line in phpinfo() output\n"); + } else { + printf("Done\n"); } - - EndTest($testName); +} catch (Exception $e) { + echo $e->getMessage(); } - - - -//-------------------------------------------------------------------- -// Repro -// -//-------------------------------------------------------------------- -function Repro() -{ - - try - { - DriversInfo(); - } - catch (Exception $e) - { - echo $e->getMessage(); - } -} - -Repro(); - ?> --EXPECT-- -Test "PDO - phpinfo" completed successfully. \ No newline at end of file +Done diff --git a/test/functional/pdo_sqlsrv/PDO21_Connection.phpt b/test/functional/pdo_sqlsrv/PDO21_Connection.phpt index 35bbcdc6..f0989962 100644 --- a/test/functional/pdo_sqlsrv/PDO21_Connection.phpt +++ b/test/functional/pdo_sqlsrv/PDO21_Connection.phpt @@ -6,57 +6,32 @@ Verifies as well that invalid connection attempts fail as expected. --ENV-- PHPT_EXEC=true --SKIPIF-- - + --FILE-- errors are expected - Trace("Invalid connection attempt (to a non-existing server) ....\n"); - $conn1 = PDOConnect('PDO', "InvalidServerName", $uid, $pwd, false); - if ($conn1) - { + $serverName="InvalidServerName"; + + $dsn = getDSN($serverName, $databaseName); + $conn1 = new PDO($dsn, $uid, $pwd, $connectionOptions); + if ($conn1) { printf("Invalid connection attempt should have failed.\n"); } - $conn1 = null; - - + unset($conn1); +} catch (Exception $e) { + unset($conn1); + echo "Done\n"; +} +try { // Valid connection attempt => no errors are expected - Trace("\nValid connection attempt (to $server) ....\n"); - $conn2 = Connect(); - $conn2 = null; - - EndTest($testName); - + $conn2 = connect(); + unset($conn2); +} catch (Exception $e) { + echo $e->getMessage(); } - -//-------------------------------------------------------------------- -// Repro -// -//-------------------------------------------------------------------- -function Repro() -{ - - try - { - ConnectionTest(); - } - catch (Exception $e) - { - echo $e->getMessage(); - } -} - -Repro(); - ?> --EXPECT-- -Test "PDO Connection" completed successfully. - +Done diff --git a/test/functional/pdo_sqlsrv/PDO24_ErrorCode.phpt b/test/functional/pdo_sqlsrv/PDO24_ErrorCode.phpt index f6649ba1..3d80869d 100644 --- a/test/functional/pdo_sqlsrv/PDO24_ErrorCode.phpt +++ b/test/functional/pdo_sqlsrv/PDO24_ErrorCode.phpt @@ -5,76 +5,45 @@ Verification of PDO::errorCode() --ENV-- PHPT_EXEC=true --SKIPIF-- - + --FILE-- "varchar(10)")); // Check errors when executing SELECT queries $stmt1 = $conn1->prepare("SELECT id, label FROM [$table1]"); - CheckError(2, $conn1); - CheckError(3, $stmt1); + checkError(2, $conn1); + checkError(3, $stmt1); $stmt1->execute(); $stmt2 = &$stmt1; - CheckError(4, $stmt1); + checkError(4, $stmt1); $stmt1->closeCursor(); - DropTable($conn1, $table1); - CheckError(5, $conn1); + dropTable($conn1, $table1); + checkError(5, $conn1); // Cleanup - $stmt1 = null; - $conn1 = null; - - EndTest($testName); - + unset($stmt); + unset($conn); + echo "Done\n"; +} catch (Exception $e) { + echo $e->getMessage(); } -function CheckError($offset, &$obj, $expected = '00000') +function checkError($offset, &$obj, $expected = '00000') { $code = $obj->errorCode(); - if (($code != $expected) && (($expected != '00000') || ($code !=''))) - { - printf("[%03d] Expecting error code '%s' got code '%s'\n", - $offset, $expected, $code); + if (($code != $expected) && (($expected != '00000') || ($code !=''))) { + printf("[%03d] Expecting error code '%s' got code '%s'\n", $offset, $expected, $code); } } - -//-------------------------------------------------------------------- -// Repro -// -//-------------------------------------------------------------------- -function Repro() -{ - - try - { - CheckErrorCode(); - } - catch (Exception $e) - { - echo $e->getMessage(); - } -} - -Repro(); - ?> --EXPECT-- -Test "PDO Connection - Error Code" completed successfully. \ No newline at end of file +Done diff --git a/test/functional/pdo_sqlsrv/PDO25_ErrorInfo.phpt b/test/functional/pdo_sqlsrv/PDO25_ErrorInfo.phpt index 8c68bdf1..ef5da345 100644 --- a/test/functional/pdo_sqlsrv/PDO25_ErrorInfo.phpt +++ b/test/functional/pdo_sqlsrv/PDO25_ErrorInfo.phpt @@ -5,112 +5,81 @@ Verification of PDO::errorInfo() --ENV-- PHPT_EXEC=true --SKIPIF-- - + --FILE-- "varchar(10)")); // Check errors when executing SELECT queries $stmt1 = $conn1->prepare("SELECT id, label FROM [$table1]"); - CheckError(2, $conn1); - CheckError(3, $stmt1); + checkError(2, $conn1); + checkError(3, $stmt1); $stmt1->execute(); $stmt2 = &$stmt1; - CheckError(4, $stmt1); + checkError(4, $stmt1); $stmt1->closeCursor(); - - //DropTable($conn1, $table1); - @$stmt1->execute(); - CheckError(5, $conn1); - //CheckError(6, $stmt1, '42S02'); - //CheckError(7, $stmt2, '42S02'); + dropTable($conn1, $table1); + $stmt1->execute(); + checkError(5, $conn1); + checkError(6, $stmt1, '42S02'); + checkError(7, $stmt2, '42S02'); $stmt1->closeCursor(); - - DropTable($conn1, $table2); + + dropTable($conn1, $table2); $conn2 = &$conn1; - //@$conn1->query("SELECT id, label FROM [$table2]"); - //CheckError(8, $conn1, '42S02'); - //CheckError(9, $conn2, '42S02'); - + @$conn1->query("SELECT id, label FROM [$table2]"); + checkError(8, $conn1, '42S02'); + checkError(9, $conn2, '42S02'); + + createTable($conn1, $table1, array(new ColumnMeta("int", "id", "NOT NULL PRIMARY KEY"), "label" => "varchar(10)")); - CreateTableEx($conn1, $table1, "id int NOT NULL PRIMARY KEY, label VARCHAR(10)", null); $stmt1 = $conn1->query("SELECT id, label FROM [$table1]"); - CheckError(10, $conn1); - CheckError(11, $stmt1); + checkError(10, $conn1); + checkError(11, $stmt1); $stmt1->closeCursor(); -// @$conn1->query("SELECT id, label FROM [$table2]"); -// CheckError(12, $conn1, '42S02'); -// CheckError(13, $conn2, '42S02'); - CheckError(14, $stmt1); + @$conn1->query("SELECT id, label FROM [$table2]"); + checkError(12, $conn1, '42S02'); + checkError(13, $conn2, '42S02'); + checkError(14, $stmt1); // Cleanup - DropTable($conn1, $table1); - $stmt1 = null; - $conn1 = null; - - EndTest($testName); + dropTable($conn1, $table1); + unset($stmt1); + unset($conn1); + echo "Done\n"; +} catch (Exception $e) { + echo $e->getMessage(); } -function CheckError($offset, &$obj, $expected = '00000') +function checkError($offset, &$obj, $expected = '00000') { $info = $obj->errorInfo(); $code = $info[0]; - if (($code != $expected) && (($expected != '00000') || ($code != ''))) - { - printf("[%03d] Expecting error code '%s' got code '%s'\n", - $offset, $expected, $code); + if (($code != $expected) && (($expected != '00000') || ($code != ''))) { + printf("[%03d] Expecting error code '%s' got code '%s'\n", $offset, $expected, $code); } - if ($expected != '00000') - { - if (!isset($info[1]) || ($info[1] == '')) - { + if ($expected != '00000') { + if (!isset($info[1]) || ($info[1] == '')) { printf("[%03d] Driver-specific error code not set\n", $offset); } - if (!isset($info[2]) || ($info[2] == '')) - { + if (!isset($info[2]) || ($info[2] == '')) { printf("[%03d] Driver-specific error message.not set\n", $offset); } } } - -//-------------------------------------------------------------------- -// Repro -// -//-------------------------------------------------------------------- -function Repro() -{ - - try - { - CheckErrorInfo(); - } - catch (Exception $e) - { - echo $e->getMessage(); - } -} - -Repro(); - ?> --EXPECT-- -Test "PDO Connection - Error Info" completed successfully. \ No newline at end of file +Done diff --git a/test/functional/pdo_sqlsrv/break_pdo.php b/test/functional/pdo_sqlsrv/break_pdo.php index 0be99e6f..d1aa4e9e 100644 --- a/test/functional/pdo_sqlsrv/break_pdo.php +++ b/test/functional/pdo_sqlsrv/break_pdo.php @@ -3,7 +3,7 @@ require_once("MsSetup.inc"); // Using the test database for two tables specifically constructed // for the connection resiliency tests -$dbName = $databaseName; +$dbName = $databaseName; $tableName1 = "test_connres1"; $tableName2 = "test_connres2"; @@ -12,40 +12,37 @@ $tableName2 = "test_connres2"; // Using generated tables will eventually allow us to put the // connection resiliency tests on Github, since the integrated testing // from AppVeyor does not have AdventureWorks. -function GenerateTables( $server, $uid, $pwd, $dbName, $tableName1, $tableName2 ) +function generateTables($server, $uid, $pwd, $dbName, $tableName1, $tableName2) { - $conn = new PDO( "sqlsrv:server = $server ; Database = $dbName ;", $uid, $pwd ); - if ( $conn === false ) - { - die ( print_r( sqlsrv_errors() ) ); + $conn = new PDO("sqlsrv:server = $server ; Database = $dbName ;", $uid, $pwd); + if ($conn === false) { + die(print_r(sqlsrv_errors())); } // Create table $sql = "CREATE TABLE $tableName1 ( c1 INT, c2 VARCHAR(40) )"; - $stmt = $conn->query( $sql ); + $stmt = $conn->query($sql); // Insert data $sql = "INSERT INTO $tableName1 VALUES ( ?, ? )"; - for( $t = 100; $t < 116; $t++ ) - { - $stmt = $conn->prepare( $sql ); - $ts = substr( sha1( $t ),0,5 ); + for ($t = 100; $t < 116; $t++) { + $stmt = $conn->prepare($sql); + $ts = substr(sha1($t), 0, 5); $params = array( $t,$ts ); - $stmt->execute( $params ); + $stmt->execute($params); } // Create table $sql = "CREATE TABLE $tableName2 ( c1 INT, c2 VARCHAR(40) )"; - $stmt = $conn->query( $sql ); + $stmt = $conn->query($sql); // Insert data $sql = "INSERT INTO $tableName2 VALUES ( ?, ? )"; - for( $t = 200; $t < 209; $t++ ) - { - $stmt = $conn->prepare( $sql ); - $ts = substr( sha1( $t ),0,5 ); + for ($t = 200; $t < 209; $t++) { + $stmt = $conn->prepare($sql); + $ts = substr(sha1($t), 0, 5); $params = array( $t,$ts ); - $stmt->execute( $params ); + $stmt->execute($params); } $conn = null; @@ -54,31 +51,29 @@ function GenerateTables( $server, $uid, $pwd, $dbName, $tableName1, $tableName2 // Break connection by getting the session ID and killing it. // Note that breaking a connection and testing reconnection requires a // TCP/IP protocol connection (as opposed to a Shared Memory protocol). -function BreakConnection( $conn, $conn_break ) +function breakConnection($conn, $conn_break) { - $stmt1 = $conn->query( "SELECT @@SPID" ); - $obj = $stmt1->fetch( PDO::FETCH_NUM ); + $stmt1 = $conn->query("SELECT @@SPID"); + $obj = $stmt1->fetch(PDO::FETCH_NUM); $spid = $obj[0]; - $stmt2 = $conn_break->query( "KILL ".$spid ); + $stmt2 = $conn_break->query("KILL ".$spid); sleep(1); } // Remove any databases previously created by GenerateDatabase -function DropTables( $server, $uid, $pwd, $tableName1, $tableName2 ) +function dropTables($server, $uid, $pwd, $tableName1, $tableName2) { global $dbName; - $conn = new PDO( "sqlsrv:server = $server ; Database = $dbName ;", $uid, $pwd ); - + $conn = new PDO("sqlsrv:server = $server ; Database = $dbName ;", $uid, $pwd); + $query="IF OBJECT_ID('$tableName1', 'U') IS NOT NULL DROP TABLE $tableName1"; - $stmt=$conn->query( $query ); + $stmt=$conn->query($query); $query="IF OBJECT_ID('$tableName2', 'U') IS NOT NULL DROP TABLE $tableName2"; - $stmt=$conn->query( $query ); + $stmt=$conn->query($query); } -DropTables( $server, $uid, $pwd, $tableName1, $tableName2 ); -GenerateTables( $server, $uid, $pwd, $dbName, $tableName1, $tableName2 ); - -?> +dropTables($server, $uid, $pwd, $tableName1, $tableName2); +generateTables($server, $uid, $pwd, $dbName, $tableName1, $tableName2); diff --git a/test/functional/pdo_sqlsrv/pdo_TNIR.phpt b/test/functional/pdo_sqlsrv/pdo_TNIR.phpt index 436c033d..f71b10a4 100644 --- a/test/functional/pdo_sqlsrv/pdo_TNIR.phpt +++ b/test/functional/pdo_sqlsrv/pdo_TNIR.phpt @@ -1,7 +1,7 @@ --TEST-- Test the TNIR keyword with enabled and disabled options and the MultiSubnetFailover keyword with true and false options --SKIPIF-- - + --FILE-- PDO::ERRMODE_EXCEPTION)); + $conn = connect("TransparentNetworkIPResolution=$TNIRValue; MultiSubnetFailover=$MSFValueStr;"); + echo "Connection successful with TNIR $TNIRValue and MultiSubnetFailover $MSFValueStr.\n"; $connect_time = round(microtime(true) - $start, 2); echo "Time to connect is $connect_time sec.\n\n"; - $conn = NULL; - } - catch(PDOException $e) { + unset($conn); + } catch (PDOException $e) { echo "Connection failed with TNIR $TNIRValue and MultiSubnetFailover $MSFValueStr.\n"; print_r($e->errorInfo); } @@ -57,4 +54,4 @@ Connection successful with TNIR Disabled and MultiSubnetFailover false\. Time to connect is [0-9]+.?[0-9]* sec\. Connection successful with TNIR Disabled and MultiSubnetFailover true\. -Time to connect is [0-9]+.?[0-9]* sec\. \ No newline at end of file +Time to connect is [0-9]+.?[0-9]* sec\. diff --git a/test/functional/pdo_sqlsrv/pdo_bigint_outparam.phpt b/test/functional/pdo_sqlsrv/pdo_bigint_outparam.phpt index 15234ff5..58c370d9 100644 --- a/test/functional/pdo_sqlsrv/pdo_bigint_outparam.phpt +++ b/test/functional/pdo_sqlsrv/pdo_bigint_outparam.phpt @@ -14,6 +14,7 @@ createTable($conn, $tbname, array("c1_bigint" => "bigint")); // Create a Stored Procedure $spname = "selectBigint"; +dropProc($conn, $spname); $spSql = "CREATE PROCEDURE $spname (@c1_bigint bigint OUTPUT) AS SELECT @c1_bigint = c1_bigint FROM $tbname"; $conn->query($spSql); diff --git a/test/functional/pdo_sqlsrv/pdo_bool_outparam.phpt b/test/functional/pdo_sqlsrv/pdo_bool_outparam.phpt index 2048e496..7f54710a 100644 --- a/test/functional/pdo_sqlsrv/pdo_bool_outparam.phpt +++ b/test/functional/pdo_sqlsrv/pdo_bool_outparam.phpt @@ -14,6 +14,7 @@ createTable($conn, $tbname, array("c1_bool" => "int")); // Create a Stored Procedure $spname = "selectBool"; +dropProc($conn, $spname); $spSql = "CREATE PROCEDURE $spname (@c1_bool int OUTPUT) AS SELECT @c1_bool = c1_bool FROM $tbname"; $conn->query($spSql); diff --git a/test/functional/pdo_sqlsrv/pdo_connection_resiliency.phpt b/test/functional/pdo_sqlsrv/pdo_connection_resiliency.phpt index a2838d8e..cb4201c4 100644 --- a/test/functional/pdo_sqlsrv/pdo_connection_resiliency.phpt +++ b/test/functional/pdo_sqlsrv/pdo_connection_resiliency.phpt @@ -17,218 +17,192 @@ non-MARS connection. This should fail too. // when exiting the helper method? Do the associated cursors remain active? It is an // unnecessary complication, so I have left the code like this. -require_once( "break_pdo.php" ); +require_once("break_pdo.php"); +require_once("MsCommon_mid-refactor.inc"); -$conn_break = new PDO( "sqlsrv:server = $server ; Database = $dbName ;", $uid, $pwd ); +$conn_break = connect(); /////////////////////////////////////////////////////////////////////////////// -// Part 1 +// Part 1 // Expected to successfully execute second query because buffered cursor for // first query means connection is idle when broken /////////////////////////////////////////////////////////////////////////////// $connectionInfo = "ConnectRetryCount = 10; ConnectRetryInterval = 10;"; -try -{ - $conn = new PDO( "sqlsrv:server = $server ; Database = $dbName ; $connectionInfo", $uid, $pwd ); - $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); -} -catch( PDOException $e ) -{ +try { + $conn = connect($connectionInfo, array(), PDO::ERRMODE_EXCEPTION, true); +} catch (PDOException $e) { echo "Could not connect.\n"; - print_r( $e->getMessage() ); + print_r($e->getMessage()); } $query1 = "SELECT * FROM $tableName1"; - -try -{ - $stmt1 = $conn->prepare( $query1, array( PDO::ATTR_CURSOR=> PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=> PDO::SQLSRV_CURSOR_BUFFERED ) ); - if ( $stmt1->execute() ) echo "Statement 1 successful.\n"; +try { + $stmt1 = $conn->prepare($query1, array( PDO::ATTR_CURSOR=> PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=> PDO::SQLSRV_CURSOR_BUFFERED )); + if ($stmt1->execute()) { + echo "Statement 1 successful.\n"; + } $rowcount = $stmt1->rowCount(); echo $rowcount." rows in result set.\n"; -} -catch( PDOException $e ) -{ +} catch (PDOException $e) { echo "Error executing statement 1.\n"; - print_r( $e->getMessage() ); + print_r($e->getMessage()); } -BreakConnection( $conn, $conn_break ); +breakConnection($conn, $conn_break); $query2 = "SELECT * FROM $tableName2"; - -try -{ - $stmt2 = $conn->prepare( $query2, array( PDO::ATTR_CURSOR=> PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=> PDO::SQLSRV_CURSOR_BUFFERED ) ); - if ( $stmt2->execute() ) echo "Statement 2 successful.\n"; - +try { + $stmt2 = $conn->prepare($query2, array( PDO::ATTR_CURSOR=> PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=> PDO::SQLSRV_CURSOR_BUFFERED )); + if ($stmt2->execute()) { + echo "Statement 2 successful.\n"; + } $rowcount = $stmt2->rowCount(); echo $rowcount." rows in result set.\n"; -} -catch( PDOException $e ) -{ +} catch (PDOException $e) { echo "Error executing statement 2.\n"; - print_r( $e->getMessage() ); + print_r($e->getMessage()); } -$conn = null; +unset($conn); /////////////////////////////////////////////////////////////////////////////// -// Part 2 +// Part 2 // Expected to successfully execute second query because first statement is // freed before breaking connection /////////////////////////////////////////////////////////////////////////////// -try -{ - $conn = new PDO( "sqlsrv:server = $server ; Database = $dbName ; $connectionInfo", $uid, $pwd ); - $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); -} -catch( PDOException $e ) -{ +try { + $conn = connect($connectionInfo, array(), PDO::ERRMODE_EXCEPTION, true); +} catch (PDOException $e) { echo "Could not connect.\n"; - print_r( $e->getMessage() ); + print_r($e->getMessage()); } $query1 = "SELECT * FROM $tableName1"; -try -{ - $stmt3 = $conn->query( $query1 ); - if ( $stmt3 ) echo "Statement 3 successful.\n"; +try { + $stmt3 = $conn->query($query1); + if ($stmt3) { + echo "Statement 3 successful.\n"; + } $rowcount = $stmt3->rowCount(); echo $rowcount." rows in result set.\n"; -} -catch( PDOException $e ) -{ +} catch (PDOException $e) { echo "Error executing statement 3.\n"; - print_r( $e->getMessage() ); + print_r($e->getMessage()); } -$stmt3 = null; +unset($stmt3); -BreakConnection( $conn, $conn_break ); +breakConnection($conn, $conn_break); $query2 = "SELECT * FROM $tableName2"; -try -{ - $stmt4 = $conn->query( $query2 ); - if ( $stmt4 ) echo "Statement 4 successful.\n"; +try { + $stmt4 = $conn->query($query2); + if ($stmt4) { + echo "Statement 4 successful.\n"; + } $rowcount = $stmt4->rowCount(); echo $rowcount." rows in result set.\n"; -} -catch( PDOException $e ) -{ +} catch (PDOException $e) { echo "Error executing statement 4.\n"; - print_r( $e->getMessage() ); + print_r($e->getMessage()); } -$conn = null; +unset($conn); /////////////////////////////////////////////////////////////////////////////// -// Part 3 +// Part 3 // Expected to fail executing second query because default cursor for first // query is still active when connection is broken /////////////////////////////////////////////////////////////////////////////// -try -{ - $conn = new PDO( "sqlsrv:server = $server ; Database = $dbName ; $connectionInfo", $uid, $pwd ); - $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); -} -catch( PDOException $e ) -{ +try { + $conn = connect($connectionInfo, array(), PDO::ERRMODE_EXCEPTION, true); +} catch (PDOException $e) { echo "Could not connect.\n"; - print_r( $e->getMessage() ); + print_r($e->getMessage()); } $query1 = "SELECT * FROM $tableName1"; -try -{ - $stmt5 = $conn->query( $query1 ); - if ( $stmt5 ) echo "Statement 5 successful.\n"; +try { + $stmt5 = $conn->query($query1); + if ($stmt5) { + echo "Statement 5 successful.\n"; + } $rowcount = $stmt5->rowCount(); echo $rowcount." rows in result set.\n"; -} -catch( PDOException $e ) -{ +} catch (PDOException $e) { echo "Error executing statement 5.\n"; - print_r( $e->getMessage() ); + print_r($e->getMessage()); } -BreakConnection( $conn, $conn_break ); +breakConnection($conn, $conn_break); $query2 = "SELECT * FROM $tableName2"; -try -{ - $stmt6 = $conn->query( $query2 ); - if ( $stmt6 ) echo "Statement 6 successful.\n"; +try { + $stmt6 = $conn->query($query2); + if ($stmt6) { + echo "Statement 6 successful.\n"; + } $rowcount = $stmt6->rowCount(); echo $rowcount." rows in result set.\n"; -} -catch( PDOException $e ) -{ +} catch (PDOException $e) { echo "Error executing statement 6.\n"; - print_r( $e->getMessage() ); + print_r($e->getMessage()); } -$conn = null; +unset($conn); /////////////////////////////////////////////////////////////////////////////// -// Part 4 +// Part 4 // Expected to trigger an error because there are two active statements with // pending results and MARS is off /////////////////////////////////////////////////////////////////////////////// $connectionInfo = "ConnectRetryCount = 10; ConnectRetryInterval = 10; MultipleActiveResultSets = false;"; -try -{ - $conn = new PDO( "sqlsrv:server = $server ; Database = $dbName ; $connectionInfo", $uid, $pwd ); - $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); -} -catch( PDOException $e ) -{ +try { + $conn = connect($connectionInfo, array(), PDO::ERRMODE_EXCEPTION, true); +} catch (PDOException $e) { echo "Could not connect.\n"; - print_r( $e->getMessage() ); + print_r($e->getMessage()); } -BreakConnection( $conn, $conn_break ); +breakConnection($conn, $conn_break); -try -{ - $stmt7 = $conn->query( "SELECT * FROM $tableName1" ); - if ( $stmt7 ) echo "Statement 7 successful.\n"; -} -catch( PDOException $e ) -{ +try { + $stmt7 = $conn->query("SELECT * FROM $tableName1"); + if ($stmt7) { + echo "Statement 7 successful.\n"; + } +} catch (PDOException $e) { echo "Error executing statement 7.\n"; - print_r( $e->getMessage() ); + print_r($e->getMessage()); } -try -{ - $stmt8 = $conn->query( "SELECT * FROM $tableName2" ); - if ( $stmt8 ) echo "Statement 8 successful.\n"; -} -catch( PDOException $e ) -{ +try { + $stmt8 = $conn->query("SELECT * FROM $tableName2"); + if ($stmt8) { + echo "Statement 8 successful.\n"; + } +} catch (PDOException $e) { echo "Error executing statement 8.\n"; - print_r( $e->getMessage() ); + print_r($e->getMessage()); } -$conn = null; -$conn_break = null; +unset($conn); +unset($conn_break); ?> --EXPECTREGEX-- diff --git a/test/functional/pdo_sqlsrv/pdo_error.phpt b/test/functional/pdo_sqlsrv/pdo_error.phpt index efbb6ca5..6272df3e 100644 --- a/test/functional/pdo_sqlsrv/pdo_error.phpt +++ b/test/functional/pdo_sqlsrv/pdo_error.phpt @@ -1,28 +1,27 @@ --TEST-- Test the PDO::errorCode() and PDO::errorInfo() methods. --SKIPIF-- - + --FILE-- query( "Select * from " . $table1 . " where IntColX = 1" ); -} +require_once("MsCommon_mid-refactor.inc"); +require_once("MsData_PDO_AllTypes.inc"); -catch( PDOException $e ) { +try { + $db = connect(); + $tbname = "PDO_MainTypes"; + createTableMainTypes($db, $tbname); + // query with a wrong column name. + $db->query("Select * from " . $tbname . " where IntColX = 1"); + + dropTable($db, $tbname); + unset($conn); +} catch (PDOException $e) { print($db->errorCode()); echo "\n"; print_r($db->errorInfo()); - exit; } - - -?> +?> --EXPECTREGEX-- 42S22 Array diff --git a/test/functional/pdo_sqlsrv/pdo_insertDataType.phpt b/test/functional/pdo_sqlsrv/pdo_insertDataType.phpt index af5106c7..a684046c 100644 --- a/test/functional/pdo_sqlsrv/pdo_insertDataType.phpt +++ b/test/functional/pdo_sqlsrv/pdo_insertDataType.phpt @@ -1,50 +1,59 @@ --TEST-- Test the different type of data for retrieving --SKIPIF-- - + --FILE-- 1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.',"; - $query .= "'1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.',"; - $query .= "'1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.')"; - $numRows = $db->exec($query); - - echo "Insert complete!"; -} -catch(PDOException $e) -{ + $tbname = "PDO_AllTypes"; + createTableAllTypes($db, $tbname); + + $bin = fopen('php://memory', 'a'); + fwrite($bin, '00'); + rewind($bin); + $inputs = array("BigIntCol" => 0, + "BitCol" => '0', + "IntCol" => 1, + "SmallIntCol" => 1, + "TinyIntCol" => 1, + "DecimalCol" => 111, + "NumCol" => 1, + "MoneyCol" => 111.1110, + "SmallMoneyCol" => 111.1110, + "FloatCol" => 111.111, + "RealCol" => 111.111, + "CharCol" => 'STRINGCOL1', + "VarcharCol" => 'STRINGCOL1', + "TextCol" => '1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.', + "NCharCol" => 'STRINGCOL1', + "NVarcharCol" => 'STRINGCOL1', + "ImageCol" => new BindParamOp(17, $bin, "PDO::PARAM_LOB", 0, "PDO::SQLSRV_ENCODING_BINARY"), + "BinaryCol" => new BindParamOp(18, $bin, "PDO::PARAM_LOB", 0, "PDO::SQLSRV_ENCODING_BINARY"), + "VarbinaryCol" => new BindParamOp(19, $bin, "PDO::PARAM_LOB", 0, "PDO::SQLSRV_ENCODING_BINARY"), + "SmallDTCol" => '2000-11-11 11:11:00', + "DateTimeCol" => '2000-11-11 11:11:11.110', + "DTOffsetCol" => '2000-11-11 11:11:11.1110000 +00:00', + "TimeCol" => '11:11:11.1110000', + "Guidcol" => 'AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA', + "VarbinaryMaxCol" => new BindParamOp(25, $bin, "PDO::PARAM_LOB", 0, "PDO::SQLSRV_ENCODING_BINARY"), + "VarcharMaxCol" => '1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.', + "XmlCol" => ' 1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.', + "NTextCol" => '1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.', + "NVarCharMaxCol" => '1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.'); + $stmt = insertRow($db, $tbname, $inputs, "prepareBindParam"); + + dropTable($db, $tbname); + unset($stmt); + unset($conn); + echo "Insert complete!\n"; +} catch (PDOException $e) { var_dump($e); } ?> - --EXPECT-- -Insert complete! \ No newline at end of file +Insert complete! diff --git a/test/functional/pdo_sqlsrv/pdo_prepare.phpt b/test/functional/pdo_sqlsrv/pdo_prepare.phpt index a0b5c18c..856ac998 100644 --- a/test/functional/pdo_sqlsrv/pdo_prepare.phpt +++ b/test/functional/pdo_sqlsrv/pdo_prepare.phpt @@ -3,94 +3,84 @@ Test the PDO::prepare() method. --ENV-- PHPT_EXEC=true --SKIPIF-- - + --FILE-- setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); - + $tbname = "PDO_MainTypes"; + createAndInsertTableMainTypes($db, $tbname); + // Test_1 : Test with no parameters echo "Test_1 : Test with no parameters :\n"; - $stmt = $db->prepare('select * from ' . $table1); - if(!$stmt->execute()) - { + $stmt = $db->prepare("select * from $tbname"); + if (!$stmt->execute()) { die("Test_1 failed."); } $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); + var_dump($result); // Test_2 : Test with indexed parameters echo "Test_2 : Test with indexed parameters :\n"; - $stmt = $db->prepare('select IntCol, CharCol from ' . $table1 . ' where IntCol = ? and CharCol = ?'); - if(!$stmt->execute(array(1, 'STRINGCOL1'))) - { + $stmt = $db->prepare("select IntCol, CharCol from $tbname where IntCol = ? and CharCol = ?"); + if (!$stmt->execute(array(1, 'STRINGCOL1'))) { die("Test_2 failed."); } $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); + var_dump($result); // Test_3 : Test with named parameters echo "Test_3 : Test with named parameters :\n"; $IntColVal = 2; $CharColVal = 'STRINGCOL2'; - $stmt = $db->prepare('select IntCol, CharCol from ' . $table1 . ' where IntCol = :IntColVal and CharCol = :CharColVal'); - if(!$stmt->execute(array(':IntColVal' => $IntColVal, ':CharColVal' => $CharColVal))) - { + $stmt = $db->prepare("select IntCol, CharCol from $tbname where IntCol = :IntColVal and CharCol = :CharColVal"); + if (!$stmt->execute(array(':IntColVal' => $IntColVal, ':CharColVal' => $CharColVal))) { die("Test_3 failed."); } $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); + var_dump($result); // Test_4: Test single prepare, multiple execution with indexed parameters echo "Test_4 : Test single prepare, multiple execution with indexed parameters :\n"; $IntColVal = 1; - $stmt = $db->prepare('select IntCol from ' . $table1 . ' where IntCol = ?'); + $stmt = $db->prepare("select IntCol from $tbname where IntCol = ?"); $stmt->bindParam(1, $IntColVal); - if(!$stmt->execute()) - { + if (!$stmt->execute()) { die("Test_4 failed."); } $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); + var_dump($result); // Execute the stmt again $IntColVal = 2; - if(!$stmt->execute()) - { + if (!$stmt->execute()) { die("Test_4 failed."); } $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); + var_dump($result); // Test_5: Test single prepare, multiple execution with named parameters echo "Test_5 : Test single prepare, multiple execution with named parameters :\n"; $IntColVal = 1; - $stmt = $db->prepare('select IntCol from ' . $table1 . ' where IntCol = :IntColVal'); + $stmt = $db->prepare("select IntCol from $tbname where IntCol = :IntColVal"); $stmt->bindParam(':IntColVal', $IntColVal); - if(!$stmt->execute()) - { + if (!$stmt->execute()) { die("Test_5 failed."); } $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); + var_dump($result); // Execute the stmt again $IntColVal = 2; - if(!$stmt->execute()) - { + if (!$stmt->execute()) { die("Test_5 failed."); } $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); -} -catch(PDOException $err) -{ + var_dump($result); +} catch (PDOException $err) { var_dump($err); exit(); } diff --git a/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_float.phpt b/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_float.phpt index ce3f7e80..2ac8145c 100644 --- a/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_float.phpt +++ b/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_float.phpt @@ -1,81 +1,82 @@ --TEST-- prepare with emulate prepare and binding integer --SKIPIF-- - + --FILE-- query($query); + $tableName = "number_types"; + if (!isColEncrypted()) { + createTable($conn, $tableName, array("c1_decimal" => "decimal", "c2_money" => "money", "c3_float" => "float")); + } else { + // money is not supported for column encryption, use decimal(19,4) instead + createTable($conn, $tableName, array("c1_decimal" => "decimal", "c2_money" => "decimal(19,4)", "c3_float" => "float")); + } -$query = "CREATE TABLE [$tableName] (c1_decimal decimal, c2_money money, c3_float float)"; -$stmt = $conn->query($query); + insertRow($conn, $tableName, array("c1_decimal" => 411.1, "c2_money" => 131.11, "c3_float" => 611.111)); + insertRow($conn, $tableName, array("c1_decimal" => 422.2222, "c2_money" => 132.22, "c3_float" => 622.22)); + insertRow($conn, $tableName, array("c1_decimal" => 433.333, "c2_money" => 133.3333, "c3_float" => 633.33333)); -$query = "INSERT INTO [$tableName] (c1_decimal, c2_money, c3_float) VALUES (411.1, 131.11, 611.111)"; -$stmt = $conn->query($query); + $query = "SELECT * FROM [$tableName] WHERE c3_float = :c3"; -$query = "INSERT INTO [$tableName] (c1_decimal, c2_money, c3_float) VALUES (422.2222, 132.222, 622.22)"; -$stmt = $conn->query($query); + // prepare without emulate prepare + print_r("Prepare without emulate prepare:\n"); + $options = array(PDO::ATTR_EMULATE_PREPARES => false); + $stmt = $conn->prepare($query, $options); + $c3 = 611.111; + $stmt->bindParam(':c3', $c3); + $stmt->execute(); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + print_r($row); -$query = "INSERT INTO [$tableName] (c1_decimal, c2_money, c3_float) VALUES (433.333, 133.3333, 633.33333 )"; -$stmt = $conn->query($query); + //with emulate prepare and no bind param options + print_r("Prepare with emulate prepare and no bind param options:\n"); + if (!isColEncrypted()) { + // emulate prepare is not supported for encrypted columns + $options = array(PDO::ATTR_EMULATE_PREPARES => true); + } + $stmt = $conn->prepare($query, $options); + $stmt->bindParam(':c3', $c3); + $stmt->execute(); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + print_r($row); -$query = "SELECT * FROM [$tableName] WHERE c3_float = :c3"; + //with emulate prepare and encoding SQLSRV_ENCODING_SYSTEM + print_r("Prepare with emulate prepare and SQLSRV_ENCODING_SYSTEM:\n"); + $stmt = $conn->prepare($query, $options); + $stmt->bindParam(':c3', $c3, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_SYSTEM); + $stmt->execute(); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + print_r($row); -// prepare without emulate prepare -print_r("Prepare without emulate prepare:\n"); -$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => false)); -$c3 = 611.111; -$stmt->bindParam(':c3', $c3); -$stmt->execute(); -$row = $stmt->fetch( PDO::FETCH_ASSOC ); -print_r($row); + //prepare with emulate prepare and encoding SQLSRV_ENCODING_UTF8 + print_r("Prepare with emulate prepare and SQLSRV_ENCODING_UTF8:\n"); + $stmt = $conn->prepare($query, $options); + $stmt->bindParam(':c3', $c3, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_UTF8); + $stmt->execute(); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + print_r($row); -//with emulate prepare and no bind param options -print_r("Prepare with emulate prepare and no bind param options:\n"); -$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true)); -$c3 = 611.111; -$stmt->bindParam(':c3', $c3); -$stmt->execute(); -$row = $stmt->fetch( PDO::FETCH_ASSOC ); -print_r($row); - -//with emulate prepare and encoding SQLSRV_ENCODING_SYSTEM -print_r("Prepare with emulate prepare and SQLSRV_ENCODING_SYSTEM:\n"); -$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true)); -$c3 = 611.111; -$stmt->bindParam(':c3', $c3, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_SYSTEM); -$stmt->execute(); -$row = $stmt->fetch( PDO::FETCH_ASSOC ); -print_r($row); - -//prepare with emulate prepare and encoding SQLSRV_ENCODING_UTF8 -print_r("Prepare with emulate prepare and SQLSRV_ENCODING_UTF8:\n"); -$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true)); -$c3 = 611.111; -$stmt->bindParam(':c3', $c3, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_UTF8); -$stmt->execute(); -$row = $stmt->fetch( PDO::FETCH_ASSOC ); -print_r($row); - -//prepare with emulate prepare and encoding SQLSRV_ENCODING_BINARY -print_r("Prepare with emulate prepare and SQLSRV_ENCODING_BINARY:\n"); -$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true)); -$c3 = 611.111; -$stmt->bindParam(':c3', $c3, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_BINARY); -$stmt->execute(); -$row = $stmt->fetch( PDO::FETCH_ASSOC ); -print_r($row); -if ($stmt->rowCount() == 0){ - print_r("No results for this query\n"); + //prepare with emulate prepare and encoding SQLSRV_ENCODING_BINARY + print_r("Prepare with emulate prepare and SQLSRV_ENCODING_BINARY:\n"); + $stmt = $conn->prepare($query, $options); + $stmt->bindParam(':c3', $c3, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_BINARY); + $stmt->execute(); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + print_r($row); + if ($stmt->rowCount() == 0) { + print_r("No results for this query\n"); + } + dropTable($conn, $tableName); + unset($stmt); + unset($conn); +} catch (PDOException $e) { + var_dump($e->errorInfo); } - -$stmt = null; -$conn=null; ?> --EXPECT-- @@ -108,4 +109,4 @@ Array [c3_float] => 611.11099999999999 ) Prepare with emulate prepare and SQLSRV_ENCODING_BINARY: -No results for this query \ No newline at end of file +No results for this query diff --git a/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_int.phpt b/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_int.phpt index c8d6122e..33bee845 100644 --- a/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_int.phpt +++ b/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_int.phpt @@ -1,80 +1,82 @@ --TEST-- prepare with emulate prepare and binding integer --SKIPIF-- - + --FILE-- "varchar(max)", "calories" => "int")); -$query = "IF OBJECT_ID('fruit') IS NOT NULL DROP TABLE [$tableName]"; -$stmt = $conn->query($query); + insertRow($conn, $tableName, array("name" => "apple", "calories" => 150)); + insertRow($conn, $tableName, array("name" => "banana", "calories" => 175)); + insertRow($conn, $tableName, array("name" => "blueberry", "calories" => 1)); -$query = "CREATE TABLE [$tableName] (name varchar(max), calories int)"; -$stmt = $conn->query($query); + $query = "SELECT * FROM [$tableName] WHERE calories = :cal"; -$query = "INSERT INTO [$tableName] (name, calories) VALUES ('apple', 150)"; -$stmt = $conn->query($query); + // prepare without emulate prepare + print_r("Prepare without emulate prepare:\n"); + $options = array(PDO::ATTR_EMULATE_PREPARES => false); + $stmt = $conn->prepare($query, $options); + $cal = 1; + $stmt->bindParam(':cal', $cal, PDO::PARAM_INT); + $stmt->execute(); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + print_r($row); -$query = "INSERT INTO [$tableName] (name, calories) VALUES ('banana', 175)"; -$stmt = $conn->query($query); + // prepare with emulate prepare + print_r("Prepare with emulate prepare and no bindParam options:\n"); + if (!isColEncrypted()) { + // emulate prepare is not supported for encrypted columns + $options = array(PDO::ATTR_EMULATE_PREPARES => true); + } + $stmt = $conn->prepare($query, $options); + $stmt->bindParam(':cal', $cal, PDO::PARAM_INT); + $stmt->execute(); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + print_r($row); -$query = "INSERT INTO [$tableName] (name, calories) VALUES ('blueberry', 1)"; -$stmt = $conn->query($query); + 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 -$query = "SELECT * FROM [$tableName] WHERE calories = :cal"; + $results = array(); + //prepare with emulate prepare and encoding SQLSRV_ENCODING_SYSTEM + $stmt = $conn->prepare($query, $options); + $stmt->bindParam(':cal', $cal, PDO::PARAM_INT, 0, PDO::SQLSRV_ENCODING_SYSTEM); + $stmt->execute(); + $results["SYSTEM"] = $stmt->fetch(PDO::FETCH_ASSOC); -// prepare without emulate prepare -print_r("Prepare without emulate prepare:\n"); -$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => false)); -$cal = 1; -$stmt->bindParam(':cal', $cal, PDO::PARAM_INT); -$stmt->execute(); -$row = $stmt->fetch( PDO::FETCH_ASSOC ); -print_r($row); + //prepare with emulate prepare and encoding SQLSRV_ENCODING_UTF8 + $stmt = $conn->prepare($query, $options); + $stmt->bindParam(':cal', $cal, PDO::PARAM_INT, 0, PDO::SQLSRV_ENCODING_UTF8); + $stmt->execute(); + $results["UTF8"] = $stmt->fetch(PDO::FETCH_ASSOC); -// prepare with emulate prepare -print_r("Prepare with emulate prepare and no bindParam options:\n"); -$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true)); -$cal = 1; -$stmt->bindParam(':cal', $cal, PDO::PARAM_INT); -$stmt->execute(); -$row = $stmt->fetch( PDO::FETCH_ASSOC ); -print_r($row); + //prepare with emulate prepare and encoding SQLSRV_ENCODING_BINARY + $stmt = $conn->prepare($query, $options); + $stmt->bindParam(':cal', $cal, PDO::PARAM_INT, 0, PDO::SQLSRV_ENCODING_BINARY); + $stmt->execute(); + $results["BINARY"] = $stmt->fetch(PDO::FETCH_ASSOC); -//prepare with emulate prepare and encoding SQLSRV_ENCODING_SYSTEM -print_r("Prepare with emulate prepare and SQLSRV_ENCODING_UTF8:\n"); -$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true)); -$cal = 1; -$stmt->bindParam(':cal', $cal, PDO::PARAM_INT, 0, PDO::SQLSRV_ENCODING_SYSTEM); -$stmt->execute(); -$row = $stmt->fetch( PDO::FETCH_ASSOC ); -print_r($row); + foreach ($results as $key => $value) { + if ($value['name'] != "blueberry" || $value['calories'] != 1) { + echo "Failed to fetch when binding parameter with $key encoding.\n"; + } + } + } -//prepare with emulate prepare and encoding SQLSRV_ENCODING_UTF8 -print_r("Prepare with emulate prepare and and SQLSRV_ENCODING_SYSTEM:\n"); -$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true)); -$cal = 1; -$stmt->bindParam(':cal', $cal, PDO::PARAM_INT, 0, PDO::SQLSRV_ENCODING_UTF8); -$stmt->execute(); -$row = $stmt->fetch( PDO::FETCH_ASSOC ); -print_r($row); - -//prepare with emulate prepare and encoding SQLSRV_ENCODING_BINARY -print_r("Prepare with emulate prepare and encoding SQLSRV_ENCODING_BINARY:\n"); -$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true)); -$cal = 1; -$stmt->bindParam(':cal', $cal, PDO::PARAM_INT, 0, PDO::SQLSRV_ENCODING_BINARY); -$stmt->execute(); -$row = $stmt->fetch( PDO::FETCH_ASSOC ); -print_r($row); - -$stmt = null; -$conn=null; + dropTable($conn, $tableName); + unset($stmt); + unset($conn); +} catch (PDOException $e) { + var_dump($e->errorInfo); +} ?> - --EXPECT-- Prepare without emulate prepare: Array @@ -88,21 +90,3 @@ Array [name] => blueberry [calories] => 1 ) -Prepare with emulate prepare and SQLSRV_ENCODING_UTF8: -Array -( - [name] => blueberry - [calories] => 1 -) -Prepare with emulate prepare and and SQLSRV_ENCODING_SYSTEM: -Array -( - [name] => blueberry - [calories] => 1 -) -Prepare with emulate prepare and encoding SQLSRV_ENCODING_BINARY: -Array -( - [name] => blueberry - [calories] => 1 -) \ No newline at end of file diff --git a/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_money.phpt b/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_money.phpt index 669cd586..d152ed16 100644 --- a/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_money.phpt +++ b/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_money.phpt @@ -1,81 +1,83 @@ --TEST-- prepare with emulate prepare and binding integer --SKIPIF-- - + --FILE-- query($query); + $tableName = "number_types"; + if (!isColEncrypted()) { + createTable($conn, $tableName, array("c1_decimal" => "decimal", "c2_money" => "money", "c3_float" => "float")); + } else { + // money is not supported for column encryption, use decimal(19,4) instead + createTable($conn, $tableName, array("c1_decimal" => "decimal", "c2_money" => "decimal(19,4)", "c3_float" => "float")); + } -$query = "CREATE TABLE [$tableName] (c1_decimal decimal, c2_money money, c3_float float)"; -$stmt = $conn->query($query); + insertRow($conn, $tableName, array("c1_decimal" => 411.1, "c2_money" => 131.11, "c3_float" => 611.111)); + insertRow($conn, $tableName, array("c1_decimal" => 422.2222, "c2_money" => 132.22, "c3_float" => 622.22)); + insertRow($conn, $tableName, array("c1_decimal" => 433.333, "c2_money" => 133.3333, "c3_float" => 633.33333)); -$query = "INSERT INTO [$tableName] (c1_decimal, c2_money, c3_float) VALUES (411.1, 131.11, 611.111)"; -$stmt = $conn->query($query); + $query = "SELECT * FROM [$tableName] WHERE c2_money = :c2"; -$query = "INSERT INTO [$tableName] (c1_decimal, c2_money, c3_float) VALUES (422.2222, 132.222, 622.22)"; -$stmt = $conn->query($query); + // prepare without emulate prepare + print_r("Prepare without emulate prepare:\n"); + $options = array(PDO::ATTR_EMULATE_PREPARES => false); + $stmt = $conn->prepare($query, $options); + $c2 = 133.3333; + $stmt->bindParam(':c2', $c2); + $stmt->execute(); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + print_r($row); -$query = "INSERT INTO [$tableName] (c1_decimal, c2_money, c3_float) VALUES (433.333, 133.3333, 633.33333 )"; -$stmt = $conn->query($query); + //with emulate prepare and no bind param options + print_r("Prepare with emulate prepare and no bind param options:\n"); + if (!isColEncrypted()) { + // emulate prepare is not supported for encrypted columns + $options = array(PDO::ATTR_EMULATE_PREPARES => true); + } + $stmt = $conn->prepare($query, $options); + $stmt->bindParam(':c2', $c2); + $stmt->execute(); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + print_r($row); -$query = "SELECT * FROM [$tableName] WHERE c2_money = :c2"; + //with emulate prepare and encoding SQLSRV_ENCODING_SYSTEM + print_r("Prepare with emulate prepare and SQLSRV_ENCODING_SYSTEM:\n"); + $stmt = $conn->prepare($query, $options); + $stmt->bindParam(':c2', $c2, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_SYSTEM); + $stmt->execute(); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + print_r($row); -// prepare without emulate prepare -print_r("Prepare without emulate prepare:\n"); -$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => false)); -$c2 = 133.3333; -$stmt->bindParam(':c2', $c2); -$stmt->execute(); -$row = $stmt->fetch( PDO::FETCH_ASSOC ); -print_r($row); + //prepare with emulate prepare and encoding SQLSRV_ENCODING_UTF8 + print_r("Prepare with emulate prepare and SQLSRV_ENCODING_UTF8:\n"); + $stmt = $conn->prepare($query, $options); + $stmt->bindParam(':c2', $c2, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_UTF8); + $stmt->execute(); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + print_r($row); -//with emulate prepare and no bind param options -print_r("Prepare with emulate prepare and no bind param options:\n"); -$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true)); -$c2 = 133.3333; -$stmt->bindParam(':c2', $c2); -$stmt->execute(); -$row = $stmt->fetch( PDO::FETCH_ASSOC ); -print_r($row); + //prepare with emulate prepare and encoding SQLSRV_ENCODING_BINARY + print_r("Prepare with emulate prepare and SQLSRV_ENCODING_BINARY:\n"); + $stmt = $conn->prepare($query, $options); + $stmt->bindParam(':c2', $c2, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_BINARY); + $stmt->execute(); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + print_r($row); + if ($stmt->rowCount() == 0) { + print_r("No results for this query\n"); + } -//with emulate prepare and encoding SQLSRV_ENCODING_SYSTEM -print_r("Prepare with emulate prepare and SQLSRV_ENCODING_SYSTEM:\n"); -$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true)); -$c2 = 133.3333; -$stmt->bindParam(':c2', $c2, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_SYSTEM); -$stmt->execute(); -$row = $stmt->fetch( PDO::FETCH_ASSOC ); -print_r($row); - -//prepare with emulate prepare and encoding SQLSRV_ENCODING_UTF8 -print_r("Prepare with emulate prepare and SQLSRV_ENCODING_UTF8:\n"); -$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true)); -$c2 = 133.3333; -$stmt->bindParam(':c2', $c2, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_UTF8); -$stmt->execute(); -$row = $stmt->fetch( PDO::FETCH_ASSOC ); -print_r($row); - -//prepare with emulate prepare and encoding SQLSRV_ENCODING_BINARY -print_r("Prepare with emulate prepare and SQLSRV_ENCODING_BINARY:\n"); -$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true)); -$c2 = 133.3333; -$stmt->bindParam(':c2', $c2, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_BINARY); -$stmt->execute(); -$row = $stmt->fetch( PDO::FETCH_ASSOC ); -print_r($row); -if ($stmt->rowCount() == 0){ - print_r("No results for this query\n"); + dropTable($conn, $tableName); + unset($stmt); + unset($conn); +} catch (PDOException $e) { + var_dump($e->errorInfo); } - -$stmt = null; -$conn=null; ?> --EXPECT-- @@ -108,4 +110,4 @@ Array [c3_float] => 633.33333000000005 ) Prepare with emulate prepare and SQLSRV_ENCODING_BINARY: -No results for this query \ No newline at end of file +No results for this query diff --git a/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_unicode.phpt b/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_unicode.phpt index e6e841dd..834718fc 100644 --- a/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_unicode.phpt +++ b/test/functional/pdo_sqlsrv/pdo_prepare_emulatePrepare_unicode.phpt @@ -1,89 +1,96 @@ --TEST-- prepare with emulate prepare and binding uft8 characters --SKIPIF-- - + --FILE-- setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); -//$conn->setAttribute( PDO::SQLSRV_ATTR_QUERY_TIMEOUT, 1 ); +require_once('MsCommon_mid-refactor.inc'); -$tableName = "users"; - -$query = "IF OBJECT_ID('users') IS NOT NULL DROP TABLE [$tableName]"; -$stmt = $conn->query($query); - -$query = "CREATE TABLE [$tableName] (name nvarchar(max), status int, age int)"; -$stmt = $conn->query($query); - -$query = "INSERT INTO [$tableName] (name, status, age) VALUES (N'Belle', 1, 34)"; -$stmt = $conn->query($query); - -$query = "INSERT INTO [$tableName] (name, status, age) VALUES (N'Ðбрам', 1, 40)"; -$stmt = $conn->query($query); - -$query = "INSERT INTO [$tableName] (name, status, age) VALUES (N'ê°€ê°', 1, 30)"; -$stmt = $conn->query($query); - -$name = "ê°€ê°"; - -$query = "SELECT * FROM [$tableName] WHERE name = :name AND status = 1"; - -//without emulate prepare -print_r("Prepare without emulate prepare:\n"); -$stmt = $conn->prepare($query); -$stmt->bindParam(':name', $name, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_UTF8); -$stmt->execute(); -$row = $stmt->fetch(PDO::FETCH_ASSOC); -print_r($row); - -//with emulate prepare and no bind param options -print_r("Prepare with emulate prepare and no bindParam options:\n"); -$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true)); -$stmt->bindParam(':name', $name ); -$stmt->execute(); -$row = $stmt->fetch( PDO::FETCH_ASSOC ); -print_r($row); -if ($stmt->rowCount() == 0){ - print_r("No results for this query\n"); +function prepareStmt($conn, $query, $prepareOptions = array(), $dataType = null, $length = null, $driverOptions = null) +{ + $name = "ê°€ê°"; + if (!isColEncrypted()) { + $stmt = $conn->prepare($query, $prepareOptions); + $stmt->bindParam(':name', $name, $dataType, $length, $driverOptions); + } else { + $status = 1; + $stmt = $conn->prepare($query, $prepareOptions); + $stmt->bindParam(':name', $name, $dataType, $length, $driverOptions); + $stmt->bindParam(':status', $status); + } + $stmt->execute(); + return $stmt; } -//with emulate prepare and SQLSRV_ENCODING_UTF8 -print_r("Prepare with emulate prepare and SQLSRV_ENCODING_UTF8:\n"); -$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true)); -$stmt->bindParam(':name', $name, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_UTF8); -$stmt->execute(); -$row = $stmt->fetch( PDO::FETCH_ASSOC ); -print_r($row); +try { + $conn = connect("", array(), PDO::ERRMODE_SILENT); + //$conn->setAttribute( PDO::SQLSRV_ATTR_QUERY_TIMEOUT, 1 ); -//with emulate prepare and SQLSRV_ENCODING_SYSTEM -print_r("Prepare with emulate prepare and and SQLSRV_ENCODING_SYSTEM:\n"); -$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true)); -$stmt->bindParam(':name', $name, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_SYSTEM); -$stmt->execute(); -$row = $stmt->fetch( PDO::FETCH_ASSOC ); -print_r($row); -if ($stmt->rowCount() == 0){ - print_r("No results for this query\n"); + $tableName = "users"; + createTable($conn, $tableName, array("name" => "nvarchar(max)", "status" => "int", "age" => "int")); + + if (!isColEncrypted()) { + $conn->exec("INSERT INTO [$tableName] (name, status, age) VALUES (N'Belle', 1, 34)"); + $conn->exec("INSERT INTO [$tableName] (name, status, age) VALUES (N'Ðбрам', 1, 40)"); + $conn->exec("INSERT INTO [$tableName] (name, status, age) VALUES (N'ê°€ê°', 1, 30)"); + $query = "SELECT * FROM [$tableName] WHERE name = :name AND status = 1"; + } else { + insertRow($conn, $tableName, array("name" => "Belle", "status" => 1, "age" => 34)); + insertRow($conn, $tableName, array("name" => "Ðбрам", "status" => 1, "age" => 40)); + insertRow($conn, $tableName, array("name" => "ê°€ê°", "status" => 1, "age" => 30)); + $query = "SELECT * FROM [$tableName] WHERE name = :name AND status = :status"; + } + + //without emulate prepare + print_r("Prepare without emulate prepare:\n"); + $stmt = prepareStmt($conn, $query, array(), PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_UTF8); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + print_r($row); + + //with emulate prepare and no bind param options + print_r("Prepare with emulate prepare and no bindParam options:\n"); + if (!isColEncrypted()) { + $options = array(PDO::ATTR_EMULATE_PREPARES => true); + } else { + $options = array(PDO::ATTR_EMULATE_PREPARES => false); + } + $stmt = prepareStmt($conn, $query, $options); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + print_r($row); + if ($stmt->rowCount() == 0) { + print_r("No results for this query\n"); + } + + //with emulate prepare and SQLSRV_ENCODING_UTF8 + print_r("Prepare with emulate prepare and SQLSRV_ENCODING_UTF8:\n"); + $stmt = prepareStmt($conn, $query, $options, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_UTF8); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + print_r($row); + + //with emulate prepare and SQLSRV_ENCODING_SYSTEM + print_r("Prepare with emulate prepare and and SQLSRV_ENCODING_SYSTEM:\n"); + $stmt = prepareStmt($conn, $query, $options, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_SYSTEM); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + print_r($row); + if ($stmt->rowCount() == 0) { + print_r("No results for this query\n"); + } + + //with emulate prepare and encoding SQLSRV_ENCODING_BINARY + print_r("Prepare with emulate prepare and encoding SQLSRV_ENCODING_BINARY:\n"); + $stmt = prepareStmt($conn, $query, $options, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_BINARY); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + print_r($row); + if ($stmt->rowCount() == 0) { + print_r("No results for this query\n"); + } + + dropTable($conn, $tableName); + unset($stmt); + unset($conn); +} catch (PDOException $e) { + var_dump($e->errorInfo); } - -//with emulate prepare and encoding SQLSRV_ENCODING_BINARY -print_r("Prepare with emulate prepare and encoding SQLSRV_ENCODING_BINARY:\n"); -$stmt = $conn->prepare($query, array(PDO::ATTR_EMULATE_PREPARES => true)); -$stmt->bindParam(':name', $name, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_BINARY); -$stmt->execute(); -$row = $stmt->fetch( PDO::FETCH_ASSOC ); -print_r($row); -if ($stmt->rowCount() == 0){ - print_r("No results for this query\n"); -} - -//$query = "DROP TABLE [$tableName]"; -//$stmt = $conn->query($query); - -$stmt = null; -$conn=null; ?> --EXPECT-- @@ -106,4 +113,4 @@ Array Prepare with emulate prepare and and SQLSRV_ENCODING_SYSTEM: No results for this query Prepare with emulate prepare and encoding SQLSRV_ENCODING_BINARY: -No results for this query \ No newline at end of file +No results for this query diff --git a/test/functional/pdo_sqlsrv/pdo_prepare_invalid_cursor.phpt b/test/functional/pdo_sqlsrv/pdo_prepare_invalid_cursor.phpt index c6e485c3..5870a8a4 100644 --- a/test/functional/pdo_sqlsrv/pdo_prepare_invalid_cursor.phpt +++ b/test/functional/pdo_sqlsrv/pdo_prepare_invalid_cursor.phpt @@ -1,33 +1,28 @@ --TEST-- Test PDO::prepare by passing in invalid cursor value --SKIPIF-- - + --FILE-- prepare( "SELECT 1", array( PDO::ATTR_CURSOR => "PDO::CURSOR_FWDONLY" )); - print_r(($conn->errorInfo())[2]); - echo "\n"; - - // 10 is an invalid value for PDO::ATTR_CURSOR - $stmt2 = $conn->prepare( "SELECT 2", array( PDO::ATTR_CURSOR => 10 )); + $stmt1 = $conn->prepare("SELECT 1", array( PDO::ATTR_CURSOR => "PDO::CURSOR_FWDONLY" )); print_r(($conn->errorInfo())[2]); echo "\n"; + // 10 is an invalid value for PDO::ATTR_CURSOR + $stmt2 = $conn->prepare("SELECT 2", array( PDO::ATTR_CURSOR => 10 )); + print_r(($conn->errorInfo())[2]); + echo "\n"; +} catch (PDOException $e) { + var_dump($e->errorInfo); } -catch( PDOException $e ) { - var_dump( $e->errorInfo ); -} -?> +?> --EXPECT-- - An invalid cursor type was specified for either PDO::ATTR_CURSOR or PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE -An invalid cursor type was specified for either PDO::ATTR_CURSOR or PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE \ No newline at end of file +An invalid cursor type was specified for either PDO::ATTR_CURSOR or PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE diff --git a/test/functional/pdo_sqlsrv/pdo_prepare_invalid_encoding.phpt b/test/functional/pdo_sqlsrv/pdo_prepare_invalid_encoding.phpt index dc782755..099f4d94 100644 --- a/test/functional/pdo_sqlsrv/pdo_prepare_invalid_encoding.phpt +++ b/test/functional/pdo_sqlsrv/pdo_prepare_invalid_encoding.phpt @@ -1,32 +1,28 @@ --TEST-- Test PDO::prepare by passing in invalid encoding values --SKIPIF-- - + --FILE-- prepare( "SELECT 1", array( PDO::SQLSRV_ATTR_ENCODING => "PDO::SQLSRV_ENCODING_SYSTEM" )); + $stmt1 = $conn->prepare("SELECT 1", array( PDO::SQLSRV_ATTR_ENCODING => "PDO::SQLSRV_ENCODING_SYSTEM" )); print_r(($conn->errorInfo())[2]); echo "\n"; - + // 10 is an invalid value for PDO::SQLSRV_ATTR_ENCODING - $stmt2 = $conn->prepare( "SELECT 2", array( PDO::SQLSRV_ATTR_ENCODING => 10 )); + $stmt2 = $conn->prepare("SELECT 2", array( PDO::SQLSRV_ATTR_ENCODING => 10 )); print_r(($conn->errorInfo())[2]); echo "\n"; +} catch (PDOException $e) { + var_dump($e->errorInfo); } -catch( PDOException $e ) { - var_dump( $e->errorInfo ); -} -?> +?> --EXPECT-- - An invalid encoding was specified for SQLSRV_ATTR_ENCODING. -An invalid encoding was specified for SQLSRV_ATTR_ENCODING. \ No newline at end of file +An invalid encoding was specified for SQLSRV_ATTR_ENCODING. diff --git a/test/functional/pdo_sqlsrv/pdo_prepare_invalid_option_key.phpt b/test/functional/pdo_sqlsrv/pdo_prepare_invalid_option_key.phpt index a526cceb..bd6a4cf0 100644 --- a/test/functional/pdo_sqlsrv/pdo_prepare_invalid_option_key.phpt +++ b/test/functional/pdo_sqlsrv/pdo_prepare_invalid_option_key.phpt @@ -1,28 +1,23 @@ --TEST-- Test PDO::prepare by passing in a string key --SKIPIF-- - + --FILE-- PDO::ERRMODE_EXCEPTION); - $conn = new PDO( $dsn, $uid, $pwd, $attr); - - $stmt = $conn->prepare( "SELECT 1", array( "PDO::ATTR_CURSOR" => PDO::CURSOR_FWDONLY )); +try { + $conn = connect(); + + $stmt = $conn->prepare("SELECT 1", array( "PDO::ATTR_CURSOR" => PDO::CURSOR_FWDONLY )); echo "Test Successful"; +} catch (PDOException $e) { + var_dump($e->errorInfo); } -catch( PDOException $e ) { - var_dump( $e->errorInfo ); -} -?> +?> --EXPECT-- - array(3) { [0]=> string(5) "IMSSP" @@ -30,4 +25,4 @@ array(3) { int(-43) [2]=> string(42) "An invalid statement option was specified." -} \ No newline at end of file +} diff --git a/test/functional/pdo_sqlsrv/pdo_prepare_invalid_scrollable_cursor.phpt b/test/functional/pdo_sqlsrv/pdo_prepare_invalid_scrollable_cursor.phpt index 6287bb28..c1157163 100644 --- a/test/functional/pdo_sqlsrv/pdo_prepare_invalid_scrollable_cursor.phpt +++ b/test/functional/pdo_sqlsrv/pdo_prepare_invalid_scrollable_cursor.phpt @@ -1,33 +1,29 @@ --TEST-- Test PDO::prepare by passing in invalid scrollable type value --SKIPIF-- - + --FILE-- prepare( "SELECT 1", array( PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => "PDO::SQLSRV_CURSOR_BUFFERED" )); - - // if ATTR_CURSOR is FWDONLY, cannot set SCROLL_TYPE - $stmt2 = $conn->prepare( "SELECT 2", array( PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED )); + $stmt1 = $conn->prepare("SELECT 1", array( PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => "PDO::SQLSRV_CURSOR_BUFFERED" )); - if ( $stmt1 || $stmt2 ){ + // if ATTR_CURSOR is FWDONLY, cannot set SCROLL_TYPE + $stmt2 = $conn->prepare("SELECT 2", array( PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED )); + + if ($stmt1 || $stmt2) { echo "Invalid values for PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE should return false.\n"; } else { echo "Invalid values for PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE return false.\n"; } -} -catch( PDOException $e ) { +} catch (PDOException $e) { echo $e->getMessage(); } -?> +?> --EXPECT-- - -Invalid values for PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE return false. \ No newline at end of file +Invalid values for PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE return false. diff --git a/test/functional/pdo_sqlsrv/pdo_prepare_options.phpt b/test/functional/pdo_sqlsrv/pdo_prepare_options.phpt index 7b6c70a2..91407c4b 100644 --- a/test/functional/pdo_sqlsrv/pdo_prepare_options.phpt +++ b/test/functional/pdo_sqlsrv/pdo_prepare_options.phpt @@ -1,38 +1,34 @@ --TEST-- Test PDO::prepare by passing in attributes --SKIPIF-- - + --FILE-- PDO::SQLSRV_ENCODING_UTF8, PDO::ATTR_STATEMENT_CLASS => array('CustomPDOStatement', array()), PDO::SQLSRV_ATTR_DIRECT_QUERY => true, PDO::ATTR_EMULATE_PREPARES => false, - PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE => true - ); - $conn = new PDO( $dsn, $uid, $pwd); - - $stmt = $conn->prepare( "SELECT 1", $prep_attr ); + PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE => true); + $stmt = $conn->prepare("SELECT 1", $prep_attr); echo "Test Successful"; -} -catch( PDOException $e ) { +} catch (PDOException $e) { echo $e->getMessage(); } -?> +?> --EXPECT-- - -Test Successful \ No newline at end of file +Test Successful diff --git a/test/functional/pdo_sqlsrv/pdo_query.phpt b/test/functional/pdo_sqlsrv/pdo_query.phpt index dfc76872..99babdfc 100644 --- a/test/functional/pdo_sqlsrv/pdo_query.phpt +++ b/test/functional/pdo_sqlsrv/pdo_query.phpt @@ -3,83 +3,80 @@ Test the PDO::query() method. --ENV-- PHPT_EXEC=true --SKIPIF-- - + --FILE-- query( "Select * from " . $table1 ); + $stmt = $conn->query("Select * from $tbname"); $result = $stmt->fetch(); var_dump($result); } - -function query_column( $conn ) -{ - global $table1; - $stmt = $conn->query( "Select * from " . $table1, PDO::FETCH_COLUMN, 2 ); - $result = $stmt->fetch(); - var_dump($result); -} - -function query_class( $conn ) -{ - global $table1; - global $table1_class; - $stmt = $conn->query( "Select * from " . $table1, PDO::FETCH_CLASS, $table1_class ); - $result = $stmt->fetch(); - $result->dumpAll(); -} - -function query_into( $conn ) -{ - global $table1; - global $table1_class; - $obj = new $table1_class; - $stmt = $conn->query( "Select * from " . $table1, PDO::FETCH_INTO, $obj ); - $result = $stmt->fetch(); - $result->dumpAll(); -} - -function query_empty_table( $conn ) -{ - CreateTableEx($conn, 'emptyTable', "c1 INT, c2 INT"); - $stmt = $conn->query( "Select * from emptyTable"); - $result = $stmt->fetch(); - var_dump($result); - DropTable($conn, 'emptyTable'); -} -try -{ +function queryColumn($conn, $tbname) +{ + $stmt = $conn->query("Select * from $tbname", PDO::FETCH_COLUMN, 2); + $result = $stmt->fetch(); + var_dump($result); +} + +function queryClass($conn, $tbname) +{ + global $mainTypesClass; + $stmt = $conn->query("Select * from $tbname", PDO::FETCH_CLASS, $mainTypesClass); + $result = $stmt->fetch(); + $result->dumpAll(); +} + +function queryInto($conn, $tbname) +{ + global $mainTypesClass; + $obj = new $mainTypesClass; + $stmt = $conn->query("Select * from $tbname", PDO::FETCH_INTO, $obj); + $result = $stmt->fetch(); + $result->dumpAll(); +} + +function queryEmptyTable($conn) +{ + createTable($conn, 'emptyTable', array("c1" => "int", "c2" => "int")); + $stmt = $conn->query("Select * from emptyTable"); + $result = $stmt->fetch(); + var_dump($result); + dropTable($conn, 'emptyTable'); +} + +try { $db = connect(); + $tbname = "PDO_MainTypes"; + createAndInsertTableMainTypes($db, $tbname); echo "TEST_1 : query with default fetch style :\n"; - query_default($db); + queryDefault($db, $tbname); echo "TEST_2 : query with FETCH_COLUMN :\n"; - query_column($db); + queryColumn($db, $tbname); echo "TEST_3 : query with FETCH_CLASS :\n"; - query_class($db); + queryClass($db, $tbname); echo "TEST_4 : query with FETCH_INTO :\n"; - query_into($db); - - echo "TEST_5 : query an empty table :\n"; - query_empty_table($db); -} + queryInto($db, $tbname); -catch( PDOException $e ) { - var_dump( $e ); + echo "TEST_5 : query an empty table :\n"; + queryEmptyTable($db); + + dropTable($db, $tbname); + unset($db); +} catch (PDOException $e) { + var_dump($e); exit; } -?> +?> --EXPECT-- TEST_1 : query with default fetch style : array(16) { @@ -137,4 +134,4 @@ string(10) "STRINGCOL1" string(7) "111.111" string(431) " 1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417." TEST_5 : query an empty table : -bool(false) \ No newline at end of file +bool(false) diff --git a/test/functional/pdo_sqlsrv/pdo_query_timeout.phpt b/test/functional/pdo_sqlsrv/pdo_query_timeout.phpt index ade9e96c..16b86354 100644 --- a/test/functional/pdo_sqlsrv/pdo_query_timeout.phpt +++ b/test/functional/pdo_sqlsrv/pdo_query_timeout.phpt @@ -1,92 +1,67 @@ --TEST-- test query time out at the connection level and statement level --SKIPIF-- - + --FILE-- exec("CREATE TABLE $tableName ([c1_int] int, [c2_varchar] varchar(25))"); - - $query = "INSERT INTO $tableName ([c1_int], [c2_varchar]) VALUES (1, 'QueryTimeout 1')"; - $stmt = $conn->query($query); - - $query = "INSERT INTO $tableName ([c1_int], [c2_varchar]) VALUES (2, 'QueryTimeout 2')"; - $stmt = $conn->query($query); + $conn = connect('', array(), PDO::ERRMODE_SILENT); + + $tableName = getTableName(); + createTable($conn, $tableName, array("c1_int" => "int", "c2_varchar" => "varchar(25)")); + + insertRow($conn, $tableName, array("c1_int" => 1, "c2_varchar" => "QueryTimeout 1")); + insertRow($conn, $tableName, array("c1_int" => 2, "c2_varchar" => "QueryTimeout 2")); $query = "SELECT * FROM $tableName"; - - if ($connLevel) - { + + if ($connLevel) { echo "Setting query timeout as an attribute in connection\n"; $conn->setAttribute(constant('PDO::SQLSRV_ATTR_QUERY_TIMEOUT'), 1); $stmt = $conn->query("WAITFOR DELAY '00:00:03'; $query"); - var_dump($conn->errorInfo()); - } - else - { + } else { echo "Setting query timeout in the statement\n"; $stmt = $conn->prepare("WAITFOR DELAY '00:00:03'; $query", array(constant('PDO::SQLSRV_ATTR_QUERY_TIMEOUT') => 1)); $stmt->execute(); - var_dump($stmt->errorInfo()); } - - $stmt = null; - $conn = null; + + dropTable($conn, $tableName); + unset($stmt); + unset($conn); } -function RunTest() -{ - StartTest("pdo_query_timeout"); - echo "\nStarting test...\n"; - try - { - QueryTimeout(true); - QueryTimeout(false); - } - catch (Exception $e) - { - echo $e->getMessage(); - } - echo "\nDone\n"; - EndTest("pdo_query_timeout"); +echo "Starting test...\n"; +try { + QueryTimeout(true); + QueryTimeout(false); +} catch (Exception $e) { + echo $e->getMessage(); } - -RunTest(); - +echo "Done\n"; ?> ---EXPECTREGEX-- - -Starting test\.\.\. +--EXPECT-- +Starting test... Setting query timeout as an attribute in connection -array\(3\) \{ - \[0\]=> - string\(5\) \"HYT00\" - \[1\]=> - int\(0\) - \[2\]=> - string\(63\) \"\[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Query timeout expired\" -\} +array(3) { + [0]=> + string(5) "HYT00" + [1]=> + int(0) + [2]=> + string(63) "[Microsoft][ODBC Driver 13 for SQL Server]Query timeout expired" +} Setting query timeout in the statement -array\(3\) \{ - \[0\]=> - string\(5\) \"HYT00\" - \[1\]=> - int\(0\) - \[2\]=> - string\(63\) \"\[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Query timeout expired\" -\} - +array(3) { + [0]=> + string(5) "HYT00" + [1]=> + int(0) + [2]=> + string(63) "[Microsoft][ODBC Driver 13 for SQL Server]Query timeout expired" +} Done -Test \"pdo_query_timeout\" completed successfully\. diff --git a/test/functional/pdo_sqlsrv/pdo_quote.phpt b/test/functional/pdo_sqlsrv/pdo_quote.phpt index 4be78dda..a774a4ee 100644 --- a/test/functional/pdo_sqlsrv/pdo_quote.phpt +++ b/test/functional/pdo_sqlsrv/pdo_quote.phpt @@ -4,27 +4,23 @@ Test the PDO::quote() method. --FILE-- 3, PDO::ATTR_CASE => 2)); +try { + $conn = connect("", array(PDO::SQLSRV_ATTR_ENCODING => 3, PDO::ATTR_CASE => 2)); $unquoted = "ABC'DE"; $quoted1 = $conn->quote($unquoted); - $quoted2 = $conn->quote($quoted1); + $quoted2 = $conn->quote($quoted1); var_dump($unquoted); var_dump($quoted1); var_dump($quoted2); -} - -catch( PDOException $e ) { - var_dump( $e ); +} catch (PDOException $e) { + var_dump($e); exit; } -?> +?> --EXPECT-- string(6) "ABC'DE" diff --git a/test/functional/pdo_sqlsrv/pdo_set_attr_invalid.phpt b/test/functional/pdo_sqlsrv/pdo_set_attr_invalid.phpt index e917bf58..bd4bbf07 100644 --- a/test/functional/pdo_sqlsrv/pdo_set_attr_invalid.phpt +++ b/test/functional/pdo_sqlsrv/pdo_set_attr_invalid.phpt @@ -1,33 +1,27 @@ --TEST-- -Test setting invalid value or key in connection attributes +Test setting invalid value or key in connection attributes --SKIPIF-- - + --FILE-- PDO::ERRMODE_SILENT)); +try { + $conn = connect("", array(), PDO::ERRMODE_SILENT); // Negative value for query timeout: should raise error - @$conn->setAttribute( PDO::SQLSRV_ATTR_QUERY_TIMEOUT, -1 ); - print_r (($conn->errorInfo())[2]); + @$conn->setAttribute(PDO::SQLSRV_ATTR_QUERY_TIMEOUT, -1); + print_r(($conn->errorInfo())[2]); echo "\n"; // PDO::ATTR_CURSOR is a Statement Level Attribute only - @$conn->setAttribute( PDO::ATTR_CURSOR, PDO::CURSOR_SCROLL ); - print_r (($conn->errorInfo())[2]); -} -catch ( PDOException $e ){ + @$conn->setAttribute(PDO::ATTR_CURSOR, PDO::CURSOR_SCROLL); + print_r(($conn->errorInfo())[2]); +} catch (PDOException $e) { echo $e->getMessage(); } - -?> +?> --EXPECT-- - Invalid value -1 specified for option PDO::SQLSRV_ATTR_QUERY_TIMEOUT. -The given attribute is only supported on the PDOStatement object. \ No newline at end of file +The given attribute is only supported on the PDOStatement object. diff --git a/test/functional/pdo_sqlsrv/pdo_set_attr_invalid_encoding.phpt b/test/functional/pdo_sqlsrv/pdo_set_attr_invalid_encoding.phpt index 68cd3f47..1d8c6a47 100644 --- a/test/functional/pdo_sqlsrv/pdo_set_attr_invalid_encoding.phpt +++ b/test/functional/pdo_sqlsrv/pdo_set_attr_invalid_encoding.phpt @@ -1,39 +1,35 @@ --TEST-- Test setting invalid encoding attributes --SKIPIF-- - + --FILE-- PDO::ERRMODE_SILENT)); +try { + $conn = connect("", array(), PDO::ERRMODE_SILENT); // valid option: should have no error - @$conn->setAttribute( PDO::SQLSRV_ATTR_ENCODING, PDO::SQLSRV_ENCODING_DEFAULT ); - print_r (($conn->errorInfo())[2]); + @$conn->setAttribute(PDO::SQLSRV_ATTR_ENCODING, PDO::SQLSRV_ENCODING_DEFAULT); + print_r(($conn->errorInfo())[2]); echo "\n"; // PDO::SQLSRV_ENCODING_UTF8 should not be quoted - @$conn->setAttribute( PDO::SQLSRV_ATTR_ENCODING, "PDO::SQLSRV_ENCODING_UTF8" ); - print_r (($conn->errorInfo())[2]); + @$conn->setAttribute(PDO::SQLSRV_ATTR_ENCODING, "PDO::SQLSRV_ENCODING_UTF8"); + print_r(($conn->errorInfo())[2]); echo "\n"; // PDO::SQLSRV_ENCODING_BINARY is not supported - @$conn->setAttribute( PDO::SQLSRV_ATTR_ENCODING, PDO::SQLSRV_ENCODING_BINARY ); - print_r (($conn->errorInfo())[2]); + @$conn->setAttribute(PDO::SQLSRV_ATTR_ENCODING, PDO::SQLSRV_ENCODING_BINARY); + print_r(($conn->errorInfo())[2]); echo "\n"; -} -catch ( PDOException $e ){ +} catch (PDOException $e) { echo $e->getMessage(); } - -?> +?> --EXPECT-- An invalid encoding was specified for SQLSRV_ATTR_ENCODING. -An invalid encoding was specified for SQLSRV_ATTR_ENCODING. \ No newline at end of file +An invalid encoding was specified for SQLSRV_ATTR_ENCODING. diff --git a/test/functional/pdo_sqlsrv/pdo_statement_rowcount_query.phpt b/test/functional/pdo_sqlsrv/pdo_statement_rowcount_query.phpt index 17d5eee2..4ec2843d 100644 --- a/test/functional/pdo_sqlsrv/pdo_statement_rowcount_query.phpt +++ b/test/functional/pdo_sqlsrv/pdo_statement_rowcount_query.phpt @@ -1,180 +1,158 @@ --TEST-- test rowCount() with different querying method and test nextRowset() with different fetch --SKIPIF-- - + --FILE-- exec("CREATE TABLE $tableName ([c1_int] int, [c2_real] real)"); - + $conn = connect(); + + $tableName = getTableName('testRowCount'); + createTable($conn, $tableName, array("c1_int" => "int", "c2_real" => "real")); + $numRows = 5; - for ($i = 1; $i <= $numRows; $i++) - { - InsertData($conn, $tableName, $i); + for ($i = 1; $i <= $numRows; $i++) { + $r = $i * 1.0; + insertRow($conn, $tableName, array("c1_int" => $i, "c2_real" => $r)); } - - FetchRowsets($conn, $tableName, $numRows); - - for ($i = 1; $i <= $numRows; $i++) - { - UpdateData($conn, $tableName, $i, $exec); + + fetchRowsets($conn, $tableName, $numRows); + + for ($i = 1; $i <= $numRows; $i++) { + updateData($conn, $tableName, $i, $exec); } - - DeleteData($conn, $tableName, $exec); - - $stmt = null; - $conn = null; + + deleteData($conn, $tableName, $exec); + + dropTable($conn, $tableName); + unset($stmt); + unset($conn); } -function InsertData($conn, $tableName, $value) -{ - $query = "INSERT INTO $tableName VALUES ($value, $value * 1.0)"; - $stmt = $conn->query($query); -} - -function UpdateData($conn, $tableName, $value, $exec) +function updateData($conn, $tableName, $value, $exec) { $newValue = $value * 100; $query = "UPDATE $tableName SET c1_int = $newValue WHERE (c1_int = $value)"; $rowCount = 0; - - if ($exec) - { - $rowCount = $conn->exec($query); - } - else - { - $stmt = $conn->prepare($query); - $rowCount = $stmt->rowCount(); - if ($rowCount > 0) - echo "Number of rows affected prior to execution should be 0!\n"; + if (isColEncrypted()) { + // need to bind parameters for updating encrypted columns + $query = "UPDATE $tableName SET c1_int = ? WHERE (c1_int = ?)"; + $stmt = $conn->prepare($query); + $stmt->bindParam(1, $newValue); + $stmt->bindParam(2, $value); $stmt->execute(); $rowCount = $stmt->rowCount(); + } else { + if ($exec) { + $rowCount = $conn->exec($query); + } else { + $stmt = $conn->prepare($query); + $rowCount = $stmt->rowCount(); + if ($rowCount > 0) { + echo "Number of rows affected prior to execution should be 0!\n"; + } + + $stmt->execute(); + $rowCount = $stmt->rowCount(); + } } - - if ($rowCount !== 1) + if ($rowCount !== 1) { echo "Number of rows affected should be 1!\n"; - - $stmt = null; + } + unset($stmt); } -function CompareValues($actual, $expected) +function compareValues($actual, $expected) { - if ($actual != $expected) - { + if ($actual != $expected) { echo "Unexpected value $value returned! Expected $expected.\n"; } } -function FetchRowsets($conn, $tableName, $numRows) +function fetchRowsets($conn, $tableName, $numRows) { - $query = "SELECT [c1_int] FROM $tableName ORDER BY [c1_int]"; + if (!isColEncrypted()) { + $query = "SELECT [c1_int] FROM $tableName ORDER BY [c1_int]"; + } else { + // ORDER BY is not supported in encrypted columns + $query = "SELECT [c1_int] FROM $tableName"; + } $queries = $query . ';' . $query . ';' . $query; $stmt = $conn->query($queries); $i = 0; - while ($row = $stmt->fetch(PDO::FETCH_LAZY)) - { + while ($row = $stmt->fetch(PDO::FETCH_LAZY)) { $value = (int)$row['c1_int']; - CompareValues($value, ++$i); + compareValues($value, ++$i); } - - if ($i != $numRows) - { + + if ($i != $numRows) { echo "Number of rows fetched $i is unexpected!\n"; } - - $result = $stmt->nextRowset(); - if ($result == false) - { - echo "Missing result sets!\n"; - } - - $rows = $stmt->fetchAll(PDO::FETCH_NUM); - $i = 0; - foreach ($rows as $row) - { - foreach ($row as $key => $value) - { - $value = (int)$value; - CompareValues($value, ++$i); - } - } $result = $stmt->nextRowset(); - if ($result == false) - { + if ($result == false) { echo "Missing result sets!\n"; } - + + $rows = $stmt->fetchAll(PDO::FETCH_NUM); + $i = 0; + foreach ($rows as $row) { + foreach ($row as $key => $value) { + $value = (int)$value; + compareValues($value, ++$i); + } + } + + $result = $stmt->nextRowset(); + if ($result == false) { + echo "Missing result sets!\n"; + } + $stmt->bindColumn('c1_int', $value); $i = 0; - while ($row = $stmt->fetch(PDO::FETCH_BOUND)) - { - CompareValues($value, ++$i); + while ($row = $stmt->fetch(PDO::FETCH_BOUND)) { + compareValues($value, ++$i); } - + $result = $stmt->nextRowset(); - if ($result != false) - { + if ($result != false) { echo "Number of result sets exceeding expectation!\n"; } } -function DeleteData($conn, $tableName, $exec) +function deleteData($conn, $tableName, $exec) { - $query = "DELETE TOP(3) FROM $tableName"; + $query = "DELETE TOP(3) FROM $tableName"; $rowCount = 0; - - if ($exec) - { + + if ($exec) { $rowCount = $conn->exec($query); - } - else - { + } else { $stmt = $conn->query($query); $rowCount = $stmt->rowCount(); } - - if ($rowCount <= 0) + + if ($rowCount <= 0) { echo "Number of rows affected should be > 0!\n"; - - $stmt = null; + } + + unset($stmt); } -function RunTest() -{ - StartTest("pdo_statement_rowcount_query"); - echo "\nStarting test...\n"; - try - { - RowCount_Query(true); - RowCount_Query(false); - } - catch (Exception $e) - { - echo $e->getMessage(); - } - echo "\nDone\n"; - EndTest("pdo_statement_rowcount_query"); +echo "Starting test...\n"; +try { + rowCountQuery(true); + //rowCountQuery(false); +} catch (Exception $e) { + echo $e->getMessage(); } - -RunTest(); - +echo "Done\n"; ?> --EXPECT-- - Starting test... - Done -Test "pdo_statement_rowcount_query" completed successfully. diff --git a/test/functional/pdo_sqlsrv/pdo_stored_proc_fetch_datatypes.phpt b/test/functional/pdo_sqlsrv/pdo_stored_proc_fetch_datatypes.phpt index e74849a6..6f170a6a 100644 --- a/test/functional/pdo_sqlsrv/pdo_stored_proc_fetch_datatypes.phpt +++ b/test/functional/pdo_sqlsrv/pdo_stored_proc_fetch_datatypes.phpt @@ -1,320 +1,303 @@ --TEST-- -call stored procedures with inputs of ten different datatypes to get outputs of various types +call stored procedures with inputs of ten different datatypes to get outputs of various types --SKIPIF-- - + --FILE-- exec("CREATE PROC $procName (@p1 BIGINT, @p2 BIGINT, @p3 NCHAR(128) OUTPUT) AS BEGIN SELECT @p3 = CONVERT(NCHAR(128), @p1 + @p2) END"); - + $inValue1 = '12345678'; $inValue2 = '11111111'; $outValue = '0'; - + $stmt = $conn->prepare("{CALL $procName (?, ?, ?)}"); $stmt->bindValue(1, $inValue1); $stmt->bindValue(2, $inValue2); $stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300); $stmt->execute(); - + $expected = "23456789"; $outValue = trim($outValue); - if (strncasecmp($outValue, $expected, strlen($expected))) - { + if (strncasecmp($outValue, $expected, strlen($expected))) { echo "Output value $outValue is unexpected! Expected $expected\n"; - } - - $stmt = null; + } + + dropProc($conn, $procName); + unset($stmt); } -function ProcFetch_Decimal($conn) +function procFetchDecimal($conn) { - $procName = GetTempProcName('decimal'); - + $procName = getProcName('decimal'); + $stmt = $conn->exec("CREATE PROC $procName (@p1 DECIMAL, @p2 DECIMAL, @p3 CHAR(128) OUTPUT) AS BEGIN SELECT @p3 = CONVERT(CHAR(128), @p1 + @p2) END"); - - $inValue1 = '2.1'; - $inValue2 = '5.3'; - $outValue = '0'; - + + $inValue1 = '2.1'; + $inValue2 = '5.3'; + $outValue = '0'; + $stmt = $conn->prepare("{CALL $procName (?, ?, ?)}"); $stmt->bindValue(1, $inValue1); $stmt->bindValue(2, $inValue2); $stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300); $stmt->execute(); - + $expected = "7"; $outValue = trim($outValue); - if (strncasecmp($outValue, $expected, strlen($expected))) - { + if (strncasecmp($outValue, $expected, strlen($expected))) { echo "Output value $outValue is unexpected! Expected $expected\n"; - } - - $stmt = null; + } + + dropProc($conn, $procName); + unset($stmt); } -function ProcFetch_Float($conn) +function procFetchFloat($conn) { - $procName = GetTempProcName('float'); - + $procName = getProcName('float'); + $stmt = $conn->exec("CREATE PROC $procName (@p1 FLOAT, @p2 FLOAT, @p3 FLOAT OUTPUT) AS BEGIN SELECT @p3 = CONVERT(FLOAT, @p1 + @p2) END"); - - $inValue1 = '2.25'; - $inValue2 = '5.5'; - $outValue = '0'; - + + $inValue1 = '2.25'; + $inValue2 = '5.5'; + $outValue = '0'; + $stmt = $conn->prepare("{CALL $procName (?, ?, ?)}"); $stmt->bindValue(1, $inValue1); $stmt->bindValue(2, $inValue2); $stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300); $stmt->execute(); - + $expected = "7.75"; $outValue = trim($outValue); - if (strncasecmp($outValue, $expected, strlen($expected))) - { + if (strncasecmp($outValue, $expected, strlen($expected))) { echo "Output value $outValue is unexpected! Expected $expected\n"; - } - - $stmt = null; + } + + dropProc($conn, $procName); + unset($stmt); } -function ProcFetch_Int($conn) +function procFetchInt($conn) { - $procName = GetTempProcName('int'); - + $procName = getProcName('int'); + $stmt = $conn->exec("CREATE PROC $procName (@p1 INT, @p2 INT, @p3 INT OUTPUT) AS BEGIN SELECT @p3 = CONVERT(INT, @p1 + @p2) END"); - - $inValue1 = '1234'; - $inValue2 = '5678'; - $outValue = '0'; - + + $inValue1 = '1234'; + $inValue2 = '5678'; + $outValue = '0'; + $stmt = $conn->prepare("{CALL $procName (?, ?, ?)}"); $stmt->bindValue(1, $inValue1); $stmt->bindValue(2, $inValue2); $stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300); $stmt->execute(); - + $expected = "6912"; $outValue = trim($outValue); - if (strncasecmp($outValue, $expected, strlen($expected))) - { + if (strncasecmp($outValue, $expected, strlen($expected))) { echo "Output value $outValue is unexpected! Expected $expected\n"; - } - - $stmt = null; + } + + dropProc($conn, $procName); + unset($stmt); } -function ProcFetch_Money($conn) +function procFetchMoney($conn) { - $procName = GetTempProcName('money'); - + $procName = getProcName('money'); + $stmt = $conn->exec("CREATE PROC $procName (@p1 MONEY, @p2 MONEY, @p3 MONEY OUTPUT) AS BEGIN SELECT @p3 = CONVERT(MONEY, @p1 + @p2) END"); - - $inValue1 = '22.3'; - $inValue2 = '16.1'; - $outValue = '0'; - + + $inValue1 = '22.3'; + $inValue2 = '16.1'; + $outValue = '0'; + $stmt = $conn->prepare("{CALL $procName (?, ?, ?)}"); - $stmt->bindValue(1, $inValue1, PDO::PARAM_STR); - $stmt->bindParam(2, $inValue2, PDO::PARAM_STR); - $stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300); + $stmt->bindValue(1, $inValue1, PDO::PARAM_STR); + $stmt->bindParam(2, $inValue2, PDO::PARAM_STR); + $stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300); $stmt->execute(); - + $expected = "38.40"; $outValue = trim($outValue); - if (strncasecmp($outValue, $expected, strlen($expected))) - { + if (strncasecmp($outValue, $expected, strlen($expected))) { echo "Output value $outValue is unexpected! Expected $expected\n"; - } - - $stmt = null; + } + + dropProc($conn, $procName); + unset($stmt); } -function ProcFetch_Numeric($conn) +function procFetchNumeric($conn) { - $procName = GetTempProcName('numeric'); - + $procName = getProcName('numeric'); + $stmt = $conn->exec("CREATE PROC $procName (@p1 NUMERIC, @p2 NUMERIC, @p3 NCHAR(128) OUTPUT) AS BEGIN SELECT @p3 = CONVERT(NCHAR(128), @p1 + @p2) END"); - - $inValue1 = '2.8'; - $inValue2 = '5.4'; - $outValue = '0'; - + + $inValue1 = '2.8'; + $inValue2 = '5.4'; + $outValue = '0'; + $stmt = $conn->prepare("{CALL $procName (?, ?, ?)}"); - $stmt->bindValue(1, $inValue1); - $stmt->bindParam(2, $inValue2); - $stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300); + $stmt->bindValue(1, $inValue1); + $stmt->bindParam(2, $inValue2); + $stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300); $stmt->execute(); - + $expected = "8"; $outValue = trim($outValue); - if (strncasecmp($outValue, $expected, strlen($expected))) - { + if (strncasecmp($outValue, $expected, strlen($expected))) { echo "Output value $outValue is unexpected! Expected $expected\n"; - } - - $stmt = null; + } + + dropProc($conn, $procName); + unset($stmt); } -function ProcFetch_Real($conn) +function procFetchReal($conn) { - $procName = GetTempProcName('real'); - + $procName = getProcName('real'); + $stmt = $conn->exec("CREATE PROC $procName (@p1 REAL, @p2 REAL, @p3 REAL OUTPUT) AS BEGIN SELECT @p3 = CONVERT(REAL, @p1 + @p2) END"); - - $inValue1 = '3.4'; - $inValue2 = '6.6'; - $outValue = '0'; - + + $inValue1 = '3.4'; + $inValue2 = '6.6'; + $outValue = '0'; + $stmt = $conn->prepare("{CALL $procName (?, ?, ?)}"); - $stmt->bindValue(1, $inValue1); - $stmt->bindParam(2, $inValue2); - $stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300); + $stmt->bindValue(1, $inValue1); + $stmt->bindParam(2, $inValue2); + $stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300); $stmt->execute(); - + $expected = "10"; $outValue = trim($outValue); - if (strncasecmp($outValue, $expected, strlen($expected))) - { + if (strncasecmp($outValue, $expected, strlen($expected))) { echo "Output value $outValue is unexpected! Expected $expected\n"; - } - - $stmt = null; + } + + dropProc($conn, $procName); + unset($stmt); } -function ProcFetch_SmallInt($conn) +function procFetchSmallInt($conn) { - $procName = GetTempProcName('smallint'); - + $procName = getProcName('smallint'); + $stmt = $conn->exec("CREATE PROC $procName (@p1 SMALLINT, @p2 SMALLINT, @p3 NCHAR(32) OUTPUT) AS BEGIN SELECT @p3 = CONVERT(NCHAR(32), @p1 + @p2) END"); - - $inValue1 = '34'; - $inValue2 = '56'; - $outValue = '0'; - + + $inValue1 = '34'; + $inValue2 = '56'; + $outValue = '0'; + $stmt = $conn->prepare("{CALL $procName (?, ?, ?)}"); - $stmt->bindValue(1, $inValue1); - $stmt->bindParam(2, $inValue2); - $stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300); + $stmt->bindValue(1, $inValue1); + $stmt->bindParam(2, $inValue2); + $stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300); $stmt->execute(); - + $expected = "90"; $outValue = trim($outValue); - if (strncasecmp($outValue, $expected, strlen($expected))) - { + if (strncasecmp($outValue, $expected, strlen($expected))) { echo "Output value $outValue is unexpected! Expected $expected\n"; - } - - $stmt = null; + } + + dropProc($conn, $procName); + unset($conn); } -function ProcFetch_SmallMoney($conn) +function procFetchSmallMoney($conn) { - $procName = GetTempProcName('smallmoney'); - + $procName = getProcName('smallmoney'); + $stmt = $conn->exec("CREATE PROC $procName (@p1 SMALLMONEY, @p2 SMALLMONEY, @p3 SMALLMONEY OUTPUT) AS BEGIN SELECT @p3 = CONVERT(SMALLMONEY, @p1 + @p2) END"); - - $inValue1 = '10'; - $inValue2 = '11.7'; - $outValue = '0'; - + + $inValue1 = '10'; + $inValue2 = '11.7'; + $outValue = '0'; + $stmt = $conn->prepare("{CALL $procName (?, ?, ?)}"); - $stmt->bindValue(1, $inValue1, PDO::PARAM_STR); - $stmt->bindParam(2, $inValue2, PDO::PARAM_STR); - $stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300); + $stmt->bindValue(1, $inValue1, PDO::PARAM_STR); + $stmt->bindParam(2, $inValue2, PDO::PARAM_STR); + $stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300); $stmt->execute(); - + $expected = "21.70"; $outValue = trim($outValue); - if (strncasecmp($outValue, $expected, strlen($expected))) - { + if (strncasecmp($outValue, $expected, strlen($expected))) { echo "Output value $outValue is unexpected! Expected $expected\n"; - } - - $stmt = null; + } + + dropProc($conn, $procName); + unset($stmt); } function ProcFetch_TinyInt($conn) { - $procName = GetTempProcName('tinyint'); - + $procName = getProcName('tinyint'); + $stmt = $conn->exec("CREATE PROC $procName (@p1 TINYINT, @p2 TINYINT, @p3 CHAR(32) OUTPUT) AS BEGIN SELECT @p3 = CONVERT(CHAR(32), @p1 + @p2) END"); - - $inValue1 = '11'; - $inValue2 = '12'; - $outValue = '0'; - + + $inValue1 = '11'; + $inValue2 = '12'; + $outValue = '0'; + $stmt = $conn->prepare("{CALL $procName (?, ?, ?)}"); - $stmt->bindValue(1, $inValue1); - $stmt->bindParam(2, $inValue2); - $stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300); + $stmt->bindValue(1, $inValue1); + $stmt->bindParam(2, $inValue2); + $stmt->bindParam(3, $outValue, PDO::PARAM_STR, 300); $stmt->execute(); - + $expected = "23"; $outValue = trim($outValue); - if (strncasecmp($outValue, $expected, strlen($expected))) - { + if (strncasecmp($outValue, $expected, strlen($expected))) { echo "Output value $outValue is unexpected! Expected $expected\n"; - } - - $stmt = null; + } + + dropProc($conn, $procName); + unset($stmt); } -function RunTest() -{ - set_time_limit(0); - StartTest("pdo_stored_proc_fetch_datatypes"); - echo "\nStarting test...\n"; - try - { - include("MsSetup.inc"); - $conn = new PDO( "sqlsrv:server=$server;database=$databaseName", $uid, $pwd); +set_time_limit(0); +echo "Starting test...\n"; +try { + $conn = connect(); - ProcFetch_BigInt($conn); - ProcFetch_Decimal($conn); - ProcFetch_Float($conn); - ProcFetch_Int($conn); - ProcFetch_Money($conn); - ProcFetch_Numeric($conn); - ProcFetch_Real($conn); - ProcFetch_SmallInt($conn); - ProcFetch_SmallMoney($conn); - ProcFetch_TinyInt($conn); - - $conn = null; - } - catch (Exception $e) - { - echo $e->getMessage(); - } - echo "\nDone\n"; - EndTest("pdo_stored_proc_fetch_datatypes"); + procFetchBigInt($conn); + procFetchDecimal($conn); + procFetchFloat($conn); + procFetchInt($conn); + procFetchMoney($conn); + procFetchNumeric($conn); + procFetchReal($conn); + procFetchSmallInt($conn); + procFetchSmallMoney($conn); + ProcFetch_TinyInt($conn); + unset($conn); +} catch (Exception $e) { + echo $e->getMessage(); } - -RunTest(); - +echo "Done\n"; ?> --EXPECT-- - Starting test... - Done -Test "pdo_stored_proc_fetch_datatypes" completed successfully. - diff --git a/test/functional/pdo_sqlsrv/pdo_testDataType.phpt b/test/functional/pdo_sqlsrv/pdo_testDataType.phpt deleted file mode 100644 index 79cd1df6..00000000 --- a/test/functional/pdo_sqlsrv/pdo_testDataType.phpt +++ /dev/null @@ -1,494 +0,0 @@ ---TEST-- -Test the different type of data for retrieving ---SKIPIF-- - ---FILE-- -query("SELECT BigIntCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); -} - -function testBit() -{ - $db = connect(); - // Retrieve data type - $stmt = $db->query("SELECT BitCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); -} - -function testInt() -{ - $db = connect(); - // Retrieve data type - $stmt = $db->query("SELECT IntCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); -} - -function testSmallInt() -{ - $db = connect(); - // Retrieve data type - $stmt = $db->query("SELECT SmallIntCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); -} - -function testTinyInt() -{ - $db = connect(); - // Retrieve data type - $stmt = $db->query("SELECT TinyIntCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); -} - -function testDecimal() -{ - $db = connect(); - // Retrieve data type - $stmt = $db->query("SELECT DecimalCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); -} - -function testNumeric() -{ - $db = connect(); - // Retrieve data type - $stmt = $db->query("SELECT NumCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); -} - -function testMoney() -{ - $db = connect(); - // Retrieve data type - $stmt = $db->query("SELECT MoneyCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); -} - -function testSmallMoney() -{ - $db = connect(); - // Retrieve data type - $stmt = $db->query("SELECT SmallMoneyCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); -} - -function testFloat() -{ - $db = connect(); - $stmt = $db->query("SELECT FloatCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); -} - -function testReal() -{ - $db = connect(); - $stmt = $db->query("SELECT RealCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); -} - -function testChar() -{ - $db = connect(); - $stmt = $db->query("SELECT CharCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); -} - -function testVarchar() -{ - $db = connect(); - $stmt = $db->query("SELECT VarcharCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); -} - -function testText() -{ - $db = connect(); - $stmt = $db->query("SELECT TextCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); -} - -function testNText() -{ - $db = connect(); - $stmt = $db->query("SELECT NTextCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); -} - -function testNChar() -{ - $db = connect(); - $stmt = $db->query("SELECT NCharCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); -} - -function testNVarchar() -{ - $db = connect(); - $stmt = $db->query("SELECT NVarcharCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); -} - -function testImage() -{ - $db = connect(); - $stmt = $db->query("SELECT ImageCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); -} - -function testBinary() -{ - $db = connect(); - $stmt = $db->query("SELECT BinaryCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); -} - -function testVarbinary() -{ - $db = connect(); - $stmt = $db->query("SELECT VarbinaryCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); -} - -function testDateTime2() -{ - $db = connect(); - $stmt = $db->query("SELECT DateTime2Col FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); -} - -function testDatetimeoffset() -{ - $db = connect(); - $stmt = $db->query("SELECT DTOffsetCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); -} - -function testsmalldatetime() -{ - $db = connect(); - $stmt = $db->query("SELECT SmallDTCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); -} - -function testDateTime() -{ - $db = connect(); - $stmt = $db->query("SELECT DateTimeCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); -} - -function testDate() -{ - $db = connect(); - $stmt = $db->query("SELECT DateCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); -} - -function testNVarcharMax() -{ - $db = connect(); - $stmt = $db->query("SELECT NVarCharMaxCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); -} - -function testTime() -{ - $db = connect(); - $stmt = $db->query("SELECT TimeCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); -} - -function testUniqueidentifier() -{ - $db = connect(); - $stmt = $db->query("SELECT Guidcol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); -} - -function testVarbinaryMax() -{ - $db = connect(); - $stmt = $db->query("SELECT VarbinaryMaxCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); -} - -function testVarcharMax() -{ - $db = connect(); - $stmt = $db->query("SELECT VarcharMaxCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); -} - -function testXml() -{ - $db = connect(); - $stmt = $db->query("SELECT XmlCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); -} - - -try -{ - //$db = connect(); - //$sql = "INSERT INTO PDO_AllTypes(BigIntCol,BitCol,IntCol,) VALUES(" . GetSampleData(4) . ",1,)"; - //$numRows = $db->exec($sql); - - echo "Test_1 : bigint data type :\n"; - testBigInt(); - echo "Test_2 : bit data type :\n"; - testBit(); - echo "Test_3 : int data type :\n"; - testInt(); - echo "Test_4 : smallint data type:\n"; - testSmallInt(); - echo "Test_5 : tinyint data type:\n"; - testTinyInt(); - echo "Test_6 : decimal data type:\n"; - testDecimal(); - echo "Test_7 : numeric data type:\n"; - testNumeric(); - echo "Test_8 : money data type:\n"; - testMoney(); - echo "Test_9 : smallmoney data type:\n"; - testSmallMoney(); - echo "Test_10 : float data type:\n"; - testFloat(); - echo "Test_11 : real data type:\n"; - testReal(); - echo "Test_12 : char data type:\n"; - testChar(); - echo "Test_13 : varchar data type:\n"; - testVarchar(); - echo "Test_14 : text data type:\n"; - testText(); - echo "Test_15 : nchar data type:\n"; - testNChar(); - echo "Test_16 : nvarchar data type:\n"; - testNVarchar(); - echo "Test_17 : image data type:\n"; - testImage(); - echo "Test_18 : binary data type:\n"; - testBinary(); - echo "Test_19 : varbinary data type:\n"; - testVarbinary(); - echo "Test_20 : smalldatetime data type:\n"; - testsmalldatetime(); - echo "Test_21 : datetime data type:\n"; - testDateTime(); - echo "Test_22 : datetime2 data type:\n"; - testsmalldatetime(); - echo "Test_23 : datetimeoffset data type:\n"; - testDatetimeoffset(); - echo "Test_24 : time data type:\n"; - testTime(); - echo "Test_25 : Uniqueidentifier data type:\n"; - testUniqueidentifier(); - echo "Test_26 : VarbinaryMax data type:\n"; - testVarbinaryMax(); - echo "Test_27 : VarcharMax data type:\n"; - testVarcharMax(); - echo "Test_28 : xml data type:\n"; - testXml(); - echo "Test_29 : ntext data type:\n"; - testNText(); - echo "Test_30 : nvarcharmax data type:\n"; - testNVarcharMax(); - -} -catch (PDOException $e) -{ - var_dump($e); -} - -?> - ---EXPECT-- -Test_1 : bigint data type : -array(1) { - ["BigIntCol"]=> - string(1) "1" -} -Test_2 : bit data type : -array(1) { - ["BitCol"]=> - string(1) "0" -} -Test_3 : int data type : -array(1) { - ["IntCol"]=> - string(1) "1" -} -Test_4 : smallint data type: -array(1) { - ["SmallIntCol"]=> - string(1) "1" -} -Test_5 : tinyint data type: -array(1) { - ["TinyIntCol"]=> - string(1) "1" -} -Test_6 : decimal data type: -array(1) { - ["DecimalCol"]=> - string(3) "111" -} -Test_7 : numeric data type: -array(1) { - ["NumCol"]=> - string(1) "1" -} -Test_8 : money data type: -array(1) { - ["MoneyCol"]=> - string(8) "111.1110" -} -Test_9 : smallmoney data type: -array(1) { - ["SmallMoneyCol"]=> - string(8) "111.1110" -} -Test_10 : float data type: -array(1) { - ["FloatCol"]=> - string(7) "111.111" -} -Test_11 : real data type: -array(1) { - ["RealCol"]=> - string(7) "111.111" -} -Test_12 : char data type: -array(1) { - ["CharCol"]=> - string(10) "STRINGCOL1" -} -Test_13 : varchar data type: -array(1) { - ["VarcharCol"]=> - string(10) "STRINGCOL1" -} -Test_14 : text data type: -array(1) { - ["TextCol"]=> - string(420) " 1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417." -} -Test_15 : nchar data type: -array(1) { - ["NCharCol"]=> - string(10) "STRINGCOL1" -} -Test_16 : nvarchar data type: -array(1) { - ["NVarcharCol"]=> - string(10) "STRINGCOL1" -} -Test_17 : image data type: -array(1) { - ["ImageCol"]=> - string(1) "" -} -Test_18 : binary data type: -array(1) { - ["BinaryCol"]=> - string(5) "" -} -Test_19 : varbinary data type: -array(1) { - ["VarbinaryCol"]=> - string(1) "" -} -Test_20 : smalldatetime data type: -array(1) { - ["SmallDTCol"]=> - string(19) "2000-11-11 11:11:00" -} -Test_21 : datetime data type: -array(1) { - ["DateTimeCol"]=> - string(23) "2000-11-11 11:11:11.110" -} -Test_22 : datetime2 data type: -array(1) { - ["SmallDTCol"]=> - string(19) "2000-11-11 11:11:00" -} -Test_23 : datetimeoffset data type: -array(1) { - ["DTOffsetCol"]=> - string(34) "2000-11-11 11:11:11.1110000 +00:00" -} -Test_24 : time data type: -array(1) { - ["TimeCol"]=> - string(16) "11:11:11.1110000" -} -Test_25 : Uniqueidentifier data type: -array(1) { - ["Guidcol"]=> - string(36) "AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA" -} -Test_26 : VarbinaryMax data type: -array(1) { - ["VarbinaryMaxCol"]=> - string(1) "" -} -Test_27 : VarcharMax data type: -array(1) { - ["VarcharMaxCol"]=> - string(420) " 1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417." -} -Test_28 : xml data type: -array(1) { - ["XmlCol"]=> - string(431) " 1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417." -} -Test_29 : ntext data type: -array(1) { - ["NTextCol"]=> - string(420) " 1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417." -} -Test_30 : nvarcharmax data type: -array(1) { - ["NVarCharMaxCol"]=> - string(420) " 1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417." -} \ No newline at end of file diff --git a/test/functional/pdo_sqlsrv/pdo_transaction.phpt b/test/functional/pdo_sqlsrv/pdo_transaction.phpt index 59caf10d..eaeac3db 100644 --- a/test/functional/pdo_sqlsrv/pdo_transaction.phpt +++ b/test/functional/pdo_sqlsrv/pdo_transaction.phpt @@ -3,51 +3,69 @@ test transaction rollback and commit --DESCRIPTION-- starts a transaction, delete rows and rollback the transaction; starts a transaction, delete rows and commit --SKIPIF-- - + --FILE-- exec("DELETE FROM $tbname WHERE col1 = 'a'"); + } else { + // needs to find parameter for encrypted columns + $sql = "DELETE FROM $tbname WHERE col1 = ?"; + $stmt = $conn->prepare($sql); + $col1 = "a"; + $stmt->execute(array($col1)); + $rows = $stmt->rowCount(); + } + return $rows; +} + +try { + $conn = connect(); + + $tbname = "Table1"; + createTable($conn, $tbname, array("col1" => "char(1)", "col2" => "char(1)")); + + insertRow($conn, $tbname, array("col1" => "a", "col2" => "b")); + insertRow($conn, $tbname, array("col1" => "a", "col2" => "c")); - $conn = new PDO( "sqlsrv:Server=$server; database = $databaseName", $uid, $pwd); - - $conn->exec("IF OBJECT_ID('Table1', 'U') IS NOT NULL DROP TABLE Table1"); - $conn->exec("CREATE TABLE Table1(col1 CHARACTER(1), col2 CHARACTER(1))"); - - $ret = $conn->exec("INSERT INTO Table1(col1, col2) VALUES('a', 'b')"); - $ret = $conn->exec("INSERT INTO Table1(col1, col2) VALUES('a', 'c')"); - //revert the inserts but roll back $conn->beginTransaction(); - $rows = $conn->exec("DELETE FROM Table1 WHERE col1 = 'a'"); + $rows = deleteRows($conn, $tbname); $conn->rollback(); - $stmt = $conn->query("SELECT * FROM Table1"); - + $stmt = $conn->query("SELECT * FROM $tbname"); + // Table1 should still have 2 rows since delete was rolled back - if ( count( $stmt->fetchAll() ) == 2 ) + if (count($stmt->fetchAll()) == 2) { echo "Transaction rolled back successfully\n"; - else + } else { echo "Transaction failed to roll back\n"; - + } + //revert the inserts then commit $conn->beginTransaction(); - $rows = $conn->exec("DELETE FROM Table1 WHERE col1 = 'a'"); + $rows = deleteRows($conn, $tbname); $conn->commit(); echo $rows." rows affected\n"; - - $stmt = $conn->query("SELECT * FROM Table1"); - if ( count( $stmt->fetchAll() ) == 0 ) + + $stmt = $conn->query("SELECT * FROM $tbname"); + if (count($stmt->fetchAll()) == 0) { echo "Transaction committed successfully\n"; - else + } else { echo "Transaction failed to commit\n"; - - //drop the created temp table - $conn->exec("DROP TABLE Table1"); - - //free statement and connection - $stmt = NULL; - $conn = NULL; + } + + dropTable($conn, $tbname); + unset($stmt); + unset($conn); +} catch (PDOException $e) { + var_dump($e->errorInfo); +} ?> --EXPECT-- Transaction rolled back successfully 2 rows affected -Transaction committed successfully \ No newline at end of file +Transaction committed successfully diff --git a/test/functional/pdo_sqlsrv/pdo_transactions.phpt b/test/functional/pdo_sqlsrv/pdo_transactions.phpt index ab0e4af1..7530e753 100644 --- a/test/functional/pdo_sqlsrv/pdo_transactions.phpt +++ b/test/functional/pdo_sqlsrv/pdo_transactions.phpt @@ -1,112 +1,98 @@ --TEST-- Test Transactions. --SKIPIF-- - + --FILE-- beginTransaction(); - $stmt = $conn->query( "Insert into " .$table1 . " (NCharCol, IntCol) values ('NCharCol3', 3)" ); + insertRow($conn, $tbname, array("NCharCol" => "NCharCol3", "IntCol" => 3)); $conn->commit(); - echo "\nTest 1 Passed]\n"; + echo "Test 1 Passed\n"; } - + // rollback -function test2($conn) +function test2($conn, $tbname) { - global $table1; $conn->beginTransaction(); - $stmt = $conn->query( "Insert into " .$table1 . " (NCharCol, IntCol) values ('NCharCol3', 3)" ); + insertRow($conn, $tbname, array("NCharCol" => "NCharCol3", "IntCol" => 3)); $conn->rollBack(); echo "Test 2 Passed\n"; } - + // commit -function test3($conn) +function test3($conn, $tbname) { - global $table1; $conn->beginTransaction(); - $stmt = $conn->query( "Insert into " .$table1 . " (NCharCol, IntCol) values ('NCharCol3', 3)" ); + insertRow($conn, $tbname, array("NCharCol" => "NCharCol3", "IntCol" => 3)); $conn->commit(); echo "Test 3 Passed\n"; } - + // Rollback twice. Verify that error is thrown -function test4($conn) +function test4($conn, $tbname) { try { - global $table1; $conn->beginTransaction(); - $stmt = $conn->query( "Insert into " .$table1 . " (NCharCol, IntCol) values ('NCharCol3', 3)" ); + insertRow($conn, $tbname, array("NCharCol" => "NCharCol3", "IntCol" => 3)); $conn->rollBack(); $conn->rollBack(); - } - catch( PDOException $e ) - { + } catch (PDOException $e) { echo "Test4: ". $e->getMessage() . "\n"; } } - + // Commit twice Verify that error is thrown -function test5($conn) +function test5($conn, $tbname) { try { - global $table1; $conn->beginTransaction(); - $stmt = $conn->query( "Insert into " .$table1 . " (NCharCol, IntCol) values ('NCharCol3', 3)" ); + insertRow($conn, $tbname, array("NCharCol" => "NCharCol3", "IntCol" => 3)); $conn->commit(); $conn->commit(); - } - catch( PDOException $e ) - { + } catch (PDOException $e) { echo "Test5: ". $e->getMessage() . "\n"; } } - + // begin transaction twice. Verify that error is thrown function test6($conn) { try { $conn->beginTransaction(); $conn->beginTransaction(); - } - catch( PDOException $e ) - { + } catch (PDOException $e) { echo "Test6: ". $e->getMessage() . "\n"; } } -try -{ - $db = connect(); - create_and_insert_table1( $db ); - test1($db); - test2($db); - test3($db); - test4($db); - test5($db); - test6($db); - -} +try { + $db = connect(); + $tbname = "PDO_MainTypes"; + createTableMainTypes($db, $tbname); + test1($db, $tbname); + test2($db, $tbname); + test3($db, $tbname); + test4($db, $tbname); + test5($db, $tbname); + test6($db); -catch( PDOException $e ) { - - var_dump( $e ); + dropTable($db, $tbname); + unset($conn); +} catch (PDOException $e) { + var_dump($e); exit; } - - -?> +?> --EXPECT-- -Test 1 Passed] +Test 1 Passed Test 2 Passed Test 3 Passed Test4: There is no active transaction Test5: There is no active transaction -Test6: There is already an active transaction \ No newline at end of file +Test6: There is already an active transaction diff --git a/test/functional/pdo_sqlsrv/pdo_utf8_conn.phpt b/test/functional/pdo_sqlsrv/pdo_utf8_conn.phpt index e616f401..b0224eeb 100644 --- a/test/functional/pdo_sqlsrv/pdo_utf8_conn.phpt +++ b/test/functional/pdo_sqlsrv/pdo_utf8_conn.phpt @@ -1,26 +1,27 @@ --TEST-- UTF-8 connection strings --SKIPIF-- - + --FILE-- --EXPECTREGEX-- - -Fatal error: Uncaught PDOException: SQLSTATE\[(28000|08001|HYT00)\]: .*\[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\](\[SQL Server\])?(Named Pipes Provider: Could not open a connection to SQL Server \[2\]\. |Login timeout expired|Login failed for user 'sa'\.) in .+(\/|\\)pdo_utf8_conn\.php:[0-9]+ + +Fatal error: Uncaught PDOException: SQLSTATE\[(28000|08001|HYT00)\]: .*\[Microsoft\]\[ODBC Driver 1[0-9] for SQL Server\](\[SQL Server\])?(Named Pipes Provider: Could not open a connection to SQL Server \[2\]\. |Login timeout expired|Login failed for user 'sa'\.) in .+(\/|\\)pdo_utf8_conn\.php:[0-9]+ Stack trace: #0 .+(\/|\\)pdo_utf8_conn\.php\([0-9]+\): PDO->__construct\('sqlsrv:Server=l\.\.\.', 'sa', 'Sunshine4u'\) #1 {main} diff --git a/test/functional/pdo_sqlsrv/pdostatement_Buffqry.phpt b/test/functional/pdo_sqlsrv/pdostatement_Buffqry.phpt index ef384d8c..31e36a88 100644 --- a/test/functional/pdo_sqlsrv/pdostatement_Buffqry.phpt +++ b/test/functional/pdo_sqlsrv/pdostatement_Buffqry.phpt @@ -1,200 +1,206 @@ --TEST-- PDOStatement::BindParam for predefined constants and buffered query. --SKIPIF-- - + --FILE-- 1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.',"; - $query .= "'1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.',"; - $query .= "'1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.')"; + $bin = fopen('php://memory', 'a'); + fwrite($bin, '00'); + rewind($bin); - $numRows = $db->exec($query); - - echo "Insert complete!\n"; + $inputs = array("BigIntCol" => 0, + "BitCol" => '0', + "IntCol" => 0, + "SmallIntCol" => 1, + "TinyIntCol" => 1, + "DecimalCol" => 111, + "NumCol" => 1, + "MoneyCol" => 111.1110, + "SmallMoneyCol" => 111.1110, + "FloatCol" => 111.111, + "RealCol" => 111.111, + "CharCol" => 'STRINGCOL2', + "VarcharCol" => 'STRINGCOL2', + "TextCol" => '1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.', + "NCharCol" => 'STRINGCOL2', + "NVarcharCol" => 'STRINGCOL2', + "ImageCol" => new BindParamOp(17, $bin, "PDO::PARAM_LOB", 0, "PDO::SQLSRV_ENCODING_BINARY"), + "BinaryCol" => new BindParamOp(18, $bin, "PDO::PARAM_LOB", 0, "PDO::SQLSRV_ENCODING_BINARY"), + "VarbinaryCol" => new BindParamOp(19, $bin, "PDO::PARAM_LOB", 0, "PDO::SQLSRV_ENCODING_BINARY"), + "SmallDTCol" => '2000-11-11 11:11:00', + "DateTimeCol" => '2000-11-11 11:11:11.110', + "DTOffsetCol" => '2000-11-11 11:11:11.1110000 +00:00', + "TimeCol" => '11:11:11.1110000', + "Guidcol" => 'AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA', + "VarbinaryMaxCol" => new BindParamOp(25, $bin, "PDO::PARAM_LOB", 0, "PDO::SQLSRV_ENCODING_BINARY"), + "VarcharMaxCol" => '1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.', + "XmlCol" => ' 1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.', + "NTextCol" => '1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.', + "NVarCharMaxCol" => '1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.'); + $stmt = insertRow($db, $tbname, $inputs, "prepareBindParam"); + unset($stmt); + echo "Insert complete!\n"; } -function bindParam_LOB($db) +function bindPARAM_LOB($db, $tbname) { - // Binding LOB with buffered queries activated. - $noteID = fopen('php://memory', 'a'); - $data = '0'; - $query = "UPDATE PDO_AllTypes SET [VarbinaryCol]=:Name WHERE [BitCol]=:value"; - $stmt = $db->prepare($query,array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED)); - fwrite($noteID, '00'); - rewind($noteID); - $stmt->bindParam(':Name',$noteID,PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY); - $stmt->bindParam(':value',$data); - $result = $stmt->execute(); - - $select = "SELECT * FROM PDO_AllTypes WHERE [BitCol]=:value"; - $stmt = $db->prepare($select,array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED)); - $stmt->bindParam(':value',$data); - $stmt->execute(); - $result = $stmt->fetchColumn(26); // Retrieve VarbinaryCol - print("$result\n"); + // Binding LOB with buffered queries activated. + $noteID = fopen('php://memory', 'a'); + $data = '0'; + $query = "UPDATE $tbname SET [VarbinaryCol]=:Name WHERE [BitCol]=:value"; + $stmt = $db->prepare($query, array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED)); + fwrite($noteID, '00'); + rewind($noteID); + $stmt->bindParam(':Name', $noteID, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY); + $stmt->bindParam(':value', $data); + $result = $stmt->execute(); + + $select = "SELECT * FROM $tbname WHERE [BitCol]=:value"; + $stmt = $db->prepare($select, array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->bindParam(':value', $data); + $stmt->execute(); + $result = $stmt->fetchColumn(26); // Retrieve VarbinaryCol + unset($stmt); + print("$result\n"); } -function bindParam_STR($db) +function bindPARAM_STR($db, $tbname) { - // Binding STR with buffered queries activated. - $noteID = fopen('php://memory', 'a'); - $data = 'STRINGCOL2'; - $query = "UPDATE PDO_AllTypes SET [BitCol]=:Name WHERE [CharCol]=:value"; - $stmt = $db->prepare($query,array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED)); - fwrite($noteID, '1'); - rewind($noteID); - $stmt->bindParam(':Name',$noteID,PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_BINARY); - $stmt->bindParam(':value',$data); - $stmt->execute(); - - $select = "SELECT * FROM PDO_AllTypes WHERE [CharCol]=:value"; - $stmt = $db->prepare($select,array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED)); - $stmt->bindParam(':value',$data); - $stmt->execute(); - $result = $stmt->fetchColumn(2); // Retrieve BitCol - $result = str_replace("\0","",$result); - print("$result\n"); - + // Binding STR with buffered queries activated. + // fopen returns a resource, if using PDO::PARAM_STR, the PDO side converts it to a zend_string "Resource id #*" + // thus a resource is not meant to bind parameter using PDO::PARAM_STR + + $noteID = '1'; + $data = 'STRINGCOL2'; + $query = "UPDATE $tbname SET [BitCol]=:Name WHERE [CharCol]=:value"; + $stmt = $db->prepare($query, array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->bindParam(':Name', $noteID, PDO::PARAM_STR); + $stmt->bindParam(':value', $data); + $stmt->execute(); + + $select = "SELECT * FROM $tbname WHERE [CharCol]=:value"; + $stmt = $db->prepare($select, array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->bindParam(':value', $data); + $stmt->execute(); + $result = $stmt->fetchColumn(2); // Retrieve BitCol + unset($stmt); + $result = str_replace("\0", "", $result); + print("$result\n"); } -function bindParam_NULL($db) +function bindPARAM_NULL($db, $tbname) { - // Binding NULL with buffered queries activated. - $noteID = fopen('php://memory', 'a'); - $data = 'STRINGCOL2'; - $query = "UPDATE PDO_AllTypes SET [BitCol]=:Name WHERE [VarcharCol]=:value"; - $stmt = $db->prepare($query,array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED)); - fwrite($noteID, null); - rewind($noteID); - $stmt->bindParam(':Name',$noteID,PDO::PARAM_NULL); - $stmt->bindParam(':value',$data); - $stmt->execute(); + // Binding NULL with buffered queries activated. + $noteID = fopen('php://memory', 'a'); + $data = 'STRINGCOL2'; + $query = "UPDATE PDO_AllTypes SET [BitCol]=:Name WHERE [VarcharCol]=:value"; - $data = '0'; - $select = "SELECT * FROM PDO_AllTypes WHERE [BitCol]=:value"; - $stmt = $db->prepare($select,array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED)); - $stmt->bindParam(':value',$data); - $stmt->execute(); - $result = $stmt->fetchColumn(2); // Retrieve BitCol - $result = str_replace("\0","",$result); - print("$result\n"); - + $stmt = $db->prepare($query, array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED)); + fwrite($noteID, null); + rewind($noteID); + $stmt->bindParam(':Name', $noteID, PDO::PARAM_NULL); + $stmt->bindParam(':value', $data); + $stmt->execute(); + + $data = '0'; + $select = "SELECT * FROM PDO_AllTypes WHERE [BitCol]=:value"; + $stmt = $db->prepare($select, array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->bindParam(':value', $data); + $stmt->execute(); + $result = $stmt->fetchColumn(2); // Retrieve BitCol + unset($stmt); + $result = str_replace("\0", "", $result); + print("$result\n"); } -function bindParam_INT($db) +function bindPARAM_INT($db, $tbname) { - // Binding INT with buffered queries activated. - $noteID = fopen('php://memory', 'a'); - $data = 0; - $query = "UPDATE PDO_ALLTypes SET [IntCol]=:Name WHERE [IntCol]=:value"; - $stmt = $db->prepare($query,array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED)); - fwrite($noteID, '1'); - rewind($noteID); - $stmt->bindParam(':Name',$noteID,PDO::PARAM_INT); - $stmt->bindParam(':value',$data); - $stmt->execute(); - - $select = "SELECT * FROM PDO_AllTypes WHERE [BigIntCol]=:value"; - $stmt = $db->prepare($select,array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED)); - $stmt->bindParam(':value',$data,PDO::PARAM_INT); - $stmt->execute(); - $result = $stmt->fetchColumn(11); // Retrieve IntCol - $result = str_replace("\0","",$result); - print("$result\n"); - + // Binding INT with buffered queries activated. + $noteID = fopen('php://memory', 'a'); + $data = 0; + $query = "UPDATE $tbname SET [IntCol]=:Name WHERE [IntCol]=:value"; + $stmt = $db->prepare($query, array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED)); + fwrite($noteID, '1'); + rewind($noteID); + $stmt->bindParam(':Name', $noteID, PDO::PARAM_INT); + $stmt->bindParam(':value', $data); + $stmt->execute(); + + $select = "SELECT * FROM $tbname WHERE [BigIntCol]=:value"; + $stmt = $db->prepare($select, array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->bindParam(':value', $data, PDO::PARAM_INT); + $stmt->execute(); + $result = $stmt->fetchColumn(11); // Retrieve IntCol + unset($stmt); + $result = str_replace("\0", "", $result); + print("$result\n"); } -function bindParam_BOOL($db) +function bindPARAM_BOOL($db, $tbname) { - // Binding BOOL with buffered queries activated. - $noteID = fopen('php://memory', 'a'); - $data = '0'; - $query = "UPDATE PDO_AllTypes SET [BitCol]=:Name WHERE [BigIntCol]=:value"; - $stmt = $db->prepare($query,array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED)); - fwrite($noteID, '1'); - rewind($noteID); - $stmt->bindParam(':Name',$noteID,PDO::PARAM_BOOL); - $stmt->bindParam(':value',$data); - $stmt->execute(); - - - $query = "SELECT * FROM PDO_AllTypes WHERE [BigIntCol]=:value"; - $stmt = $db->prepare($query,array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED)); - $stmt->bindParam(':value',$data,PDO::PARAM_BOOL); - $stmt->execute(); - $result = $stmt->fetchColumn(2); // Retrieve BitCol - $result = str_replace("\0","",$result); - print("$result\n"); - + // Binding BOOL with buffered queries activated. + $noteID = fopen('php://memory', 'a'); + $data = '0'; + $query = "UPDATE $tbname SET [BitCol]=:Name WHERE [BigIntCol]=:value"; + $stmt = $db->prepare($query, array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED)); + fwrite($noteID, '1'); + rewind($noteID); + $stmt->bindParam(':Name', $noteID, PDO::PARAM_BOOL); + $stmt->bindParam(':value', $data); + $stmt->execute(); + + $query = "SELECT * FROM $tbname WHERE [BigIntCol]=:value"; + $stmt = $db->prepare($query, array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->bindParam(':value', $data, PDO::PARAM_BOOL); + $stmt->execute(); + $result = $stmt->fetchColumn(2); // Retrieve BitCol + unset($stmt); + $result = str_replace("\0", "", $result); + print("$result\n"); } -function delete($db) +function delete($db, $tbname) { - $data = "STRINGCOL2"; - $query = "DELETE FROM PDO_AllTypes WHERE [CharCol]=:value"; - $stmt = $db->prepare($query,array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED)); - $stmt->bindParam(':value',$data); - $stmt->execute(); - + $data = "STRINGCOL2"; + $query = "DELETE FROM $tbname WHERE [CharCol]=:value"; + $stmt = $db->prepare($query, array(PDO::ATTR_CURSOR=>PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=>PDO::SQLSRV_CURSOR_BUFFERED)); + $stmt->bindParam(':value', $data); + $stmt->execute(); + unset($stmt); } try { + $db = connect(); + $tbname = "PDO_AllTypes"; + createAndInsertTableAllTypes($db, $tbname); + insert($db, $tbname); + bindPARAM_LOB($db, $tbname); + bindPARAM_STR($db, $tbname); + bindPARAM_NULL($db, $tbname); + bindPARAM_INT($db, $tbname); + bindPARAM_BOOL($db, $tbname); + delete($db, $tbname); - $db = connect(); - insert($db); - bindParam_LOB($db); - bindParam_STR($db); - bindParam_NULL($db); - bindParam_INT($db); - bindParam_BOOL($db); - delete($db); - - echo "Test Completed"; -} - -catch( PDOException $e ) { - var_dump( $e ); + dropTable($db, $tbname); + unset($db); + echo "Test Completed"; +} catch (PDOException $e) { + var_dump($e); exit; } @@ -207,4 +213,4 @@ Insert complete! 0 1 1 -Test Completed \ No newline at end of file +Test Completed diff --git a/test/functional/pdo_sqlsrv/pdostatement_GetDataType.phpt b/test/functional/pdo_sqlsrv/pdostatement_GetDataType.phpt index 1258be0f..f2aed841 100644 --- a/test/functional/pdo_sqlsrv/pdostatement_GetDataType.phpt +++ b/test/functional/pdo_sqlsrv/pdostatement_GetDataType.phpt @@ -1,305 +1,302 @@ --TEST-- Test the different type of data for retrieving --SKIPIF-- - + --FILE-- query("SELECT BigIntCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); + $stmt = $db->query("SELECT BigIntCol FROM $tbname"); + $result = $stmt->fetch(PDO::FETCH_ASSOC); + var_dump($result); } -function testBit($db) +function testBit($db, $tbname) { - $stmt = $db->query("SELECT BitCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); + $stmt = $db->query("SELECT BitCol FROM $tbname"); + $result = $stmt->fetch(PDO::FETCH_ASSOC); + var_dump($result); } -function testInt($db) +function testInt($db, $tbname) { - $stmt = $db->query("SELECT IntCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); + $stmt = $db->query("SELECT IntCol FROM $tbname"); + $result = $stmt->fetch(PDO::FETCH_ASSOC); + var_dump($result); } -function testSmallInt($db) +function testSmallInt($db, $tbname) { - $stmt = $db->query("SELECT SmallIntCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); + $stmt = $db->query("SELECT SmallIntCol FROM $tbname"); + $result = $stmt->fetch(PDO::FETCH_ASSOC); + var_dump($result); } -function testTinyInt($db) +function testTinyInt($db, $tbname) { - $stmt = $db->query("SELECT TinyIntCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); + $stmt = $db->query("SELECT TinyIntCol FROM $tbname"); + $result = $stmt->fetch(PDO::FETCH_ASSOC); + var_dump($result); } -function testDecimal($db) +function testDecimal($db, $tbname) { - $stmt = $db->query("SELECT DecimalCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); + $stmt = $db->query("SELECT DecimalCol FROM $tbname"); + $result = $stmt->fetch(PDO::FETCH_ASSOC); + var_dump($result); } -function testNumeric($db) +function testNumeric($db, $tbname) { - $stmt = $db->query("SELECT NumCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); + $stmt = $db->query("SELECT NumCol FROM $tbname"); + $result = $stmt->fetch(PDO::FETCH_ASSOC); + var_dump($result); } -function testMoney($db) -{ - $stmt = $db->query("SELECT MoneyCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); -} - -function testSmallMoney($db) +function testMoney($db, $tbname) { - $stmt = $db->query("SELECT SmallMoneyCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); + $stmt = $db->query("SELECT MoneyCol FROM $tbname"); + $result = $stmt->fetch(PDO::FETCH_ASSOC); + var_dump($result); } -function testFloat($db) +function testSmallMoney($db, $tbname) { - $stmt = $db->query("SELECT FloatCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); + $stmt = $db->query("SELECT SmallMoneyCol FROM $tbname"); + $result = $stmt->fetch(PDO::FETCH_ASSOC); + var_dump($result); } -function testReal($db) +function testFloat($db, $tbname) { - $stmt = $db->query("SELECT RealCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); + $stmt = $db->query("SELECT FloatCol FROM $tbname"); + $result = $stmt->fetch(PDO::FETCH_ASSOC); + var_dump($result); } -function testChar($db) +function testReal($db, $tbname) { - $stmt = $db->query("SELECT CharCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); + $stmt = $db->query("SELECT RealCol FROM $tbname"); + $result = $stmt->fetch(PDO::FETCH_ASSOC); + var_dump($result); } -function testVarchar($db) +function testChar($db, $tbname) { - $stmt = $db->query("SELECT VarcharCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); + $stmt = $db->query("SELECT CharCol FROM $tbname"); + $result = $stmt->fetch(PDO::FETCH_ASSOC); + var_dump($result); } -function testText($db) +function testVarchar($db, $tbname) { - $stmt = $db->query("SELECT TextCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); + $stmt = $db->query("SELECT VarcharCol FROM $tbname"); + $result = $stmt->fetch(PDO::FETCH_ASSOC); + var_dump($result); } -function testNText($db) +function testText($db, $tbname) { - $stmt = $db->query("SELECT NTextCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); + $stmt = $db->query("SELECT TextCol FROM $tbname"); + $result = $stmt->fetch(PDO::FETCH_ASSOC); + var_dump($result); } -function testNChar($db) +function testNText($db, $tbname) { - $stmt = $db->query("SELECT NCharCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); + $stmt = $db->query("SELECT NTextCol FROM $tbname"); + $result = $stmt->fetch(PDO::FETCH_ASSOC); + var_dump($result); } -function testNVarchar($db) +function testNChar($db, $tbname) { - $stmt = $db->query("SELECT NVarcharCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); + $stmt = $db->query("SELECT NCharCol FROM $tbname"); + $result = $stmt->fetch(PDO::FETCH_ASSOC); + var_dump($result); } -function testImage($db) +function testNVarchar($db, $tbname) { - $stmt = $db->query("SELECT ImageCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); + $stmt = $db->query("SELECT NVarcharCol FROM $tbname"); + $result = $stmt->fetch(PDO::FETCH_ASSOC); + var_dump($result); } -function testBinary($db) +function testImage($db, $tbname) { - $stmt = $db->query("SELECT BinaryCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); + $stmt = $db->query("SELECT ImageCol FROM $tbname"); + $result = $stmt->fetch(PDO::FETCH_ASSOC); + var_dump($result); } -function testVarbinary($db) +function testBinary($db, $tbname) { - $stmt = $db->query("SELECT VarbinaryCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); + $stmt = $db->query("SELECT BinaryCol FROM $tbname"); + $result = $stmt->fetch(PDO::FETCH_ASSOC); + var_dump($result); } -function testDateTime2($db) +function testVarbinary($db, $tbname) { - $stmt = $db->query("SELECT DateTime2Col FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); + $stmt = $db->query("SELECT VarbinaryCol FROM $tbname"); + $result = $stmt->fetch(PDO::FETCH_ASSOC); + var_dump($result); } -function testDatetimeoffset($db) +function testDateTime2($db, $tbname) { - $stmt = $db->query("SELECT DTOffsetCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); + $stmt = $db->query("SELECT DateTime2Col FROM $tbname"); + $result = $stmt->fetch(PDO::FETCH_ASSOC); + var_dump($result); } -function testsmalldatetime($db) +function testDatetimeoffset($db, $tbname) { - $stmt = $db->query("SELECT SmallDTCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); + $stmt = $db->query("SELECT DTOffsetCol FROM $tbname"); + $result = $stmt->fetch(PDO::FETCH_ASSOC); + var_dump($result); } -function testDateTime($db) +function testsmalldatetime($db, $tbname) { - $stmt = $db->query("SELECT DateTimeCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); + $stmt = $db->query("SELECT SmallDTCol FROM $tbname"); + $result = $stmt->fetch(PDO::FETCH_ASSOC); + var_dump($result); } -function testDate($db) +function testDateTime($db, $tbname) { - $stmt = $db->query("SELECT DateCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); + $stmt = $db->query("SELECT DateTimeCol FROM $tbname"); + $result = $stmt->fetch(PDO::FETCH_ASSOC); + var_dump($result); } -function testNVarcharMax($db) +function testDate($db, $tbname) { - $stmt = $db->query("SELECT NVarCharMaxCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); + $stmt = $db->query("SELECT DateCol FROM $tbname"); + $result = $stmt->fetch(PDO::FETCH_ASSOC); + var_dump($result); } -function testTime($db) +function testNVarcharMax($db, $tbname) { - $stmt = $db->query("SELECT TimeCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); + $stmt = $db->query("SELECT NVarCharMaxCol FROM $tbname"); + $result = $stmt->fetch(PDO::FETCH_ASSOC); + var_dump($result); } -function testUniqueidentifier($db) +function testTime($db, $tbname) { - $stmt = $db->query("SELECT Guidcol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); + $stmt = $db->query("SELECT TimeCol FROM $tbname"); + $result = $stmt->fetch(PDO::FETCH_ASSOC); + var_dump($result); } -function testVarbinaryMax($db) +function testUniqueidentifier($db, $tbname) { - $stmt = $db->query("SELECT VarbinaryMaxCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); + $stmt = $db->query("SELECT Guidcol FROM $tbname"); + $result = $stmt->fetch(PDO::FETCH_ASSOC); + var_dump($result); } -function testVarcharMax($db) +function testVarbinaryMax($db, $tbname) { - $stmt = $db->query("SELECT VarcharMaxCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); + $stmt = $db->query("SELECT VarbinaryMaxCol FROM $tbname"); + $result = $stmt->fetch(PDO::FETCH_ASSOC); + var_dump($result); } -function testXml($db) +function testVarcharMax($db, $tbname) { - $stmt = $db->query("SELECT XmlCol FROM PDO_AllTypes"); - $result = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($result); -} - - -try -{ - $db = connect(); - //$sql = "INSERT INTO PDO_AllTypes(BigIntCol,BitCol,IntCol,) VALUES(" . GetSampleData(4) . ",1,)"; - //$numRows = $db->exec($sql); - - echo "Test_1 : bigint data type :\n"; - testBigInt($db); - echo "Test_2 : bit data type :\n"; - testBit($db); - echo "Test_3 : int data type :\n"; - testInt($db); - echo "Test_4 : smallint data type:\n"; - testSmallInt($db); - echo "Test_5 : tinyint data type:\n"; - testTinyInt($db); - echo "Test_6 : decimal data type:\n"; - testDecimal($db); - echo "Test_7 : numeric data type:\n"; - testNumeric($db); - echo "Test_8 : money data type:\n"; - testMoney($db); - echo "Test_9 : smallmoney data type:\n"; - testSmallMoney($db); - echo "Test_10 : float data type:\n"; - testFloat($db); - echo "Test_11 : real data type:\n"; - testReal($db); - echo "Test_12 : char data type:\n"; - testChar($db); - echo "Test_13 : varchar data type:\n"; - testVarchar($db); - echo "Test_14 : text data type:\n"; - testText($db); - echo "Test_15 : nchar data type:\n"; - testNChar($db); - echo "Test_16 : nvarchar data type:\n"; - testNVarchar($db); - echo "Test_17 : image data type:\n"; - testImage($db); - echo "Test_18 : binary data type:\n"; - testBinary($db); - echo "Test_19 : varbinary data type:\n"; - testVarbinary($db); - echo "Test_20 : smalldatetime data type:\n"; - testsmalldatetime($db); - echo "Test_21 : datetime data type:\n"; - testDateTime($db); - echo "Test_22 : datetime2 data type:\n"; - testsmalldatetime($db); - echo "Test_23 : datetimeoffset data type:\n"; - testDatetimeoffset($db); - echo "Test_24 : time data type:\n"; - testTime($db); - echo "Test_25 : Uniqueidentifier data type:\n"; - testUniqueidentifier($db); - echo "Test_26 : VarbinaryMax data type:\n"; - testVarbinaryMax($db); - echo "Test_27 : VarcharMax data type:\n"; - testVarcharMax($db); - echo "Test_28 : xml data type:\n"; - testXml($db); - echo "Test_29 : ntext data type:\n"; - testNText($db); - echo "Test_30 : nvarcharmax data type:\n"; - testNVarcharMax($db); - echo "Test_31 : date data type:\n"; - testDate($db); -} -catch (PDOException $e) -{ - var_dump($e); + $stmt = $db->query("SELECT VarcharMaxCol FROM $tbname"); + $result = $stmt->fetch(PDO::FETCH_ASSOC); + var_dump($result); } +function testXml($db, $tbname) +{ + $stmt = $db->query("SELECT XmlCol FROM $tbname"); + $result = $stmt->fetch(PDO::FETCH_ASSOC); + var_dump($result); +} + +try { + $db = connect(); + $tbname = "PDO_AllTypes"; + createAndInsertTableAllTypes($db, $tbname); + + echo "Test_1 : bigint data type :\n"; + testBigInt($db, $tbname); + echo "Test_2 : bit data type :\n"; + testBit($db, $tbname); + echo "Test_3 : int data type :\n"; + testInt($db, $tbname); + echo "Test_4 : smallint data type:\n"; + testSmallInt($db, $tbname); + echo "Test_5 : tinyint data type:\n"; + testTinyInt($db, $tbname); + echo "Test_6 : decimal data type:\n"; + testDecimal($db, $tbname); + echo "Test_7 : numeric data type:\n"; + testNumeric($db, $tbname); + echo "Test_8 : money data type:\n"; + testMoney($db, $tbname); + echo "Test_9 : smallmoney data type:\n"; + testSmallMoney($db, $tbname); + echo "Test_10 : float data type:\n"; + testFloat($db, $tbname); + echo "Test_11 : real data type:\n"; + testReal($db, $tbname); + echo "Test_12 : char data type:\n"; + testChar($db, $tbname); + echo "Test_13 : varchar data type:\n"; + testVarchar($db, $tbname); + echo "Test_14 : text data type:\n"; + testText($db, $tbname); + echo "Test_15 : nchar data type:\n"; + testNChar($db, $tbname); + echo "Test_16 : nvarchar data type:\n"; + testNVarchar($db, $tbname); + echo "Test_17 : image data type:\n"; + testImage($db, $tbname); + echo "Test_18 : binary data type:\n"; + testBinary($db, $tbname); + echo "Test_19 : varbinary data type:\n"; + testVarbinary($db, $tbname); + echo "Test_20 : smalldatetime data type:\n"; + testsmalldatetime($db, $tbname); + echo "Test_21 : datetime data type:\n"; + testDateTime($db, $tbname); + echo "Test_22 : datetime2 data type:\n"; + testsmalldatetime($db, $tbname); + echo "Test_23 : datetimeoffset data type:\n"; + testDatetimeoffset($db, $tbname); + echo "Test_24 : time data type:\n"; + testTime($db, $tbname); + echo "Test_25 : Uniqueidentifier data type:\n"; + testUniqueidentifier($db, $tbname); + echo "Test_26 : VarbinaryMax data type:\n"; + testVarbinaryMax($db, $tbname); + echo "Test_27 : VarcharMax data type:\n"; + testVarcharMax($db, $tbname); + echo "Test_28 : xml data type:\n"; + testXml($db, $tbname); + echo "Test_29 : ntext data type:\n"; + testNText($db, $tbname); + echo "Test_30 : nvarcharmax data type:\n"; + testNVarcharMax($db, $tbname); + echo "Test_31 : date data type:\n"; + testDate($db, $tbname); + + dropTable($db, $tbname); + unset($db); +} catch (PDOException $e) { + var_dump($e); +} ?> --EXPECT-- @@ -386,17 +383,17 @@ array(1) { Test_17 : image data type: array(1) { ["ImageCol"]=> - string(1) "" + string(0) "" } Test_18 : binary data type: array(1) { ["BinaryCol"]=> - string(5) "" + string(5) "00" } Test_19 : varbinary data type: array(1) { ["VarbinaryCol"]=> - string(1) "" + string(0) "" } Test_20 : smalldatetime data type: array(1) { @@ -431,7 +428,7 @@ array(1) { Test_26 : VarbinaryMax data type: array(1) { ["VarbinaryMaxCol"]=> - string(1) "" + string(0) "" } Test_27 : VarcharMax data type: array(1) { @@ -457,4 +454,4 @@ Test_31 : date data type: array(1) { ["DateCol"]=> string(10) "2000-11-11" -} \ No newline at end of file +} diff --git a/test/functional/pdo_sqlsrv/pdostatement_bindColumn.phpt b/test/functional/pdo_sqlsrv/pdostatement_bindColumn.phpt index 0bff98f7..89f5773f 100644 --- a/test/functional/pdo_sqlsrv/pdostatement_bindColumn.phpt +++ b/test/functional/pdo_sqlsrv/pdostatement_bindColumn.phpt @@ -1,53 +1,50 @@ --TEST-- Test the bindColumn method using either by bind by column number or bind by column name --SKIPIF-- - + --FILE-- prepare("SELECT IntCol, CharCol, DateTimeCol FROM " . $table1); + $stmt = $db->prepare("SELECT IntCol, CharCol, DateTimeCol FROM $tbname"); $stmt->execute(); $stmt->bindColumn('IntCol', $intCol); $stmt->bindColumn('CharCol', $charCol); $stmt->bindColumn('DateTimeCol', $dateTimeCol); - - while($row = $stmt->fetch(PDO::FETCH_BOUND)) - { + + while ($row = $stmt->fetch(PDO::FETCH_BOUND)) { echo $intCol . " : " . $charCol . " : " . $dateTimeCol . "\n"; } } -function bindColumn_byNumber($db) +function bindColumn_byNumber($db, $tbname) { - global $table1; - $stmt = $db->prepare("SELECT IntCol, CharCol, DateTimeCol FROM " . $table1); + $stmt = $db->prepare("SELECT IntCol, CharCol, DateTimeCol FROM $tbname"); $stmt->execute(); $stmt->bindColumn(1, $intCol); $stmt->bindColumn(2, $charCol); $stmt->bindColumn(3, $dateTimeCol); - - while($row = $stmt->fetch(PDO::FETCH_BOUND)) - { + + while ($row = $stmt->fetch(PDO::FETCH_BOUND)) { echo $intCol . " : " . $charCol . " : " . $dateTimeCol . "\n"; } } -try -{ +try { $db = connect(); + $tbname = "PDO_MainTypes"; + createAndInsertTableMainTypes($db, $tbname); echo "Bind Column by name :\n"; - bindColumn_byName($db); + bindColumn_byName($db, $tbname); echo "Bind Column by number :\n"; - bindColumn_byNumber($db); - -} -catch (PDOException $e) -{ + bindColumn_byNumber($db, $tbname); + + dropTable($db, $tbname); + unset($db); +} catch (PDOException $e) { var_dump($e); } @@ -58,4 +55,4 @@ Bind Column by name : 2 : STRINGCOL2 : 2000-11-11 11:11:11.223 Bind Column by number : 1 : STRINGCOL1 : 2000-11-11 11:11:11.110 -2 : STRINGCOL2 : 2000-11-11 11:11:11.223 \ No newline at end of file +2 : STRINGCOL2 : 2000-11-11 11:11:11.223 diff --git a/test/functional/pdo_sqlsrv/pdostatement_bindParam.phpt b/test/functional/pdo_sqlsrv/pdostatement_bindParam.phpt index 8525d4c7..19609e2d 100644 --- a/test/functional/pdo_sqlsrv/pdostatement_bindParam.phpt +++ b/test/functional/pdo_sqlsrv/pdostatement_bindParam.phpt @@ -1,7 +1,7 @@ --TEST-- PDOStatement::BindParam for NULL types and for value types. --SKIPIF-- - + --FILE-- prepare($sql); + $stmt = $db->prepare($sql); $param = null; $stmt->bindParam(1, $param); - $stmt->bindParam(2, $param, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY ); - $stmt->bindParam(3, $param ); - $stmt->bindParam(4, $param ); - $stmt->bindParam(5, $param ); - $stmt->bindParam(6, $param ); - $stmt->bindParam(7, $param ); - $stmt->bindParam(8, $param ); - $stmt->bindParam(9, $param ); - $stmt->bindParam(10, $param ); - $stmt->bindParam(11, $param ); - $stmt->bindParam(12, $param ); - $stmt->bindParam(13, $param ); - $stmt->bindParam(14, $param ); - $stmt->bindParam(15, $param ); - $stmt->bindParam(16, $param ); - $stmt->bindParam(17, $param ); - $stmt->bindParam(18, $param ); - $stmt->bindParam(19, $param ); - $stmt->bindParam(20, $param ); - $stmt->bindParam(21, $param ); - $stmt->bindParam(22, $param ); - $stmt->bindParam(23, $param ); - $stmt->bindParam(24, $param ); - $stmt->bindParam(25, $param ); - $stmt->bindParam(26, $param ); - $stmt->bindParam(27, $param, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_BINARY ); //PDO::PARAM_STR OR PDO::PARAM_LOB DOES NOT MATTER - $stmt->bindParam(28, $param, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_BINARY ); - $stmt->bindParam(29, $param ); - $stmt->bindParam(30, $param ); - $stmt->bindParam(31, $param ); - - $stmt->execute(); + $stmt->bindParam(2, $param, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY); + $stmt->bindParam(3, $param); + $stmt->bindParam(4, $param); + $stmt->bindParam(5, $param); + $stmt->bindParam(6, $param); + $stmt->bindParam(7, $param); + $stmt->bindParam(8, $param); + $stmt->bindParam(9, $param); + $stmt->bindParam(10, $param); + $stmt->bindParam(11, $param); + $stmt->bindParam(12, $param); + $stmt->bindParam(13, $param); + $stmt->bindParam(14, $param); + $stmt->bindParam(15, $param); + $stmt->bindParam(16, $param); + $stmt->bindParam(17, $param); + $stmt->bindParam(18, $param); + $stmt->bindParam(19, $param); + $stmt->bindParam(20, $param); + $stmt->bindParam(21, $param); + $stmt->bindParam(22, $param); + $stmt->bindParam(23, $param); + $stmt->bindParam(24, $param); + $stmt->bindParam(25, $param); + $stmt->bindParam(26, $param); + $stmt->bindParam(27, $param, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_BINARY); //PDO::PARAM_STR OR PDO::PARAM_LOB DOES NOT MATTER + $stmt->bindParam(28, $param, PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_BINARY); + $stmt->bindParam(29, $param); + $stmt->bindParam(30, $param); + $stmt->bindParam(31, $param); + + $stmt->execute(); } -function bind_params_int($db) +function bindParamsInt($db, $tbname) { - global $table2; - $stmt = $db->prepare("SELECT * FROM " . $table2 . " WHERE BigIntCol = :bigIntCol "); - $int = 1; - $stmt->bindParam(":bigIntCol", $int, PDO::PARAM_INT); - $stmt->execute(); + $stmt = $db->prepare("SELECT * FROM $tbname WHERE BigIntCol = :bigIntCol"); + $int = 1; + $stmt->bindParam(":bigIntCol", $int, PDO::PARAM_INT); + $stmt->execute(); } - -function bind_params_str($db) +function bindParamsStr($db, $tbname) { - global $table2; - $stmt = $db->prepare("SELECT * FROM " . $table2 . " WHERE CharCol = :charCol "); - $char = "STRINGCOL1"; - $stmt->bindParam(":charCol", $char, PDO::PARAM_STR); - $stmt->execute(); + $stmt = $db->prepare("SELECT * FROM $tbname WHERE CharCol = :charCol"); + $char = "STRINGCOL1"; + $stmt->bindParam(":charCol", $char, PDO::PARAM_STR); + $stmt->execute(); } -function bind_params_bool($db) +function bindParamsBool($db, $tbname) { - global $table2; - $stmt = $db->prepare("SELECT * FROM " . $table2 . " WHERE BitCol = :bool "); - $bool = 0; - $stmt->bindParam(":bool" , $bool, PDO::PARAM_BOOL); - $stmt->execute(); + $stmt = $db->prepare("SELECT * FROM " . $tbname . " WHERE BitCol = :bool"); + $bool = 0; + $stmt->bindParam(":bool", $bool, PDO::PARAM_BOOL); + $stmt->execute(); } -function bind_params_lob($db) +function bindParamsLob($db, $tbname) { - global $table2; - $stmt = $db->prepare("SELECT * FROM " . $table2 . " WHERE BinaryCol = :lob "); - $lob = 0; - $stmt->bindParam(":lob" , $lob, PDO::PARAM_LOB); - $stmt->execute(); + $stmt = $db->prepare("SELECT * FROM $tbname WHERE BinaryCol = :lob"); + $lob = fopen('php://memory', 'a'); + fwrite($lob, '00'); + rewind($lob); + $stmt->bindParam(":lob", $lob, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY); + $stmt->execute(); } - - try { + $db = connect(); + $tbname = "PDO_AllTypes"; + createAndInsertTableAllTypes($db, $tbname); + bindParamsWithNull($db, $tbname); + bindParamsInt($db, $tbname); + bindParamsStr($db, $tbname); + bindParamsBool($db, $tbname); + bindParamsLob($db, $tbname); - $db = connect(); - create_and_insert_table2( $db ); - bind_params_with_null($db); - bind_params_int($db); - bind_params_str($db); - bind_params_bool($db); - bind_params_lob($db); - - echo "Test Succeeded"; -} - -catch( PDOException $e ) { - var_dump( $e ); + dropTable($db, $tbname); + unset($db); + echo "Test Succeeded\n"; +} catch (PDOException $e) { + var_dump($e); exit; } - ?> - --EXPECT-- Test Succeeded diff --git a/test/functional/pdo_sqlsrv/pdostatement_bindValue.phpt b/test/functional/pdo_sqlsrv/pdostatement_bindValue.phpt index 561cf12d..9202928f 100644 --- a/test/functional/pdo_sqlsrv/pdostatement_bindValue.phpt +++ b/test/functional/pdo_sqlsrv/pdostatement_bindValue.phpt @@ -1,27 +1,30 @@ --TEST-- Test bindValue method. --SKIPIF-- - + --FILE-- prepare("SELECT IntCol FROM " . $table2 . " 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(); + + dropTable($db, $tbname); + unset($stmt); + unset($db); echo "Test Complete!\n"; -} -catch (PDOException $e) -{ +} catch (PDOException $e) { var_dump($e); } ?> --EXPECT-- -Test Complete! \ No newline at end of file +Test Complete! diff --git a/test/functional/pdo_sqlsrv/pdostatement_closeCursor.phpt b/test/functional/pdo_sqlsrv/pdostatement_closeCursor.phpt index e6a2d4eb..da4dea13 100644 --- a/test/functional/pdo_sqlsrv/pdostatement_closeCursor.phpt +++ b/test/functional/pdo_sqlsrv/pdostatement_closeCursor.phpt @@ -1,28 +1,27 @@ --TEST-- Test PDOStatement::closeCursor method. --SKIPIF-- - + --FILE-- prepare("SELECT * FROM " . $table2); + $tbname = "PDO_AllTypes"; + createAndInsertTableAllTypes($db, $tbname); + $stmt = $db->prepare("SELECT * FROM $tbname"); $stmt->execute(); $result = $stmt->fetch(); - $stmt->closeCursor(); - echo "Test complete!"; -} -catch ( PDOException $e) -{ + + dropTable($db, $tbname); + unset($stmt); + unset($db); + echo "Test complete!\n"; +} catch (PDOException $e) { var_dump($e); } - - - ?> - --EXPECT-- -Test complete! \ No newline at end of file +Test complete! diff --git a/test/functional/pdo_sqlsrv/pdostatement_columnCount.phpt b/test/functional/pdo_sqlsrv/pdostatement_columnCount.phpt index 1d47adbd..2b8c0784 100644 --- a/test/functional/pdo_sqlsrv/pdostatement_columnCount.phpt +++ b/test/functional/pdo_sqlsrv/pdostatement_columnCount.phpt @@ -1,24 +1,23 @@ --TEST-- Test PDOStatement::columnCount if the number of the columns in a result set. --SKIPIF-- - + --FILE-- prepare($sql); - $stmt->execute(); - print_r("Existing table contains: " . $stmt->columnCount()); - } - catch(PDOException $e) - { - var_dump($e); - } +try { + $db = connect(); + $tbname = "PDO_AllTypes"; + createAndInsertTableAllTypes($db, $tbname); + $sql = "SELECT * FROM $tbname"; + $stmt = $db->prepare($sql); + $stmt->execute(); + print_r("Existing table contains: " . $stmt->columnCount() . "\n"); +} catch (PDOException $e) { + var_dump($e); +} ?> --EXPECT-- -Existing table contains: 31 \ No newline at end of file +Existing table contains: 31 diff --git a/test/functional/pdo_sqlsrv/pdostatement_debugDumpParams.phpt b/test/functional/pdo_sqlsrv/pdostatement_debugDumpParams.phpt index fd21fc8c..834a213e 100644 --- a/test/functional/pdo_sqlsrv/pdostatement_debugDumpParams.phpt +++ b/test/functional/pdo_sqlsrv/pdostatement_debugDumpParams.phpt @@ -1,26 +1,30 @@ --TEST-- Test debugDumpParams method. --SKIPIF-- - + --FILE-- prepare("SELECT IntCol FROM " . $table2 . " 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(); - + $stmt->debugDumpParams(); -} -catch (PDOException $e) -{ + + dropTable($db, $tbname); + unset($stmt); + unset($db); +} catch (PDOException $e) { var_dump($e); } ?> @@ -36,4 +40,4 @@ Key: Name: [7] :string paramno=1 name=[7] ":string" is_param=1 -param_type=2 \ No newline at end of file +param_type=2 diff --git a/test/functional/pdo_sqlsrv/pdostatement_error.phpt b/test/functional/pdo_sqlsrv/pdostatement_error.phpt index acd6d646..22e9be1e 100644 --- a/test/functional/pdo_sqlsrv/pdostatement_error.phpt +++ b/test/functional/pdo_sqlsrv/pdostatement_error.phpt @@ -1,31 +1,30 @@ --TEST-- Test PDOStatement::errorInfo and PDOStatement::errorCode methods. --SKIPIF-- - + --FILE-- prepare("SELECT * FROM PDO_Types_1"); + $tbname = "PDO_MainTypes"; + createAndInsertTableMainTypes($db, $tbname); + $stmt = $db->prepare("SELECT * FROM $tbname"); $stmt->execute(); $arr = $stmt->errorInfo(); print_r("Error Info :\n"); var_dump($arr); $arr = $stmt->errorCode(); print_r("Error Code : " . $arr . "\n"); - - - - $db = null; -} -catch (PDOException $e) -{ + + dropTable($db, $tbname); + unset($stmt); + unset($db); +} catch (PDOException $e) { var_dump($e); } - ?> --EXPECT-- Error Info : @@ -37,4 +36,4 @@ array(3) { [2]=> NULL } -Error Code : 00000 \ No newline at end of file +Error Code : 00000 diff --git a/test/functional/pdo_sqlsrv/pdostatement_execute.phpt b/test/functional/pdo_sqlsrv/pdostatement_execute.phpt index 463447d9..76459429 100644 --- a/test/functional/pdo_sqlsrv/pdostatement_execute.phpt +++ b/test/functional/pdo_sqlsrv/pdostatement_execute.phpt @@ -1,34 +1,52 @@ --TEST-- Test PDOStatement::execute method. --SKIPIF-- - + --FILE-- prepare("SELECT * FROM PDO_Types_1"); - $stmt->execute(); - $rows = $stmt->fetch(PDO::FETCH_ASSOC); - var_dump($rows); - // Test update table value - $stmt = $db->prepare("UPDATE PDO_Types_1 SET IntCol=1"); - $rows = $stmt->execute(); - var_dump($rows); - // Test insert value to table - $stmt1 = $db->prepare("INSERT INTO PDO_Types_1 (IntCol,CharCol,NCharCol,DateTimeCol,VarcharCol,NVarCharCol,FloatCol,XmlCol) VALUES (2,'STRINGCOL1','STRINGCOL1','2000-11-11 11:11:11.110','STRINGCOL1','STRINGCOL1',111.111,' 1 This is a really large string used to test certain large data types like xml data type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.')"); - $rows = $stmt1->execute(); - var_dump($rows); - $db = null; - } - catch(PDOException $e) - { - var_dump($e); + $stmt = $db->prepare("SELECT * FROM $tbname"); + $stmt->execute(); + $rows = $stmt->fetch(PDO::FETCH_ASSOC); + var_dump($rows); + + // Test update table value + if (isColEncrypted()) { + $stmt = $db->prepare("UPDATE $tbname SET IntCol=?"); + $r = $stmt->execute(array(1)); + } else { + $stmt = $db->prepare("UPDATE $tbname SET IntCol=1"); + $r = $stmt->execute(); } + var_dump($r); + // Test insert value to table + $inputs = array("IntCol" => 2, + "CharCol" => 'STRINGCOL1', + "NCharCol" => 'STRINGCOL1', + "DateTimeCol" => '2000-11-11 11:11:11.110', + "VarcharCol" => 'STRINGCOL1', + "NVarCharCol" => 'STRINGCOL1', + "FloatCol" => 111.111, + "XmlCol" => ' 1 This is a really large string used to test certain large data types like xml data type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417.'); + $r; + $stmt1 = insertRow($db, $tbname, $inputs, "prepareExecuteBind", $r); + var_dump($r); + + dropTable($db, $tbname); + unset($stmt); + unset($stmt1); + unset($conn); +} catch (PDOException $e) { + var_dump($e); +} ?> --EXPECT-- array(8) { diff --git a/test/functional/pdo_sqlsrv/pdostatement_fetchAll.phpt b/test/functional/pdo_sqlsrv/pdostatement_fetchAll.phpt index d7053d4e425e500cc1de810111968a0a0c822f98..dc7ccae64c4d9fda3c8e9e985b30d2227ec19ae5 100644 GIT binary patch delta 1626 zcmbVM&rcIU6iyK-Y=cA)ONqf@UF@#3q-_)r2&5EDNXid|n=y5EcM5BEXY1}1Az+Ad z)I`l(z4#Y+sPW`MW4svu0{;hZdUtkqmvm_{DZO<1zIor9_ulvQ>&w{pSFtxQ-X4t~ zRxCr$I;aXYVmng?*3!xhn4c4}*}Kc-rEFHXGhf@T2@ZNvHyl*4v4&)E#Vy&EW#g7) zQJHDEx(ErZtS_!ril(`_S3|B>#k(j}>sZo=VPjB5MB8Tgefy~^OPY;w21rE3&_ar^ zPoH;pz7FGh>G;lxp9hPqXU3_>exj@mRw>HT8t-0O14?IaL0rhI?;8l z9buBczhk~rA9#7eCfgm;-AkP4Gg)+9TkDu7Lt*#zlU&1V>fz=FskxOQ;{!K0nd**ckoYlc0a&1EWBLOz1#nc39fgP>qXULXM-*iQe>~pCRcg zm<65*nBL`pFmOYjA);rdm9SmWFBss35D(23z?y>~K}D=DGmAK66RIXUrjS`h&u_Q6 z;qpPnb}1oin86bY^keVppl@BD$mgMnzVfBef)PONE7L8Ze>kvH6IM`W=#Reqpl^&O zAWyr6n?r%nBk={HaFL5P51tuR%~g6dneO&3(GQa&{LuJ0 c`8g$plVMZ#6v^bLWI#Hi!ZdxiG!Ya20h$={fB*mh delta 1542 zcmb_cTTc@~6mH8!IxT7f20?^F+0s@hvGqcVxn4V4_btv)htrY$3sY*xhsH%y%yHee>q2f9Hw++2aVH zWHL81y*NFUOrk4Uqhx?d?mMbU;xX%7BBQl+NMsQE6u88`G<6Qim}*X0KLBEXLqq@$+0S}gLToNDD4?UVy>5`kwWi%# zPt`?E0~-houwQ{=VTem6u^i1#WPm*ioRH)^wMz%6yFPkKppUSZP0}eNcD5*PWgZ2_*g$jR>m5i)jnDN z!B%gd%LAy(gB0g1=Xs4{$0uhea=DQjp=Hc=TZig(ACpymRngSKKD7zeoZGJgw*lK+ zcfX$a*yli>;QiTK^E2}cx97RKgeEuLH&(c874$k)STS%0*cL8~-=Bq-8yTMe@6QT%5=sc<_MwmBHy3M7x zFkT2l@K6}Ou68c4c;HA&48?_c7|_7 zC_4_7@1fW2Ek5zESK+SK3kit$e3kdz9Zk##H~W3;TklEluhM?{?a`|9!*JEfehkNi l5BVbQ1n#8Am=f;r`zqOy?e5OKf*0~D;;eX`3D!Rq{S6Cd%l!ZV diff --git a/test/functional/pdo_sqlsrv/pdostatement_fetchColumn.phpt b/test/functional/pdo_sqlsrv/pdostatement_fetchColumn.phpt index 1f664eee..344475f4 100644 --- a/test/functional/pdo_sqlsrv/pdostatement_fetchColumn.phpt +++ b/test/functional/pdo_sqlsrv/pdostatement_fetchColumn.phpt @@ -1,54 +1,42 @@ --TEST-- Test the fetchColumn() method. --SKIPIF-- - + --FILE-- query( "Select * from ". $table1 ); - - // Fetch the first column from the next row in resultset. (This wud be first row since this is a first call to fetchcol) - $result = $stmt->fetchColumn(); - var_dump($result); - - // Fetch the second column from the next row. (This would be second row since this is a second call to fetchcol). - $result = $stmt->fetchColumn(1); - var_dump($result); +require_once("MsCommon_mid-refactor.inc"); +require_once("MsData_PDO_AllTypes.inc"); - // Test false is returned when there are no more rows. - $result = $stmt->fetchColumn(1); - var_dump($result); - } - - -try -{ - //$verbose = false; - - $db = connect(); - create_and_insert_table1( $db ); - fetch_column($db); - -} +try { + $db = connect(); + $tbname = "PDO_MainTypes"; + createAndInsertTableMainTypes($db, $tbname); -catch( PDOException $e ) { + $stmt = $db->query("Select * from $tbname"); - var_dump( $e ); + // Fetch the first column from the next row in resultset. (This wud be first row since this is a first call to fetchcol) + $result = $stmt->fetchColumn(); + var_dump($result); + + // Fetch the second column from the next row. (This would be second row since this is a second call to fetchcol). + $result = $stmt->fetchColumn(1); + var_dump($result); + + // Test false is returned when there are no more rows. + $result = $stmt->fetchColumn(1); + var_dump($result); + + dropTable($db, $tbname); + unset($stmt); + unset($conn); +} catch (PDOException $e) { + var_dump($e); exit; } -?> +?> --EXPECT-- - string(1) "1" string(10) "STRINGCOL2" bool(false) - - diff --git a/test/functional/pdo_sqlsrv/pdostatement_fetchObject.phpt b/test/functional/pdo_sqlsrv/pdostatement_fetchObject.phpt index c3abd602c351bf06b985292354cd735467df9a4d..3a2802dcd8e89c80e956300e74cbefb9019d446f 100644 GIT binary patch literal 3978 zcmeHIZBN@U5ax4!#i{CtvMpVL_96i*g3_{X&>|X5e3(=@$+h)J?BY0#YTAF_*-3dD zxcfLHsuWWDxx2@AzUO>D>Ww4c_aZDbOi?HEQTziF4LRz$Od(!^LajJnA+RiilxYTf zxxk|B`TqFp;B?R@^WDA0d_l;|k}GUAiVMEr(@D-#U*VJ`TB*d_Bv$O9~}2q zR$gs2ks=|}lcFp0T#Cnx|AHP8o5|_nXtJMWktJ0{@jR`T@XG`GG}9P9K_Z2qW3@JS zszn_OmLqL6?wU8M-9#bNxG&OyC{XE$#Tl+5w8-BZXjb+sZ^dP1T#b9jy>0}rpno4BF86F6uz{0D`Hd6W}uM&Y5x;Q}S`mcEt04fo!?lM5F1nKo`$LOnA;R zhm(FLnajf(HS~(IHnY5 zhmpg9MYvOCA?xzBCLL=oRm8>8P2#BJY4UW}P(EY6rg3gC?vxTNahIk>xZRxR_b#^; zj8w^m6{g1osU+Rfq%R~UwQSTYX-vO=L&8Yt!3a$6I>CkJQa}?oYsI``YLb@uqD4!D z_N-+0&QD3(NVG#Q2sSo0yucerXM^EUcXS+jTR{-`VMx!NR|vyx`?SL_cw#*yL+2j6 z4uWlhgyfpO1cVUHc>(k=nniS7myj_vLnvs1i5Zjyrl2KgGwc#lcE&}G zxSeZ|@e73O{LZXvlV5}k#Z1pZPC=U}wNHAR*>Rz0nF-i>|G|Vvq*63*h=C2p9)>Y4 zE2>FJNMVqc9t~WkGi1b&>R@h<9k;-Q9ma;28NU@JJ11-eILFnwcf~SJ2R3+CPko>pQ02-FclasQ1x&f913i9rR#22uXv!)jQlrWX6HSzPT*Wo? zY5JqGMR^x~Y*Xp(T$`7QJ%@_bU3c5#bz_^ZylupnT0V08{CVl@E=`KgOHcm)J-PeVRLc7UmtOOT delta 588 zcmeB@zb7*xlvhE$I6Jc-GfgiuFIjzJfwaGZx^J;_er|4l9$3hli>sullB=4FQza!y z!B!zTKQAvexkN+L8Yog+m;)423U>8zbq-O`Qg93M_f=3*&{I$;NleN~H3F)coW&@` z%n77B8CB~!Q#X(8D=RU+lm<^ z5(Or!z~n5j_zq@}uG`E?K$4L~8b~Uz$SERQ7o3}zlY{Q{$*C-gK($?99V@})2^Nse zufS|hRs|qimsME-*`%<HSD9OyvQ&36O1jTMyVo`ibX>NfAkPlMH#bs~DrK{^25de%@U0p6iE(V6l=4|zh Z44b#H6|piia4~E?$hMJj^DW->i~z;~o9O@m diff --git a/test/functional/pdo_sqlsrv/pdostatement_fetch_style.phpt b/test/functional/pdo_sqlsrv/pdostatement_fetch_style.phpt index b942e78e..e596327f 100644 --- a/test/functional/pdo_sqlsrv/pdostatement_fetch_style.phpt +++ b/test/functional/pdo_sqlsrv/pdostatement_fetch_style.phpt @@ -1,62 +1,55 @@ --TEST-- Test the PDOStatement::fetch() method with different fetch styles. --SKIPIF-- - + --FILE-- query( "Select * from ". $table1 ); + $stmt = $conn->query("Select * from $tbname"); $result = $stmt->fetch(PDO::FETCH_BOTH); var_dump($result); $stmt->closeCursor(); } -function fetch_assoc( $conn ) +function fetchAssoc($conn, $tbname) { - global $table1; - $stmt = $conn->query( "Select * from ". $table1 ); + $stmt = $conn->query("Select * from $tbname"); $result = $stmt->fetch(PDO::FETCH_ASSOC); var_dump($result); $stmt->closeCursor(); } -function fetch_lazy( $conn ) +function fetchLazy($conn, $tbname) { - global $table1; - $stmt = $conn->query( "Select * from " . $table1 ); + $stmt = $conn->query("Select * from $tbname"); $result = $stmt->fetch(PDO::FETCH_LAZY); var_dump($result); $stmt->closeCursor(); } -function fetch_obj( $conn ) +function fetchObj($conn, $tbname) { - global $table1; - $stmt = $conn->query( "Select * from ". $table1 ); + $stmt = $conn->query("Select * from $tbname"); $result = $stmt->fetch(PDO::FETCH_OBJ); var_dump($result); $stmt->closeCursor(); } -function fetch_num( $conn ) +function fetchNum($conn, $tbname) { - global $table1; - $stmt = $conn->query( "Select * from ". $table1 ); + $stmt = $conn->query("Select * from $tbname"); $result = $stmt->fetch(PDO::FETCH_NUM); var_dump($result); $stmt->closeCursor(); - } -function fetch_bound( $conn ) +function fetchBound($conn, $tbname) { - global $table1; - $stmt = $conn->query( "Select * from ". $table1 ); + $stmt = $conn->query("Select * from $tbname"); $stmt->bindColumn('IntCol', $IntCol); $stmt->bindColumn('CharCol', $CharCol); $stmt->bindColumn('NCharCol', $NCharCol); @@ -66,8 +59,7 @@ function fetch_bound( $conn ) $stmt->bindColumn('FloatCol', $FloatCol); $stmt->bindColumn('XmlCol', $XmlCol); $result = $stmt->fetch(PDO::FETCH_BOUND); - if (!$result) - { + if (!$result) { die("Error in FETCH_BOUND\n"); } var_dump($IntCol); @@ -81,73 +73,69 @@ function fetch_bound( $conn ) $stmt->closeCursor(); } -function fetch_class( $conn ) +function fetchClass($conn, $tbname) { - global $table1; - global $table1_class; - $stmt = $conn->query( "Select * from ". $table1 ); - $stmt->setFetchMode(PDO::FETCH_CLASS, $table1_class); + global $mainTypesClass; + $stmt = $conn->query("Select * from $tbname"); + $stmt->setFetchMode(PDO::FETCH_CLASS, $mainTypesClass); $result = $stmt->fetch(PDO::FETCH_CLASS); - $result->dumpAll(); + $result->dumpAll(); $stmt->closeCursor(); } -function fetch_into( $conn ) +function fetchInto($conn, $tbname) { - global $table1; - global $table1_class; - $stmt = $conn->query( "Select * from ". $table1 ); - $obj = new $table1_class; + 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(); + $obj->dumpAll(); $stmt->closeCursor(); } -function fetch_invalid( $conn ) +function fetchInvalid($conn, $tbname) { - global $table1; - $stmt = $conn->query( "Select * from ". $table1 ); - try - { + $stmt = $conn->query("Select * from $tbname"); + try { $result = $stmt->fetch(PDO::FETCH_UNKNOWN); - } - catch(PDOException $err) - { + } catch (PDOException $err) { print_r($err); - } + } } -try -{ +try { $db = connect(); - create_and_insert_table1( $db ); + $tbname = "PDO_MainTypes"; + createAndInsertTableMainTypes($db, $tbname); echo "Test_1 : FETCH_BOTH :\n"; - fetch_both($db); + fetchBoth($db, $tbname); echo "Test_2 : FETCH_ASSOC :\n"; - fetch_assoc($db); + fetchAssoc($db, $tbname); echo "Test_3 : FETCH_LAZY :\n"; - fetch_lazy($db); + fetchLazy($db, $tbname); echo "Test_4 : FETCH_OBJ :\n"; - fetch_obj($db); + fetchObj($db, $tbname); echo "Test_5 : FETCH_NUM :\n"; - fetch_num($db); + fetchNum($db, $tbname); echo "Test_6 : FETCH_BOUND :\n"; - fetch_bound($db); + fetchBound($db, $tbname); echo "Test_7 : FETCH_CLASS :\n"; - fetch_class($db); + fetchClass($db, $tbname); echo "Test_8 : FETCH_INTO :\n"; - fetch_into($db); + fetchInto($db, $tbname); echo "Test_9 : FETCH_INVALID :\n"; - fetch_invalid($db); -} -catch( PDOException $e ) { - var_dump( $e ); + fetchInvalid($db, $tbname); + + dropTable($db, $tbname); + unset($db); +} catch (PDOException $e) { + var_dump($e); exit; } -?> +?> --EXPECTF-- Test_1 : FETCH_BOTH : @@ -207,7 +195,7 @@ array(8) { Test_3 : FETCH_LAZY : object(PDORow)#%x (%x) { ["queryString"]=> - string(25) "Select * from PDO_Types_1" + string(27) "Select * from PDO_MainTypes" ["IntCol"]=> string(1) "1" ["CharCol"]=> @@ -294,6 +282,6 @@ Test_9 : FETCH_INVALID : Fatal error: Uncaught Error: Undefined class constant 'FETCH_UNKNOWN' in %s:%x Stack trace: -#0 %s: fetch_invalid(Object(PDO)) +#0 %s: fetchInvalid(Object(PDO), 'PDO_MainTypes') #1 {main} - thrown in %s on line %x \ No newline at end of file + 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 32b35f66..ea61164e 100644 --- a/test/functional/pdo_sqlsrv/pdostatement_getColumnMeta.phpt +++ b/test/functional/pdo_sqlsrv/pdostatement_getColumnMeta.phpt @@ -1,76 +1,81 @@ --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). --SKIPIF-- - + --FILE-- query( "Select * from ". $table1 ); + $stmt = $conn->query("Select * from $tbname"); // 1 - $meta = $stmt->getColumnMeta( 0 ); - var_dump($meta); + $meta = $stmt->getColumnMeta(0); + var_dump($meta); // 2 - $meta = $stmt->getColumnMeta( 1 ); - var_dump($meta); + $meta = $stmt->getColumnMeta(1); + var_dump($meta); // 3 - $meta = $stmt->getColumnMeta( 2 ); - var_dump($meta); + $meta = $stmt->getColumnMeta(2); + var_dump($meta); // 4 - $meta = $stmt->getColumnMeta( 3 ); - var_dump($meta); - + $meta = $stmt->getColumnMeta(3); + var_dump($meta); + // 5 - $meta = $stmt->getColumnMeta( 4 ); - var_dump($meta); + $meta = $stmt->getColumnMeta(4); + var_dump($meta); // 6 - $meta = $stmt->getColumnMeta( 5 ); - var_dump($meta); + $meta = $stmt->getColumnMeta(5); + var_dump($meta); // 7 - $meta = $stmt->getColumnMeta( 6 ); - var_dump($meta); + $meta = $stmt->getColumnMeta(6); + var_dump($meta); // 8 - $meta = $stmt->getColumnMeta( 7 ); - var_dump($meta); + $meta = $stmt->getColumnMeta(7); + if (isColEncrypted()) { + $xmlType = "nvarchar"; + } else { + $xmlType = "xml"; + } + if ($meta["sqlsrv:decl_type"] != $xmlType) { + echo "Wrong column metadata was retrieved for a $xmlType column.\n"; + } + unset($meta["sqlsrv:decl_type"]); + var_dump($meta); // Test invalid arguments, set error mode to silent to reduce the amount of error messages generated $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT); // Test negative column number, ignore the error messages - $meta = $stmt->getColumnMeta( -1 ); + $meta = $stmt->getColumnMeta(-1); var_dump($meta); // Test non-existent column number - //$meta = $stmt->getColumnMeta( 10 ); - //var_dump($meta); + $meta = $stmt->getColumnMeta(10); + var_dump($meta); } - -try -{ + +try { $db = connect(); - create_and_insert_table1( $db ); - fetch_both($db); -} - -catch( PDOException $e ) { - - var_dump( $e ); + $tbname = "PDO_MainTypes"; + createAndInsertTableMainTypes($db, $tbname); + fetchBoth($db, $tbname); +} catch (PDOException $e) { + var_dump($e); exit; } -?> +?> --EXPECTF-- array(8) { @@ -199,11 +204,9 @@ array(8) { ["precision"]=> int(0) } -array(8) { +array(7) { ["flags"]=> int(0) - ["sqlsrv:decl_type"]=> - string(3) "xml" ["native_type"]=> string(6) "string" ["table"]=> @@ -219,4 +222,6 @@ array(8) { } Warning: PDOStatement::getColumnMeta(): SQLSTATE[42P10]: Invalid column reference: column number must be non-negative in %s on line %x -bool(false) \ No newline at end of file +bool(false) + +Fatal error: pdo_sqlsrv_stmt_get_col_meta: invalid column number. in %s on line %x 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 145e59eb..e60f80b0 100644 --- a/test/functional/pdo_sqlsrv/pdostatement_getColumnMeta_unicode_col_name.phpt +++ b/test/functional/pdo_sqlsrv/pdostatement_getColumnMeta_unicode_col_name.phpt @@ -1,124 +1,115 @@ --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). --SKIPIF-- - + --FILE-- query( "Select * from ". $table1 ); + $stmt = $conn->query("Select * from $tbname"); // 1 - $meta = $stmt->getColumnMeta( 0 ); - var_dump($meta); + $meta = $stmt->getColumnMeta(0); + var_dump($meta); // 2 - $meta = $stmt->getColumnMeta( 1 ); - var_dump($meta); + $meta = $stmt->getColumnMeta(1); + var_dump($meta); // 3 - $meta = $stmt->getColumnMeta( 2 ); - var_dump($meta); + $meta = $stmt->getColumnMeta(2); + var_dump($meta); // 4 - $meta = $stmt->getColumnMeta( 3 ); - var_dump($meta); - + $meta = $stmt->getColumnMeta(3); + var_dump($meta); + // 5 - $meta = $stmt->getColumnMeta( 4 ); - var_dump($meta); + $meta = $stmt->getColumnMeta(4); + var_dump($meta); // 6 - $meta = $stmt->getColumnMeta( 5 ); - var_dump($meta); + $meta = $stmt->getColumnMeta(5); + var_dump($meta); // 7 - $meta = $stmt->getColumnMeta( 6 ); - var_dump($meta); + $meta = $stmt->getColumnMeta(6); + var_dump($meta); // 8 - $meta = $stmt->getColumnMeta( 7 ); - var_dump($meta); + $meta = $stmt->getColumnMeta(7); + if (isColEncrypted()) { + $xmlType = "nvarchar"; + } else { + $xmlType = "xml"; + } + if ($meta["sqlsrv:decl_type"] != $xmlType) { + echo "Wrong column metadata was retrieved for a $xmlType column.\n"; + } + unset($meta["sqlsrv:decl_type"]); + var_dump($meta); // Test invalid arguments, set error mode to silent to reduce the amount of error messages generated $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT); // Test negative column number, ignore the error messages - $meta = $stmt->getColumnMeta( -1 ); + $meta = $stmt->getColumnMeta(-1); var_dump($meta); // Test non-existent column number - //$meta = $stmt->getColumnMeta( 10 ); - //var_dump($meta); + $meta = $stmt->getColumnMeta(10); + var_dump($meta); } - -function create_and_insert_table_unicode( $conn ) + +function createAndInsertTableUnicode($conn, $tbname) { - global $string_col, $date_col, $large_string_col, $xml_col, $binary_col, $int_col, $decimal_col, $guid_col, $null_col, $comma, $closing_brace, $table1; - - try - { - $create_query = - - "IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'" . $table1 . "') AND type in (N'U')) - DROP TABLE " . $table1 . - - " CREATE TABLE [dbo].[" . $table1 . "]( - [此是後話] [int] NULL, - [Κοντάוְ×ַתָּה第] [char](10) NULL, - [NΚοντάוְ×ַתָּה第] [nchar](10) NULL, - [ნáƒáƒ›áƒ˜áƒœáƒáƒ•áƒ˜iaÅ‚opioБун] [datetime] NULL, - [VarcharCol] [varchar](50) NULL, - [NVarΚοντάוְ×ַתָּה第] [nvarchar](50) NULL, - [FloatCol] [float] NULL, - [XmlCol] [xml] NULL - ) ON [PRIMARY] - "; - - $conn->query( $create_query ); - - for ($i = 0 ; $i <= 1; ++ $i) - { - $insert_query = - "INSERT INTO PDO_Types_1 VALUES (". - $int_col[$i] . $comma . - $string_col[$i] . $comma . - $string_col[$i] . $comma . - "Convert(datetime, ". $date_col[$i] . ")" . $comma . - $string_col[$i] . $comma . - $string_col[$i] . $comma . - $decimal_col[$i] . $comma . - $xml_col[$i] . - ")"; - - $conn->query ( $insert_query ); + try { + global $string_col, $xml_col, $int_col, $decimal_col, $datetime_col; + if (isColEncrypted()) { + $xmlType = "nvarchar(max)"; + } else { + $xmlType = "xml"; } - } - catch(Exception $e) - { - var_dump( $e); + $columnMetaArr = array("此是後話" => "int", + "Κοντάוְ×ַתָּה第" => "char(10)", + "NΚοντάוְ×ַתָּה第" => "nchar(10)", + "ნáƒáƒ›áƒ˜áƒœáƒáƒ•áƒ˜iaÅ‚opioБун" => "datetime", + "VarcharCol" => "varchar(50)", + "NVarΚοντάוְ×ַתָּה第" => "nvarchar(50)", + "FloatCol" => "float", + "XmlCol" => $xmlType); + createTable($conn, $tbname, $columnMetaArr, "ON [PRIMARY]"); + + for ($i = 0 ; $i <= 1; ++ $i) { + $inputs = array("此是後話" => $int_col[$i], + "Κοντάוְ×ַתָּה第" => $string_col[$i], + "NΚοντάוְ×ַתָּה第" => $string_col[$i], + "ნáƒáƒ›áƒ˜áƒœáƒáƒ•áƒ˜iaÅ‚opioБун" => $datetime_col[$i], + "VarcharCol" => $string_col[$i], + "NVarΚοντάוְ×ַתָּה第" => $string_col[$i], + "FloatCol" => $decimal_col[$i], + "XmlCol" => $xml_col[$i]); + $stmt = insertRow($conn, $tbname, $inputs, "prepareBindParam"); + } + } catch (Exception $e) { + var_dump($e); exit; } -} -try -{ - $db = connect(); - create_and_insert_table_unicode( $db ); - fetch_both($db); } -catch( PDOException $e ) { - - var_dump( $e ); +try { + $db = connect(); + $tbname = "PDO_MainTypes"; + createAndInsertTableUnicode($db, $tbname); + fetchBoth($db, $tbname); +} catch (PDOException $e) { + var_dump($e); exit; } - - -?> +?> --EXPECTF-- array(8) { @@ -247,11 +238,9 @@ array(8) { ["precision"]=> int(0) } -array(8) { +array(7) { ["flags"]=> int(0) - ["sqlsrv:decl_type"]=> - string(3) "xml" ["native_type"]=> string(6) "string" ["table"]=> @@ -267,4 +256,6 @@ array(8) { } Warning: PDOStatement::getColumnMeta(): SQLSTATE[42P10]: Invalid column reference: column number must be non-negative in %s on line %x -bool(false) \ No newline at end of file +bool(false) + +Fatal error: pdo_sqlsrv_stmt_get_col_meta: invalid column number. in %s on line %x diff --git a/test/functional/pdo_sqlsrv/pdostatement_nextRowset.phpt b/test/functional/pdo_sqlsrv/pdostatement_nextRowset.phpt index 85a658a0e7f2ea0524193c9dd394bee1979dc826..7cf0bc41f833176cfd8987539a94597ea283217e 100644 GIT binary patch delta 749 zcmZvaL2J}N6vx>WO9>*#>Zw|uA+QOUlICF1rIoeaLcwA!ITS>~?Bs1Wm`u{iq}xSg zJ$ey#$ZdnS-L$i-@D2GKva4AcFWO2QU489DCCYbLFH! zP4Fqa(?C8(Foa#8DPu^5skG`=3>isqTS~ezI3^MErZZ`w_pSqO12hS>OgR#PeHI+C z9J%nwFvcqnX<^FDM_|+uGEyb3s%T7`g0-qCcQJpU)zxkf7T-758?VLhja$aKoNWu# z;g+4&e5Tw3o@P}Ojn&n7b@po2t<^$~AXJ_Feh-ugItEiNWpGI`6H&^*K&#&71>t^B zB$+9%B&|K$(`L4PcGy39VcXjCB7{jK#&X?pkuX3;`Lwcl3a2P|gclJDAt9FyK}G_( z%#33tFr1vG6V;6c97Vxd4tbg&goF=Ch(O1L%U=e0uG#kB>}0U-+2ya+$F}2?NqbWs z%TMjjjfai}x?ZjQ^|te7cdvTQWdkfUE3N!`-&+2;`Qb>Cv={M_99Jg|^87gtG9CD+7*;*+Zx zr391|^b}M|5|eULjesmA>&f#O1KBY9b zKm#ab%~i_<1on1ZlM9$9DKUV65?EEVVXUnkm{nX-l$n>VVXCPBl;5nvBFsFwK$L|G xuFha`qNp$vgVJOxInB+D>ao#(u@p~oy62Z5 + --FILE-- query("SELECT * FROM " . $table1 ); - echo "Set Fetch Mode for PDO::FETCH_ASSOC \n"; + $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 " . $table1 ); - echo "Set Fetch Mode for PDO::FETCH_NUM \n"; + $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 " . $table1 ); - echo "Set Fetch Mode for PDO::FETCH_BOTH \n"; + $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 " . $table1 ); - echo "Set Fetch Mode for PDO::FETCH_LAZY \n"; + 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 " . $table1 ); - echo "Set Fetch Mode for PDO::FETCH_OBJ \n"; + $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); } ?> --EXPECT-- -Set Fetch Mode for PDO::FETCH_ASSOC +Set Fetch Mode for PDO::FETCH_ASSOC array(8) { ["IntCol"]=> string(1) "1" @@ -61,7 +61,7 @@ array(8) { ["XmlCol"]=> string(431) " 1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417." } -Set Fetch Mode for PDO::FETCH_NUM +Set Fetch Mode for PDO::FETCH_NUM array(8) { [0]=> string(1) "1" @@ -80,7 +80,7 @@ array(8) { [7]=> string(431) " 1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417." } -Set Fetch Mode for PDO::FETCH_BOTH +Set Fetch Mode for PDO::FETCH_BOTH array(16) { ["IntCol"]=> string(1) "1" @@ -115,10 +115,10 @@ array(16) { [7]=> string(431) " 1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417." } -Set Fetch Mode for PDO::FETCH_LAZY +Set Fetch Mode for PDO::FETCH_LAZY object(PDORow)#3 (9) { ["queryString"]=> - string(25) "SELECT * FROM PDO_Types_1" + string(27) "SELECT * FROM PDO_MainTypes" ["IntCol"]=> string(1) "1" ["CharCol"]=> @@ -136,7 +136,7 @@ object(PDORow)#3 (9) { ["XmlCol"]=> string(431) " 1 This is a really large string used to test certain large data types like xml data type. The length of this string is greater than 256 to correctly test a large data type. This is currently used by atleast varchar type and by xml type. The fetch tests are the primary consumer of this string to validate that fetch on large types work fine. The length of this string as counted in terms of number of characters is 417." } -Set Fetch Mode for PDO::FETCH_OBJ +Set Fetch Mode for PDO::FETCH_OBJ object(stdClass)#5 (8) { ["IntCol"]=> string(1) "1" From 1317d671700daaa900dd0f8f13d0e2e3eab2448e Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Wed, 1 Nov 2017 17:24:17 -0700 Subject: [PATCH 02/16] remove xfail from pdostatement_nextRowset.phpt --- test/functional/pdo_sqlsrv/PDO11_Drivers.phpt | 2 +- .../pdo_sqlsrv/pdo_query_timeout.phpt | 36 +++++++++--------- .../pdo_sqlsrv/pdostatement_nextRowset.phpt | Bin 10845 -> 10727 bytes 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/test/functional/pdo_sqlsrv/PDO11_Drivers.phpt b/test/functional/pdo_sqlsrv/PDO11_Drivers.phpt index 5353a5f3..3756f851 100644 --- a/test/functional/pdo_sqlsrv/PDO11_Drivers.phpt +++ b/test/functional/pdo_sqlsrv/PDO11_Drivers.phpt @@ -1,7 +1,7 @@ --TEST-- PDO Drivers Info Test --DESCRIPTION-- -Verifies the functionality of "PDO:getAvailableDrivers()�. +Verifies the functionality of "PDO:getAvailableDrivers()". --ENV-- PHPT_EXEC=true --SKIPIF-- diff --git a/test/functional/pdo_sqlsrv/pdo_query_timeout.phpt b/test/functional/pdo_sqlsrv/pdo_query_timeout.phpt index 16b86354..8e5e1ce4 100644 --- a/test/functional/pdo_sqlsrv/pdo_query_timeout.phpt +++ b/test/functional/pdo_sqlsrv/pdo_query_timeout.phpt @@ -44,24 +44,24 @@ try { } echo "Done\n"; ?> ---EXPECT-- -Starting test... +--EXPECTREGEX-- +Starting test\.\.\. Setting query timeout as an attribute in connection -array(3) { - [0]=> - string(5) "HYT00" - [1]=> - int(0) - [2]=> - string(63) "[Microsoft][ODBC Driver 13 for SQL Server]Query timeout expired" -} +array\(3\) \{ + \[0\]=> + string\(5\) \"HYT00\" + \[1\]=> + int\(0\) + \[2\]=> + string\(63\) \"\[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Query timeout expired\" +\} Setting query timeout in the statement -array(3) { - [0]=> - string(5) "HYT00" - [1]=> - int(0) - [2]=> - string(63) "[Microsoft][ODBC Driver 13 for SQL Server]Query timeout expired" -} +array\(3\) \{ + \[0\]=> + string\(5\) \"HYT00\" + \[1\]=> + int\(0\) + \[2\]=> + string\(63\) \"\[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]Query timeout expired\" +\} Done diff --git a/test/functional/pdo_sqlsrv/pdostatement_nextRowset.phpt b/test/functional/pdo_sqlsrv/pdostatement_nextRowset.phpt index 7cf0bc41f833176cfd8987539a94597ea283217e..339880bc800bb4a44bf279f260aa22f0b8f210a8 100644 GIT binary patch delta 12 TcmcZ`@;rFMU#88)%&*h{ExHC& delta 140 zcmaDJd^cpnU#9v9H%Ct&U0p7x(sYIL%#sX+-Per~EldSX#h hVtT4Vaz Date: Thu, 2 Nov 2017 09:51:01 -0700 Subject: [PATCH 03/16] change include file to MsCommon_mid-refactor.inc in pdo_quote.phpt --- test/functional/pdo_sqlsrv/pdo_quote.phpt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/functional/pdo_sqlsrv/pdo_quote.phpt b/test/functional/pdo_sqlsrv/pdo_quote.phpt index a774a4ee..9c2c431c 100644 --- a/test/functional/pdo_sqlsrv/pdo_quote.phpt +++ b/test/functional/pdo_sqlsrv/pdo_quote.phpt @@ -1,10 +1,10 @@ --TEST-- Test the PDO::quote() method. --SKIPIF-- - + --FILE-- 3, PDO::ATTR_CASE => 2)); From 529c5aa77bc22e2fefe8cd4509f82f803c87e09d Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Thu, 2 Nov 2017 10:33:18 -0700 Subject: [PATCH 04/16] fix typo in pdo_utf8_conn.phpt --- test/functional/pdo_sqlsrv/pdo_utf8_conn.phpt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functional/pdo_sqlsrv/pdo_utf8_conn.phpt b/test/functional/pdo_sqlsrv/pdo_utf8_conn.phpt index b0224eeb..4bcbcc4f 100644 --- a/test/functional/pdo_sqlsrv/pdo_utf8_conn.phpt +++ b/test/functional/pdo_sqlsrv/pdo_utf8_conn.phpt @@ -4,7 +4,7 @@ UTF-8 connection strings --FILE-- Date: Fri, 3 Nov 2017 14:35:16 -0700 Subject: [PATCH 05/16] address review comments --- test/functional/pdo_sqlsrv/PDO12_Info.phpt | 2 +- .../pdo_sqlsrv/PDO24_ErrorCode.phpt | 7 ++- .../pdo_sqlsrv/PDO25_ErrorInfo.phpt | 4 +- test/functional/pdo_sqlsrv/break_pdo.php | 63 ++++++++++--------- .../pdo_sqlsrv/pdo_connection_resiliency.phpt | 2 + test/functional/pdo_sqlsrv/pdo_error.phpt | 2 +- 6 files changed, 42 insertions(+), 38 deletions(-) diff --git a/test/functional/pdo_sqlsrv/PDO12_Info.phpt b/test/functional/pdo_sqlsrv/PDO12_Info.phpt index dd9acb16..18deeb74 100644 --- a/test/functional/pdo_sqlsrv/PDO12_Info.phpt +++ b/test/functional/pdo_sqlsrv/PDO12_Info.phpt @@ -18,7 +18,7 @@ try { if (stristr($info, "PDO support => enabled") === false) { printf("PDO is not enabled\n"); } elseif (stristr($info, "pdo_sqlsrv support => enabled") === false) { - printf("Cannot find PDO driver line in phpinfo() output\n"); + printf("Cannot find PDO_SQLSRV driver in phpinfo() output\n"); } else { printf("Done\n"); } diff --git a/test/functional/pdo_sqlsrv/PDO24_ErrorCode.phpt b/test/functional/pdo_sqlsrv/PDO24_ErrorCode.phpt index 3d80869d..57ac55d0 100644 --- a/test/functional/pdo_sqlsrv/PDO24_ErrorCode.phpt +++ b/test/functional/pdo_sqlsrv/PDO24_ErrorCode.phpt @@ -11,7 +11,7 @@ PHPT_EXEC=true require_once("MsCommon_mid-refactor.inc"); try { $conn1 = connect(); - checkError(1, $conn1, '00000'); + checkError(1, $conn1); // Prepare test table $table1 = "Table1"; @@ -37,10 +37,11 @@ try { echo $e->getMessage(); } -function checkError($offset, &$obj, $expected = '00000') +function checkError($offset, &$obj) { $code = $obj->errorCode(); - if (($code != $expected) && (($expected != '00000') || ($code !=''))) { + $expected = '00000'; + if ($code != $expected && !empty($code)) { printf("[%03d] Expecting error code '%s' got code '%s'\n", $offset, $expected, $code); } } diff --git a/test/functional/pdo_sqlsrv/PDO25_ErrorInfo.phpt b/test/functional/pdo_sqlsrv/PDO25_ErrorInfo.phpt index ef5da345..6d16ed40 100644 --- a/test/functional/pdo_sqlsrv/PDO25_ErrorInfo.phpt +++ b/test/functional/pdo_sqlsrv/PDO25_ErrorInfo.phpt @@ -29,7 +29,7 @@ try { $stmt1->closeCursor(); dropTable($conn1, $table1); - $stmt1->execute(); + @$stmt1->execute(); checkError(5, $conn1); checkError(6, $stmt1, '42S02'); checkError(7, $stmt2, '42S02'); @@ -76,7 +76,7 @@ function checkError($offset, &$obj, $expected = '00000') printf("[%03d] Driver-specific error code not set\n", $offset); } if (!isset($info[2]) || ($info[2] == '')) { - printf("[%03d] Driver-specific error message.not set\n", $offset); + printf("[%03d] Driver-specific error message not set\n", $offset); } } } diff --git a/test/functional/pdo_sqlsrv/break_pdo.php b/test/functional/pdo_sqlsrv/break_pdo.php index d1aa4e9e..c5287a33 100644 --- a/test/functional/pdo_sqlsrv/break_pdo.php +++ b/test/functional/pdo_sqlsrv/break_pdo.php @@ -14,38 +14,39 @@ $tableName2 = "test_connres2"; // from AppVeyor does not have AdventureWorks. function generateTables($server, $uid, $pwd, $dbName, $tableName1, $tableName2) { - $conn = new PDO("sqlsrv:server = $server ; Database = $dbName ;", $uid, $pwd); - if ($conn === false) { - die(print_r(sqlsrv_errors())); + try { + $conn = new PDO("sqlsrv:server = $server ; Database = $dbName ;", $uid, $pwd); + + // Create table + $sql = "CREATE TABLE $tableName1 (c1 INT, c2 VARCHAR(40))"; + $stmt = $conn->query($sql); + + // Insert data + $sql = "INSERT INTO $tableName1 VALUES ( ?, ? )"; + for ($t = 100; $t < 116; $t++) { + $stmt = $conn->prepare($sql); + $ts = substr(sha1($t), 0, 5); + $params = array( $t,$ts ); + $stmt->execute($params); + } + + // Create table + $sql = "CREATE TABLE $tableName2 ( c1 INT, c2 VARCHAR(40) )"; + $stmt = $conn->query($sql); + + // Insert data + $sql = "INSERT INTO $tableName2 VALUES ( ?, ? )"; + for ($t = 200; $t < 209; $t++) { + $stmt = $conn->prepare($sql); + $ts = substr(sha1($t), 0, 5); + $params = array( $t,$ts ); + $stmt->execute($params); + } + + unset($conn); + } catch (PDOException $e) { + var_dump($e->errorInfo); } - - // Create table - $sql = "CREATE TABLE $tableName1 ( c1 INT, c2 VARCHAR(40) )"; - $stmt = $conn->query($sql); - - // Insert data - $sql = "INSERT INTO $tableName1 VALUES ( ?, ? )"; - for ($t = 100; $t < 116; $t++) { - $stmt = $conn->prepare($sql); - $ts = substr(sha1($t), 0, 5); - $params = array( $t,$ts ); - $stmt->execute($params); - } - - // Create table - $sql = "CREATE TABLE $tableName2 ( c1 INT, c2 VARCHAR(40) )"; - $stmt = $conn->query($sql); - - // Insert data - $sql = "INSERT INTO $tableName2 VALUES ( ?, ? )"; - for ($t = 200; $t < 209; $t++) { - $stmt = $conn->prepare($sql); - $ts = substr(sha1($t), 0, 5); - $params = array( $t,$ts ); - $stmt->execute($params); - } - - $conn = null; } // Break connection by getting the session ID and killing it. diff --git a/test/functional/pdo_sqlsrv/pdo_connection_resiliency.phpt b/test/functional/pdo_sqlsrv/pdo_connection_resiliency.phpt index cb4201c4..6c2adeec 100644 --- a/test/functional/pdo_sqlsrv/pdo_connection_resiliency.phpt +++ b/test/functional/pdo_sqlsrv/pdo_connection_resiliency.phpt @@ -31,6 +31,8 @@ $conn_break = connect(); $connectionInfo = "ConnectRetryCount = 10; ConnectRetryInterval = 10;"; try { + // TODO: Idle connection resiliency does not work with Column Encryption at this point + // Do not connect with ColumnEncryption for now $conn = connect($connectionInfo, array(), PDO::ERRMODE_EXCEPTION, true); } catch (PDOException $e) { echo "Could not connect.\n"; diff --git a/test/functional/pdo_sqlsrv/pdo_error.phpt b/test/functional/pdo_sqlsrv/pdo_error.phpt index 6272df3e..65ddce7e 100644 --- a/test/functional/pdo_sqlsrv/pdo_error.phpt +++ b/test/functional/pdo_sqlsrv/pdo_error.phpt @@ -12,7 +12,7 @@ try { $tbname = "PDO_MainTypes"; createTableMainTypes($db, $tbname); // query with a wrong column name. - $db->query("Select * from " . $tbname . " where IntColX = 1"); + $db->query("SELECT * FROM $tbname WHERE IntColX = 1"); dropTable($db, $tbname); unset($conn); From a60992f8a550ceaebe8f20a7e8dc4f49aa016b0a Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Fri, 3 Nov 2017 17:01:09 -0700 Subject: [PATCH 06/16] 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); } From e09dd9163df2e296b6a385bd722dbcb30af8c9f5 Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Fri, 3 Nov 2017 17:10:45 -0700 Subject: [PATCH 07/16] add exception handling for pdo_transaction.phpt --- .../pdo_sqlsrv/pdo_transaction.phpt | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/test/functional/pdo_sqlsrv/pdo_transaction.phpt b/test/functional/pdo_sqlsrv/pdo_transaction.phpt index eaeac3db..65829b3f 100644 --- a/test/functional/pdo_sqlsrv/pdo_transaction.phpt +++ b/test/functional/pdo_sqlsrv/pdo_transaction.phpt @@ -10,17 +10,21 @@ require_once("MsCommon_mid-refactor.inc"); function deleteRows($conn, $tbname) { - if (!isColEncrypted()) { - $rows = $conn->exec("DELETE FROM $tbname WHERE col1 = 'a'"); - } else { - // needs to find parameter for encrypted columns - $sql = "DELETE FROM $tbname WHERE col1 = ?"; - $stmt = $conn->prepare($sql); - $col1 = "a"; - $stmt->execute(array($col1)); - $rows = $stmt->rowCount(); + try { + if (!isColEncrypted()) { + $rows = $conn->exec("DELETE FROM $tbname WHERE col1 = 'a'"); + } else { + // needs to find parameter for encrypted columns + $sql = "DELETE FROM $tbname WHERE col1 = ?"; + $stmt = $conn->prepare($sql); + $col1 = "a"; + $stmt->execute(array($col1)); + $rows = $stmt->rowCount(); + } + return $rows; + } catch (PDOException $e) { + var_dump($e->errorInfo); } - return $rows; } try { From 1e69c86d69ec5e265ef9d4288fd17244f9c467ce Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Mon, 6 Nov 2017 17:30:11 -0800 Subject: [PATCH 08/16] add refactored ae related tests --- .../pdo_sqlsrv/pdo_ae_insert_datetime.phpt | 46 +++-- .../pdo_sqlsrv/pdo_ae_insert_money.phpt | 79 ++++----- .../pdo_sqlsrv/pdo_ae_insert_numeric.phpt | 51 +++--- .../pdo_ae_insert_pdoparam_datetime.phpt | 53 +++--- .../pdo_ae_insert_pdoparam_money.phpt | 87 ++++------ .../pdo_ae_insert_pdoparam_numeric.phpt | 54 +++--- .../pdo_ae_insert_pdoparam_string.phpt | 57 +++---- .../pdo_sqlsrv/pdo_ae_insert_retrieve.phpt | 77 ++++----- .../pdo_ae_insert_retrieve_fixed_size.phpt | 104 +++++------- .../pdo_ae_insert_retrieve_nvarchar.phpt | 79 ++++----- .../pdo_ae_insert_retrieve_varchar.phpt | 78 ++++----- .../pdo_sqlsrv/pdo_ae_insert_string.phpt | 51 +++--- .../pdo_sqlsrv/pdo_ae_output_param_all.phpt | 157 +++++++++--------- 13 files changed, 411 insertions(+), 562 deletions(-) diff --git a/test/functional/pdo_sqlsrv/pdo_ae_insert_datetime.phpt b/test/functional/pdo_sqlsrv/pdo_ae_insert_datetime.phpt index f81cf8a8..dbff0f59 100644 --- a/test/functional/pdo_sqlsrv/pdo_ae_insert_datetime.phpt +++ b/test/functional/pdo_sqlsrv/pdo_ae_insert_datetime.phpt @@ -3,44 +3,40 @@ Test for inserting and retrieving encrypted data of datetime types --DESCRIPTION-- No PDO::PARAM_ type specified when binding parameters --SKIPIF-- - + --FILE-- colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r ); - if ( $r === false ) { - is_incompatible_types_error( $stmt, $dataType, "default type" ); - } - else { + $stmt = insertRow($conn, $tbname, array("c_det" => $inputValues[0], "c_rand" => $inputValues[1] ), null, $r); + if ($r === false) { + isIncompatibleTypesError($stmt, $dataType, "default type"); + } else { echo "****Encrypted default type is compatible with encrypted $dataType****\n"; - fetch_all( $conn, $tbname ); + fetchAll($conn, $tbname); } - DropTable( $conn, $tbname ); + dropTable($conn, $tbname); } - unset( $stmt ); - unset( $conn ); -} -catch( PDOException $e ) -{ + unset($stmt); + unset($conn); +} catch (PDOException $e) { echo $e->getMessage(); } ?> diff --git a/test/functional/pdo_sqlsrv/pdo_ae_insert_money.phpt b/test/functional/pdo_sqlsrv/pdo_ae_insert_money.phpt index e778290c..1cc76fd3 100644 --- a/test/functional/pdo_sqlsrv/pdo_ae_insert_money.phpt +++ b/test/functional/pdo_sqlsrv/pdo_ae_insert_money.phpt @@ -3,77 +3,60 @@ Test for inserting and retrieving encrypted data of money types --DESCRIPTION-- No PDO::PARAM_ tpe specified when binding parameters --SKIPIF-- - + --FILE-- setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT ); - - foreach ( $dataTypes as $dataType ) { +require_once("MsCommon_mid-refactor.inc"); +require_once("AEData.inc"); +$dataTypes = array("smallmoney", "money"); +try { + $conn = connect('', array(), PDO::ERRMODE_SILENT); + foreach ($dataTypes as $dataType) { echo "\nTesting $dataType:\n"; $success = true; - + // create table - $tbname = GetTempTableName( "", false ); - $colMetaArr = array( new columnMeta( $dataType, "c_det" ), new columnMeta( $dataType, "c_rand", null, "randomized" )); - create_table( $conn, $tbname, $colMetaArr ); - + $tbname = getTableName(); + $colMetaArr = array( new columnMeta($dataType, "c_det"), new columnMeta($dataType, "c_rand", null, "randomized")); + createTable($conn, $tbname, $colMetaArr); + // insert a row - $inputValues = array_slice( ${explode( "(", $dataType )[0] . "_params"}, 1, 2 ); + $inputValues = array_slice(${explode("(", $dataType)[0] . "_params"}, 1, 2); $r; - $stmt = insert_row( $conn, $tbname, array( $colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r ); - - if ( !is_col_enc() ) - { - if ( $r === false ) - { + $stmt = insertRow($conn, $tbname, array("c_det" => $inputValues[0], "c_rand" => $inputValues[1] ), null, $r); + + if (!isColEncrypted()) { + if ($r === false) { echo "Default type should be compatible with $dataType.\n"; $success = false; - } - else - { + } else { $sql = "SELECT * FROM $tbname"; - $stmt = $conn->query( $sql ); - $row = $stmt->fetch( PDO::FETCH_ASSOC ); - if ( $row["c_det"] != $inputValues[0] || $row["c_rand"] != $inputValues[1] ) - { + $stmt = $conn->query($sql); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + if ($row["c_det"] != $inputValues[0] || $row["c_rand"] != $inputValues[1]) { echo "Incorrect output retrieved for datatype $dataType.\n"; $success = false; } } - } - else - { - if ( $r === false ) - { - if ( $stmt->errorInfo()[0] != "22018" ) - { + } else { + if ($r === false) { + if ($stmt->errorInfo()[0] != "22018") { echo "Incorrect error returned.\n"; $success = false; } - } - else - { + } else { echo "$dataType is not compatible with any type.\n"; $success = false; } } - if ( $success ) + if ($success) { echo "Test successfully done.\n"; - DropTable( $conn, $tbname ); + } + dropTable($conn, $tbname); } - unset( $stmt ); - unset( $conn ); -} -catch( PDOException $e ) -{ + unset($stmt); + unset($conn); +} catch (PDOException $e) { echo $e->getMessage(); } ?> diff --git a/test/functional/pdo_sqlsrv/pdo_ae_insert_numeric.phpt b/test/functional/pdo_sqlsrv/pdo_ae_insert_numeric.phpt index 753d59b0..7d5627a2 100644 --- a/test/functional/pdo_sqlsrv/pdo_ae_insert_numeric.phpt +++ b/test/functional/pdo_sqlsrv/pdo_ae_insert_numeric.phpt @@ -3,44 +3,37 @@ Test for inserting and retrieving encrypted data of numeric types --DESCRIPTION-- No PDO::PARAM_ tpe specified when binding parameters --SKIPIF-- - + --FILE-- colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r ); - if ( $r === false ) { - is_incompatible_types_error( $stmt, $dataType, "default type" ); - } - else { + $stmt = insertRow($conn, $tbname, array( "c_det" => $inputValues[0], "c_rand" => $inputValues[1] ), null, $r); + if ($r === false) { + isIncompatibleTypesError($stmt, $dataType, "default type"); + } else { echo "****Encrypted default type is compatible with encrypted $dataType****\n"; - fetch_all( $conn, $tbname ); + fetchAll($conn, $tbname); } - DropTable( $conn, $tbname ); + dropTable($conn, $tbname); } - unset( $stmt ); - unset( $conn ); -} -catch( PDOException $e ) -{ + unset($stmt); + unset($conn); +} catch (PDOException $e) { echo $e->getMessage(); } ?> diff --git a/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_datetime.phpt b/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_datetime.phpt index c6b3523c..df3fbfc5 100644 --- a/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_datetime.phpt +++ b/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_datetime.phpt @@ -3,49 +3,42 @@ Test for inserting and retrieving encrypted data of datetime types --DESCRIPTION-- Use PDOstatement::bindParam with all PDO::PARAM_ types --SKIPIF-- - + --FILE-- colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r, "prepareBindParam", array( new bindParamOption( 1, $pdoParamType ), new bindParamOption( 2, $pdoParamType ))); - if ( $r === false ) - { - is_incompatible_types_error( $stmt, $dataType, $pdoParamType ); - } - else { + $stmt = insertRow($conn, $tbname, array( "c_det" => new BindParamOp(1, $inputValues[0], $pdoParamType), "c_rand" => new BindParamOp(2, $inputValues[1], $pdoParamType)), "prepareBindParam", $r); + if ($r === false) { + isIncompatibleTypesError($stmt, $dataType, $pdoParamType); + } else { echo "****PDO param type $pdoParamType is compatible with encrypted $dataType****\n"; - fetch_all( $conn, $tbname ); + fetchAll($conn, $tbname); } - $conn->query( "TRUNCATE TABLE $tbname" ); + $conn->query("TRUNCATE TABLE $tbname"); } - DropTable( $conn, $tbname ); + dropTable($conn, $tbname); } - unset( $stmt ); - unset( $conn ); -} -catch( PDOException $e ) -{ + unset($stmt); + unset($conn); +} catch (PDOException $e) { echo $e->getMessage(); } ?> diff --git a/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_money.phpt b/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_money.phpt index 9a8b2412..abdf5159 100644 --- a/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_money.phpt +++ b/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_money.phpt @@ -3,84 +3,67 @@ Test for inserting and retrieving encrypted data of money types --DESCRIPTION-- Use PDOstatement::bindParam with all PDO::PARAM_ types --SKIPIF-- - + --FILE-- setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT ); - - foreach ( $dataTypes as $dataType ) { +try { + $conn = connect('', array(), PDO::ERRMODE_SILENT); + foreach ($dataTypes as $dataType) { echo "\nTesting $dataType:\n"; $success = true; - + // create table - $tbname = GetTempTableName( "", false ); - $colMetaArr = array( new columnMeta( $dataType, "c_det" ), new columnMeta( $dataType, "c_rand", null, "randomized" )); - create_table( $conn, $tbname, $colMetaArr ); - + $tbname = getTableName(); + $colMetaArr = array(new ColumnMeta($dataType, "c_det"), new ColumnMeta($dataType, "c_rand", null, "randomized")); + createTable($conn, $tbname, $colMetaArr); + // test each PDO::PARAM_ type - foreach ( $pdoParamTypes as $pdoParamType ) { + foreach ($pdoParamTypes as $pdoParamType) { // insert a row - $inputValues = array_slice( ${explode( "(", $dataType )[0] . "_params"}, 1, 2 ); + $inputValues = array_slice(${explode("(", $dataType)[0] . "_params"}, 1, 2); $r; - $stmt = insert_row( $conn, $tbname, array( $colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r, "prepareBindParam", array( new bindParamOption( 1, $pdoParamType ), new bindParamOption( 2, $pdoParamType ))); - - - if ( !is_col_enc() ) - { - if ( $r === false ) - { + $stmt = insertRow($conn, $tbname, array("c_det" => new BindParamOp(1, $inputValues[0], $pdoParamType), "c_rand" => new BindParamOp(2, $inputValues[1], $pdoParamType)), "prepareBindParam", $r); + + + if (!isColEncrypted()) { + if ($r === false) { echo "$pdoParamType should be compatible with $dataType.\n"; $success = false; - } - else - { + } else { $sql = "SELECT * FROM $tbname"; - $stmt = $conn->query( $sql ); - $row = $stmt->fetch( PDO::FETCH_ASSOC ); - if ( ( $row["c_det"] != $inputValues[0] || $row["c_rand"] != $inputValues[1] ) && $pdoParamType != "PDO::PARAM_NULL" ) - { + $stmt = $conn->query($sql); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + if (($row["c_det"] != $inputValues[0] || $row["c_rand"] != $inputValues[1]) && $pdoParamType != "PDO::PARAM_NULL") { echo "Incorrect output retrieved for datatype $dataType.\n"; - var_dump( $inputValues ); - var_dump( $row ); + var_dump($inputValues); + var_dump($row); $success = false; } } - } - else - { - if ( $r === false ) - { - if ( $stmt->errorInfo()[0] != "22018" ) - { + } else { + if ($r === false) { + if ($stmt->errorInfo()[0] != "22018") { echo "Incorrect error returned.\n"; $success = false; } - } - else - { + } else { echo "$dataType is not compatible with any type.\n"; $success = false; } } - $conn->query( "TRUNCATE TABLE $tbname" ); + $conn->query("TRUNCATE TABLE $tbname"); } - if ( $success ) + if ($success) { echo "Test successfully done.\n"; - DropTable( $conn, $tbname ); + } + DropTable($conn, $tbname); } - unset( $stmt ); - unset( $conn ); -} -catch( PDOException $e ) -{ + unset($stmt); + unset($conn); +} catch (PDOException $e) { echo $e->getMessage(); } ?> diff --git a/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_numeric.phpt b/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_numeric.phpt index c40e2aeb..6cfd7f81 100644 --- a/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_numeric.phpt +++ b/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_numeric.phpt @@ -3,49 +3,41 @@ Test for inserting and retrieving encrypted data of numeric types --DESCRIPTION-- Use PDOstatement::bindParam with all PDO::PARAM_ types --SKIPIF-- - + --FILE-- colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r, "prepareBindParam", array( new bindParamOption( 1, $pdoParamType ), new bindParamOption( 2, $pdoParamType ))); - if ( $r === false ) - { - is_incompatible_types_error( $stmt, $dataType, $pdoParamType ); - } - else { + $stmt = insertRow($conn, $tbname, array( "c_det" => new BindParamOp(1, $inputValues[0], $pdoParamType), "c_rand" => new BindParamOp(2, $inputValues[1], $pdoParamType)), "prepareBindParam", $r); + if ($r === false) { + isIncompatibleTypesError($stmt, $dataType, $pdoParamType); + } else { echo "****PDO param type $pdoParamType is compatible with encrypted $dataType****\n"; - fetch_all( $conn, $tbname ); + fetchAll($conn, $tbname); } - $conn->query( "TRUNCATE TABLE $tbname" ); + $conn->query("TRUNCATE TABLE $tbname"); } - DropTable( $conn, $tbname ); + dropTable($conn, $tbname); } - unset( $stmt ); - unset( $conn ); -} -catch( PDOException $e ) -{ + unset($stmt); + unset($conn); +} catch (PDOException $e) { echo $e->getMessage(); } ?> diff --git a/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_string.phpt b/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_string.phpt index 4b2b9c59..44ec7d0a 100644 --- a/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_string.phpt +++ b/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_string.phpt @@ -3,50 +3,41 @@ Test for inserting and retrieving encrypted data of string types --DESCRIPTION-- Use PDOstatement::bindParam with all PDO::PARAM_ types --SKIPIF-- - + --FILE-- setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT ); - - foreach ( $dataTypes as $dataType ) { +require_once("MsCommon_mid-refactor.inc"); +require_once("AEData.inc"); +$dataTypes = array("char(5)", "varchar(max)", "nchar(5)", "nvarchar(max)"); +try { + $conn = connect('', array(), PDO::ERRMODE_SILENT); + foreach ($dataTypes as $dataType) { echo "\nTesting $dataType:\n"; - + // create table - $tbname = GetTempTableName( "", false ); - $colMetaArr = array( new columnMeta( $dataType, "c_det" ), new columnMeta( $dataType, "c_rand", null, "randomized" )); - create_table( $conn, $tbname, $colMetaArr ); - + $tbname = getTableName(); + $colMetaArr = array(new ColumnMeta($dataType, "c_det"), new ColumnMeta($dataType, "c_rand", null, "randomized")); + createTable($conn, $tbname, $colMetaArr); + // prepare statement for inserting into table - foreach ( $pdoParamTypes as $pdoParamType ) { + foreach ($pdoParamTypes as $pdoParamType) { // insert a row - $inputValues = array_slice( ${explode( "(", $dataType )[0] . "_params"}, 1, 2 ); + $inputValues = array_slice(${explode("(", $dataType)[0] . "_params"}, 1, 2); $r; - $stmt = insert_row( $conn, $tbname, array( $colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r, "prepareBindParam", array( new bindParamOption( 1, $pdoParamType ), new bindParamOption( 2, $pdoParamType ))); - if ( $r === false ) - { - is_incompatible_types_error( $stmt, $dataType, $pdoParamType ); - } - else { + $stmt = insertRow($conn, $tbname, array( "c_det" => new BindParamOp(1, $inputValues[0], $pdoParamType),"c_rand" => new BindParamOp(2, $inputValues[1], $pdoParamType)), "prepareBindParam", $r); + if ($r === false) { + isIncompatibleTypesError($stmt, $dataType, $pdoParamType); + } else { echo "****PDO param type $pdoParamType is compatible with encrypted $dataType****\n"; - fetch_all( $conn, $tbname ); + fetchAll($conn, $tbname); } - $conn->query( "TRUNCATE TABLE $tbname" ); + $conn->query("TRUNCATE TABLE $tbname"); } - DropTable( $conn, $tbname ); + dropTable($conn, $tbname); } - unset( $stmt ); - unset( $conn ); -} -catch( PDOException $e ) -{ + unset($stmt); + unset($conn); +} catch (PDOException $e) { echo $e->getMessage(); } ?> diff --git a/test/functional/pdo_sqlsrv/pdo_ae_insert_retrieve.phpt b/test/functional/pdo_sqlsrv/pdo_ae_insert_retrieve.phpt index 7bba2212..4f464c9d 100644 --- a/test/functional/pdo_sqlsrv/pdo_ae_insert_retrieve.phpt +++ b/test/functional/pdo_sqlsrv/pdo_ae_insert_retrieve.phpt @@ -3,73 +3,60 @@ Test for inserting encrypted data and retrieving both encrypted and decrypted da --DESCRIPTION-- Retrieving SQL query contains encrypted filter --SKIPIF-- - + --FILE-- $SSN, "FirstName" => "Catherine", "LastName" => "Abel", "BirthDate" => "1996-10-19" ); - $stmt = insert_row( $conn, $tbname, $inputs ); - + $stmt = insertRow($conn, $tbname, $inputs); + echo "Retrieving plaintext data:\n"; $selectSql = "SELECT SSN, FirstName, LastName, BirthDate FROM $tbname WHERE SSN = ?"; - $stmt = $conn->prepare( $selectSql ); - $stmt->bindParam( 1, $SSN ); + $stmt = $conn->prepare($selectSql); + $stmt->bindParam(1, $SSN); $stmt->execute(); - $decrypted_row = $stmt->fetch( PDO::FETCH_ASSOC ); - foreach ( $decrypted_row as $key => $value ) - { + $decrypted_row = $stmt->fetch(PDO::FETCH_ASSOC); + foreach ($decrypted_row as $key => $value) { print "$key: $value\n"; } - unset( $stmt ); -} -catch( PDOException $e ) -{ + unset($stmt); +} catch (PDOException $e) { echo $e->getMessage(); } - // for AE only echo "\nChecking ciphertext data:\n"; -if ( is_col_enc() ) -{ - try - { - $conn1 = ae_connect( null, null, true ); +if (isColEncrypted()) { + try { + $conn1 = connect('', array(), PDO::ERRMODE_EXCEPTION, true); $selectSql = "SELECT SSN, FirstName, LastName, BirthDate FROM $tbname"; - $stmt = $conn1->query( $selectSql ); - $encrypted_row = $stmt->fetch( PDO::FETCH_ASSOC ); - foreach ( $encrypted_row as $key => $value ) - { - if ( ctype_print( $value )) + $stmt = $conn1->query($selectSql); + $encrypted_row = $stmt->fetch(PDO::FETCH_ASSOC); + foreach ($encrypted_row as $key => $value) { + if (ctype_print($value)) { print "Error: expected a binary array for $key\n"; + } } - unset( $stmt ); - unset( $conn1 ); - } - catch( PDOException $e ) - { + unset($stmt); + unset($conn1); + } catch (PDOException $e) { echo $e->getMessage(); } } - -DropTable( $conn, $tbname ); -unset( $conn ); - +dropTable($conn, $tbname); +unset($conn); echo "Done\n"; ?> --EXPECT-- diff --git a/test/functional/pdo_sqlsrv/pdo_ae_insert_retrieve_fixed_size.phpt b/test/functional/pdo_sqlsrv/pdo_ae_insert_retrieve_fixed_size.phpt index ca76ba2f..6990e3dd 100644 --- a/test/functional/pdo_sqlsrv/pdo_ae_insert_retrieve_fixed_size.phpt +++ b/test/functional/pdo_sqlsrv/pdo_ae_insert_retrieve_fixed_size.phpt @@ -1,80 +1,64 @@ --TEST-- Test for inserting encrypted fixed size types data and retrieve both encrypted and decrypted data --SKIPIF-- - + --FILE-- 255, - "SmallIntData" => 32767, - "IntData" => 2147483647, - "BigIntData" => 92233720368547, - "DecimalData" => 79228162514264, - "BitData" => true, - "DateTimeData" => '9999-12-31 23:59:59.997', - "DateTime2Data" => '9999-12-31 23:59:59.9999999'); - $paramOptions = array( new bindParamOption( 4, "PDO::PARAM_INT" ) ); - $r; - $stmt = insert_row( $conn, $tbname, $inputs, $r, "prepareBindParam", $paramOptions ); - - print "Decrypted values:\n"; - fetch_all( $conn, $tbname ); + $colMetaArr = array("TinyIntData" => "tinyint", + "SmallIntData" => "smallint", + "IntData" => "int", + "BigIntData" => "bigint", + "DecimalData" => "decimal(18,0)", + "BitData" => "bit", + "DateTimeData" => "datetime", + "DateTime2Data" => "datetime2"); + createTable($conn, $tbname, $colMetaArr); - unset( $stmt ); -} -catch( PDOException $e ) -{ + // insert a row + $inputs = array( "TinyIntData" => 255, + "SmallIntData" => 32767, + "IntData" => 2147483647, + "BigIntData" => 92233720368547, + "DecimalData" => 79228162514264, + "BitData" => true, + "DateTimeData" => '9999-12-31 23:59:59.997', + "DateTime2Data" => '9999-12-31 23:59:59.9999999'); + //$paramOptions = array( new bindParamOption(4, "PDO::PARAM_INT") ); + $r; + $stmt = insertRow($conn, $tbname, $inputs, "prepareBindParam", $r); + + print "Decrypted values:\n"; + fetchAll($conn, $tbname); + unset($stmt); +} catch (PDOException $e) { echo $e->getMessage(); } - // for AE only -if ( is_col_enc() ) -{ - try - { - $conn1 = ae_connect( null, null, true ); - +if (isColEncrypted()) { + try { + $conn1 = connect('', array(), PDO::ERRMODE_EXCEPTION, true); + $selectSql = "SELECT * FROM $tbname"; - $stmt = $conn1->query( $selectSql ); - $encrypted_row = $stmt->fetch( PDO::FETCH_ASSOC ); - foreach ( $encrypted_row as $key => $value ) - { - if ( ctype_print( $value )) - { + $stmt = $conn1->query($selectSql); + $encrypted_row = $stmt->fetch(PDO::FETCH_ASSOC); + foreach ($encrypted_row as $key => $value) { + if (ctype_print($value)) { print "Error: expected a binary array for $key\n"; } } - - unset( $stmt ); - unset( $conn1 ); - } - catch( PDOException $e ) - { + unset($stmt); + unset($conn1); + } catch (PDOException $e) { echo $e->getMessage(); } } - -DropTable( $conn, $tbname ); -unset( $conn ); - +dropTable($conn, $tbname); +unset($conn); echo "Done\n"; ?> --EXPECT-- @@ -87,4 +71,4 @@ DecimalData: 79228162514264 BitData: 1 DateTimeData: 9999-12-31 23:59:59.997 DateTime2Data: 9999-12-31 23:59:59.9999999 -Done \ No newline at end of file +Done diff --git a/test/functional/pdo_sqlsrv/pdo_ae_insert_retrieve_nvarchar.phpt b/test/functional/pdo_sqlsrv/pdo_ae_insert_retrieve_nvarchar.phpt index bd2dab8f..92f03f88 100644 --- a/test/functional/pdo_sqlsrv/pdo_ae_insert_retrieve_nvarchar.phpt +++ b/test/functional/pdo_sqlsrv/pdo_ae_insert_retrieve_nvarchar.phpt @@ -1,79 +1,60 @@ --TEST-- Test for inserting encrypted nvarchar data of variable lengths and retrieving encrypted and decrypted data --SKIPIF-- - + --FILE-- $data ) ); + for ($i = 0; $i < 1000; $i++) { + $data = str_repeat("*", $i); + $stmt = insertRow($conn, $tbname, array(getDefaultColName("nvarchar(1000)") => $data)); } - + $selectSql = "SELECT * FROM $tbname"; - $stmt = $conn->query( $selectSql ); - while ( $decrypted_row = $stmt->fetch( PDO::FETCH_ASSOC )) - { - if ( $decrypted_row[ 'CharCount' ] != strlen( $decrypted_row[ get_default_colname( "nvarchar(1000)" ) ] )) - { - $rowInd = $decrypted_row[ 'CharCount' ] + 1; + $stmt = $conn->query($selectSql); + while ($decrypted_row = $stmt->fetch(PDO::FETCH_ASSOC)) { + if ($decrypted_row['CharCount'] != strlen($decrypted_row[getDefaultColName("nvarchar(1000)")])) { + $rowInd = $decrypted_row['CharCount'] + 1; echo "Failed to decrypted at row $rowInd\n"; $testPass = false; } } - unset( $stmt ); -} -catch( PDOException $e ) -{ + unset($stmt); +} catch (PDOException $e) { echo $e->getMessage(); } - // for AE only -if ( is_col_enc() ) -{ - try - { - $conn1 = ae_connect( null, null, true ); - $stmt = $conn1->query( $selectSql ); - while ( $decrypted_row = $stmt->fetch( PDO::FETCH_ASSOC )) - { - if ( $decrypted_row[ 'CharCount' ] == strlen( $decrypted_row[ get_default_colname( "nvarchar(1000)" ) ] )) - { +if (isColEncrypted()) { + try { + $conn1 = connect('', array(), PDO::ERRMODE_EXCEPTION, true); + $stmt = $conn1->query($selectSql); + while ($decrypted_row = $stmt->fetch(PDO::FETCH_ASSOC)) { + if ($decrypted_row[ 'CharCount' ] == strlen($decrypted_row[getDefaultColName("nvarchar(1000)")])) { $rowInd = $decrypted_row[ 'CharCount' ] + 1; echo "Failed to encrypted at row $rowInd\n"; $testPass = false; } } - - unset( $stmt ); - unset( $conn1 ); - } - catch( PDOException $e ) - { + unset($stmt); + unset($conn1); + } catch (PDOException $e) { echo $e->getMessage(); } } - -DropTable( $conn, $tbname ); -unset( $conn ); - -if ( $testPass ) { +dropTable($conn, $tbname); +unset($conn); +if ($testPass) { echo "Test successfully done.\n"; } - ?> --EXPECT-- -Test successfully done. \ No newline at end of file +Test successfully done. diff --git a/test/functional/pdo_sqlsrv/pdo_ae_insert_retrieve_varchar.phpt b/test/functional/pdo_sqlsrv/pdo_ae_insert_retrieve_varchar.phpt index 3b5218c1..f30de5cf 100644 --- a/test/functional/pdo_sqlsrv/pdo_ae_insert_retrieve_varchar.phpt +++ b/test/functional/pdo_sqlsrv/pdo_ae_insert_retrieve_varchar.phpt @@ -1,78 +1,60 @@ --TEST-- Test for inserting encrypted varchar data of variable lengths and retrieving encrypted and decrypted data --SKIPIF-- - + --FILE-- $data ) ); + for ($i = 0; $i < 1000; $i++) { + $data = str_repeat("*", $i); + $stmt = insertRow($conn, $tbname, array(getDefaultColname("varchar(1000)") => $data)); } - + $selectSql = "SELECT * FROM $tbname"; - $stmt = $conn->query( $selectSql ); - while ( $decrypted_row = $stmt->fetch( PDO::FETCH_ASSOC )) - { - if ( $decrypted_row[ 'CharCount' ] != strlen( $decrypted_row[ get_default_colname( "varchar(1000)" ) ] )) - { - $rowInd = $decrypted_row[ 'CharCount' ] + 1; + $stmt = $conn->query($selectSql); + while ($decrypted_row = $stmt->fetch(PDO::FETCH_ASSOC)) { + if ($decrypted_row['CharCount'] != strlen($decrypted_row[getDefaultColname("varchar(1000)")])) { + $rowInd = $decrypted_row['CharCount'] + 1; echo "Failed to decrypted at row $rowInd\n"; $testPass = false; } } - unset( $stmt ); -} -catch( PDOException $e ) -{ + unset($stmt); +} catch (PDOException $e) { echo $e->getMessage(); } - // for AE only -if ( is_col_enc() ) -{ - try - { - $conn1 = ae_connect( null, null, true ); - $stmt = $conn1->query( $selectSql ); - while ( $decrypted_row = $stmt->fetch( PDO::FETCH_ASSOC )) - { - if ( $decrypted_row[ 'CharCount' ] == strlen( $decrypted_row[ get_default_colname( "varchar(1000)" ) ] )) - { +if (isColEncrypted()) { + try { + $conn1 = connect('', array(), PDO::ERRMODE_EXCEPTION, true); + $stmt = $conn1->query($selectSql); + while ($decrypted_row = $stmt->fetch(PDO::FETCH_ASSOC)) { + if ($decrypted_row['CharCount'] == strlen($decrypted_row[getDefaultColname("varchar(1000)")])) { $rowInd = $decrypted_row[ 'CharCount' ] + 1; echo "Failed to encrypted at row $rowInd\n"; $testPass = false; } } - - unset( $stmt ); - unset( $conn1 ); - } - catch( PDOException $e ) - { + unset($stmt); + unset($conn1); + } catch (PDOException $e) { echo $e->getMessage(); } } - -DropTable( $conn, $tbname ); -unset( $conn ); - -if ( $testPass ) { +dropTable($conn, $tbname); +unset($conn); +if ($testPass) { echo "Test successfully done.\n"; } ?> --EXPECT-- -Test successfully done. \ No newline at end of file +Test successfully done. diff --git a/test/functional/pdo_sqlsrv/pdo_ae_insert_string.phpt b/test/functional/pdo_sqlsrv/pdo_ae_insert_string.phpt index 4ef6b026..e9f295bc 100644 --- a/test/functional/pdo_sqlsrv/pdo_ae_insert_string.phpt +++ b/test/functional/pdo_sqlsrv/pdo_ae_insert_string.phpt @@ -3,44 +3,37 @@ Test for inserting and retrieving encrypted data of string types --DESCRIPTION-- No PDO::PARAM_ type specified when binding parameters --SKIPIF-- - + --FILE-- colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r ); - if ( $r === false ) { - is_incompatible_types_error( $stmt, $dataType, "default type" ); - } - else { + $stmt = insertRow($conn, $tbname, array("c_det" => $inputValues[0], "c_rand" => $inputValues[1] ), null, $r); + if ($r === false) { + isIncompatibleTypesError($stmt, $dataType, "default type"); + } else { echo "****Encrypted default type is compatible with encrypted $dataType****\n"; - fetch_all( $conn, $tbname ); + fetchAll($conn, $tbname); } - DropTable( $conn, $tbname ); + dropTable($conn, $tbname); } - unset( $stmt ); - unset( $conn ); -} -catch( PDOException $e ) -{ + unset($stmt); + unset($conn); +} catch (PDOException $e) { echo $e->getMessage(); } ?> diff --git a/test/functional/pdo_sqlsrv/pdo_ae_output_param_all.phpt b/test/functional/pdo_sqlsrv/pdo_ae_output_param_all.phpt index b870d957..6becaf4d 100644 --- a/test/functional/pdo_sqlsrv/pdo_ae_output_param_all.phpt +++ b/test/functional/pdo_sqlsrv/pdo_ae_output_param_all.phpt @@ -1,84 +1,78 @@ --TEST-- Test for binding output params for encrypted data for all types --SKIPIF-- - + --FILE-- "int", + "c2_smallint" => "smallint", + "c3_tinyint" => "tinyint", + "c4_bit" => "bit", + "c5_bigint" => "bigint", + "c6_decimal" => "decimal(18,5)", + "c7_numeric" => "numeric(10,5)", + "c8_float" => "float", + "c9_real" => "real", + "c10_date" => "date", + "c11_datetime" => "datetime", + "c12_datetime2" => "datetime2", + "c13_datetimeoffset" => "datetimeoffset", + "c14_time" => "time", + "c15_char" => "char(5)", + "c16_varchar" => "varchar(max)", + "c17_nchar" => "nchar(5)", + "c18_nvarchar" => "nvarchar(max)"); +createTable($conn, $tbname, $colMetaArr); // Create a Store Procedure $spname = 'selectAllColumns'; $spSql = "CREATE PROCEDURE $spname ( - @c1_int int OUTPUT, @c2_smallint smallint OUTPUT, - @c3_tinyint tinyint OUTPUT, @c4_bit bit OUTPUT, + @c1_int int OUTPUT, @c2_smallint smallint OUTPUT, + @c3_tinyint tinyint OUTPUT, @c4_bit bit OUTPUT, @c5_bigint bigint OUTPUT, @c6_decimal decimal(18,5) OUTPUT, - @c7_numeric numeric(10,5) OUTPUT, @c8_float float OUTPUT, + @c7_numeric numeric(10,5) OUTPUT, @c8_float float OUTPUT, @c9_real real OUTPUT, @c10_date date OUTPUT, @c11_datetime datetime OUTPUT, @c12_datetime2 datetime2 OUTPUT, @c13_datetimeoffset datetimeoffset OUTPUT, @c14_time time OUTPUT, @c15_char char(5) OUTPUT, @c16_varchar varchar(max) OUTPUT, @c17_nchar nchar(5) OUTPUT, @c18_nvarchar nvarchar(max) OUTPUT) AS - SELECT @c1_int = c1_int, @c2_smallint = c2_smallint, - @c3_tinyint = c3_tinyint, @c4_bit = c4_bit, - @c5_bigint = c5_bigint, @c6_decimal = c6_decimal, - @c7_numeric = c7_numeric, @c8_float = c8_float, - @c9_real = c9_real, @c10_date = c10_date, + SELECT @c1_int = c1_int, @c2_smallint = c2_smallint, + @c3_tinyint = c3_tinyint, @c4_bit = c4_bit, + @c5_bigint = c5_bigint, @c6_decimal = c6_decimal, + @c7_numeric = c7_numeric, @c8_float = c8_float, + @c9_real = c9_real, @c10_date = c10_date, @c11_datetime = c11_datetime, @c12_datetime2 = c12_datetime2, @c13_datetimeoffset = c13_datetimeoffset, @c14_time = c14_time, @c15_char = c15_char, @c16_varchar = c16_varchar, @c17_nchar = c17_nchar, @c18_nvarchar = c18_nvarchar FROM $tbname"; -$conn->query( $spSql ); - +$conn->query($spSql); // Insert data -$inputs = array( "c1_int" => 2147483647, - "c2_smallint" => 32767, - "c3_tinyint" => 255, - "c4_bit" => 1, - "c5_bigint" => 922337203685479936, - "c6_decimal" => 9223372036854.80000, - "c7_numeric" => 21474.83647, +$inputs = array( "c1_int" => 2147483647, + "c2_smallint" => 32767, + "c3_tinyint" => 255, + "c4_bit" => 1, + "c5_bigint" => 922337203685479936, + "c6_decimal" => 9223372036854.80000, + "c7_numeric" => 21474.83647, "c8_float" => 9223372036.8548, - "c9_real" => 2147.483, - "c10_date" => '9999-12-31', - "c11_datetime" => '9999-12-31 23:59:59.997', - "c12_datetime2" => '9999-12-31 23:59:59.9999999', - "c13_datetimeoffset" => '9999-12-31 23:59:59.9999999 +14:00', - "c14_time" => '23:59:59.9999999', - "c15_char" => 'th, n', - "c16_varchar" => 'This large row size can cause errors (such as error 512) during some normal operations, such as a clustered index key update, or sorts of the full column set, which users cannot anticipate until performing an operation.', - "c17_nchar" => 'th Un', + "c9_real" => 2147.483, + "c10_date" => '9999-12-31', + "c11_datetime" => '9999-12-31 23:59:59.997', + "c12_datetime2" => '9999-12-31 23:59:59.9999999', + "c13_datetimeoffset" => '9999-12-31 23:59:59.9999999 +14:00', + "c14_time" => '23:59:59.9999999', + "c15_char" => 'th, n', + "c16_varchar" => 'This large row size can cause errors (such as error 512) during some normal operations, such as a clustered index key update, or sorts of the full column set, which users cannot anticipate until performing an operation.', + "c17_nchar" => 'th Un', "c18_nvarchar" => 'When prefixing a string constant with the letter N, the implicit conversion will result in a Unicode string if the constant to convert does not exceed the max length for a Unicode string data type (4,000).' ); -$paramOptions = array( new bindParamOption( 5, "PDO::PARAM_INT" ) ); $r; -$stmt = insert_row( $conn, $tbname, $inputs, $r, "prepareBindParam", $paramOptions ); - +$stmt = insertRow($conn, $tbname, $inputs, "prepareBindParam", $r); // Call store procedure -$outSql = get_callProcSql_placeholders( $spname, count( $inputs )); +$outSql = getCallProcSqlPlaceholders($spname, count($inputs)); $intOut = 0; $smallintOut = 0; $tinyintOut = 0; @@ -97,7 +91,7 @@ $charOut = ''; $varcharOut = ''; $ncharOut = ''; $nvarcharOut = ''; -$stmt = $conn->prepare( $outSql ); +$stmt = $conn->prepare($outSql); $stmt->bindParam(1, $intOut, PDO::PARAM_INT, PDO::SQLSRV_PARAM_OUT_DEFAULT_SIZE); $stmt->bindParam(2, $smallintOut, PDO::PARAM_INT, PDO::SQLSRV_PARAM_OUT_DEFAULT_SIZE); $stmt->bindParam(3, $tinyintOut, PDO::PARAM_INT, PDO::SQLSRV_PARAM_OUT_DEFAULT_SIZE); @@ -117,31 +111,28 @@ $stmt->bindParam(16, $varcharOut, PDO::PARAM_STR, 2048); $stmt->bindParam(17, $ncharOut, PDO::PARAM_STR, 2048); $stmt->bindParam(18, $nvarcharOut, PDO::PARAM_STR, 2048); $stmt->execute(); - -print ( "intOut: " . $intOut . "\n" ); -print ( "smallintOut: " . $smallintOut . "\n" ); -print ( "tinyintOut: " . $tinyintOut . "\n" ); -print ( "bitOut: " . $bitOut . "\n" ); -print ( "bigintOut: " . $bigintOut . "\n" ); -print ( "decimalOut: " . $decimalOut . "\n" ); -print ( "numericOut: " . $numericOut . "\n" ); -print ( "floatOut: " . $floatOut . "\n" ); -print ( "realOut: " . $realOut . "\n" ); -print ( "dateOut: " . $dateOut . "\n" ); -print ( "datetimeOut: " . $datetimeOut . "\n" ); -print ( "datetime2Out: " . $datetime2Out . "\n" ); -print ( "datetimeoffsetOut: " . $datetimeoffsetOut . "\n" ); -print ( "timeOut: " . $timeOut . "\n" ); -print ( "charOut: " . $charOut . "\n" ); -print ( "varcharOut: " . $varcharOut . "\n" ); -print ( "ncharOut: " . $ncharOut . "\n" ); -print ( "nvarcharOut: " . $nvarcharOut . "\n" ); - -$conn->query( "DROP PROCEDURE $spname" ); -$conn->query( "DROP TABLE $tbname" ); -unset( $stmt ); -unset( $conn ); - +print("intOut: " . $intOut . "\n"); +print("smallintOut: " . $smallintOut . "\n"); +print("tinyintOut: " . $tinyintOut . "\n"); +print("bitOut: " . $bitOut . "\n"); +print("bigintOut: " . $bigintOut . "\n"); +print("decimalOut: " . $decimalOut . "\n"); +print("numericOut: " . $numericOut . "\n"); +print("floatOut: " . $floatOut . "\n"); +print("realOut: " . $realOut . "\n"); +print("dateOut: " . $dateOut . "\n"); +print("datetimeOut: " . $datetimeOut . "\n"); +print("datetime2Out: " . $datetime2Out . "\n"); +print("datetimeoffsetOut: " . $datetimeoffsetOut . "\n"); +print("timeOut: " . $timeOut . "\n"); +print("charOut: " . $charOut . "\n"); +print("varcharOut: " . $varcharOut . "\n"); +print("ncharOut: " . $ncharOut . "\n"); +print("nvarcharOut: " . $nvarcharOut . "\n"); +dropProc($conn, $spname); +dropTable($conn, $tbname); +unset($stmt); +unset($conn); ?> --EXPECTREGEX-- intOut: 2147483647 @@ -161,4 +152,4 @@ timeOut: 23:59:59\.9999999 charOut: th\, n varcharOut: This large row size can cause errors \(such as error 512\) during some normal operations\, such as a clustered index key update\, or sorts of the full column set\, which users cannot anticipate until performing an operation\. ncharOut: th Un -nvarcharOut: When prefixing a string constant with the letter N\, the implicit conversion will result in a Unicode string if the constant to convert does not exceed the max length for a Unicode string data type \(4,000\). \ No newline at end of file +nvarcharOut: When prefixing a string constant with the letter N\, the implicit conversion will result in a Unicode string if the constant to convert does not exceed the max length for a Unicode string data type \(4,000\). From 8ea405b69e2ba10f9f36b0ba1e40c5da62a68cea Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Tue, 7 Nov 2017 08:59:38 -0800 Subject: [PATCH 09/16] update AEData.inc and MsCommon_mid-refactor.inc for the ae related tests --- test/functional/pdo_sqlsrv/AEData.inc | 12 ++++++------ test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/test/functional/pdo_sqlsrv/AEData.inc b/test/functional/pdo_sqlsrv/AEData.inc index f5247c33..f5d24f16 100644 --- a/test/functional/pdo_sqlsrv/AEData.inc +++ b/test/functional/pdo_sqlsrv/AEData.inc @@ -62,11 +62,11 @@ $pdoParamTypes = array( // Checks if the current error is the incompatible types error // if so, state which sql type is incompatible with which data type -function is_incompatible_types_error( $stmt, $dataType, $pdoParamType ) { - if ( $stmt->errorInfo()[0] == "22018" ) +function isIncompatibleTypesError($stmt, $dataType, $pdoParamType) +{ + if ($stmt->errorInfo()[0] == "22018") { echo "PDO param type $pdoParamType is incompatible with encrypted $dataType\n"; - else - var_dump( $stmt->errorInfo() ); + } else { + var_dump($stmt->errorInfo()); + } } - -?> \ No newline at end of file diff --git a/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc b/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc index 37fdb775..5e0f0a76 100644 --- a/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc +++ b/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc @@ -133,7 +133,7 @@ class ColumnMeta public function __construct($dataType, $colName = null, $options = null, $encType = "deterministic") { if (is_null($colName)) { - $this->colName = get_default_colname($dataType); + $this->colName = getDefaultColName($dataType); } else { $this->colName = $colName; } @@ -232,14 +232,14 @@ class BindParamOp $this->variable = $variable; $pdoParams = array("PDO::PARAM_BOOL", "PDO::PARAM_NULL", "PDO::PARAM_INT", "PDO::PARAM_STR", "PDO::PARAM_LOB"); - if (in_array($pdoType, $pdoParams)) { + if (in_array($pdoType, $pdoParams) || is_null($pdoType)) { $this->pdoType = $pdoType; } else { printf("BindParamOp construct: The pdoType provided must be one of PDO::PARAM_BOOL, PDO::PARAM_NULL, PDO::PARAM_INT, PDO::PARAM_STR, or PDO::PARAM_LOB.\n"); exit; } - if ($length >= 0) { + if ($length >= 0 || is_null($length)) { $this->length = $length; } else { printf("BindParamOp construct: The length provided must be greater or equal to 0.\n"); @@ -247,7 +247,7 @@ class BindParamOp } $encodingAttrs = array("PDO::SQLSRV_ENCODING_BINARY", "PDO::SQLSRV_ENCODING_SYSTEM", "PDO::SQLSRV_ENCODING_UTF8", "PDO::SQLSRV_ENCODING_DEFAULT"); - if (in_array($options, $encodingAttrs)) { + if (in_array($options, $encodingAttrs) || is_null($options)) { $this->options = $options; } else { printf("BindParamOp construct: The option provided must be one of PDO::SQLSRV_ENCODING_BINARY, PDO::SQLSRV_ENCODING_SYSTEM, PDO::SQLSRV_ENCODING_UTF8, PDO::SQLSRV_ENCODING_DEFAULT"); From ce23b38557bce615341a032a214d27518e6b5db0 Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Tue, 7 Nov 2017 10:01:14 -0800 Subject: [PATCH 10/16] change to default API used for inserting row in pdo_ae_output_param.phpt --- test/functional/pdo_sqlsrv/pdo_ae_output_param_all.phpt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functional/pdo_sqlsrv/pdo_ae_output_param_all.phpt b/test/functional/pdo_sqlsrv/pdo_ae_output_param_all.phpt index 6becaf4d..580bbdcf 100644 --- a/test/functional/pdo_sqlsrv/pdo_ae_output_param_all.phpt +++ b/test/functional/pdo_sqlsrv/pdo_ae_output_param_all.phpt @@ -70,7 +70,7 @@ $inputs = array( "c1_int" => 2147483647, "c17_nchar" => 'th Un', "c18_nvarchar" => 'When prefixing a string constant with the letter N, the implicit conversion will result in a Unicode string if the constant to convert does not exceed the max length for a Unicode string data type (4,000).' ); $r; -$stmt = insertRow($conn, $tbname, $inputs, "prepareBindParam", $r); +$stmt = insertRow($conn, $tbname, $inputs, null, $r); // Call store procedure $outSql = getCallProcSqlPlaceholders($spname, count($inputs)); $intOut = 0; From b695cc1655973cc03700588e12a560257e55c120 Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Tue, 7 Nov 2017 11:45:13 -0800 Subject: [PATCH 11/16] test column encryption unsupported types --- .../pdo_sqlsrv/MsCommon_mid-refactor.inc | 23 +++++++++++++++---- .../pdo_sqlsrv/pdo_ae_insert_money.phpt | 3 ++- .../pdo_ae_insert_pdoparam_money.phpt | 3 ++- .../pdostatement_getColumnMeta.phpt | 9 ++------ 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc b/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc index 5e0f0a76..efaad345 100644 --- a/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc +++ b/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc @@ -127,10 +127,11 @@ 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 $encType; //randomized or deterministic; default is deterministic 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 function __construct($dataType, $colName = null, $options = null, $encType = "deterministic") + public function __construct($dataType, $colName = null, $options = null, $encType = "deterministic", $forceEncrypt = false) { if (is_null($colName)) { $this->colName = getDefaultColName($dataType); @@ -138,8 +139,9 @@ class ColumnMeta $this->colName = $colName; } $this->dataType = $dataType; - $this->encType = $encType; $this->options = $options; + $this->encType = $encType; + $this->forceEncrypt = $forceEncrypt; } /** * @return string column definition for creating a table @@ -150,7 +152,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() && stripos($this->options, "identity") === false) { + if (isColEncrypted() && $this->isEncryptableType() && stripos($this->options, "identity") === false) { $cekName = getCekName(); if (stripos($this->dataType, "char") !== false) { $append .= "COLLATE Latin1_General_BIN2 "; @@ -161,6 +163,19 @@ class ColumnMeta $colDef = "[" . $this->colName . "] " . $this->dataType . $append; return $colDef; } + + /** + * @return bool if the datatype for this column is encryptable + */ + public function isEncryptableType() + { + $unsupportedTypes = array("money", "smallmoney", "image", "ntext", "text", "xml", "sql_variant"); + if (in_array(strtolower($this->dataType), $unsupportedTypes) && !$this->forceEncrypt) { + return false; + } else { + return true; + } + } } diff --git a/test/functional/pdo_sqlsrv/pdo_ae_insert_money.phpt b/test/functional/pdo_sqlsrv/pdo_ae_insert_money.phpt index 1cc76fd3..d11cf6b6 100644 --- a/test/functional/pdo_sqlsrv/pdo_ae_insert_money.phpt +++ b/test/functional/pdo_sqlsrv/pdo_ae_insert_money.phpt @@ -17,7 +17,8 @@ try { // create table $tbname = getTableName(); - $colMetaArr = array( new columnMeta($dataType, "c_det"), new columnMeta($dataType, "c_rand", null, "randomized")); + $colMetaArr = array(new columnMeta($dataType, "c_det", null, "deterministic", true), + new columnMeta($dataType, "c_rand", null, "randomized", true)); createTable($conn, $tbname, $colMetaArr); // insert a row diff --git a/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_money.phpt b/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_money.phpt index abdf5159..563b0b90 100644 --- a/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_money.phpt +++ b/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_money.phpt @@ -17,7 +17,8 @@ try { // create table $tbname = getTableName(); - $colMetaArr = array(new ColumnMeta($dataType, "c_det"), new ColumnMeta($dataType, "c_rand", null, "randomized")); + $colMetaArr = array(new ColumnMeta($dataType, "c_det", null, "deterministic", true), + new ColumnMeta($dataType, "c_rand", null, "randomized", true)); createTable($conn, $tbname, $colMetaArr); // test each PDO::PARAM_ type diff --git a/test/functional/pdo_sqlsrv/pdostatement_getColumnMeta.phpt b/test/functional/pdo_sqlsrv/pdostatement_getColumnMeta.phpt index 419f5a98..f42d1d3d 100644 --- a/test/functional/pdo_sqlsrv/pdostatement_getColumnMeta.phpt +++ b/test/functional/pdo_sqlsrv/pdostatement_getColumnMeta.phpt @@ -43,13 +43,8 @@ function fetchBoth($conn, $tbname) // 8 $meta = $stmt->getColumnMeta(7); - if (isColEncrypted()) { - $xmlType = "nvarchar"; - } else { - $xmlType = "xml"; - } - if ($meta["sqlsrv:decl_type"] != $xmlType) { - echo "Wrong column metadata was retrieved for a $xmlType column.\n"; + if ($meta["sqlsrv:decl_type"] != "xml") { + echo "Wrong column metadata was retrieved for a xml column.\n"; } unset($meta["sqlsrv:decl_type"]); var_dump($meta); From 708a29c45d3ac395c77ef75ae03be5f45d259238 Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Tue, 7 Nov 2017 12:04:19 -0800 Subject: [PATCH 12/16] remove odl MsData.inc --- test/functional/pdo_sqlsrv/MsCommon.inc | 154 +----------------- .../pdo_sqlsrv/MsCommon_mid-refactor.inc | 141 ---------------- test/functional/pdo_sqlsrv/MsData.inc | 65 -------- 3 files changed, 1 insertion(+), 359 deletions(-) delete mode 100644 test/functional/pdo_sqlsrv/MsData.inc diff --git a/test/functional/pdo_sqlsrv/MsCommon.inc b/test/functional/pdo_sqlsrv/MsCommon.inc index cef996f1..89f6c8ee 100644 --- a/test/functional/pdo_sqlsrv/MsCommon.inc +++ b/test/functional/pdo_sqlsrv/MsCommon.inc @@ -12,7 +12,6 @@ // looks like an additional file (in addition to pdo_test_base.inc) may be needed for these PHPTs // to be runnable from the MSSQL teams' internal proprietary test running system // -require 'MsData.inc'; function IsAEQualified($conn) { @@ -35,9 +34,7 @@ function connect($options=array()) require 'MsSetup.inc'; $conn = new PDO( "sqlsrv:Server=$server;database=$databaseName;ConnectionPooling=false;" , $uid, $pwd, $options); $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); - create_and_insert_table1($conn); - create_and_insert_table2($conn); - return $conn; + return $conn; } catch( PDOException $e ) @@ -447,155 +444,6 @@ function is_col_enc() return true; } - -// Create and insert -function create_and_insert_table1( $conn ) -{ - global $string_col, $date_col, $large_string_col, $xml_col, $binary_col, $int_col, $decimal_col, $guid_col, $null_col, $comma, $closing_brace, $table1; - - try - { - $create_query = - - "IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'" . $table1 . "') AND type in (N'U')) - DROP TABLE " . $table1 . - - " CREATE TABLE [dbo].[" . $table1 . "]( - [IntCol] [int] NULL, - [CharCol] [char](10) NULL, - [NCharCol] [nchar](10) NULL, - [DateTimeCol] [datetime] NULL, - [VarcharCol] [varchar](50) NULL, - [NVarCharCol] [nvarchar](50) NULL, - [FloatCol] [float] NULL, - [XmlCol] [xml] NULL - ) ON [PRIMARY] - "; - - $conn->query( $create_query ); - - for ($i = 0 ; $i <= 1; ++ $i) - { - $insert_query = - "INSERT INTO PDO_Types_1 VALUES (". - $int_col[$i] . $comma . - $string_col[$i] . $comma . - $string_col[$i] . $comma . - "Convert(datetime, ". $date_col[$i] . ")" . $comma . - $string_col[$i] . $comma . - $string_col[$i] . $comma . - $decimal_col[$i] . $comma . - $xml_col[$i] . - ")"; - - $conn->query ( $insert_query ); - } - } - catch(Exception $e) - { - var_dump( $e); - exit; - } -} - -function create_and_insert_table2( $conn ) -{ - try - { - //Timestamp is not present. - //VARIANT is not supported. - global $string_col, $date_col, $large_string_col, $xml_col, $binary_col, $int_col, $decimal_col, $guid_col, $null_col, $comma, $closing_brace, $table1, $table2; - - $create_query = - "IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'".$table2."') AND type in (N'U')) DROP TABLE " . $table2 . - - " CREATE TABLE " .$table2 . " ( - [BigIntCol] [bigint] NULL, - [BinaryCol] [binary](5) NULL, - [BitCol] [bit] NULL, - [CharCol] [char](10) NULL, - [DateCol] [date] NULL, - [DateTimeCol] [datetime] NULL, - [DateTime2Col] [datetime2](7) NULL, - [DTOffsetCol] [datetimeoffset](7) NULL, - [DecimalCol] [decimal](18, 0) NULL, - [FloatCol] [float] NULL, - [ImageCol] [image] NULL, - [IntCol] [int] NULL, - [MoneyCol] [money] NULL, - [NCharCol] [nchar](10) NULL, - [NTextCol] [ntext] NULL, - [NumCol] [numeric](18, 0) NULL, - [NVarCharCol] [nvarchar](50) NULL, - [NVarCharMaxCol] [nvarchar](max) NULL, - [RealCol] [real] NULL, - [SmallDTCol] [smalldatetime] NULL, - [SmallIntCol] [smallint] NULL, - [SmallMoneyCol] [smallmoney] NULL, - [TextCol] [text] NULL, - [TimeCol] [time](7) NULL, - [TinyIntCol] [tinyint] NULL, - [Guidcol] [uniqueidentifier] NULL, - [VarbinaryCol] [varbinary](50) NULL, - [VarbinaryMaxCol] [varbinary](max) NULL, - [VarcharCol] [varchar](50) NULL, - [VarcharMaxCol] [varchar](max) NULL, - [XmlCol] [xml] NULL - ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] - - "; - - $stmt = $conn->query( $create_query ); - - for ($i =0; $i<= 0 ; ++ $i) - { - $insert_query = - - " INSERT INTO " .$table2 . " VALUES (". - $int_col[$i] . $comma . - $binary_col[$i] . $comma . - "0" . $comma . - $string_col[$i] . $comma . - "Convert(date, ". $date_col[$i] . $closing_brace . - "Convert(datetime, ". $date_col[$i] . $closing_brace . - "Convert(datetime2(7),". $date_col[$i] . $closing_brace . - "Convert(datetimeoffset(7)," . $date_col[$i] . $closing_brace . - $decimal_col[$i] . $comma . - $decimal_col[$i] .$comma . - $binary_col[$i] . $comma . - $int_col[$i] . $comma . - $decimal_col[$i] . $comma . - $string_col[$i]. $comma . - $large_string_col[$i]. $comma. - $int_col[$i]. $comma . - $string_col[$i]. $comma . - $large_string_col[$i]. $comma . - $decimal_col[$i]. $comma . - "Convert(smalldatetime, ". $date_col[$i]. $closing_brace . - $int_col[$i]. $comma . - $decimal_col[$i]. $comma . - $large_string_col[$i]. $comma . - "Convert(time(7), ". $date_col[$i] . $closing_brace . - $int_col[$i] . $comma . - $guid_col[$i] . $comma . - $binary_col[$i] . $comma . - $binary_col[$i] . $comma . - $string_col[$i] . $comma . - $large_string_col[$i] . $comma . - $xml_col[$i] . - ")"; - - $stmt = $conn->query ($insert_query ); - } - - } - catch(Exception $e) - { - var_dump( $e); - exit; - } -} - function teardown() { // TBD diff --git a/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc b/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc index efaad345..62e06426 100644 --- a/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc +++ b/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc @@ -12,7 +12,6 @@ // looks like an additional file (in addition to pdo_test_base.inc) may be needed for these PHPTs // to be runnable from the MSSQL teams' internal proprietary test running system // -require 'MsData.inc'; function isAEQualified($conn) { @@ -524,146 +523,6 @@ function isColEncrypted() } } - -// Create and insert -function create_and_insert_table1($conn) -{ - global $string_col, $date_col, $large_string_col, $xml_col, $binary_col, $int_col, $decimal_col, $guid_col, $null_col, $comma, $closing_brace, $table1; - - try { - $create_query = - - "IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'" . $table1 . "') AND type in (N'U')) - DROP TABLE " . $table1 . - - " CREATE TABLE [dbo].[" . $table1 . "]( - [IntCol] [int] NULL, - [CharCol] [char](10) NULL, - [NCharCol] [nchar](10) NULL, - [DateTimeCol] [datetime] NULL, - [VarcharCol] [varchar](50) NULL, - [NVarCharCol] [nvarchar](50) NULL, - [FloatCol] [float] NULL, - [XmlCol] [xml] NULL - ) ON [PRIMARY] - "; - - $conn->query($create_query); - - for ($i = 0 ; $i <= 1; ++ $i) { - $insert_query = - "INSERT INTO PDO_Types_1 VALUES (". - $int_col[$i] . $comma . - $string_col[$i] . $comma . - $string_col[$i] . $comma . - "Convert(datetime, ". $date_col[$i] . ")" . $comma . - $string_col[$i] . $comma . - $string_col[$i] . $comma . - $decimal_col[$i] . $comma . - $xml_col[$i] . - ")"; - - $conn->query($insert_query); - } - } catch (Exception $e) { - var_dump($e); - exit; - } -} - -function create_and_insert_table2($conn) -{ - try { - //Timestamp is not present. - //VARIANT is not supported. - global $string_col, $date_col, $large_string_col, $xml_col, $binary_col, $int_col, $decimal_col, $guid_col, $null_col, $comma, $closing_brace, $table1, $table2; - - $create_query = - "IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'".$table2."') AND type in (N'U')) DROP TABLE " . $table2 . - - " CREATE TABLE " .$table2 . " ( - [BigIntCol] [bigint] NULL, - [BinaryCol] [binary](5) NULL, - [BitCol] [bit] NULL, - [CharCol] [char](10) NULL, - [DateCol] [date] NULL, - [DateTimeCol] [datetime] NULL, - [DateTime2Col] [datetime2](7) NULL, - [DTOffsetCol] [datetimeoffset](7) NULL, - [DecimalCol] [decimal](18, 0) NULL, - [FloatCol] [float] NULL, - [ImageCol] [image] NULL, - [IntCol] [int] NULL, - [MoneyCol] [money] NULL, - [NCharCol] [nchar](10) NULL, - [NTextCol] [ntext] NULL, - [NumCol] [numeric](18, 0) NULL, - [NVarCharCol] [nvarchar](50) NULL, - [NVarCharMaxCol] [nvarchar](max) NULL, - [RealCol] [real] NULL, - [SmallDTCol] [smalldatetime] NULL, - [SmallIntCol] [smallint] NULL, - [SmallMoneyCol] [smallmoney] NULL, - [TextCol] [text] NULL, - [TimeCol] [time](7) NULL, - [TinyIntCol] [tinyint] NULL, - [Guidcol] [uniqueidentifier] NULL, - [VarbinaryCol] [varbinary](50) NULL, - [VarbinaryMaxCol] [varbinary](max) NULL, - [VarcharCol] [varchar](50) NULL, - [VarcharMaxCol] [varchar](max) NULL, - [XmlCol] [xml] NULL - ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] - - "; - - $stmt = $conn->query($create_query); - - for ($i =0; $i<= 0 ; ++ $i) { - $insert_query = - - " INSERT INTO " .$table2 . " VALUES (". - $int_col[$i] . $comma . - $binary_col[$i] . $comma . - "0" . $comma . - $string_col[$i] . $comma . - "Convert(date, ". $date_col[$i] . $closing_brace . - "Convert(datetime, ". $date_col[$i] . $closing_brace . - "Convert(datetime2(7),". $date_col[$i] . $closing_brace . - "Convert(datetimeoffset(7)," . $date_col[$i] . $closing_brace . - $decimal_col[$i] . $comma . - $decimal_col[$i] .$comma . - $binary_col[$i] . $comma . - $int_col[$i] . $comma . - $decimal_col[$i] . $comma . - $string_col[$i]. $comma . - $large_string_col[$i]. $comma. - $int_col[$i]. $comma . - $string_col[$i]. $comma . - $large_string_col[$i]. $comma . - $decimal_col[$i]. $comma . - "Convert(smalldatetime, ". $date_col[$i]. $closing_brace . - $int_col[$i]. $comma . - $decimal_col[$i]. $comma . - $large_string_col[$i]. $comma . - "Convert(time(7), ". $date_col[$i] . $closing_brace . - $int_col[$i] . $comma . - $guid_col[$i] . $comma . - $binary_col[$i] . $comma . - $binary_col[$i] . $comma . - $string_col[$i] . $comma . - $large_string_col[$i] . $comma . - $xml_col[$i] . - ")"; - - $stmt = $conn->query($insert_query); - } - } catch (Exception $e) { - var_dump($e); - exit; - } -} - function teardown() { // TBD diff --git a/test/functional/pdo_sqlsrv/MsData.inc b/test/functional/pdo_sqlsrv/MsData.inc deleted file mode 100644 index 32c5058c..00000000 --- a/test/functional/pdo_sqlsrv/MsData.inc +++ /dev/null @@ -1,65 +0,0 @@ - 1 " . $large_string . "'", "' 2 " . $large_string . "'"); - -$binary_col = array('0x0', '0x0'); - -$int_col = array ( 1, 2); - -$decimal_col = array (111.111, 222.222); - -$guid_col = array("'AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA'", "'BBBBBBBB-BBBB-BBBB-BBBB-BBBBBBBBBBBB'"); - -$null_col = 'null'; - -$comma = ","; -$closing_brace = "),"; - -class PDO_Types_1_Class{ - var $IntCol; - var $CharCol; - var $NCharCol; - var $DateTimeCol; - var $VarcharCol; - var $NVarCharCol; - var $FloatCol; - var $XmlCol; - - function dumpAll() - { - var_dump($this->IntCol); - var_dump($this->CharCol); - var_dump($this->NCharCol); - var_dump($this->DateTimeCol); - var_dump($this->VarcharCol); - var_dump($this->NVarCharCol); - var_dump($this->FloatCol); - var_dump($this->XmlCol); - } -} -$table1_class = 'PDO_Types_1_Class'; - - - -?> From 3d2c54ac2cb75a83da2ca23513373ddcb94afa6c Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Tue, 7 Nov 2017 12:06:49 -0800 Subject: [PATCH 13/16] test column encryption unsupported types in MsData_PDO_AllTypes.inc --- .../pdo_sqlsrv/MsData_PDO_AllTypes.inc | 36 ++++--------------- 1 file changed, 7 insertions(+), 29 deletions(-) diff --git a/test/functional/pdo_sqlsrv/MsData_PDO_AllTypes.inc b/test/functional/pdo_sqlsrv/MsData_PDO_AllTypes.inc index 0c20ff18..14f89a1a 100644 --- a/test/functional/pdo_sqlsrv/MsData_PDO_AllTypes.inc +++ b/test/functional/pdo_sqlsrv/MsData_PDO_AllTypes.inc @@ -66,11 +66,6 @@ function createTableMainTypes($conn, $tbname) { try { require_once("MsCommon_mid-refactor.inc"); - if (isColEncrypted()) { - $xmlType = "nvarchar(max)"; - } else { - $xmlType = "xml"; - } $columnMetaArr = array("IntCol" => "int", "CharCol" => "char(10)", "NCharCol" => "nchar(10)", @@ -78,7 +73,7 @@ function createTableMainTypes($conn, $tbname) "VarcharCol" => "varchar(50)", "NVarCharCol" => "nvarchar(50)", "FloatCol" => "float", - "XmlCol" => $xmlType); + "XmlCol" => "xml"); createTable($conn, $tbname, $columnMetaArr, "ON [PRIMARY]"); } catch (Exception $e) { var_dump($e); @@ -119,23 +114,6 @@ function createTableAllTypes($conn, $tbname) { try { require_once("MsCommon_mid-refactor.inc"); - - if (isColEncrypted()) { - $moneyType = "decimal(19,4)"; - $smallmoneyType = "decimal(10,4)"; - $imageType = "varbinary(max)"; - $ntextType = "nvarchar(max)"; - $textType = "varchar(max)"; - $xmlType = "nvarchar(max)"; - } else { - $moneyType = "money"; - $smallmoneyType = "smallmoney"; - $imageType = "image"; - $ntextType = "ntext"; - $textType = "text"; - $xmlType = "xml"; - } - $columnMetaArr = array("BigIntCol" => "bigint", "BinaryCol" => "binary(5)", "BitCol" => "bit", @@ -146,19 +124,19 @@ function createTableAllTypes($conn, $tbname) "DTOffsetCol" => "datetimeoffset(7)", "DecimalCol" => "decimal(18,0)", "FloatCol" => "float", - "ImageCol" => $imageType, + "ImageCol" => "image", "IntCol" => "int", - "MoneyCol" => $moneyType, + "MoneyCol" => "money", "NCharCol" => "nchar(10)", - "NTextCol" => $ntextType, + "NTextCol" => "ntext", "NumCol" => "numeric(18,0)", "NVarCharCol" => "nvarchar(50)", "NVarCharMaxCol" => "nvarchar(max)", "RealCol" => "real", "SmallDTCol" => "smalldatetime", "SmallIntCol" => "smallint", - "SmallMoneyCol" => $smallmoneyType, - "TextCol" => $textType, + "SmallMoneyCol" => "smallmoney", + "TextCol" => "text", "TimeCol" => "time(7)", "TinyIntCol" => "tinyint", "Guidcol" => "uniqueidentifier", @@ -166,7 +144,7 @@ function createTableAllTypes($conn, $tbname) "VarbinaryMaxCol" => "varbinary(max)", "VarcharCol" => "varchar(50)", "VarcharMaxCol" => "varchar(max)", - "XmlCol" => $xmlType); + "XmlCol" => "xml"); createTable($conn, $tbname, $columnMetaArr, "ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]"); } catch (Exception $e) { var_dump($e); From 7c02574cfc531e4eb432110096817f671eed1b0f Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Tue, 7 Nov 2017 12:56:00 -0800 Subject: [PATCH 14/16] refactor pdostatement_GetDataType.phpt to use common method for different columns --- .../pdo_sqlsrv/pdostatement_GetDataType.phpt | Bin 12591 -> 5677 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/test/functional/pdo_sqlsrv/pdostatement_GetDataType.phpt b/test/functional/pdo_sqlsrv/pdostatement_GetDataType.phpt index f2aed8413ae83de5ee731b4e8017e84913ec66c9..99c9b6c5dc9850dcfa24e9e9a65410ba1ee69fb8 100644 GIT binary patch delta 1176 zcmZvb&ubGw6vqilyZO~#iocNNWl1&(iI~Jg+k|LsLP`!vK^JLJsgvy{8Avv;NlSy2 zoV-^a_%C=8k^Bc9JbDzoC_)7<6})(ng0r(T*%h4AdvCw*$ISce+xDB>>9?!ZVLzQX zXy+g?Zd+tvGQ$}5TQ7fU3O85?-!1LppA|X&PcR&!{X6JhfL&8aU^?+=M=^uU~_S9`=3Igf~Kc%E(^ zOL@yDYW=Hf3`o}$`CHT?wj6-T+H~p*@QG@=(ALP<)agK`O1CIK>pPv!$dm*4l-q~& zz;GXqw{SW%$+5^2!^yxD)ZM}Sq5L;uLg!La2&yxIQzTOkh4|JeTUVjX?at6PiP1|Z zSmPF3?+D0fzSayp=OQP`GdK8?agN4`%UaY1TTz;6lzTh%~N3r#Yk08MN@hkW#riDF@0HaV2dn5tw zL1ocp3Gg+n1tm>@=diit@+5F_3f6-XD8N_oO+_FDcox5>2wngSYBel&!tM+BLai%e z4KVwxehCC6TYw)DwTO={z?;eKpyUhCPHwQv3!wPrKPGe0IRm_WRI7wN&H#zF6Om|f z!Fx?F$$-NeltS(=S#a0*m~-IZ#z}lyxyx2D8r#(Bri*L%Q@b83vuoKO>`CS?w0!GpVA**S Tk5!mmy8S(%2wVYw=QsWWg1mHc literal 12591 zcmeHNZExE)5bkIH3c?6b2b(j?N#D{oMdmo2u_h^MZ78q}hAh#xP>FIWIg2suzweHc ztcawnNZ5!KNMPhmyoV3T zIN>zmKE3tXveWNRf1Z4tT!Q7Bck9&}o_*c;oc5l^U;MSdn1#OA=XBw?NyLwQ<~}`q zP2Qb>-R0!NIJfF#RtXR%>! z;zx`mFs2{<<%A`@18@F4IY{Qr3F%?yuMUB)gE$Ej@|M7}{@K?J<=b9&I{q*o*(9|Z zMFF||baRy(BDyf-G~NWl6e0R&3!1pA9*{Xby&T)4pJwON>CGr>ee3X;@!8KZf<2`Ts8 zrZmCK7{#lI(QQ+L!pIm!u?br7EG&(Yy$m9!aikPR#wdQG&36vk7$Z1ZIlQS$qKz?v zzdGD)!7(#4M$@Kuja?CKj1jzU!%!HRqu9n7uZ?=+bxU{5?TpRkBy^Uv>BbgD#wh;i zGY3R=V=azW#z?|?&s*`_85*MsDG;^&kPe$p>CVt7)dZ+Ui$zQu$IT1-M%Wpn8)HfV zc`rrIO=njKqYK*@*?cvd^33gw5^Y1$7{NSfUpaS8d7>#EOkiq^F7ExNJkiD&!C#mU zbrs)(YLdV3X=B~_e&c(tsUplSez#ct`?khr7dl0u+>UN$X^iaWuyH{FO#VxH3Ez^e z5a`XJ4CqFTQ8(%3MZUCH2oJjVtBl>W1n6=Kr^7k(CM>2rv7LE9^Fm~KOF}^sYlhTa zMWl;W)|o|4$=qN1P-2B6#!2g}r@yldx~giKc6<+KC~)?HNC&Nga103hXeh-h1>pn` z#9>*2DGx@RhxJg;04jkB*&ZZq0Zrlb9DuyEhE+^(nUc1|r2xGEAeL5{s(`dbCzJS;vzkHWlBEs{ zeHp5{OSs_4V@`QXX!1vOT>ekfQkT_&cW4bhXu&VZo_#a>0O z)Tn00hUnRKfEQT?R)>Wio?{LF6?W+FIbxbrRly?1s?tL~8_+(JM0*gk7Ik>IOYXwTkf=x@bp~;Nuzf*DQ`}Qf zj&Wb)@guCBsyu`!LQ+M{_e9kkp|8oaBjk_AqqPu8@>7iC8_-Zfs^HZqaUHl!C3u@U zzH{kX+~gk6!%VB)?ru}5xJZRNWw=xxfBp#9w%Ijyg}~}KoIBf|l_LGt-QDqa|9E=_ zBxAVTW=nkDwYqRcE3}$MW2rb;(^WwRI}nY`l0iToX+a7m6-rA666b$CnqF+lV8zX& zI=q6JUT?`*#r0qr>lo+TD$w+zOGZm?@ybZ$mD6c18Aa$MW!_(=jE;a+v4)lEOU5h& z*u#LeI!p%5@36`Peo+wJ`I=6U$!OVq(*wXX%1j1Bai)ya8UVGa{b_RjesuGpSX@gl z(`3vn7(X0VquFFklx+&&$q!`EDOGm^Eg7~H^yXXQBms562x6qrp5g@_hj|2^;dz9ArjXY9!S;|gq#*E~O-d2bWAbOjzmSE`vX1m)cVg&e0|%T3 z=_k&t~F2lMf&jS5anV~POKM4g@fy~wY=E*9Z}iEE4{KpXe+3V{Zgm8Wz_r* zrpy)nvKX^gcgsMj^j3WQ86XV?Po6v};Hu=ej0odR6}SRgqPJIo%a|fQit2cIz}73^ zIUEcIeanImv8+@042lR`CCKFtP=jPu&TC-5CxijswSmBxZyoM&Hs z{3(6QpB3Hi$phprcU}wvx5kkxGXV`|mJBF}k7vp^ccu*0j7?tfv>07>+mmCIoNwT0 zJ$sZ8`0nukTSC0~0avOBA-W`6UiSQb7-``jW#hLd8}}4Llr@I~1G5_4aq$@3zq#Ok WtSMT_OOBdRImku2Q0PSr9RC0k6HfjB From bedfd462f7265e4a1f2de94b315888055516f8cc Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Tue, 7 Nov 2017 15:59:28 -0800 Subject: [PATCH 15/16] fix decimal related tests to work on SQL Server 2k12 --- .../pdo_ae_insert_pdoparam_money.phpt | 2 +- .../pdo_ae_insert_pdoparam_numeric.phpt | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_money.phpt b/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_money.phpt index 563b0b90..71c50593 100644 --- a/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_money.phpt +++ b/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_money.phpt @@ -26,7 +26,7 @@ try { // insert a row $inputValues = array_slice(${explode("(", $dataType)[0] . "_params"}, 1, 2); $r; - $stmt = insertRow($conn, $tbname, array("c_det" => new BindParamOp(1, $inputValues[0], $pdoParamType), "c_rand" => new BindParamOp(2, $inputValues[1], $pdoParamType)), "prepareBindParam", $r); + $stmt = insertRow($conn, $tbname, array("c_det" => new BindParamOp(1, (string)$inputValues[0], $pdoParamType), "c_rand" => new BindParamOp(2, (string)$inputValues[1], $pdoParamType)), "prepareBindParam", $r); if (!isColEncrypted()) { diff --git a/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_numeric.phpt b/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_numeric.phpt index 6cfd7f81..6dc7f755 100644 --- a/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_numeric.phpt +++ b/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_numeric.phpt @@ -24,7 +24,11 @@ try { // insert a row $inputValues = array_slice(${explode("(", $dataType)[0] . "_params"}, 1, 2); $r; - $stmt = insertRow($conn, $tbname, array( "c_det" => new BindParamOp(1, $inputValues[0], $pdoParamType), "c_rand" => new BindParamOp(2, $inputValues[1], $pdoParamType)), "prepareBindParam", $r); + if ($dataType == "decimal(18,5)") { + $stmt = insertRow($conn, $tbname, array( "c_det" => new BindParamOp(1, (string)$inputValues[0], $pdoParamType), "c_rand" => new BindParamOp(2, (string)$inputValues[1], $pdoParamType)), "prepareBindParam", $r); + } else { + $stmt = insertRow($conn, $tbname, array( "c_det" => new BindParamOp(1, $inputValues[0], $pdoParamType), "c_rand" => new BindParamOp(2, $inputValues[1], $pdoParamType)), "prepareBindParam", $r); + } if ($r === false) { isIncompatibleTypesError($stmt, $dataType, $pdoParamType); } else { @@ -113,20 +117,20 @@ c_rand: 2147483647 Testing decimal(18,5): ****PDO param type PDO::PARAM_BOOL is compatible with encrypted decimal(18,5)**** -c_det: -9223372036854.80078 -c_rand: 9223372036854.80078 +c_det: -9223372036854.80000 +c_rand: 9223372036854.80000 ****PDO param type PDO::PARAM_NULL is compatible with encrypted decimal(18,5)**** c_det: c_rand: ****PDO param type PDO::PARAM_INT is compatible with encrypted decimal(18,5)**** -c_det: -9223372036854.80078 -c_rand: 9223372036854.80078 +c_det: -9223372036854.80000 +c_rand: 9223372036854.80000 ****PDO param type PDO::PARAM_STR is compatible with encrypted decimal(18,5)**** c_det: -9223372036854.80000 c_rand: 9223372036854.80000 ****PDO param type PDO::PARAM_LOB is compatible with encrypted decimal(18,5)**** -c_det: -9223372036854.80078 -c_rand: 9223372036854.80078 +c_det: -9223372036854.80000 +c_rand: 9223372036854.80000 Testing numeric(10,5): ****PDO param type PDO::PARAM_BOOL is compatible with encrypted numeric(10,5)**** From 12f5e727b579f756d0f5b96471006f36fe2d8f74 Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Tue, 7 Nov 2017 17:12:43 -0800 Subject: [PATCH 16/16] apply review commnets --- test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc | 2 +- test/functional/pdo_sqlsrv/pdo_ae_insert_money.phpt | 1 + .../pdo_sqlsrv/pdo_ae_insert_pdoparam_money.phpt | 3 ++- test/functional/pdo_sqlsrv/pdo_ae_insert_retrieve.phpt | 10 +++++----- .../pdo_sqlsrv/pdo_ae_insert_retrieve_nvarchar.phpt | 2 +- test/functional/pdo_sqlsrv/pdo_ae_insert_string.phpt | 2 +- 6 files changed, 11 insertions(+), 9 deletions(-) diff --git a/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc b/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc index 62e06426..ca99ae8b 100644 --- a/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc +++ b/test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc @@ -169,7 +169,7 @@ class ColumnMeta public function isEncryptableType() { $unsupportedTypes = array("money", "smallmoney", "image", "ntext", "text", "xml", "sql_variant"); - if (in_array(strtolower($this->dataType), $unsupportedTypes) && !$this->forceEncrypt) { + if (!$this->forceEncrypt && in_array(strtolower($this->dataType), $unsupportedTypes)) { return false; } else { return true; diff --git a/test/functional/pdo_sqlsrv/pdo_ae_insert_money.phpt b/test/functional/pdo_sqlsrv/pdo_ae_insert_money.phpt index d11cf6b6..638a5550 100644 --- a/test/functional/pdo_sqlsrv/pdo_ae_insert_money.phpt +++ b/test/functional/pdo_sqlsrv/pdo_ae_insert_money.phpt @@ -10,6 +10,7 @@ require_once("MsCommon_mid-refactor.inc"); require_once("AEData.inc"); $dataTypes = array("smallmoney", "money"); try { + //set to ERRMODE_SILENT to compare actual error and expected unsupport money types in encrypted columns error $conn = connect('', array(), PDO::ERRMODE_SILENT); foreach ($dataTypes as $dataType) { echo "\nTesting $dataType:\n"; diff --git a/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_money.phpt b/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_money.phpt index 71c50593..6d5cf8b8 100644 --- a/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_money.phpt +++ b/test/functional/pdo_sqlsrv/pdo_ae_insert_pdoparam_money.phpt @@ -10,6 +10,7 @@ require_once("MsCommon_mid-refactor.inc"); require_once("AEData.inc"); $dataTypes = array( "smallmoney", "money" ); try { + //set to ERRMODE_SILENT to compare actual error and expected unsupport money types in encrypted columns error $conn = connect('', array(), PDO::ERRMODE_SILENT); foreach ($dataTypes as $dataType) { echo "\nTesting $dataType:\n"; @@ -60,7 +61,7 @@ try { if ($success) { echo "Test successfully done.\n"; } - DropTable($conn, $tbname); + dropTable($conn, $tbname); } unset($stmt); unset($conn); diff --git a/test/functional/pdo_sqlsrv/pdo_ae_insert_retrieve.phpt b/test/functional/pdo_sqlsrv/pdo_ae_insert_retrieve.phpt index 4f464c9d..d686e641 100644 --- a/test/functional/pdo_sqlsrv/pdo_ae_insert_retrieve.phpt +++ b/test/functional/pdo_sqlsrv/pdo_ae_insert_retrieve.phpt @@ -11,11 +11,11 @@ try { $conn = connect(); // Create the table $tbname = 'Patients'; - $colMetaArr = array( new columnMeta("int", "PatientId", "IDENTITY(1,1)"), - new columnMeta("char(11)", "SSN"), - new columnMeta("nvarchar(50)", "FirstName", "NULL"), - new columnMeta("nvarchar(50)", "LastName", "NULL"), - new columnMeta("date", "BirthDate", null, "randomized")); + $colMetaArr = array( new ColumnMeta("int", "PatientId", "IDENTITY(1,1)"), + new ColumnMeta("char(11)", "SSN"), + new ColumnMeta("nvarchar(50)", "FirstName", "NULL"), + new ColumnMeta("nvarchar(50)", "LastName", "NULL"), + new ColumnMeta("date", "BirthDate", null, "randomized")); createTable($conn, $tbname, $colMetaArr); // insert a row diff --git a/test/functional/pdo_sqlsrv/pdo_ae_insert_retrieve_nvarchar.phpt b/test/functional/pdo_sqlsrv/pdo_ae_insert_retrieve_nvarchar.phpt index 92f03f88..4566014a 100644 --- a/test/functional/pdo_sqlsrv/pdo_ae_insert_retrieve_nvarchar.phpt +++ b/test/functional/pdo_sqlsrv/pdo_ae_insert_retrieve_nvarchar.phpt @@ -38,7 +38,7 @@ if (isColEncrypted()) { $conn1 = connect('', array(), PDO::ERRMODE_EXCEPTION, true); $stmt = $conn1->query($selectSql); while ($decrypted_row = $stmt->fetch(PDO::FETCH_ASSOC)) { - if ($decrypted_row[ 'CharCount' ] == strlen($decrypted_row[getDefaultColName("nvarchar(1000)")])) { + if ($decrypted_row['CharCount'] == strlen($decrypted_row[getDefaultColName("nvarchar(1000)")])) { $rowInd = $decrypted_row[ 'CharCount' ] + 1; echo "Failed to encrypted at row $rowInd\n"; $testPass = false; diff --git a/test/functional/pdo_sqlsrv/pdo_ae_insert_string.phpt b/test/functional/pdo_sqlsrv/pdo_ae_insert_string.phpt index e9f295bc..6793b6c6 100644 --- a/test/functional/pdo_sqlsrv/pdo_ae_insert_string.phpt +++ b/test/functional/pdo_sqlsrv/pdo_ae_insert_string.phpt @@ -16,7 +16,7 @@ try { // create table $tbname = getTableName(); - $colMetaArr = array( new columnMeta($dataType, "c_det"), new columnMeta($dataType, "c_rand", null, "randomized")); + $colMetaArr = array(new ColumnMeta($dataType, "c_det"), new ColumnMeta($dataType, "c_rand", null, "randomized")); createTable($conn, $tbname, $colMetaArr); // insert a row