diff --git a/test/bvt/pdo_sqlsrv/break.inc b/test/bvt/pdo_sqlsrv/break.inc
deleted file mode 100644
index 0540dac8..00000000
--- a/test/bvt/pdo_sqlsrv/break.inc
+++ /dev/null
@@ -1,60 +0,0 @@
-
\ No newline at end of file
diff --git a/test/bvt/pdo_sqlsrv/break_pdo.php b/test/bvt/pdo_sqlsrv/break_pdo.php
deleted file mode 100644
index 6082387f..00000000
--- a/test/bvt/pdo_sqlsrv/break_pdo.php
+++ /dev/null
@@ -1,82 +0,0 @@
-query( $sql );
-
- // Insert data
- $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 );
- $stmt->execute( $params );
- }
-
- // Create table
- $sql = "CREATE TABLE $tableName2 ( c1 INT, c2 VARCHAR(40) )";
- $stmt = $conn->query( $sql );
-
- // Insert data
- $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 );
- $stmt->execute( $params );
- }
-
- $conn = null;
-}
-
-// 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 )
-{
- $stmt1 = $conn->query( "SELECT @@SPID" );
- $obj = $stmt1->fetch( PDO::FETCH_NUM );
- $spid = $obj[0];
-
- $stmt2 = $conn_break->query( "KILL ".$spid );
- sleep(1);
-}
-
-// Remove any databases previously created by GenerateDatabase
-function DropTables( $server, $uid, $pwd, $tableName1, $tableName2 )
-{
- $conn = new PDO( "sqlsrv:server = $server ; ", $uid, $pwd );
-
- $query="IF OBJECT_ID('tempdb.dbo.$tableName1', 'U') IS NOT NULL DROP TABLE tempdb.dbo.$tableName1";
- $stmt=$conn->query( $query );
-
- $query="IF OBJECT_ID('tempdb.dbo.$tableName2', 'U') IS NOT NULL DROP TABLE tempdb.dbo.$tableName2";
- $stmt=$conn->query( $query );
-}
-
-DropTables( $server, $uid, $pwd, $tableName1, $tableName2 );
-GenerateTables( $server, $uid, $pwd, $dbName, $tableName1, $tableName2 );
-
-?>
\ No newline at end of file
diff --git a/test/bvt/pdo_sqlsrv/connect.inc b/test/bvt/pdo_sqlsrv/connect.inc
index a6bd479f..470b5cb8 100644
--- a/test/bvt/pdo_sqlsrv/connect.inc
+++ b/test/bvt/pdo_sqlsrv/connect.inc
@@ -3,6 +3,19 @@ $server = 'TARGET_SERVER';
$databaseName = 'TARGET_DATABASE';
$uid = 'TARGET_USERNAME';
$pwd = 'TARGET_PASSWORD';
+
+function dropTable($conn, $tableName)
+{
+ $tsql = "IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'" . $tableName . "') AND type in (N'U')) DROP TABLE [$tableName]";
+ $conn->exec($tsql);
+}
+
+function dropProc($conn, $procName)
+{
+ $tsql = "IF OBJECT_ID('". $procName ."', 'P') IS NOT NULL DROP PROCEDURE [$procName]";
+ $conn->exec($tsql);
+}
+
?>
diff --git a/test/bvt/pdo_sqlsrv/msdn_pdoStatement_bindParam_3.phpt b/test/bvt/pdo_sqlsrv/msdn_pdoStatement_bindParam_3.phpt
index a409e645..df081c8d 100644
--- a/test/bvt/pdo_sqlsrv/msdn_pdoStatement_bindParam_3.phpt
+++ b/test/bvt/pdo_sqlsrv/msdn_pdoStatement_bindParam_3.phpt
@@ -7,17 +7,19 @@ uses an input/output parameter
require('connect.inc');
$dbh = new PDO( "sqlsrv:server=$server ; Database = $databaseName", "$uid", "$pwd");
- $dbh->query("IF OBJECT_ID('dbo.sp_ReverseString', 'P') IS NOT NULL DROP PROCEDURE dbo.sp_ReverseString");
- $dbh->query("CREATE PROCEDURE dbo.sp_ReverseString @String as VARCHAR(2048) OUTPUT as SELECT @String = REVERSE(@String)");
- $stmt = $dbh->prepare("EXEC dbo.sp_ReverseString ?");
+ dropProc($dbh, 'sp_ReverseString');
+ $dbh->query("CREATE PROCEDURE sp_ReverseString @String as VARCHAR(2048) OUTPUT as SELECT @String = REVERSE(@String)");
+ $stmt = $dbh->prepare("EXEC sp_ReverseString ?");
$string = "123456789";
$stmt->bindParam(1, $string, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT, 2048);
$stmt->execute();
print "Result: ".$string; // Expect 987654321
+ dropProc($dbh, 'sp_ReverseString', false);
+
//free the statement and connection
- $stmt = null;
- $dbh = null;
+ unset($stmt);
+ unset($dbh);
?>
--EXPECT--
Result: 987654321
\ No newline at end of file
diff --git a/test/bvt/pdo_sqlsrv/msdn_pdoStatement_rowCount.phpt b/test/bvt/pdo_sqlsrv/msdn_pdoStatement_rowCount.phpt
index 975a6264..3ab74fac 100644
--- a/test/bvt/pdo_sqlsrv/msdn_pdoStatement_rowCount.phpt
+++ b/test/bvt/pdo_sqlsrv/msdn_pdoStatement_rowCount.phpt
@@ -5,30 +5,33 @@ returns the number of rows added to a table; returns the number of rows in a res
--FILE--
exec("CREAtE TABLE Table1(col1 VARCHAR(15), col2 VARCHAR(15)) ");
+$conn = new PDO("sqlsrv:Server=$server; Database = $databaseName", $uid, $pwd);
+
+$tableName = "pdoRowCount";
+dropTable($conn, $tableName);
+$conn->exec("CREATE TABLE $tableName(col1 VARCHAR(15), col2 VARCHAR(15)) ");
$col1 = 'a';
$col2 = 'b';
-$query = "insert into Table1(col1, col2) values(?, ?)";
+$query = "INSERT INTO $tableName(col1, col2) values(?, ?)";
$stmt = $conn->prepare( $query );
$stmt->execute( array( $col1, $col2 ) );
print $stmt->rowCount();
-print " rows affects.";
+print " rows affected.";
echo "\n\n";
//revert the insert
-$conn->exec("delete from Table1 where col1 = 'a' AND col2 = 'b'");
+$conn->exec("DELETE FROM $tableName where col1 = 'a' AND col2 = 'b'");
-$conn->exec("DROP TABLE Table1 ");
+dropTable($conn, $tableName, false);
$conn = null;
-$conn = new PDO( "sqlsrv:server=$server ; Database = $databaseName", "$uid", "$pwd");
+$conn = new PDO("sqlsrv:Server=$server; Database = $databaseName", $uid, $pwd);
-$query = "select * from Person.ContactType";
+$query = "SELECT * FROM Person.ContactType";
$stmt = $conn->prepare( $query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL));
$stmt->execute();
print $stmt->rowCount();
@@ -40,6 +43,6 @@ $stmt = null;
$conn = null;
?>
--EXPECT--
-1 rows affects.
+1 rows affected.
20 rows in result set.
\ No newline at end of file
diff --git a/test/bvt/pdo_sqlsrv/msdn_pdo_beginTransaction.phpt b/test/bvt/pdo_sqlsrv/msdn_pdo_beginTransaction.phpt
index edc0632f..568d6d1f 100644
--- a/test/bvt/pdo_sqlsrv/msdn_pdo_beginTransaction.phpt
+++ b/test/bvt/pdo_sqlsrv/msdn_pdo_beginTransaction.phpt
@@ -4,27 +4,30 @@ starts a transaction, insert 2 rows and commit the transaction
--FILE--
exec("CREAtE TABLE Table1(col1 CHARACTER(1), col2 CHARACTER(1)) ");
-
- $conn->beginTransaction();
- $ret = $conn->exec("insert into Table1(col1, col2) values('a', 'b') ");
- $ret = $conn->exec("insert into Table1(col1, col2) values('a', 'c') ");
-
- //revert the inserts
- $ret = $conn->exec("delete from Table1 where col1 = 'a'");
- $conn->commit();
- // $conn->rollback();
- echo $ret." rows affected";
-
- //drop the created temp table
- $conn->exec("DROP TABLE Table1 ");
-
- //free statement and connection
- $ret=NULL;
- $conn=NULL;
+ require('connect.inc');
+
+ //make connection and create a temporaty table
+ $conn = new PDO( "sqlsrv:Server=$server; Database = $databaseName ", "$uid", "$pwd");
+ $tableName = "pdoBeginTransaction";
+ dropTable($conn, $tableName);
+
+ $conn->exec("CREATE TABLE $tableName(col1 CHARACTER(1), col2 CHARACTER(1)) ");
+
+ $conn->beginTransaction();
+ $ret = $conn->exec("insert into $tableName(col1, col2) values('a', 'b') ");
+ $ret = $conn->exec("insert into $tableName(col1, col2) values('a', 'c') ");
+
+ //revert the inserts
+ $ret = $conn->exec("delete from $tableName where col1 = 'a'");
+ $conn->commit();
+
+ // $conn->rollback();
+ echo $ret." rows affected";
+
+ //drop the created temp table
+ dropTable($conn, $tableName, false);
+
+ unset($conn);
?>
--EXPECT--
2 rows affected
\ No newline at end of file
diff --git a/test/bvt/pdo_sqlsrv/msdn_pdo_construct_2.phpt b/test/bvt/pdo_sqlsrv/msdn_pdo_construct_2.phpt
index 5f937210..e7a74a08 100644
--- a/test/bvt/pdo_sqlsrv/msdn_pdo_construct_2.phpt
+++ b/test/bvt/pdo_sqlsrv/msdn_pdo_construct_2.phpt
@@ -5,9 +5,8 @@ connect to a server, specifying the database later
--FILE--
exec( "USE $databaseName");
$query = 'SELECT * FROM Person.ContactType';
$stmt = $c->query( $query );
while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ){
diff --git a/test/bvt/pdo_sqlsrv/msdn_pdo_exec.phpt b/test/bvt/pdo_sqlsrv/msdn_pdo_exec.phpt
index 2f0f9b12..3def85a9 100644
--- a/test/bvt/pdo_sqlsrv/msdn_pdo_exec.phpt
+++ b/test/bvt/pdo_sqlsrv/msdn_pdo_exec.phpt
@@ -4,21 +4,22 @@ execute a delete and reports how many rows were deleted
--FILE--
exec("use tempdb");
- $c->exec("CREAtE TABLE Table1(col1 VARCHAR(100), col2 VARCHAR(100)) ");
-
- $ret = $c->exec("insert into Table1 values('xxxyy', 'yyxx')");
- $ret = $c->exec("delete from Table1 where col1 = 'xxxyy'");
- echo $ret," rows affected";
-
- $c->exec("DROP TABLE Table1 ");
-
- //free the statement and connection
- $ret=null;
- $c=null;
+ $tableName = "pdoExec";
+ dropTable($c, $tableName);
+
+ $c->exec("CREATE TABLE $tableName(col1 VARCHAR(100), col2 VARCHAR(100)) ");
+
+ $ret = $c->exec("INSERT INTO $tableName VALUES('xxxyy', 'yyxx')");
+ $ret = $c->exec("DELETE FROM $tableName WHERE col1 = 'xxxyy'");
+ echo $ret," rows affected";
+
+ dropTable($c, $tableName, false);
+
+ //free the statement and connection
+ unset($c);
?>
--EXPECT--
1 rows affected
\ No newline at end of file
diff --git a/test/bvt/pdo_sqlsrv/msdn_pdo_prepare.phpt b/test/bvt/pdo_sqlsrv/msdn_pdo_prepare.phpt
index 6b192631..935b4935 100644
--- a/test/bvt/pdo_sqlsrv/msdn_pdo_prepare.phpt
+++ b/test/bvt/pdo_sqlsrv/msdn_pdo_prepare.phpt
@@ -5,31 +5,34 @@ prepares a statement with parameter markers and forward-only (server-side) curso
--FILE--
exec("CREAtE TABLE Table1(col1 VARCHAR(100), col2 VARCHAR(100))");
+$tableName = "pdoPrepare";
+dropTable($conn, $tableName);
+
+$conn->exec("CREATE TABLE $tableName(col1 VARCHAR(100), col2 VARCHAR(100))");
$col1 = 'a';
$col2 = 'b';
-$query = "insert into Table1(col1, col2) values(?, ?)";
+$query = "INSERT INTO $tableName(col1, col2) VALUES(?, ?)";
$stmt = $conn->prepare( $query, array( PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY, PDO::SQLSRV_ATTR_QUERY_TIMEOUT => 1 ) );
$stmt->execute( array( $col1, $col2 ) );
print $stmt->rowCount();
echo " row affected\n";
-$query = "insert into Table1(col1, col2) values(:col1, :col2)";
+$query = "INSERT INTO $tableName(col1, col2) VALUES(:col1, :col2)";
$stmt = $conn->prepare( $query, array( PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY, PDO::SQLSRV_ATTR_QUERY_TIMEOUT => 1 ) );
$stmt->execute( array( ':col1' => $col1, ':col2' => $col2 ) );
print $stmt->rowCount();
echo " row affected\n";
// revert the inserts
-$conn->exec("delete from Table1 where col1 = 'a' AND col2 = 'b'");
+$conn->exec("DELETE FROM $tableName WHERE col1 = 'a' AND col2 = 'b'");
+dropTable($conn, $tableName, false);
-$conn->exec("DROP TABLE Table1 ");
-$stmt = null;
-$conn = null;
+unset($stmt);
+unset($conn);
?>
--EXPECT--
1 row affected
diff --git a/test/bvt/pdo_sqlsrv/msdn_pdo_quote.phpt b/test/bvt/pdo_sqlsrv/msdn_pdo_quote.phpt
index 6bd10956..26e1ec05 100644
--- a/test/bvt/pdo_sqlsrv/msdn_pdo_quote.phpt
+++ b/test/bvt/pdo_sqlsrv/msdn_pdo_quote.phpt
@@ -6,36 +6,40 @@ insert with quoted parameters
exec("CREAtE TABLE Table1(col1 VARCHAR(15), col2 VARCHAR(15)) ");
+$conn = new PDO("sqlsrv:Server=$server; Database = $databaseName", $uid, $pwd);
+
+$tableName = "pdoQuote";
+dropTable($conn, $tableName);
+
+$conn->exec("CREATE TABLE $tableName(col1 VARCHAR(15), col2 VARCHAR(15)) ");
$param = 'a \' g';
$param2 = $conn->quote( $param );
-$query = "INSERT INTO Table1 VALUES( ?, '1' )";
+$query = "INSERT INTO $tableName VALUES( ?, '1' )";
$stmt = $conn->prepare( $query );
$stmt->execute(array($param));
-$query = "INSERT INTO Table1 VALUES( ?, ? )";
+$query = "INSERT INTO $tableName VALUES( ?, ? )";
$stmt = $conn->prepare( $query );
$stmt->execute(array($param, $param2));
-$query = "SELECT * FROM Table1";
+$query = "SELECT * FROM $tableName";
$stmt = $conn->query($query);
while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ){
print_r( $row['col1'] ." was inserted\n" );
}
// revert the inserts
-$query = "delete from Table1 where col1 = ?";
+$query = "DELETE FROM $tableName WHERE col1 = ?";
$stmt = $conn->prepare( $query );
$stmt->execute(array($param));
-$conn->exec("DROP TABLE Table1 ");
-
+dropTable($conn, $tableName, false);
+
//free the statement and connection
-$stmt=null;
-$conn=null;
+unset($stmt);
+unset($conn);
?>
--EXPECT--
a ' g was inserted
diff --git a/test/bvt/pdo_sqlsrv/msdn_pdo_setAttribute_direct_query.phpt b/test/bvt/pdo_sqlsrv/msdn_pdo_setAttribute_direct_query.phpt
index f78c59ba..3b940739 100644
--- a/test/bvt/pdo_sqlsrv/msdn_pdo_setAttribute_direct_query.phpt
+++ b/test/bvt/pdo_sqlsrv/msdn_pdo_setAttribute_direct_query.phpt
@@ -4,27 +4,24 @@ sets to PDO::SQLSRV_ATTR_DIRECT_QUERY
--FILE--
setAttribute(constant('PDO::SQLSRV_ATTR_DIRECT_QUERY'), true);
+ require('connect.inc');
+ $conn = new PDO("sqlsrv:Server=$server; Database = $databaseName", $uid, $pwd);
+ $conn->setAttribute(PDO::SQLSRV_ATTR_DIRECT_QUERY, true);
$tableName = 'pdo_direct_query';
- $tsql = "IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'" . $tableName . "') AND type in (N'U')) DROP TABLE $tableName";
-
- $stmt1 = $conn->query($tsql);
- $stmt2 = $conn->query("CREATE TABLE $tableName ([c1_int] int, [c2_int] int)");
+ $conn->query("CREATE TABLE $tableName ([c1_int] int, [c2_int] int)");
$v1 = 1;
$v2 = 2;
- $stmt3 = $conn->prepare("INSERT INTO $tableName (c1_int, c2_int) VALUES (:var1, :var2)");
+ $stmt = $conn->prepare("INSERT INTO $tableName (c1_int, c2_int) VALUES (:var1, :var2)");
- if ($stmt3) {
- $stmt3->bindValue(1, $v1);
- $stmt3->bindValue(2, $v2);
+ if ($stmt) {
+ $stmt->bindValue(1, $v1);
+ $stmt->bindValue(2, $v2);
- if ($stmt3->execute()) {
- echo "Execution succeeded\n";
+ if ($stmt->execute()) {
+ echo "Execution succeeded\n";
} else {
echo "Execution failed\n";
}
@@ -32,13 +29,10 @@ sets to PDO::SQLSRV_ATTR_DIRECT_QUERY
var_dump($conn->errorInfo());
}
- $stmt4 = $conn->query("DROP TABLE $tableName");
+ $stmt = $conn->query("DROP TABLE $tableName");
// free the statements and connection
- unset($stmt1);
- unset($stmt2);
- unset($stmt3);
- unset($stmt4);
+ unset($stmt);
unset($conn);
?>
--EXPECT--
diff --git a/test/bvt/pdo_sqlsrv/pdo_bindParam_inout_double.phpt b/test/bvt/pdo_sqlsrv/pdo_bindParam_inout_double.phpt
index f82871f3..11919573 100644
--- a/test/bvt/pdo_sqlsrv/pdo_bindParam_inout_double.phpt
+++ b/test/bvt/pdo_sqlsrv/pdo_bindParam_inout_double.phpt
@@ -7,11 +7,7 @@ call a stored procedure and retrieve the errorNumber that is returned
require('connect.inc');
$conn = new PDO( "sqlsrv:server=$server ; Database = $databaseName", "$uid", "$pwd");
- // Drop the stored procedure if it already exists
- $tsql_dropSP = "IF OBJECT_ID('sp_Test_Double', 'P') IS NOT NULL
- DROP PROCEDURE sp_Test_Double";
-
- $stmt = $conn->query($tsql_dropSP);
+ dropProc($conn, 'sp_Test_Double');
// Create the stored procedure
$tsql_createSP = "CREATE PROCEDURE sp_Test_Double
@@ -39,10 +35,11 @@ call a stored procedure and retrieve the errorNumber that is returned
print("Error Number minus 2: $value\n\n");
print_r($result);
-
+ dropProc($conn, 'sp_Test_Double', false);
+
//free the statement and connection
- $stmt = null;
- $conn = null;
+ unset($stmt);
+ unset($conn);
?>
--EXPECT--
Error Number: -1.111
diff --git a/test/bvt/pdo_sqlsrv/pdo_bindParam_inout_integer.phpt b/test/bvt/pdo_sqlsrv/pdo_bindParam_inout_integer.phpt
index 57135fe9..2a882acb 100644
--- a/test/bvt/pdo_sqlsrv/pdo_bindParam_inout_integer.phpt
+++ b/test/bvt/pdo_sqlsrv/pdo_bindParam_inout_integer.phpt
@@ -4,43 +4,43 @@ call a stored procedure and retrieve the errorNumber that is returned
--FILE--
query($tsql_dropSP);
+ // Drop the stored procedure if it already exists
+ dropProc($conn, 'sp_Test_Integer');
- // Create the stored procedure
- $tsql_createSP = "CREATE PROCEDURE sp_Test_Integer
- @ErrorNumber AS INT = 0 OUTPUT
- AS
- BEGIN
- SET @ErrorNumber = -1
- SELECT 1,2,3
- END";
+ // Create the stored procedure
+ $tsql_createSP = "CREATE PROCEDURE sp_Test_Integer
+ @ErrorNumber AS INT = 0 OUTPUT
+ AS
+ BEGIN
+ SET @ErrorNumber = -1
+ SELECT 1,2,3
+ END";
- $stmt = $conn->query($tsql_createSP);
+ $stmt = $conn->query($tsql_createSP);
- // Call the stored procedure
- $stmt = $conn->prepare("{CALL sp_Test_Integer (:errornumber)}");
+ // Call the stored procedure
+ $stmt = $conn->prepare("{CALL sp_Test_Integer (:errornumber)}");
- $errorNumber = 0;
- $stmt->bindParam('errornumber', $errorNumber, PDO::PARAM_INT|PDO::PARAM_INPUT_OUTPUT, 4);
+ $errorNumber = 0;
+ $stmt->bindParam('errornumber', $errorNumber, PDO::PARAM_INT|PDO::PARAM_INPUT_OUTPUT, 4);
- $stmt->execute();
- $result = $stmt->fetchAll(PDO::FETCH_NUM);
+ $stmt->execute();
+ $result = $stmt->fetchAll(PDO::FETCH_NUM);
- $stmt->closeCursor();
+ $stmt->closeCursor();
- print("Error Number: $errorNumber\n\n");
- print_r($result);
-
- //free the statement and connection
- $stmt = null;
- $conn = null;
+ print("Error Number: $errorNumber\n\n");
+ print_r($result);
+
+ // Drop the stored procedure
+ dropProc($conn, 'sp_Test_Integer', false);
+
+ //free the statement and connection
+ unset($stmt);
+ unset($conn);
?>
--EXPECT--
Error Number: -1
diff --git a/test/bvt/pdo_sqlsrv/pdo_bindParam_inout_string.phpt b/test/bvt/pdo_sqlsrv/pdo_bindParam_inout_string.phpt
index f2743392..5899419e 100644
--- a/test/bvt/pdo_sqlsrv/pdo_bindParam_inout_string.phpt
+++ b/test/bvt/pdo_sqlsrv/pdo_bindParam_inout_string.phpt
@@ -4,44 +4,43 @@ call a stored procedure and retrieve the errorString that is returned
--FILE--
query($tsql_dropSP);
+ // Create the stored procedure
+ $tsql_createSP = "CREATE PROCEDURE sp_Test_String
+ @ErrorString as varchar(20) OUTPUT
+ AS
+ BEGIN
+ SET @ErrorString = REVERSE(@ErrorString)
+ SELECT 1,2,3
+ END";
+ $stmt = $conn->query($tsql_createSP);
- // Create the stored procedure
- $tsql_createSP = "CREATE PROCEDURE sp_Test_String
- @ErrorString as varchar(20) OUTPUT
- AS
- BEGIN
- SET @ErrorString = REVERSE(@ErrorString)
- SELECT 1,2,3
- END";
- $stmt = $conn->query($tsql_createSP);
+ // Call the stored procedure
+ $stmt = $conn->prepare("{CALL sp_Test_String (?)}");
- // Call the stored procedure
- $stmt = $conn->prepare("{CALL sp_Test_String (?)}");
+ $errorString = "12345";
+ $stmt->bindParam(1, $errorString, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 20);
+ print("Error String: $errorString\n\n");
- $errorString = "12345";
- $stmt->bindParam(1, $errorString, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 20);
- print("Error String: $errorString\n\n");
+ $stmt->execute();
- $stmt->execute();
+ $result = $stmt->fetchAll(PDO::FETCH_NUM);
- $result = $stmt->fetchAll(PDO::FETCH_NUM);
+ $stmt->closeCursor();
+
+ print("Error String: $errorString\n\n");
+ print_r($result);
+
+ dropProc($conn, 'sp_Test_String', false);
- $stmt->closeCursor();
-
- print("Error String: $errorString\n\n");
- print_r($result);
-
- //free the statement and connection
- $stmt = null;
- $conn = null;
+ //free the statement and connection
+ unset($stmt);
+ unset($conn);
?>
--EXPECT--
Error String: 12345
diff --git a/test/bvt/sqlsrv/break.inc b/test/bvt/sqlsrv/break.inc
deleted file mode 100644
index 5e6429f7..00000000
--- a/test/bvt/sqlsrv/break.inc
+++ /dev/null
@@ -1,109 +0,0 @@
-"$databaseName", "username"=>"$username", "password"=>"$password" );
-$conn = sqlsrv_connect( $serverName, $connectionInfo );
-
-// CREATE database
-$stmt0 = sqlsrv_query($conn, "CREATE DATABASE $databaseName");
-
-// Create table
-$sql = "CREATE TABLE $tableName1 (c1 INT, c2 VARCHAR(40))";
-$stmt = sqlsrv_query($conn, $sql);
-
-// Insert data using bind parameters
-$sql = "INSERT INTO $tableName1 VALUES (?,?)";
-for($t=100; $t<115; $t++) {
- $stmt = sqlsrv_prepare($conn, $sql);
- $ts = substr(sha1($t),0,5);
- $params = array($t,$ts);
- sqlsrv_execute($stmt, $params);
-}
-
-// Create table
-$sql = "CREATE TABLE $tableName2 (c1 INT, c2 VARCHAR(40))";
-$stmt = sqlsrv_query($conn, $sql);
-
-// Insert data using bind parameters
-$sql = "INSERT INTO $tableName2 VALUES (?,?)";
-for($t=200; $t<208; $t++) {
- $stmt = sqlsrv_prepare($conn, $sql);
- $ts = substr(sha1($t),0,5);
- $params = array($t,$ts);
- sqlsrv_execute($stmt, $params);
-}
-
-sqlsrv_close( $conn );
-
-function RestartConn($serverName)
-{
- $powershell = "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe";
- $restart_string = "$powershell (get-service -ComputerName $serverName -Name mssqlserver).Stop()";
- exec( $restart_string );
- $servstring = shell_exec("$powershell get-service -ComputerName $serverName -Name mssqlserver");
-
- // Wait until the service is fully stopped
- while (substr_count($servstring, "Stopped") != 1)
- {
- sleep(1);
- $servstring = shell_exec("$powershell get-service -ComputerName $serverName -Name mssqlserver");
- }
- $restart_string = "$powershell (get-service -ComputerName $serverName -Name mssqlserver).Start()";
- exec( $restart_string );
- $servstring = shell_exec("$powershell get-service -ComputerName $serverName -Name mssqlserver");
-
- // Wait until the service is fully started
- while (substr_count($servstring, "Running") != 1)
- {
- sleep(1);
- $servstring = shell_exec("$powershell get-service -ComputerName $serverName -Name mssqlserver");
- }
-}
-
-function StopConn($serverName)
-{
- $powershell = "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe";
- $restart_string = "$powershell (get-service -ComputerName $serverName -Name mssqlserver).Stop()";
- exec( $restart_string );
- $servstring = shell_exec("$powershell get-service -ComputerName $serverName -Name mssqlserver");
-
- // Wait until the service is fully stopped
- while (substr_count($servstring, "Stopped") != 1)
- {
- sleep(1);
- $servstring = shell_exec("$powershell get-service -ComputerName $serverName -Name mssqlserver");
- }
-}
-
-function StartConn($serverName)
-{
- $powershell = "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe";
- $servstring = shell_exec("$powershell get-service -ComputerName $serverName -Name mssqlserver");
- if (substr_count($servstring, "Running") != 1)
- {
- $restart_string = "$powershell (get-service -ComputerName $serverName -Name mssqlserver).Start()";
- exec( $restart_string );
- }
- $servstring = shell_exec("$powershell get-service -ComputerName $serverName -Name mssqlserver");
-
- // Wait until the service is fully started
- while (substr_count($servstring, "Running") != 1)
- {
- sleep(1);
- $servstring = shell_exec("$powershell get-service -ComputerName $serverName -Name mssqlserver");
- }
-}
-?>
\ No newline at end of file
diff --git a/test/bvt/sqlsrv/break.php b/test/bvt/sqlsrv/break.php
deleted file mode 100644
index da5826c5..00000000
--- a/test/bvt/sqlsrv/break.php
+++ /dev/null
@@ -1,88 +0,0 @@
-$dbName, "uid"=>$uid, "pwd"=>$pwd );
-
- $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 );
-
- // 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 );
- }
-
- // Create table
- $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 );
- }
-
- 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 )
-{
- $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 );
- sleep(1);
-}
-
-// Remove the tables generated by GenerateTables
-function DropTables( $server, $uid, $pwd, $tableName1, $tableName2 )
-{
- $connectionInfo = array( "UID"=>$uid, "PWD"=>$pwd );
- $conn = sqlsrv_connect( $server, $connectionInfo );
-
- $query="IF OBJECT_ID('tempdb.dbo.$tableName1, 'U') IS NOT NULL DROP TABLE tempdb.dbo.$tableName1";
- $stmt=sqlsrv_query( $conn, $query );
-
- $query="IF OBJECT_ID('tempdb.dbo.$tableName2, 'U') IS NOT NULL DROP TABLE tempdb.dbo.$tableName2";
- $stmt=sqlsrv_query( $conn, $query );
-}
-
-DropTables( $server, $uid, $pwd, $tableName1, $tableName2 );
-GenerateTables( $server, $uid, $pwd, $dbName, $tableName1, $tableName2 );
-
-?>
\ No newline at end of file
diff --git a/test/bvt/sqlsrv/connect.inc b/test/bvt/sqlsrv/connect.inc
index 6ac30a9c..bbe25ad0 100644
--- a/test/bvt/sqlsrv/connect.inc
+++ b/test/bvt/sqlsrv/connect.inc
@@ -4,30 +4,16 @@ $databaseName = 'TARGET_DATABASE';
$uid = 'TARGET_USERNAME';
$pwd = 'TARGET_PASSWORD';
-$server2 = 'ANOTHER_SERVER';
-
-// RevisionNumber in SalesOrderHeader is subject to a trigger incrementing it whenever
-// changes are made to SalesOrderDetail. Since RevisionNumber is a tinyint, it can
-// overflow quickly if the BVT tests often run. So we change it directly here first
-// before it can overflow.
-function ResetRevisionNumber( $server, $databaseName, $uid, $pwd )
+function dropTable($conn, $tableName)
{
- $connectionInfo = array( "Database"=>$databaseName, "UID"=>$uid, "PWD"=>$pwd );
- $conn = sqlsrv_connect( $server, $connectionInfo);
- if( $conn === false )
- {
- echo "Could not connect.
";
- die( print_r( sqlsrv_errors(), true));
- }
+ $tsql = "IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'" . $tableName . "') AND type in (N'U')) DROP TABLE [$tableName]";
+ sqlsrv_query($conn, $tsql);
+}
- $stmt0 = sqlsrv_query( $conn, "UPDATE Sales.SalesOrderHeader SET RevisionNumber = 2");
- if ( !$stmt0 )
- {
- echo "Resetting the RevisionNumber failed.\n";
- die( print_r( sqlsrv_errors(), true));
- }
-
- sqlsrv_close( $conn );
+function dropProc($conn, $procName)
+{
+ $tsql = "IF OBJECT_ID('". $procName ."', 'P') IS NOT NULL DROP PROCEDURE [$procName]";
+ sqlsrv_query($conn, $tsql);
}
?>
diff --git a/test/bvt/sqlsrv/msdn_sqlsrv_begin_transaction.phpt b/test/bvt/sqlsrv/msdn_sqlsrv_begin_transaction.phpt
index 399f7a73..d5fcddb1 100644
--- a/test/bvt/sqlsrv/msdn_sqlsrv_begin_transaction.phpt
+++ b/test/bvt/sqlsrv/msdn_sqlsrv_begin_transaction.phpt
@@ -6,9 +6,6 @@ executes two queries as part of a transaction
"$databaseName", "UID"=>$uid, "PWD"=>$pwd);
$conn = sqlsrv_connect( $server, $connectionInfo);
if( $conn === false )
@@ -17,6 +14,9 @@ if( $conn === false )
die( print_r( sqlsrv_errors(), true ));
}
+$tsql = "DISABLE TRIGGER uSalesOrderHeader ON Sales.SalesOrderHeader";
+$stmt = sqlsrv_query($conn, $tsql);
+
/* Initiate transaction. */
/* Exit script if transaction cannot be initiated. */
if ( sqlsrv_begin_transaction( $conn ) === false )
@@ -64,6 +64,9 @@ else
$d_sql = "DELETE FROM Sales.SalesOrderDetail WHERE SalesOrderID=43659 AND OrderQty=5 AND ProductID=709 AND SpecialOfferID=1 AND Unitprice=5.70";
$stmt3 = sqlsrv_query($conn, $d_sql);
+$tsql = "ENABLE TRIGGER uSalesOrderHeader ON Sales.SalesOrderHeader";
+$stmt = sqlsrv_query($conn, $tsql);
+
/* Free statement and connection resources. */
sqlsrv_free_stmt( $stmt1);
sqlsrv_free_stmt( $stmt2);
diff --git a/test/bvt/sqlsrv/msdn_sqlsrv_configure_2.phpt b/test/bvt/sqlsrv/msdn_sqlsrv_configure_2.phpt
index 86cbd3b4..540d2fae 100644
--- a/test/bvt/sqlsrv/msdn_sqlsrv_configure_2.phpt
+++ b/test/bvt/sqlsrv/msdn_sqlsrv_configure_2.phpt
@@ -34,26 +34,15 @@ $r_sql="UPDATE HumanResources.Employee SET VacationHours=61 WHERE BusinessEntity
UPDATE HumanResources.Employee SET VacationHours=62 WHERE BusinessEntityID=8;
UPDATE HumanResources.Employee SET VacationHours=63 WHERE BusinessEntityID=9;
UPDATE HumanResources.Employee SET VacationHours=7 WHERE BusinessEntityID=11";
-$stmt4=sqlsrv_query($conn, $r_sql);
-sqlsrv_free_stmt( $stmt4 );
+$stmt=sqlsrv_query($conn, $r_sql);
+sqlsrv_free_stmt( $stmt );
/* Drop the stored procedure if it already exists. */
-$tsql1 = "IF OBJECT_ID('SubtractVacationHours', 'P') IS NOT NULL
- DROP PROCEDURE SubtractVacationHours";
-$stmt1 = sqlsrv_query($conn, $tsql1);
+dropProc($conn, "SubtractVacationHours");
-/* If the query fails, display errors and exit the script. */
-if( $stmt1 === false)
-{
- DisplayErrors();
- die;
-}
/* Display any warnings. */
DisplayWarnings();
-/* Free the statement resources. */
-sqlsrv_free_stmt( $stmt1 );
-
/* Create the stored procedure. */
$tsql2 = "CREATE PROCEDURE SubtractVacationHours
@BusinessEntityId int,
@@ -69,10 +58,10 @@ $tsql2 = "CREATE PROCEDURE SubtractVacationHours
BEGIN
PRINT 'WARNING: Vacation hours are now less than zero.'
END;";
-$stmt2 = sqlsrv_query( $conn, $tsql2 );
+$stmt = sqlsrv_query( $conn, $tsql2 );
/* If the query fails, display errors and exit the script. */
-if( $stmt2 === false)
+if( $stmt === false)
{
DisplayErrors();
die;
@@ -81,7 +70,7 @@ if( $stmt2 === false)
DisplayWarnings();
/* Free the statement resources. */
-sqlsrv_free_stmt( $stmt2 );
+sqlsrv_free_stmt( $stmt );
/* Set up the array that maps employee ID to used vacation hours. */
$emp_hrs = array (7=>4, 8=>5, 9=>8, 11=>50);
@@ -98,10 +87,10 @@ $params = array(
/* Define and prepare the query to substract used vacation hours. */
$tsql3 = "{call SubtractVacationHours(?, ?)}";
-$stmt3 = sqlsrv_prepare($conn, $tsql3, $params);
+$stmt = sqlsrv_prepare($conn, $tsql3, $params);
/* If the statement preparation fails, display errors and exit the script. */
-if( $stmt3 === false)
+if( $stmt === false)
{
DisplayErrors();
die;
@@ -115,7 +104,7 @@ foreach(array_keys($emp_hrs) as $businessEntityId)
{
$vacationHrs = $emp_hrs[$businessEntityId];
/* Execute the query. If it fails, display the errors. */
- if( sqlsrv_execute($stmt3) === false)
+ if( sqlsrv_execute($stmt) === false)
{
DisplayErrors();
die;
@@ -124,7 +113,7 @@ foreach(array_keys($emp_hrs) as $businessEntityId)
DisplayWarnings();
/*Move to the next result returned by the stored procedure. */
- if( sqlsrv_next_result($stmt3) === false)
+ if( sqlsrv_next_result($stmt) === false)
{
DisplayErrors();
die;
@@ -138,7 +127,9 @@ foreach(array_keys($emp_hrs) as $businessEntityId)
}
/* Free the statement*/
-sqlsrv_free_stmt( $stmt3 );
+sqlsrv_free_stmt( $stmt );
+
+dropProc($conn, "SubtractVacationHours", false);
/* close connection resources. */
sqlsrv_close( $conn );
@@ -169,10 +160,10 @@ function DisplayWarnings()
}
?>
--EXPECTREGEX--
-Warning: \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]\[SQL Server\]Changed database context to 'AdventureWorks201[4|7]'.
+Warning: \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]\[SQL Server\]Changed database context to 'AdventureWorks201.'.
Warning: \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]\[SQL Server\]Changed language setting to us_english.
BusinessEntityId 7 has 57 remaining vacation hours.
BusinessEntityId 8 has 57 remaining vacation hours.
BusinessEntityId 9 has 55 remaining vacation hours.
-Error: \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]\[SQL Server\]The UPDATE statement conflicted with the CHECK constraint "CK_Employee_VacationHours". The conflict occurred in database "AdventureWorks201[4|7]", table "HumanResources.Employee", column 'VacationHours'.
+Error: \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]\[SQL Server\]The UPDATE statement conflicted with the CHECK constraint "CK_Employee_VacationHours". The conflict occurred in database "AdventureWorks201.", table "HumanResources.Employee", column 'VacationHours'.
Error: \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]\[SQL Server\]The statement has been terminated.
\ No newline at end of file
diff --git a/test/bvt/sqlsrv/msdn_sqlsrv_connect_MARS.phpt b/test/bvt/sqlsrv/msdn_sqlsrv_connect_MARS.phpt
index 55d40f4f..e751b7e2 100644
--- a/test/bvt/sqlsrv/msdn_sqlsrv_connect_MARS.phpt
+++ b/test/bvt/sqlsrv/msdn_sqlsrv_connect_MARS.phpt
@@ -5,17 +5,9 @@ disables MARS support.
--FILE--
"$databaseName", "UID"=>"$uid", "PWD"=>"$pwd");
+$connectionInfo = array("Database"=>$databaseName, "UID"=>$uid, "PWD"=>$pwd, 'MultipleActiveResultSets'=> false);
$conn = sqlsrv_connect( $server, $connectionInfo);
-
-/* Connect to the local server using Windows Authentication and
-specify the AdventureWorks database as the database in use. */
-$serverName = $server2;
-$connectionInfo = array( "Database"=>$databaseName, "UID"=>$uid, "PWD"=>$pwd, 'MultipleActiveResultSets'=> false);
-
-$conn = sqlsrv_connect( $serverName, $connectionInfo);
-if( $conn === false )
-{
+if( $conn === false ) {
echo "Could not connect.\n";
die( print_r( sqlsrv_errors(), true));
}
diff --git a/test/bvt/sqlsrv/msdn_sqlsrv_execute_string.phpt b/test/bvt/sqlsrv/msdn_sqlsrv_execute_string.phpt
index ce173e3e..322ab392 100644
--- a/test/bvt/sqlsrv/msdn_sqlsrv_execute_string.phpt
+++ b/test/bvt/sqlsrv/msdn_sqlsrv_execute_string.phpt
@@ -57,17 +57,18 @@ echo "
";
sqlsrv_free_stmt( $stmt);
+// RevisionNumber in SalesOrderHeader is subject to a trigger incrementing it whenever
+// changes are made to SalesOrderDetail. Since RevisonNumber is a tinyint, it can
+// overflow quickly if this test is often run. So disable the trigger.
+$tsql = "DISABLE TRIGGER uSalesOrderHeader ON Sales.SalesOrderHeader";
+$stmt = sqlsrv_query($conn, $tsql);
+
+
/* Prepare with string type in parameter. */
$tsql = "UPDATE Sales.SalesOrderDetail
SET OrderQty=(?)
WHERE CarrierTrackingNumber=(?)";
-// RevisionNumber in SalesOrderHeader is subject to a trigger incrementing it whenever
-// changes are made to SalesOrderDetail. Since RevisonNumber is a tinyint, it can
-// overflow quickly if this test is often run. So we change it directly here first
-// before it can overflow.
-$stmt0 = sqlsrv_query( $conn, "UPDATE Sales.SalesOrderHeader SET RevisionNumber = 2 WHERE SalesOrderID = $soID" );
-
//Pass in parameters directly
$params = array(5, '8650-4A20-B1');
$stmt = sqlsrv_prepare( $conn, $tsql, $params);
@@ -140,11 +141,13 @@ else
die( print_r( sqlsrv_errors(), true));
}
echo sqlsrv_rows_affected( $stmt)." rows affected.
";
-sqlsrv_free_stmt( $stmt);
+// Re-enable the trigger
+$tsql = "ENABLE TRIGGER uSalesOrderHeader ON Sales.SalesOrderHeader";
+$stmt = sqlsrv_query($conn, $tsql);
/* Free the statement and connection resources. */
-//sqlsrv_free_stmt( $stmt);
+sqlsrv_free_stmt( $stmt);
sqlsrv_close( $conn);
?>
--EXPECT--
diff --git a/test/bvt/sqlsrv/msdn_sqlsrv_next_result.phpt b/test/bvt/sqlsrv/msdn_sqlsrv_next_result.phpt
index 92250def..657c3530 100644
--- a/test/bvt/sqlsrv/msdn_sqlsrv_next_result.phpt
+++ b/test/bvt/sqlsrv/msdn_sqlsrv_next_result.phpt
@@ -17,17 +17,10 @@ if( $conn === false )
/*revert inserts from previous tests*/
$d_sql = "DELETE FROM Production.ProductReview WHERE EmailAddress!='john@fourthcoffee.com' AND ProductID=709";
-$stmt4 = sqlsrv_query($conn, $d_sql);
+$stmt = sqlsrv_query($conn, $d_sql);
/* Drop the stored procedure if it already exists. */
-$tsql_dropSP = "IF OBJECT_ID('InsertProductReview', 'P') IS NOT NULL
- DROP PROCEDURE InsertProductReview";
-$stmt1 = sqlsrv_query( $conn, $tsql_dropSP);
-if( $stmt1 === false )
-{
- echo "Error in executing statement 1.\n";
- die( print_r( sqlsrv_errors(), true));
-}
+dropProc($conn, 'InsertProductReview');
/* Create the stored procedure. */
$tsql_createSP = " CREATE PROCEDURE InsertProductReview
@@ -56,9 +49,9 @@ $tsql_createSP = " CREATE PROCEDURE InsertProductReview
SELECT * FROM Production.ProductReview
WHERE ProductID = @ProductID;
END";
-$stmt2 = sqlsrv_query( $conn, $tsql_createSP);
+$stmt = sqlsrv_query( $conn, $tsql_createSP);
-if( $stmt2 === false)
+if( $stmt === false)
{
echo "Error in executing statement 2.\n";
die( print_r( sqlsrv_errors(), true));
@@ -86,8 +79,8 @@ $params = array(
);
/* Execute the query. */
-$stmt3 = sqlsrv_query( $conn, $tsql_callSP, $params);
-if( $stmt3 === false)
+$stmt = sqlsrv_query( $conn, $tsql_callSP, $params);
+if( $stmt === false)
{
echo "Error in executing statement 3.\n";
die( print_r( sqlsrv_errors(), true));
@@ -97,17 +90,17 @@ echo "
"; /* Consume the first result (rows affected by INSERT query in the stored procedure) without calling sqlsrv_next_result. */ -echo "Rows affectd: ".sqlsrv_rows_affected($stmt3)."-----\n"; +echo "Rows affectd: ".sqlsrv_rows_affected($stmt)."-----\n"; echo "
"; /* Move to the next result and display results. */ -$next_result = sqlsrv_next_result($stmt3); +$next_result = sqlsrv_next_result($stmt); if( $next_result ) { echo "
";
echo "\nReview information for product ID ".$productID.".---\n";
- while( $row = sqlsrv_fetch_array( $stmt3, SQLSRV_FETCH_ASSOC))
+ while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC))
{
echo "
ReviewerName: ".$row['ReviewerName']."\n";
echo "
ReviewDate: ".date_format($row['ReviewDate'],
@@ -127,13 +120,10 @@ else
die(print_r(sqlsrv_errors(), true));
}
+dropProc($conn, 'InsertProductReview', false);
+
/* Free statement and connection resources. */
-sqlsrv_free_stmt( $stmt1 );
-sqlsrv_free_stmt( $stmt2 );
-sqlsrv_free_stmt( $stmt3 );
-sqlsrv_free_stmt( $stmt4 );
-
-
+sqlsrv_free_stmt( $stmt );
sqlsrv_close( $conn );
?>
--EXPECT--
diff --git a/test/bvt/sqlsrv/msdn_sqlsrv_query.phpt b/test/bvt/sqlsrv/msdn_sqlsrv_query.phpt
index f3f45f59..62a16627 100644
--- a/test/bvt/sqlsrv/msdn_sqlsrv_query.phpt
+++ b/test/bvt/sqlsrv/msdn_sqlsrv_query.phpt
@@ -15,6 +15,12 @@ if( $conn === false )
die( print_r( sqlsrv_errors(), true));
}
+// RevisionNumber in SalesOrderHeader is subject to a trigger incrementing it whenever
+// changes are made to SalesOrderDetail. Since RevisonNumber is a tinyint, it can
+// overflow quickly if this test is often run. So disable the trigger.
+$tsql = "DISABLE TRIGGER uSalesOrderHeader ON Sales.SalesOrderHeader";
+$stmt = sqlsrv_query($conn, $tsql);
+
/* Set up the parameterized query. */
$tsql = "INSERT INTO Sales.SalesOrderDetail
(SalesOrderID,
@@ -29,12 +35,6 @@ $tsql = "INSERT INTO Sales.SalesOrderDetail
/* Set parameter values. */
$params = array(75123, 5, 741, 1, 818.70, 0.00);
-// RevisionNumber in SalesOrderHeader is subject to a trigger incrementing it whenever
-// changes are made to SalesOrderDetail. Since RevisonNumber is a tinyint, it can
-// overflow quickly if this test is often run. So we change it directly here first
-// before it can overflow.
-$stmt0 = sqlsrv_query( $conn, "UPDATE Sales.SalesOrderHeader SET RevisionNumber = 2 WHERE SalesOrderID = $params[0]");
-
/* Prepare and execute the query. */
$stmt = sqlsrv_query( $conn, $tsql, $params);
if( $stmt )
@@ -47,6 +47,10 @@ else
die( print_r( sqlsrv_errors(), true));
}
+// Re-enable the trigger
+$tsql = "ENABLE TRIGGER uSalesOrderHeader ON Sales.SalesOrderHeader";
+$stmt = sqlsrv_query($conn, $tsql);
+
/* Free statement and connection resources. */
sqlsrv_free_stmt( $stmt);
sqlsrv_close( $conn);
diff --git a/test/bvt/sqlsrv/msdn_sqlsrv_query_param_inout.phpt b/test/bvt/sqlsrv/msdn_sqlsrv_query_param_inout.phpt
index 227780d0..f0e8e7e7 100644
--- a/test/bvt/sqlsrv/msdn_sqlsrv_query_param_inout.phpt
+++ b/test/bvt/sqlsrv/msdn_sqlsrv_query_param_inout.phpt
@@ -13,14 +13,7 @@ if( $conn === false )
die( print_r( sqlsrv_errors(), true));
}
/* Drop the stored procedure if it already exists. */
-$tsql_dropSP = "IF OBJECT_ID('SubtractVacationHours', 'P') IS NOT NULL
- DROP PROCEDURE SubtractVacationHours";
-$stmt1 = sqlsrv_query( $conn, $tsql_dropSP);
-if( $stmt1 === false )
-{
- echo "Error in executing statement 1.\n";
- die( print_r( sqlsrv_errors(), true));
-}
+dropProc($conn, 'SubtractVacationHours');
/* Create the stored procedure. */
$tsql_createSP = "CREATE PROCEDURE SubtractVacationHours
@@ -34,8 +27,8 @@ $tsql_createSP = "CREATE PROCEDURE SubtractVacationHours
FROM HumanResources.Employee
WHERE BusinessEntityID = @BusinessEntityID)";
-$stmt2 = sqlsrv_query( $conn, $tsql_createSP);
-if( $stmt2 === false )
+$stmt = sqlsrv_query( $conn, $tsql_createSP);
+if( $stmt === false )
{
echo "Error in executing statement 2.\n";
die( print_r( sqlsrv_errors(), true));
@@ -62,26 +55,25 @@ $params = array(
);
/* Execute the query. */
-$stmt3 = sqlsrv_query( $conn, $tsql_callSP, $params);
-if( $stmt3 === false )
+$stmt = sqlsrv_query( $conn, $tsql_callSP, $params);
+if( $stmt === false )
{
echo "Error in executing statement 3.\n";
die( print_r( sqlsrv_errors(), true));
}
/* Display the value of the output parameter $vacationHrs. */
-sqlsrv_next_result($stmt3);
+sqlsrv_next_result($stmt);
echo "Remaining vacation hours: ".$vacationHrs;
/* Revert the update in vacation hours */
$r_sql = "UPDATE HumanResources.Employee SET VacationHours=48 WHERE BusinessEntityID=4";
-$stmt4 = sqlsrv_query($conn, $r_sql);
+$stmt = sqlsrv_query($conn, $r_sql);
+
+dropProc($conn, 'SubtractVacationHours', false);
/*Free the statement and connection resources. */
-sqlsrv_free_stmt( $stmt1);
-sqlsrv_free_stmt( $stmt2);
-sqlsrv_free_stmt( $stmt3);
-sqlsrv_free_stmt( $stmt4);
+sqlsrv_free_stmt( $stmt);
sqlsrv_close( $conn);
?>
--EXPECT--
diff --git a/test/bvt/sqlsrv/msdn_sqlsrv_query_param_out.phpt b/test/bvt/sqlsrv/msdn_sqlsrv_query_param_out.phpt
index 3c8696b8..0b1e9dd7 100644
--- a/test/bvt/sqlsrv/msdn_sqlsrv_query_param_out.phpt
+++ b/test/bvt/sqlsrv/msdn_sqlsrv_query_param_out.phpt
@@ -16,14 +16,7 @@ if( $conn === false )
}
/* Drop the stored procedure if it already exists. */
-$tsql_dropSP = "IF OBJECT_ID('GetEmployeeSalesYTD', 'P') IS NOT NULL
- DROP PROCEDURE GetEmployeeSalesYTD";
-$stmt1 = sqlsrv_query( $conn, $tsql_dropSP);
-if( $stmt1 === false )
-{
- echo "Error in executing statement 1.\n";
- die( print_r( sqlsrv_errors(), true));
-}
+dropProc($conn, 'GetEmployeeSalesYTD');
/* Create the stored procedure. */
$tsql_createSP = " CREATE PROCEDURE GetEmployeeSalesYTD
@@ -35,8 +28,8 @@ $tsql_createSP = " CREATE PROCEDURE GetEmployeeSalesYTD
JOIN HumanResources.vEmployee AS e
ON e.BusinessEntityID = sp.BusinessEntityID
WHERE LastName = @SalesPerson";
-$stmt2 = sqlsrv_query( $conn, $tsql_createSP);
-if( $stmt2 === false )
+$stmt = sqlsrv_query( $conn, $tsql_createSP);
+if( $stmt === false )
{
echo "Error in executing statement 2.\n";
die( print_r( sqlsrv_errors(), true));
@@ -62,8 +55,8 @@ $params = array(
);
/* Execute the query. */
-$stmt3 = sqlsrv_query( $conn, $tsql_callSP, $params);
-if( $stmt3 === false )
+$stmt = sqlsrv_query( $conn, $tsql_callSP, $params);
+if( $stmt === false )
{
echo "Error in executing statement 3.\n";
die( print_r( sqlsrv_errors(), true));
@@ -72,10 +65,10 @@ if( $stmt3 === false )
/* Display the value of the output parameter $salesYTD. */
echo "YTD sales for ".$lastName." are ". $salesYTD. ".";
+dropProc($conn, 'GetEmployeeSalesYTD', false);
+
/*Free the statement and connection resources. */
-sqlsrv_free_stmt( $stmt1);
-sqlsrv_free_stmt( $stmt2);
-sqlsrv_free_stmt( $stmt3);
+sqlsrv_free_stmt( $stmt);
sqlsrv_close( $conn);
?>
--EXPECT--
diff --git a/test/bvt/sqlsrv/msdn_sqlsrv_query_scrollable.phpt b/test/bvt/sqlsrv/msdn_sqlsrv_query_scrollable.phpt
index f4649d3f..6d86a942 100644
--- a/test/bvt/sqlsrv/msdn_sqlsrv_query_scrollable.phpt
+++ b/test/bvt/sqlsrv/msdn_sqlsrv_query_scrollable.phpt
@@ -11,34 +11,32 @@ if ( $conn === false ) {
die( print_r( sqlsrv_errors(), true ));
}
-$stmt = sqlsrv_query( $conn, "DROP TABLE dbo.ScrollTest" );
-if ( $stmt !== false ) {
- sqlsrv_free_stmt( $stmt );
-}
+$tableName = 'ScrollTest';
+dropTable($conn, $tableName);
-$stmt = sqlsrv_query( $conn, "CREATE TABLE ScrollTest (id int, value char(10))" );
+$stmt = sqlsrv_query( $conn, "CREATE TABLE $tableName (id int, value char(10))" );
if ( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
-$stmt = sqlsrv_query( $conn, "INSERT INTO ScrollTest (id, value) VALUES(?,?)", array( 1, "Row 1" ));
+$stmt = sqlsrv_query( $conn, "INSERT INTO $tableName (id, value) VALUES(?,?)", array( 1, "Row 1" ));
if ( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
-$stmt = sqlsrv_query( $conn, "INSERT INTO ScrollTest (id, value) VALUES(?,?)", array( 2, "Row 2" ));
+$stmt = sqlsrv_query( $conn, "INSERT INTO $tableName (id, value) VALUES(?,?)", array( 2, "Row 2" ));
if ( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
-$stmt = sqlsrv_query( $conn, "INSERT INTO ScrollTest (id, value) VALUES(?,?)", array( 3, "Row 3" ));
+$stmt = sqlsrv_query( $conn, "INSERT INTO $tableName (id, value) VALUES(?,?)", array( 3, "Row 3" ));
if ( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
-$stmt = sqlsrv_query( $conn, "SELECT * FROM ScrollTest", array(), array( "Scrollable" => 'keyset' ));
-// $stmt = sqlsrv_query( $conn, "SELECT * FROM ScrollTest", array(), array( "Scrollable" => 'dynamic' ));
-// $stmt = sqlsrv_query( $conn, "SELECT * FROM ScrollTest", array(), array( "Scrollable" => 'static' ));
+$stmt = sqlsrv_query( $conn, "SELECT * FROM $tableName", array(), array( "Scrollable" => 'keyset' ));
+// $stmt = sqlsrv_query( $conn, "SELECT * FROM $tableName", array(), array( "Scrollable" => 'dynamic' ));
+// $stmt = sqlsrv_query( $conn, "SELECT * FROM $tableName", array(), array( "Scrollable" => 'static' ));
$rows = sqlsrv_has_rows( $stmt );
if ( $rows != true ) {
@@ -50,9 +48,9 @@ $field1 = sqlsrv_get_field( $stmt, 0 );
$field2 = sqlsrv_get_field( $stmt, 1 );
echo "\n$field1 $field2\n";
-//$stmt2 = sqlsrv_query( $conn, "delete from ScrollTest where id = 3" );
+//$stmt2 = sqlsrv_query( $conn, "delete from $tableName where id = 3" );
// or
-$stmt2 = sqlsrv_query( $conn, "UPDATE ScrollTest SET id = 4 WHERE id = 3" );
+$stmt2 = sqlsrv_query( $conn, "UPDATE $tableName SET id = 4 WHERE id = 3" );
if ( $stmt2 !== false ) {
sqlsrv_free_stmt( $stmt2 );
}
@@ -62,6 +60,8 @@ $field1 = sqlsrv_get_field( $stmt, 0 );
$field2 = sqlsrv_get_field( $stmt, 1 );
echo "\n$field1 $field2\n";
+dropTable($conn, $tableName, false);
+
sqlsrv_free_stmt( $stmt );
sqlsrv_close( $conn );
?>
diff --git a/test/bvt/sqlsrv/msdn_sqlsrv_server_info.phpt b/test/bvt/sqlsrv/msdn_sqlsrv_server_info.phpt
index b941d1e3..00624650 100644
--- a/test/bvt/sqlsrv/msdn_sqlsrv_server_info.phpt
+++ b/test/bvt/sqlsrv/msdn_sqlsrv_server_info.phpt
@@ -32,4 +32,4 @@ else
sqlsrv_close( $conn);
?>
--EXPECTREGEX--
-CurrentDatabase: AdventureWorks.*
SQLServerVersion: 1[2-9].00.[0-9]{4}
SQLServerName: SQL.+
\ No newline at end of file
+CurrentDatabase: AdventureWorks201.
SQLServerVersion: 1[2-9].00.[0-9]{4}
SQLServerName: .+
\ No newline at end of file
diff --git a/test/bvt/sqlsrv/sqlsrv_param_inout.phpt b/test/bvt/sqlsrv/sqlsrv_param_inout.phpt
index 5bc3e2a5..7e97a6d0 100644
--- a/test/bvt/sqlsrv/sqlsrv_param_inout.phpt
+++ b/test/bvt/sqlsrv/sqlsrv_param_inout.phpt
@@ -15,14 +15,8 @@ call a stored procedure (SQLSRV Driver) and retrieve the errorNumber that is ret
}
// Drop the stored procedure if it already exists
- $tsql_dropSP = "IF OBJECT_ID('sp_Test', 'P') IS NOT NULL
- DROP PROCEDURE sp_Test";
- $stmt1 = sqlsrv_query($conn, $tsql_dropSP);
- if ($stmt1 === false) {
- echo "Error in executing statement 1.\n";
- die (print_r (sqlsrv_errors(), true));
- }
-
+ dropProc($conn, "sp_Test");
+
// Create the stored procedure
$tsql_createSP = "CREATE PROCEDURE sp_Test
@ErrorNumber INT = 0 OUTPUT
@@ -31,8 +25,8 @@ call a stored procedure (SQLSRV Driver) and retrieve the errorNumber that is ret
SET @ErrorNumber = -1
SELECT 1,2,3
END";
- $stmt2 = sqlsrv_query($conn, $tsql_createSP);
- if ($stmt2 === false) {
+ $stmt = sqlsrv_query($conn, $tsql_createSP);
+ if ($stmt === false) {
echo "Error in executing statement 2.\n";
die (print_r (sqlsrv_errors(), true));
}
@@ -47,20 +41,20 @@ call a stored procedure (SQLSRV Driver) and retrieve the errorNumber that is ret
);
// Execute the query
- $stmt3 = sqlsrv_query($conn, $tsql_callSP, $params);
- if ($stmt3 === false) {
+ $stmt = sqlsrv_query($conn, $tsql_callSP, $params);
+ if ($stmt === false) {
echo "Error in executing statement 3.\n";
die (print_r (sqlsrv_errors(), true));
}
// Display the value of the output parameter $errorNumber
- sqlsrv_next_result($stmt3);
+ sqlsrv_next_result($stmt);
print("Error Number: $errorNumber\n\n");
-
+
+ dropProc($conn, "sp_Test", false);
+
// Free the statement and connection resources. */
- sqlsrv_free_stmt( $stmt1);
- sqlsrv_free_stmt( $stmt2);
- sqlsrv_free_stmt( $stmt3);
+ sqlsrv_free_stmt( $stmt);
sqlsrv_close( $conn);
?>
--EXPECT--