Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor PDO tests with client buffer or table with all datatypes #582

Merged
merged 16 commits into from
Nov 8, 2017
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions test/functional/pdo_sqlsrv/MsCommon_mid-refactor.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down
227 changes: 227 additions & 0 deletions test/functional/pdo_sqlsrv/MsData_PDO_AllTypes.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
<?php
/*
Microsoft SQL Server Driver for PHP - Unit Test Framework
Copyright (c) Microsoft Corporation. All rights reserved.

Description:
Random data generator for INSERT statements.

*/

// globals
$int_col = array(1, 2);

$bin = fopen('php://memory', 'a');
fwrite($bin, '00');
rewind($bin);
$binary_col = array($bin, $bin);

$string_col = array("STRINGCOL1", "STRINGCOL2");

$decimal_col = array(111.111, 222.222);

$large_string = "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.";

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean at least?
Even 417 is not that big...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I look at this the data is all simple chars... consider using more sophisticated data, at least with more extended ASCII characters?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the original data in MsData.inc. For this PR, I won't change it, but maybe we can add a task for testing with more sophisticated data on the PDO side.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure please. No doubt this is way too simple.

$date_col = array('2000-11-11', '2000-11-11');
$datetime_col = array('2000-11-11 11:11:11.111', '2000-11-11 11:11:11.222');
$datetime2_col = array('2000-11-11 11:11:11.111', '2000-11-11 11:11:11.222');
$dtoffset_col = array('2000-11-11 11:11:11.111 +00:00', '2000-11-11 11:11:11.222 +00:00');
$smalldt_col = array('2000-11-11 11:11:00', '2000-11-11 11:11:00');
$timeCol = array('11:11:11.111', '11:11:11.222');

$large_string_col = array(" 1 " . $large_string . "", " 2 " . $large_string . "");

$guid_col = array("AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA", "BBBBBBBB-BBBB-BBBB-BBBB-BBBBBBBBBBBB");

$xml_col = array("<xml> 1 " . $large_string . "</xml>", "<xml> 2 " . $large_string . "</xml>");

$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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably should keep the xml type with AE enabled

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why? xml is not supported for encrypted columns.

Copy link
Contributor

@yitam yitam Nov 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, just thought we should test xml type even with AE enabled. There are hardly any other tests on XML type

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how do I test it if it's not supported? no dot encrypt the column explicitly?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, just do not encrypt xml column or any other types that are not supported

$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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test table is relatively small when compared to the test table in sqlsrv. Just saying ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:P too bad. This is the original table schema

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");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do quite a few columns use the same data?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again this is originally in MsData.inc

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you overwrite MsData.inc? Why creating a new include file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because we're in the middle of refactoring. Some not yet refactored tests may rely on the original MsData.inc

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there many of them left not refactored? Perhaps refactor them all for this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure. All the tests that use the old connect() function from MsCommon.inc could use the data in MsData.inc. This PR is already large enough I don't think it's a wise decision to refactor any more tests.

} 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";
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, should probably keep the original data types even when AE is enabled?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but these datatypes are not supported for encrypted columns

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see my reasons for xml types

$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);
}
}
55 changes: 9 additions & 46 deletions test/functional/pdo_sqlsrv/PDO11_Drivers.phpt
Original file line number Diff line number Diff line change
@@ -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--
<?php require('skipif.inc'); ?>
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';

function DriversInfo()
{
include 'MsSetup.inc';

$testName = "PDO - Drivers";
StartTest($testName);

try {
$drivers = PDO::getAvailableDrivers();
if (in_array("sqlsrv", $drivers))
{
$count = count($drivers);
for ($i = 0; $i < $count; $i++)
{
Trace("Driver #".($i + 1).": ".$drivers[$i]."\n");
}
}
else
{
if (!in_array("sqlsrv", $drivers)) {
printf("$PhpDriver is missing.\n");
} else {
printf("Done\n");
}

EndTest($testName);
}



//--------------------------------------------------------------------
// Repro
//
//--------------------------------------------------------------------
function Repro()
{

try
{
DriversInfo();
}
catch (Exception $e)
{
echo $e->getMessage();
}
} catch (Exception $e) {
echo $e->getMessage();
}

Repro();

?>
--EXPECT--
Test "PDO - Drivers" completed successfully.
Done
Loading