-
Notifications
You must be signed in to change notification settings - Fork 375
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
Changes from 4 commits
50d3c19
1317d67
a68abdb
529c5aa
0c74a27
a60992f
e09dd91
1e69c86
8ea405b
ce23b38
b695cc1
708a29c
3d2c54a
7c02574
bedfd46
12f5e72
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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."; | ||
|
||
$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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We probably should keep the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why? xml is not supported for encrypted columns. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ;) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do quite a few columns use the same data? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. again this is originally in MsData.inc There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but these datatypes are not supported for encrypted columns There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
} |
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 |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.