Skip to content

Commit

Permalink
Streamlined two very similar large column name tests (#815)
Browse files Browse the repository at this point in the history
* Streamlined two very similar large column name tests

* Added random number of test table names to avoid operand clash issues

* Replaced to with for based on review
  • Loading branch information
yitam authored Jul 13, 2018
1 parent 9479d03 commit 35631cf
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 121 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Updated PECL release packages. Here is the list of updates:
- Added support for Azure Key Vault for Always Encrypted for basic CRUD functionalities such that Always Encrypted feature is available to all supported Windows, Linux or macOS platforms
- Added support for macOS High Sierra (requires [MS ODBC Driver 17+](https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-2017))
- Added support for Ubuntu 18.04 LTS (requires MS ODBC Driver 17.2)
- Added support for Linux and macOS to Connection Resiliency (requires MS ODBC Driver 17.2)
- Added support for Linux and macOS for Connection Resiliency (requires MS ODBC Driver 17.2)

### Fixed
- Issue [#577](https://github.com/Microsoft/msphpsql/issues/577) - Idle Connection Resiliency doesn't work with Column Encryption enabled connection (fixed in MS ODBC Driver 17.1)
Expand Down
2 changes: 1 addition & 1 deletion test/functional/sqlsrv/TC52_StreamSend.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function sendStream($minType, $maxType, $atExec)
startTest($testName);

setup();
$tableName = "TC52test";
$tableName = "TC52test" . rand(0, 100);
$fileName = "TC52test.dat";
$conn1 = AE\connect();

Expand Down
2 changes: 1 addition & 1 deletion test/functional/sqlsrv/TC54_StreamPrepared.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function sendStream($minType, $maxType)
startTest($testName);

setup();
$tableName = "TC54test";
$tableName = "TC54test" . rand(0, 100);
$fileName = "TC53test.dat";
$conn1 = AE\connect();

Expand Down
49 changes: 27 additions & 22 deletions test/functional/sqlsrv/TC84_LargeColumnName.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ PHPT_EXEC=true
<?php
require_once('MsCommon.inc');

function LargeColumnNameTest($columnName, $expectfail)
function largeColumnNameTest($columnName, $expectFail = false)
{
setup();

Expand All @@ -20,26 +20,32 @@ function LargeColumnNameTest($columnName, $expectfail)

dropTable($conn, $tableName);

sqlsrv_query($conn, "CREATE TABLE [$tableName] ([$columnName] int)");

sqlsrv_query($conn, "INSERT INTO [$tableName] ([$columnName]) VALUES (5)");
$stmt = sqlsrv_query($conn, "CREATE TABLE [$tableName] ([$columnName] int)");
if ($stmt == null) {
if (!$expectFail) {
fatalError("Possible regression: Unable to create test $tableName.");
} else {
$expected = 'is too long. Maximum length is 128.';
if (strpos(sqlsrv_errors()[0]['message'], $expected) === false) {
print_r(sqlsrv_errors());
}
echo "$";
echo "stmt = null";
echo "\n";
}
} else {
sqlsrv_query($conn, "INSERT INTO [$tableName] ([$columnName]) VALUES (5)");

$stmt = sqlsrv_query($conn, "SELECT * from [$tableName]");
$stmt = sqlsrv_query($conn, "SELECT * from [$tableName]");

if (null == $stmt) {
echo "$";
echo "stmt = null";
echo "\n";
} else {
if (null == sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
if (!$expectfail) {
if (!$expectFail) {
fatalError("Possible regression: Unable to retrieve inserted value.");
}
}
sqlsrv_free_stmt($stmt);
}


dropTable($conn, $tableName);

sqlsrv_close($conn);
Expand All @@ -56,17 +62,16 @@ function repro()

startTest($testName);

$columnName = "a";

try {
for ($a = 1; $a <= 129; $a++) {
LargeColumnNameTest($columnName, $a > 128);
$columnName .= "A";
}
} catch (Exception $e) {
echo $e->getMessage();
}
// The maximum size of a column name is 128 characters
$maxlen = 128;
$columnName = str_repeat('a', $maxlen);

largeColumnNameTest($columnName);

// Now add another character to the name
$columnName .= "A";

largeColumnNameTest($columnName, true);

endTest($testName);
}
Expand Down
51 changes: 30 additions & 21 deletions test/functional/sqlsrv/TC84_LargeColumnName_unicode.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,44 @@ PHPT_EXEC=true
<?php
require_once('MsCommon.inc');

function LargeColumnNameTest($columnName, $expectfail)
function largeColumnNameTest($columnName, $expectFail = false)
{
setup();

$conn = connect(array( 'CharacterSet'=>'UTF-8' ));
$conn = connect(array('CharacterSet'=>'UTF-8'));

$tableName = "LargeColumnNameTest";

dropTable($conn, $tableName);

sqlsrv_query($conn, "CREATE TABLE [$tableName] ([$columnName] int)");

sqlsrv_query($conn, "INSERT INTO [$tableName] ([$columnName]) VALUES (5)");
$stmt = sqlsrv_query($conn, "CREATE TABLE [$tableName] ([$columnName] int)");
if ($stmt == null) {
if (!$expectFail) {
fatalError("Possible regression: Unable to create test $tableName.");
} else {
$expected = 'is too long. Maximum length is 128.';
if (strpos(sqlsrv_errors()[0]['message'], $expected) === false) {
print_r(sqlsrv_errors());
}
echo "$";
echo "stmt = null";
echo "\n";
}
} else {
sqlsrv_query($conn, "INSERT INTO [$tableName] ([$columnName]) VALUES (5)");

$stmt = sqlsrv_query($conn, "SELECT * from [$tableName]");
$stmt = sqlsrv_query($conn, "SELECT * from [$tableName]");

if (null == $stmt) {
echo "$";
echo "stmt = null";
echo "\n";
} else {
if (null == sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
if (!$expectfail) {
if (!$expectFail) {
fatalError("Possible regression: Unable to retrieve inserted value.");
}
}
sqlsrv_free_stmt($stmt);
}

dropTable($conn, $tableName);

sqlsrv_close($conn);
}

Expand All @@ -53,16 +62,16 @@ function repro()

startTest($testName);

$columnName = "";
// The maximum size of a column name is 128 characters
$maxlen = 128;
$columnName = str_repeat('', $maxlen);

try {
for ($a = 1; $a <= 129; $a++) {
LargeColumnNameTest($columnName, $a > 128);
$columnName .= "";
}
} catch (Exception $e) {
echo $e->getMessage();
}
largeColumnNameTest($columnName);

// Now add another character to the name
$columnName .= "";

largeColumnNameTest($columnName, true);

endTest($testName);
}
Expand Down
75 changes: 0 additions & 75 deletions test/functional/sqlsrv/TC84_LargeColumnName_unicode_col_name.phpt

This file was deleted.

0 comments on commit 35631cf

Please sign in to comment.