From 608a08005c5fb38cb2553a40d989868f07198ccd Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Tue, 19 Oct 2021 11:36:53 -0700 Subject: [PATCH] Simplified a skipif file for checking tcp protocol (#1317) --- .../pdo_sqlsrv/skipif_protocol_not_tcp.inc | 42 ++++++++--------- .../sqlsrv/skipif_protocol_not_tcp.inc | 45 +++++++++---------- 2 files changed, 42 insertions(+), 45 deletions(-) diff --git a/test/functional/pdo_sqlsrv/skipif_protocol_not_tcp.inc b/test/functional/pdo_sqlsrv/skipif_protocol_not_tcp.inc index e59d550b..4ba27a99 100644 --- a/test/functional/pdo_sqlsrv/skipif_protocol_not_tcp.inc +++ b/test/functional/pdo_sqlsrv/skipif_protocol_not_tcp.inc @@ -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 = <<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."); } ?> diff --git a/test/functional/sqlsrv/skipif_protocol_not_tcp.inc b/test/functional/sqlsrv/skipif_protocol_not_tcp.inc index 26d960ca..44cf6875 100644 --- a/test/functional/sqlsrv/skipif_protocol_not_tcp.inc +++ b/test/functional/sqlsrv/skipif_protocol_not_tcp.inc @@ -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 = <<