Skip to content

Conn res fix #1091

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

Merged
merged 9 commits into from
Feb 6, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
22 changes: 13 additions & 9 deletions test/functional/pdo_sqlsrv/break_pdo.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,24 @@ function generateTables($server, $uid, $pwd, $dbName, $tableName1, $tableName2)
$stmt = $conn->query($sql);

// Insert data
$sql = "INSERT INTO $tableName1 VALUES ( ?, ? )";
$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 );
$params = array($t, $ts);
$stmt->execute($params);
}

// Create table
$sql = "CREATE TABLE $tableName2 ( c1 INT, c2 VARCHAR(40) )";
$sql = "CREATE TABLE $tableName2 (c1 INT, c2 VARCHAR(40))";
$stmt = $conn->query($sql);

// Insert data
$sql = "INSERT INTO $tableName2 VALUES ( ?, ? )";
$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 );
$params = array($t, $ts);
$stmt->execute($params);
}

Expand All @@ -52,8 +52,12 @@ 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).
// Wait one second before and after breaking to ensure the break occurs
// in the correct order, otherwise there may be timing issues in Linux
// that can cause tests to fail intermittently and unpredictably.
function breakConnection($conn, $conn_break)
{
sleep(1);
$stmt1 = $conn->query("SELECT @@SPID");
$obj = $stmt1->fetch(PDO::FETCH_NUM);
$spid = $obj[0];
Expand All @@ -69,11 +73,11 @@ function dropTables($server, $uid, $pwd, $tableName1, $tableName2)

$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);
$query = "IF OBJECT_ID('$tableName1', 'U') IS NOT NULL DROP TABLE $tableName1";
$stmt = $conn->query($query);

$query="IF OBJECT_ID('$tableName2', 'U') IS NOT NULL DROP TABLE $tableName2";
$stmt=$conn->query($query);
$query = "IF OBJECT_ID('$tableName2', 'U') IS NOT NULL DROP TABLE $tableName2";
$stmt = $conn->query($query);
}

dropTables($server, $uid, $pwd, $tableName1, $tableName2);
Expand Down
82 changes: 41 additions & 41 deletions test/functional/sqlsrv/break.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,79 +12,79 @@
// 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)
{
$connectionInfo = array( "Database"=>$dbName, "uid"=>$uid, "pwd"=>$pwd );
$connectionInfo = array("Database"=>$dbName, "uid"=>$uid, "pwd"=>$pwd);

$conn = sqlsrv_connect( $server, $connectionInfo );
if ( $conn === false )
{
die ( print_r( sqlsrv_errors() ) );
$conn = sqlsrv_connect($server, $connectionInfo);
if ($conn === false) {
die (print_r(sqlsrv_errors()));
}

// Create table
$sql = "CREATE TABLE $tableName1 ( c1 INT, c2 VARCHAR(40) )";
$stmt = sqlsrv_query( $conn, $sql );
$sql = "CREATE TABLE $tableName1 (c1 INT, c2 VARCHAR(40))";
$stmt = sqlsrv_query($conn, $sql);

// Insert data
$sql = "INSERT INTO $tableName1 VALUES ( ?, ? )";
for( $t = 100; $t < 116; $t++ )
{
$ts = substr( sha1( $t ),0,5 );
$params = array( $t,$ts );
$stmt = sqlsrv_prepare( $conn, $sql, $params );
sqlsrv_execute( $stmt );
$sql = "INSERT INTO $tableName1 VALUES (?, ?)";
for ($t = 100; $t < 116; $t++) {
$ts = substr(sha1($t), 0, 5);
$params = array($t, $ts);
$stmt = sqlsrv_prepare($conn, $sql, $params);
sqlsrv_execute($stmt);
}

// Create table
$sql = "CREATE TABLE $tableName2 ( c1 INT, c2 VARCHAR(40) )";
$stmt = sqlsrv_query( $conn, $sql );
$sql = "CREATE TABLE $tableName2 (c1 INT, c2 VARCHAR(40))";
$stmt = sqlsrv_query($conn, $sql);

// Insert data
$sql = "INSERT INTO $tableName2 VALUES ( ?, ? )";
for( $t = 200; $t < 209; $t++ )
{
$ts = substr( sha1( $t ),0,5 );
$params = array( $t,$ts );
$stmt = sqlsrv_prepare( $conn, $sql, $params );
sqlsrv_execute( $stmt );
$sql = "INSERT INTO $tableName2 VALUES (?, ?)";
for ($t = 200; $t < 209; $t++) {
$ts = substr(sha1($t), 0, 5);
$params = array($t, $ts);
$stmt = sqlsrv_prepare($conn, $sql, $params);
sqlsrv_execute($stmt);
}

sqlsrv_close( $conn );
sqlsrv_close($conn);
}

// 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 )
// Wait one second before and after breaking to ensure the break occurs
// in the correct order, otherwise there may be timing issues in Linux
// that can cause tests to fail intermittently and unpredictably.
function BreakConnection($conn, $conn_break)
{
$stmt1 = sqlsrv_query( $conn, "SELECT @@SPID" );
if ( sqlsrv_fetch( $stmt1 ) )
{
$spid=sqlsrv_get_field( $stmt1, 0 );
sleep(1);
$stmt1 = sqlsrv_query($conn, "SELECT @@SPID");
if (sqlsrv_fetch($stmt1)) {
$spid=sqlsrv_get_field($stmt1, 0);
}

$stmt2 = sqlsrv_prepare( $conn_break, "KILL ".$spid );
sqlsrv_execute( $stmt2 );
$stmt2 = sqlsrv_prepare($conn_break, "KILL ".$spid);
sqlsrv_execute($stmt2);
sleep(1);
}

// Remove the tables generated by GenerateTables
function DropTables( $server, $uid, $pwd, $tableName1, $tableName2 )
function DropTables($server, $uid, $pwd, $tableName1, $tableName2)
{
global $dbName;

$connectionInfo = array( "Database"=>$dbName, "UID"=>$uid, "PWD"=>$pwd );
$conn = sqlsrv_connect( $server, $connectionInfo );
$connectionInfo = array("Database"=>$dbName, "UID"=>$uid, "PWD"=>$pwd);
$conn = sqlsrv_connect($server, $connectionInfo);

$query="IF OBJECT_ID('$tableName1', 'U') IS NOT NULL DROP TABLE $tableName1";
$stmt=sqlsrv_query( $conn, $query );
$query = "IF OBJECT_ID('$tableName1', 'U') IS NOT NULL DROP TABLE $tableName1";
$stmt = sqlsrv_query($conn, $query);

$query="IF OBJECT_ID('$tableName2', 'U') IS NOT NULL DROP TABLE $tableName2";
$stmt=sqlsrv_query( $conn, $query );
$query = "IF OBJECT_ID('$tableName2', 'U') IS NOT NULL DROP TABLE $tableName2";
$stmt = sqlsrv_query($conn, $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);

?>