modified helper methods for temp tables/procs
This commit is contained in:
parent
849725d742
commit
5a395d2e95
|
@ -22,7 +22,7 @@ catch( PDOException $e ) {
|
|||
}
|
||||
try{
|
||||
echo "\nTesting new connection after exception thrown in previous connection...\n";
|
||||
$tableName1 = GetTempTableName('tab1');
|
||||
$tableName1 = GetTempTableName('tab1', false);
|
||||
$conn = new PDO( $dsn, $username, $password );
|
||||
$sql = "CREATE TABLE $tableName1 (c1 int, c2 varchar(10))";
|
||||
$stmt = $conn->query($sql);
|
||||
|
|
|
@ -114,7 +114,7 @@ function RunTest()
|
|||
$conn2 = new PDO( "sqlsrv:server=$serverName;Database=$database", $username, $password);
|
||||
$conn2->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
|
||||
|
||||
$tableName = GetTempTableName('testTransaction');
|
||||
$tableName = GetTempTableName('testTransaction', false);
|
||||
|
||||
// ComplexTransaction() returns number of rows left in $tableName
|
||||
$numRows = ComplexTransaction($conn, $tableName);
|
||||
|
|
|
@ -17,27 +17,40 @@ function EndTest($testName)
|
|||
echo "...Test '$testName' completed successfully.\n";
|
||||
}
|
||||
|
||||
function GetTempTableName($table = '')
|
||||
function GetTempTableName($table = '', $temporary = true)
|
||||
{
|
||||
// A temporary table name with the '#' prefix will be automatically
|
||||
// dropped once the connection is closed
|
||||
$random = mt_rand(1,1000);
|
||||
// dropped once the connection is closed. Otherwise, the caller
|
||||
// should take care of dropping the temp table afterwards.
|
||||
|
||||
$timestamp = round(microtime(true)*1000);
|
||||
|
||||
$prefix = '';
|
||||
if ($temporary)
|
||||
$prefix = '#';
|
||||
|
||||
if (strlen($table) == 0)
|
||||
return "#php_test_table" . '_' . $timestamp . '_' . $random;
|
||||
else
|
||||
return $table . $timestamp;
|
||||
$table = 'php_test_table';
|
||||
|
||||
return $prefix . $table . '_' . $timestamp;
|
||||
}
|
||||
|
||||
function GetTempProcName($proc = '')
|
||||
function GetTempProcName($proc = '', $temporary = true)
|
||||
{
|
||||
// A temporary stored procedure name with the '#' prefix will be
|
||||
// automatically dropped once the connection is closed
|
||||
// automatically dropped once the connection is closed. Otherwise,
|
||||
// the caller should take care of dropping the temp procedure afterwards.
|
||||
|
||||
$timestamp = round(microtime(true)*1000);
|
||||
|
||||
$prefix = '';
|
||||
if ($temporary)
|
||||
$prefix = '#';
|
||||
|
||||
if (strlen($proc) == 0)
|
||||
return "#php_test_proc" . $timestamp;
|
||||
else
|
||||
return $proc . $timestamp;
|
||||
$proc = 'php_test_proc';
|
||||
|
||||
return $prefix . $proc . '_' . $timestamp;
|
||||
}
|
||||
|
||||
function CompareNumericData($actual, $expected)
|
||||
|
|
|
@ -6,7 +6,7 @@ include 'tools.inc';
|
|||
|
||||
function ComplexTransaction($conn, $conn2)
|
||||
{
|
||||
$tableName = GetTempTableName('testTransaction');
|
||||
$tableName = GetTempTableName('testTransaction', false);
|
||||
|
||||
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_real] real)");
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
|
|
@ -6,7 +6,7 @@ include 'tools.inc';
|
|||
|
||||
function ParamQueryError_PhpType_Mismatch($conn)
|
||||
{
|
||||
$tableName = GetTempTableName();
|
||||
$tableName = GetTempTableName('PhpType_Mismatch');
|
||||
|
||||
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_varchar_max] varchar(max))");
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
@ -30,7 +30,7 @@ function ParamQueryError_PhpType_Mismatch($conn)
|
|||
|
||||
function ParamQueryError_Dir_Invalid($conn)
|
||||
{
|
||||
$tableName = GetTempTableName();
|
||||
$tableName = GetTempTableName('Dir_Invalid');
|
||||
|
||||
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_varchar_max] varchar(max))");
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
@ -46,7 +46,7 @@ function ParamQueryError_Dir_Invalid($conn)
|
|||
|
||||
function ParamQueryError_PhpType_Encoding($conn)
|
||||
{
|
||||
$tableName = GetTempTableName();
|
||||
$tableName = GetTempTableName('PhpType_Encoding');
|
||||
|
||||
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_varchar_max] varchar(max))");
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
@ -57,7 +57,7 @@ function ParamQueryError_PhpType_Encoding($conn)
|
|||
|
||||
function ParamQueryError_PhpType_Invalid($conn)
|
||||
{
|
||||
$tableName = GetTempTableName();
|
||||
$tableName = GetTempTableName('PhpType_Invalid');
|
||||
|
||||
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_varchar_max] varchar(max))");
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
|
|
@ -6,7 +6,7 @@ include 'tools.inc';
|
|||
|
||||
function ParamQueryError_MinMaxScale($conn)
|
||||
{
|
||||
$tableName = GetTempTableName();
|
||||
$tableName = GetTempTableName('MinMaxScale');
|
||||
|
||||
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_decimal] decimal(28,4), [c3_numeric] numeric(32,4))");
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
@ -20,7 +20,7 @@ function ParamQueryError_MinMaxScale($conn)
|
|||
|
||||
function ParamQueryError_MinMaxSize($conn)
|
||||
{
|
||||
$tableName = GetTempTableName();
|
||||
$tableName = GetTempTableName('MinMaxSize');
|
||||
|
||||
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_varchar_max] varchar(max))");
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
@ -34,7 +34,7 @@ function ParamQueryError_MinMaxSize($conn)
|
|||
|
||||
function ParamQueryError_MinMaxPrecision($conn)
|
||||
{
|
||||
$tableName = GetTempTableName();
|
||||
$tableName = GetTempTableName('MinMaxPrecision');
|
||||
|
||||
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_decimal] decimal(28,4), [c3_numeric] numeric(32,4))");
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
|
|
@ -6,7 +6,7 @@ include 'tools.inc';
|
|||
|
||||
function QueryTimeout($conn1, $conn2, $commit)
|
||||
{
|
||||
$tableName = GetTempTableName('testQueryTimeout');
|
||||
$tableName = GetTempTableName('testQueryTimeout', false);
|
||||
|
||||
$stmt = sqlsrv_query($conn1, "CREATE TABLE $tableName ([c1_int] int, [c2_tinyint] tinyint, [c3_smallint] smallint, [c4_bigint] bigint, [c5_bit] bit, [c6_float] float, [c7_real] real, [c8_decimal] decimal(28,4), [c9_numeric] numeric(32,4), [c10_money] money, [c11_smallmoney] smallmoney)");
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
|
|
@ -43,27 +43,40 @@ function EndTest($testName)
|
|||
echo "...Test '$testName' completed successfully.\n";
|
||||
}
|
||||
|
||||
function GetTempTableName($table = '')
|
||||
function GetTempTableName($table = '', $temporary = true)
|
||||
{
|
||||
// A temporary table name with the '#' prefix will be automatically
|
||||
// dropped once the connection is closed
|
||||
$random = mt_rand(1,1000);
|
||||
// dropped once the connection is closed. Otherwise, the caller
|
||||
// should take care of dropping the temp table afterwards.
|
||||
|
||||
$timestamp = round(microtime(true)*1000);
|
||||
|
||||
$prefix = '';
|
||||
if ($temporary)
|
||||
$prefix = '#';
|
||||
|
||||
if (strlen($table) == 0)
|
||||
return "#php_test_table" . '_' . $timestamp . '_' . $random;
|
||||
else
|
||||
return $table . $timestamp;
|
||||
$table = 'php_test_table';
|
||||
|
||||
return $prefix . $table . '_' . $timestamp;
|
||||
}
|
||||
|
||||
function GetTempProcName($proc = '')
|
||||
function GetTempProcName($proc = '', $temporary = true)
|
||||
{
|
||||
// A temporary stored procedure name with the '#' prefix will be
|
||||
// automatically dropped once the connection is closed
|
||||
// automatically dropped once the connection is closed. Otherwise,
|
||||
// the caller should take care of dropping the temp procedure afterwards.
|
||||
|
||||
$timestamp = round(microtime(true)*1000);
|
||||
|
||||
$prefix = '';
|
||||
if ($temporary)
|
||||
$prefix = '#';
|
||||
|
||||
if (strlen($proc) == 0)
|
||||
return "#php_test_proc" . $timestamp;
|
||||
else
|
||||
return $proc . $timestamp;
|
||||
$proc = 'php_test_proc';
|
||||
|
||||
return $prefix . $proc . '_' . $timestamp;
|
||||
}
|
||||
|
||||
function FatalError($errorMsg)
|
||||
|
|
Loading…
Reference in a new issue