Simplified a skipif file for checking tcp protocol (#1317)

This commit is contained in:
Jenny Tam 2021-10-19 11:36:53 -07:00 committed by GitHub
parent 8e461ca0ee
commit 608a08005c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 45 deletions

View file

@ -3,31 +3,31 @@ if (!extension_loaded("pdo_sqlsrv")) {
die("skip Extension not loaded"); die("skip Extension not loaded");
} }
require_once( "MsSetup.inc" ); require_once("MsSetup.inc");
$conn = new PDO( "sqlsrv:server = $server ;", $uid, $pwd ); try {
if( $conn === false ) $conn = new PDO("sqlsrv:server = $server", $uid, $pwd);
{ } catch (PDOException $e) {
die( "skip Could not connect during SKIPIF." ); die("skip Could not connect during SKIPIF.");
} }
// Get process ID. Not the same as the one during the actual test, but $tsql = <<<SQL
// we only need to know the protocol for a particular connection. SELECT c.session_id, c.net_transport
$stmt = $conn->query( "SELECT @@SPID" ); FROM sys.dm_exec_connections AS c
if ( $stmt ) JOIN sys.dm_exec_sessions AS s
{ ON c.session_id = s.session_id
$spid = $stmt->fetch(PDO::FETCH_NUM)[0]; WHERE c.session_id = @@SPID;
} SQL;
else
{
die( "skip Could not fetch SPID during SKIPIF.");
}
$stmt = $conn->query( "SELECT * FROM sys.dm_exec_connections WHERE session_id = ".$spid); try {
$prot = $stmt->fetchColumn(3); // Check the transport protocol for the current connection
$stmt = $conn->query($tsql);
$prot = $stmt->fetchColumn(1);
if ($prot != 'TCP') if ($prot != 'TCP') {
{ die("skip Not using a TCP protocol.");
die("skip Not using a TCP protocol." ); }
} catch (PDOException $e) {
die("skip Failed to fetch SPID and transport protocol.");
} }
?> ?>

View file

@ -3,35 +3,32 @@ if (!extension_loaded("sqlsrv")) {
die("skip Extension not loaded"); die("skip Extension not loaded");
} }
require_once( "MsSetup.inc" ); require_once("MsSetup.inc");
$connectionInfo = array( "UID"=>$userName, "PWD"=>$userPassword ); $connectionInfo = array("UID"=>$userName, "PWD"=>$userPassword);
$conn = sqlsrv_connect( $server, $connectionInfo ); $conn = sqlsrv_connect($server, $connectionInfo);
if( $conn === false ) if ($conn === false) {
{ die("skip Could not connect during SKIPIF.");
die( "skip Could not connect during SKIPIF." );
} }
// Get process ID. Not the same as the one during the actual test, but $tsql = <<<SQL
// we only need to know the protocol for a particular connection. SELECT c.session_id, c.net_transport
$stmt = sqlsrv_query( $conn, "SELECT @@SPID" ); FROM sys.dm_exec_connections AS c
if ( sqlsrv_fetch( $stmt ) ) JOIN sys.dm_exec_sessions AS s
{ ON c.session_id = s.session_id
$spid = sqlsrv_get_field( $stmt, 0 ); WHERE c.session_id = @@SPID;
} SQL;
else
{
die("skip Could not fetch SPID.");
}
$stmt = sqlsrv_query( $conn, "SELECT * FROM sys.dm_exec_connections WHERE session_id = $spid"); // Check the transport protocol for the current connection
if ( sqlsrv_fetch( $stmt ) ) $stmt = sqlsrv_query($conn, $tsql);
{ if (sqlsrv_fetch($stmt)) {
$prot = sqlsrv_get_field( $stmt, 3 ); $prot = sqlsrv_get_field($stmt, 1);
if ($prot != 'TCP') if ($prot != 'TCP'){
{ die("skip Not using a TCP protocol.");
die( "skip Not using a TCP protocol." );
} }
} else {
die("skip Failed to fetch SPID and transport protocol.");
} }
?> ?>