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