Updated BVT tests to test against only one database (#1273)
This commit is contained in:
parent
d255591633
commit
66b7ced5f9
|
@ -1,60 +0,0 @@
|
||||||
<?php
|
|
||||||
function RestartConn($server)
|
|
||||||
{
|
|
||||||
$powershell = "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe";
|
|
||||||
$restart_string = "$powershell (get-service -ComputerName $server -Name mssqlserver).Stop()";
|
|
||||||
exec( $restart_string );
|
|
||||||
$servstring = shell_exec("$powershell get-service -ComputerName $server -Name mssqlserver");
|
|
||||||
|
|
||||||
// Wait until the service is fully stopped
|
|
||||||
while (substr_count($servstring, "Stopped") != 1)
|
|
||||||
{
|
|
||||||
sleep(1);
|
|
||||||
$servstring = shell_exec("$powershell get-service -ComputerName $server -Name mssqlserver");
|
|
||||||
}
|
|
||||||
$restart_string = "$powershell (get-service -ComputerName $server -Name mssqlserver).Start()";
|
|
||||||
exec( $restart_string );
|
|
||||||
$servstring = shell_exec("$powershell get-service -ComputerName $server -Name mssqlserver");
|
|
||||||
|
|
||||||
// Wait until the service is fully started
|
|
||||||
while (substr_count($servstring, "Running") != 1)
|
|
||||||
{
|
|
||||||
sleep(1);
|
|
||||||
$servstring = shell_exec("$powershell get-service -ComputerName $server -Name mssqlserver");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function StopConn($server)
|
|
||||||
{
|
|
||||||
$powershell = "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe";
|
|
||||||
$restart_string = "$powershell (get-service -ComputerName $server -Name mssqlserver).Stop()";
|
|
||||||
exec( $restart_string );
|
|
||||||
$servstring = shell_exec("$powershell get-service -ComputerName $server -Name mssqlserver");
|
|
||||||
|
|
||||||
// Wait until the service is fully stopped
|
|
||||||
while (substr_count($servstring, "Stopped") != 1)
|
|
||||||
{
|
|
||||||
sleep(1);
|
|
||||||
$servstring = shell_exec("$powershell get-service -ComputerName $server -Name mssqlserver");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function StartConn($server)
|
|
||||||
{
|
|
||||||
$powershell = "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe";
|
|
||||||
$servstring = shell_exec("$powershell get-service -ComputerName $server -Name mssqlserver");
|
|
||||||
if (substr_count($servstring, "Running") != 1)
|
|
||||||
{
|
|
||||||
$restart_string = "$powershell (get-service -ComputerName $server -Name mssqlserver).Start()";
|
|
||||||
exec( $restart_string );
|
|
||||||
}
|
|
||||||
$servstring = shell_exec("$powershell get-service -ComputerName $server -Name mssqlserver");
|
|
||||||
|
|
||||||
// Wait until the service is fully started
|
|
||||||
while (substr_count($servstring, "Running") != 1)
|
|
||||||
{
|
|
||||||
sleep(1);
|
|
||||||
$servstring = shell_exec("$powershell get-service -ComputerName $server -Name mssqlserver");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
|
@ -1,82 +0,0 @@
|
||||||
<?php
|
|
||||||
require_once("ConInfo.inc");
|
|
||||||
|
|
||||||
// Using the tempdb database for two tables specifically constructed
|
|
||||||
// for the connection resiliency tests
|
|
||||||
$dbName = "tempdb";
|
|
||||||
|
|
||||||
$tableName1 = "test_connres1";
|
|
||||||
$tableName2 = "test_connres2";
|
|
||||||
|
|
||||||
// Generate tables for use with the connection resiliency tests.
|
|
||||||
// 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 )
|
|
||||||
{
|
|
||||||
$conn = new PDO( "sqlsrv:server = $server ; Database = $dbName ;", $uid, $pwd );
|
|
||||||
if ( $conn === false )
|
|
||||||
{
|
|
||||||
die ( print_r( sqlsrv_errors() ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create table
|
|
||||||
$sql = "CREATE TABLE $tableName1 ( c1 INT, c2 VARCHAR(40) )";
|
|
||||||
$stmt = $conn->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 );
|
|
||||||
|
|
||||||
?>
|
|
|
@ -3,6 +3,19 @@ $server = 'TARGET_SERVER';
|
||||||
$databaseName = 'TARGET_DATABASE';
|
$databaseName = 'TARGET_DATABASE';
|
||||||
$uid = 'TARGET_USERNAME';
|
$uid = 'TARGET_USERNAME';
|
||||||
$pwd = 'TARGET_PASSWORD';
|
$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);
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -7,17 +7,19 @@ uses an input/output parameter
|
||||||
require('connect.inc');
|
require('connect.inc');
|
||||||
$dbh = new PDO( "sqlsrv:server=$server ; Database = $databaseName", "$uid", "$pwd");
|
$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");
|
dropProc($dbh, 'sp_ReverseString');
|
||||||
$dbh->query("CREATE PROCEDURE dbo.sp_ReverseString @String as VARCHAR(2048) OUTPUT as SELECT @String = REVERSE(@String)");
|
$dbh->query("CREATE PROCEDURE sp_ReverseString @String as VARCHAR(2048) OUTPUT as SELECT @String = REVERSE(@String)");
|
||||||
$stmt = $dbh->prepare("EXEC dbo.sp_ReverseString ?");
|
$stmt = $dbh->prepare("EXEC sp_ReverseString ?");
|
||||||
$string = "123456789";
|
$string = "123456789";
|
||||||
$stmt->bindParam(1, $string, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT, 2048);
|
$stmt->bindParam(1, $string, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT, 2048);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
print "Result: ".$string; // Expect 987654321
|
print "Result: ".$string; // Expect 987654321
|
||||||
|
|
||||||
|
dropProc($dbh, 'sp_ReverseString', false);
|
||||||
|
|
||||||
//free the statement and connection
|
//free the statement and connection
|
||||||
$stmt = null;
|
unset($stmt);
|
||||||
$dbh = null;
|
unset($dbh);
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
Result: 987654321
|
Result: 987654321
|
|
@ -5,30 +5,33 @@ returns the number of rows added to a table; returns the number of rows in a res
|
||||||
--FILE--
|
--FILE--
|
||||||
<?php
|
<?php
|
||||||
require('connect.inc');
|
require('connect.inc');
|
||||||
$conn = new PDO( "sqlsrv:server=$server ; Database = tempdb", "$uid", "$pwd");
|
$conn = new PDO("sqlsrv:Server=$server; Database = $databaseName", $uid, $pwd);
|
||||||
$conn->exec("CREAtE TABLE Table1(col1 VARCHAR(15), col2 VARCHAR(15)) ");
|
|
||||||
|
$tableName = "pdoRowCount";
|
||||||
|
dropTable($conn, $tableName);
|
||||||
|
$conn->exec("CREATE TABLE $tableName(col1 VARCHAR(15), col2 VARCHAR(15)) ");
|
||||||
|
|
||||||
$col1 = 'a';
|
$col1 = 'a';
|
||||||
$col2 = 'b';
|
$col2 = 'b';
|
||||||
|
|
||||||
$query = "insert into Table1(col1, col2) values(?, ?)";
|
$query = "INSERT INTO $tableName(col1, col2) values(?, ?)";
|
||||||
$stmt = $conn->prepare( $query );
|
$stmt = $conn->prepare( $query );
|
||||||
$stmt->execute( array( $col1, $col2 ) );
|
$stmt->execute( array( $col1, $col2 ) );
|
||||||
print $stmt->rowCount();
|
print $stmt->rowCount();
|
||||||
print " rows affects.";
|
print " rows affected.";
|
||||||
|
|
||||||
echo "\n\n";
|
echo "\n\n";
|
||||||
|
|
||||||
//revert the insert
|
//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 = 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 = $conn->prepare( $query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL));
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
print $stmt->rowCount();
|
print $stmt->rowCount();
|
||||||
|
@ -40,6 +43,6 @@ $stmt = null;
|
||||||
$conn = null;
|
$conn = null;
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
1 rows affects.
|
1 rows affected.
|
||||||
|
|
||||||
20 rows in result set.
|
20 rows in result set.
|
|
@ -4,27 +4,30 @@ starts a transaction, insert 2 rows and commit the transaction
|
||||||
<?php require('skipif.inc'); ?>
|
<?php require('skipif.inc'); ?>
|
||||||
--FILE--
|
--FILE--
|
||||||
<?php
|
<?php
|
||||||
require('connect.inc');
|
require('connect.inc');
|
||||||
//make connection and create a temporaty table in tempdb
|
|
||||||
$conn = new PDO( "sqlsrv:Server=$server; Database = tempdb ", "$uid", "$pwd");
|
|
||||||
$conn->exec("CREAtE TABLE Table1(col1 CHARACTER(1), col2 CHARACTER(1)) ");
|
|
||||||
|
|
||||||
$conn->beginTransaction();
|
//make connection and create a temporaty table
|
||||||
$ret = $conn->exec("insert into Table1(col1, col2) values('a', 'b') ");
|
$conn = new PDO( "sqlsrv:Server=$server; Database = $databaseName ", "$uid", "$pwd");
|
||||||
$ret = $conn->exec("insert into Table1(col1, col2) values('a', 'c') ");
|
$tableName = "pdoBeginTransaction";
|
||||||
|
dropTable($conn, $tableName);
|
||||||
|
|
||||||
//revert the inserts
|
$conn->exec("CREATE TABLE $tableName(col1 CHARACTER(1), col2 CHARACTER(1)) ");
|
||||||
$ret = $conn->exec("delete from Table1 where col1 = 'a'");
|
|
||||||
$conn->commit();
|
|
||||||
// $conn->rollback();
|
|
||||||
echo $ret." rows affected";
|
|
||||||
|
|
||||||
//drop the created temp table
|
$conn->beginTransaction();
|
||||||
$conn->exec("DROP TABLE Table1 ");
|
$ret = $conn->exec("insert into $tableName(col1, col2) values('a', 'b') ");
|
||||||
|
$ret = $conn->exec("insert into $tableName(col1, col2) values('a', 'c') ");
|
||||||
|
|
||||||
//free statement and connection
|
//revert the inserts
|
||||||
$ret=NULL;
|
$ret = $conn->exec("delete from $tableName where col1 = 'a'");
|
||||||
$conn=NULL;
|
$conn->commit();
|
||||||
|
|
||||||
|
// $conn->rollback();
|
||||||
|
echo $ret." rows affected";
|
||||||
|
|
||||||
|
//drop the created temp table
|
||||||
|
dropTable($conn, $tableName, false);
|
||||||
|
|
||||||
|
unset($conn);
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
2 rows affected
|
2 rows affected
|
|
@ -5,9 +5,8 @@ connect to a server, specifying the database later
|
||||||
--FILE--
|
--FILE--
|
||||||
<?php
|
<?php
|
||||||
require('connect.inc');
|
require('connect.inc');
|
||||||
$c = new PDO( "sqlsrv:Server=$server", "$uid", "$pwd");
|
$c = new PDO("sqlsrv:Server=$server; Database = $databaseName", $uid, $pwd);
|
||||||
|
|
||||||
$c->exec( "USE $databaseName");
|
|
||||||
$query = 'SELECT * FROM Person.ContactType';
|
$query = 'SELECT * FROM Person.ContactType';
|
||||||
$stmt = $c->query( $query );
|
$stmt = $c->query( $query );
|
||||||
while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ){
|
while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ){
|
||||||
|
|
|
@ -4,21 +4,22 @@ execute a delete and reports how many rows were deleted
|
||||||
<?php require('skipif.inc'); ?>
|
<?php require('skipif.inc'); ?>
|
||||||
--FILE--
|
--FILE--
|
||||||
<?php
|
<?php
|
||||||
require('connect.inc');
|
require('connect.inc');
|
||||||
$c = new PDO( "sqlsrv:Server=$server", "$uid", "$pwd");
|
$c = new PDO("sqlsrv:server=$server; Database = $databaseName", $uid, $pwd);
|
||||||
|
|
||||||
$c->exec("use tempdb");
|
$tableName = "pdoExec";
|
||||||
$c->exec("CREAtE TABLE Table1(col1 VARCHAR(100), col2 VARCHAR(100)) ");
|
dropTable($c, $tableName);
|
||||||
|
|
||||||
$ret = $c->exec("insert into Table1 values('xxxyy', 'yyxx')");
|
$c->exec("CREATE TABLE $tableName(col1 VARCHAR(100), col2 VARCHAR(100)) ");
|
||||||
$ret = $c->exec("delete from Table1 where col1 = 'xxxyy'");
|
|
||||||
echo $ret," rows affected";
|
|
||||||
|
|
||||||
$c->exec("DROP TABLE Table1 ");
|
$ret = $c->exec("INSERT INTO $tableName VALUES('xxxyy', 'yyxx')");
|
||||||
|
$ret = $c->exec("DELETE FROM $tableName WHERE col1 = 'xxxyy'");
|
||||||
|
echo $ret," rows affected";
|
||||||
|
|
||||||
//free the statement and connection
|
dropTable($c, $tableName, false);
|
||||||
$ret=null;
|
|
||||||
$c=null;
|
//free the statement and connection
|
||||||
|
unset($c);
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
1 rows affected
|
1 rows affected
|
|
@ -5,31 +5,34 @@ prepares a statement with parameter markers and forward-only (server-side) curso
|
||||||
--FILE--
|
--FILE--
|
||||||
<?php
|
<?php
|
||||||
require('connect.inc');
|
require('connect.inc');
|
||||||
$conn = new PDO( "sqlsrv:server=$server ; Database = tempdb", "$uid", "$pwd");
|
$conn = new PDO("sqlsrv:Server=$server; Database = $databaseName", $uid, $pwd);
|
||||||
|
|
||||||
$conn->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';
|
$col1 = 'a';
|
||||||
$col2 = 'b';
|
$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 = $conn->prepare( $query, array( PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY, PDO::SQLSRV_ATTR_QUERY_TIMEOUT => 1 ) );
|
||||||
$stmt->execute( array( $col1, $col2 ) );
|
$stmt->execute( array( $col1, $col2 ) );
|
||||||
print $stmt->rowCount();
|
print $stmt->rowCount();
|
||||||
echo " row affected\n";
|
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 = $conn->prepare( $query, array( PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY, PDO::SQLSRV_ATTR_QUERY_TIMEOUT => 1 ) );
|
||||||
$stmt->execute( array( ':col1' => $col1, ':col2' => $col2 ) );
|
$stmt->execute( array( ':col1' => $col1, ':col2' => $col2 ) );
|
||||||
print $stmt->rowCount();
|
print $stmt->rowCount();
|
||||||
echo " row affected\n";
|
echo " row affected\n";
|
||||||
|
|
||||||
// revert the inserts
|
// 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 ");
|
unset($stmt);
|
||||||
$stmt = null;
|
unset($conn);
|
||||||
$conn = null;
|
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
1 row affected
|
1 row affected
|
||||||
|
|
|
@ -6,36 +6,40 @@ insert with quoted parameters
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
require('connect.inc');
|
require('connect.inc');
|
||||||
$conn = new PDO( "sqlsrv:server=$server ; Database = tempdb", "$uid", "$pwd");
|
$conn = new PDO("sqlsrv:Server=$server; Database = $databaseName", $uid, $pwd);
|
||||||
$conn->exec("CREAtE TABLE Table1(col1 VARCHAR(15), col2 VARCHAR(15)) ");
|
|
||||||
|
$tableName = "pdoQuote";
|
||||||
|
dropTable($conn, $tableName);
|
||||||
|
|
||||||
|
$conn->exec("CREATE TABLE $tableName(col1 VARCHAR(15), col2 VARCHAR(15)) ");
|
||||||
|
|
||||||
$param = 'a \' g';
|
$param = 'a \' g';
|
||||||
$param2 = $conn->quote( $param );
|
$param2 = $conn->quote( $param );
|
||||||
|
|
||||||
$query = "INSERT INTO Table1 VALUES( ?, '1' )";
|
$query = "INSERT INTO $tableName VALUES( ?, '1' )";
|
||||||
$stmt = $conn->prepare( $query );
|
$stmt = $conn->prepare( $query );
|
||||||
$stmt->execute(array($param));
|
$stmt->execute(array($param));
|
||||||
|
|
||||||
$query = "INSERT INTO Table1 VALUES( ?, ? )";
|
$query = "INSERT INTO $tableName VALUES( ?, ? )";
|
||||||
$stmt = $conn->prepare( $query );
|
$stmt = $conn->prepare( $query );
|
||||||
$stmt->execute(array($param, $param2));
|
$stmt->execute(array($param, $param2));
|
||||||
|
|
||||||
$query = "SELECT * FROM Table1";
|
$query = "SELECT * FROM $tableName";
|
||||||
$stmt = $conn->query($query);
|
$stmt = $conn->query($query);
|
||||||
while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ){
|
while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ){
|
||||||
print_r( $row['col1'] ." was inserted\n" );
|
print_r( $row['col1'] ." was inserted\n" );
|
||||||
}
|
}
|
||||||
|
|
||||||
// revert the inserts
|
// revert the inserts
|
||||||
$query = "delete from Table1 where col1 = ?";
|
$query = "DELETE FROM $tableName WHERE col1 = ?";
|
||||||
$stmt = $conn->prepare( $query );
|
$stmt = $conn->prepare( $query );
|
||||||
$stmt->execute(array($param));
|
$stmt->execute(array($param));
|
||||||
|
|
||||||
$conn->exec("DROP TABLE Table1 ");
|
dropTable($conn, $tableName, false);
|
||||||
|
|
||||||
//free the statement and connection
|
//free the statement and connection
|
||||||
$stmt=null;
|
unset($stmt);
|
||||||
$conn=null;
|
unset($conn);
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
a ' g was inserted
|
a ' g was inserted
|
||||||
|
|
|
@ -5,25 +5,22 @@ sets to PDO::SQLSRV_ATTR_DIRECT_QUERY
|
||||||
--FILE--
|
--FILE--
|
||||||
<?php
|
<?php
|
||||||
require('connect.inc');
|
require('connect.inc');
|
||||||
$conn = new PDO("sqlsrv:Server=$server", "$uid", "$pwd");
|
$conn = new PDO("sqlsrv:Server=$server; Database = $databaseName", $uid, $pwd);
|
||||||
$conn->setAttribute(constant('PDO::SQLSRV_ATTR_DIRECT_QUERY'), true);
|
$conn->setAttribute(PDO::SQLSRV_ATTR_DIRECT_QUERY, true);
|
||||||
|
|
||||||
$tableName = 'pdo_direct_query';
|
$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";
|
$conn->query("CREATE TABLE $tableName ([c1_int] int, [c2_int] int)");
|
||||||
|
|
||||||
$stmt1 = $conn->query($tsql);
|
|
||||||
$stmt2 = $conn->query("CREATE TABLE $tableName ([c1_int] int, [c2_int] int)");
|
|
||||||
|
|
||||||
$v1 = 1;
|
$v1 = 1;
|
||||||
$v2 = 2;
|
$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) {
|
if ($stmt) {
|
||||||
$stmt3->bindValue(1, $v1);
|
$stmt->bindValue(1, $v1);
|
||||||
$stmt3->bindValue(2, $v2);
|
$stmt->bindValue(2, $v2);
|
||||||
|
|
||||||
if ($stmt3->execute()) {
|
if ($stmt->execute()) {
|
||||||
echo "Execution succeeded\n";
|
echo "Execution succeeded\n";
|
||||||
} else {
|
} else {
|
||||||
echo "Execution failed\n";
|
echo "Execution failed\n";
|
||||||
|
@ -32,13 +29,10 @@ sets to PDO::SQLSRV_ATTR_DIRECT_QUERY
|
||||||
var_dump($conn->errorInfo());
|
var_dump($conn->errorInfo());
|
||||||
}
|
}
|
||||||
|
|
||||||
$stmt4 = $conn->query("DROP TABLE $tableName");
|
$stmt = $conn->query("DROP TABLE $tableName");
|
||||||
|
|
||||||
// free the statements and connection
|
// free the statements and connection
|
||||||
unset($stmt1);
|
unset($stmt);
|
||||||
unset($stmt2);
|
|
||||||
unset($stmt3);
|
|
||||||
unset($stmt4);
|
|
||||||
unset($conn);
|
unset($conn);
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
|
|
|
@ -7,11 +7,7 @@ call a stored procedure and retrieve the errorNumber that is returned
|
||||||
require('connect.inc');
|
require('connect.inc');
|
||||||
$conn = new PDO( "sqlsrv:server=$server ; Database = $databaseName", "$uid", "$pwd");
|
$conn = new PDO( "sqlsrv:server=$server ; Database = $databaseName", "$uid", "$pwd");
|
||||||
|
|
||||||
// Drop the stored procedure if it already exists
|
dropProc($conn, 'sp_Test_Double');
|
||||||
$tsql_dropSP = "IF OBJECT_ID('sp_Test_Double', 'P') IS NOT NULL
|
|
||||||
DROP PROCEDURE sp_Test_Double";
|
|
||||||
|
|
||||||
$stmt = $conn->query($tsql_dropSP);
|
|
||||||
|
|
||||||
// Create the stored procedure
|
// Create the stored procedure
|
||||||
$tsql_createSP = "CREATE PROCEDURE sp_Test_Double
|
$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("Error Number minus 2: $value\n\n");
|
||||||
|
|
||||||
print_r($result);
|
print_r($result);
|
||||||
|
dropProc($conn, 'sp_Test_Double', false);
|
||||||
|
|
||||||
//free the statement and connection
|
//free the statement and connection
|
||||||
$stmt = null;
|
unset($stmt);
|
||||||
$conn = null;
|
unset($conn);
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
Error Number: -1.111
|
Error Number: -1.111
|
||||||
|
|
|
@ -4,43 +4,43 @@ call a stored procedure and retrieve the errorNumber that is returned
|
||||||
<?php require('skipif.inc'); ?>
|
<?php require('skipif.inc'); ?>
|
||||||
--FILE--
|
--FILE--
|
||||||
<?php
|
<?php
|
||||||
require('connect.inc');
|
require('connect.inc');
|
||||||
$conn = new PDO( "sqlsrv:server=$server ; Database = tempdb", "$uid", "$pwd");
|
$conn = new PDO( "sqlsrv:server=$server ; Database = $databaseName", $uid, $pwd);
|
||||||
|
|
||||||
// Drop the stored procedure if it already exists
|
// Drop the stored procedure if it already exists
|
||||||
$tsql_dropSP = "IF OBJECT_ID('sp_Test_Integer', 'P') IS NOT NULL
|
dropProc($conn, 'sp_Test_Integer');
|
||||||
DROP PROCEDURE sp_Test_Integer";
|
|
||||||
|
|
||||||
$stmt = $conn->query($tsql_dropSP);
|
// 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
|
$stmt = $conn->query($tsql_createSP);
|
||||||
$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);
|
// Call the stored procedure
|
||||||
|
$stmt = $conn->prepare("{CALL sp_Test_Integer (:errornumber)}");
|
||||||
|
|
||||||
// Call the stored procedure
|
$errorNumber = 0;
|
||||||
$stmt = $conn->prepare("{CALL sp_Test_Integer (:errornumber)}");
|
$stmt->bindParam('errornumber', $errorNumber, PDO::PARAM_INT|PDO::PARAM_INPUT_OUTPUT, 4);
|
||||||
|
|
||||||
$errorNumber = 0;
|
$stmt->execute();
|
||||||
$stmt->bindParam('errornumber', $errorNumber, PDO::PARAM_INT|PDO::PARAM_INPUT_OUTPUT, 4);
|
$result = $stmt->fetchAll(PDO::FETCH_NUM);
|
||||||
|
|
||||||
$stmt->execute();
|
$stmt->closeCursor();
|
||||||
$result = $stmt->fetchAll(PDO::FETCH_NUM);
|
|
||||||
|
|
||||||
$stmt->closeCursor();
|
print("Error Number: $errorNumber\n\n");
|
||||||
|
print_r($result);
|
||||||
|
|
||||||
print("Error Number: $errorNumber\n\n");
|
// Drop the stored procedure
|
||||||
print_r($result);
|
dropProc($conn, 'sp_Test_Integer', false);
|
||||||
|
|
||||||
//free the statement and connection
|
//free the statement and connection
|
||||||
$stmt = null;
|
unset($stmt);
|
||||||
$conn = null;
|
unset($conn);
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
Error Number: -1
|
Error Number: -1
|
||||||
|
|
|
@ -4,44 +4,43 @@ call a stored procedure and retrieve the errorString that is returned
|
||||||
<?php require('skipif.inc'); ?>
|
<?php require('skipif.inc'); ?>
|
||||||
--FILE--
|
--FILE--
|
||||||
<?php
|
<?php
|
||||||
require('connect.inc');
|
require('connect.inc');
|
||||||
$conn = new PDO( "sqlsrv:server=$server ; Database = tempdb", "$uid", "$pwd");
|
$conn = new PDO("sqlsrv:Server=$server; Database = $databaseName", $uid, $pwd);
|
||||||
|
|
||||||
// Drop the stored procedure if it already exists
|
// Drop the stored procedure if it already exists
|
||||||
$tsql_dropSP = "IF OBJECT_ID('sp_Test_String', 'P') IS NOT NULL
|
dropProc($conn, 'sp_Test_String');
|
||||||
DROP PROCEDURE sp_Test_String";
|
|
||||||
|
|
||||||
$stmt = $conn->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
|
// Call the stored procedure
|
||||||
$tsql_createSP = "CREATE PROCEDURE sp_Test_String
|
$stmt = $conn->prepare("{CALL 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
|
$errorString = "12345";
|
||||||
$stmt = $conn->prepare("{CALL sp_Test_String (?)}");
|
$stmt->bindParam(1, $errorString, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 20);
|
||||||
|
print("Error String: $errorString\n\n");
|
||||||
|
|
||||||
$errorString = "12345";
|
$stmt->execute();
|
||||||
$stmt->bindParam(1, $errorString, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 20);
|
|
||||||
print("Error String: $errorString\n\n");
|
|
||||||
|
|
||||||
$stmt->execute();
|
$result = $stmt->fetchAll(PDO::FETCH_NUM);
|
||||||
|
|
||||||
$result = $stmt->fetchAll(PDO::FETCH_NUM);
|
$stmt->closeCursor();
|
||||||
|
|
||||||
$stmt->closeCursor();
|
print("Error String: $errorString\n\n");
|
||||||
|
print_r($result);
|
||||||
|
|
||||||
print("Error String: $errorString\n\n");
|
dropProc($conn, 'sp_Test_String', false);
|
||||||
print_r($result);
|
|
||||||
|
|
||||||
//free the statement and connection
|
//free the statement and connection
|
||||||
$stmt = null;
|
unset($stmt);
|
||||||
$conn = null;
|
unset($conn);
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
Error String: 12345
|
Error String: 12345
|
||||||
|
|
|
@ -1,109 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
require_once('connect.inc');
|
|
||||||
|
|
||||||
// Set SQL server + user + password
|
|
||||||
$serverName = getenv('MSSQL_SERVERNAME') ?: $server2;
|
|
||||||
$username = getenv('MSSQL_USERNAME') ?: $uid;
|
|
||||||
$password = getenv('MSSQL_PASSWORD') ?: $pwd;
|
|
||||||
|
|
||||||
// Generate unique DB name, example: php_20160817_1471475608267
|
|
||||||
$databaseName = "php_" . date("Ymd") . "_" . round(microtime(true)*1000);
|
|
||||||
|
|
||||||
// Generic table name example: php_20160817_1471475608267.dbo.php_table
|
|
||||||
$tableName1 = $databaseName.".dbo.php_table1";
|
|
||||||
$tableName2 = $databaseName.".dbo.php_table2";
|
|
||||||
|
|
||||||
$connectionInfo = array( "Database"=>"$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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
|
@ -1,88 +0,0 @@
|
||||||
<?php
|
|
||||||
require_once("connect.inc");
|
|
||||||
|
|
||||||
// Using the tempdb database for two tables specifically constructed
|
|
||||||
// for the connection resiliency tests
|
|
||||||
$dbName = "tempdb";
|
|
||||||
|
|
||||||
$tableName1 = "test_connres1";
|
|
||||||
$tableName2 = "test_connres2";
|
|
||||||
|
|
||||||
// Generate tables for use with the connection resiliency tests.
|
|
||||||
// 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 )
|
|
||||||
{
|
|
||||||
$connectionInfo = array( "Database"=>$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 );
|
|
||||||
|
|
||||||
?>
|
|
|
@ -4,30 +4,16 @@ $databaseName = 'TARGET_DATABASE';
|
||||||
$uid = 'TARGET_USERNAME';
|
$uid = 'TARGET_USERNAME';
|
||||||
$pwd = 'TARGET_PASSWORD';
|
$pwd = 'TARGET_PASSWORD';
|
||||||
|
|
||||||
$server2 = 'ANOTHER_SERVER';
|
function dropTable($conn, $tableName)
|
||||||
|
|
||||||
// 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 )
|
|
||||||
{
|
{
|
||||||
$connectionInfo = array( "Database"=>$databaseName, "UID"=>$uid, "PWD"=>$pwd );
|
$tsql = "IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'" . $tableName . "') AND type in (N'U')) DROP TABLE [$tableName]";
|
||||||
$conn = sqlsrv_connect( $server, $connectionInfo);
|
sqlsrv_query($conn, $tsql);
|
||||||
if( $conn === false )
|
}
|
||||||
{
|
|
||||||
echo "Could not connect.<br>";
|
|
||||||
die( print_r( sqlsrv_errors(), true));
|
|
||||||
}
|
|
||||||
|
|
||||||
$stmt0 = sqlsrv_query( $conn, "UPDATE Sales.SalesOrderHeader SET RevisionNumber = 2");
|
function dropProc($conn, $procName)
|
||||||
if ( !$stmt0 )
|
{
|
||||||
{
|
$tsql = "IF OBJECT_ID('". $procName ."', 'P') IS NOT NULL DROP PROCEDURE [$procName]";
|
||||||
echo "Resetting the RevisionNumber failed.\n";
|
sqlsrv_query($conn, $tsql);
|
||||||
die( print_r( sqlsrv_errors(), true));
|
|
||||||
}
|
|
||||||
|
|
||||||
sqlsrv_close( $conn );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -6,9 +6,6 @@ executes two queries as part of a transaction
|
||||||
<?php
|
<?php
|
||||||
require('connect.inc');
|
require('connect.inc');
|
||||||
|
|
||||||
// First, reset the RevisionNumber to make sure it won't overflow
|
|
||||||
ResetRevisionNumber( $server, $databaseName, $uid, $pwd );
|
|
||||||
|
|
||||||
$connectionInfo = array( "Database"=>"$databaseName", "UID"=>$uid, "PWD"=>$pwd);
|
$connectionInfo = array( "Database"=>"$databaseName", "UID"=>$uid, "PWD"=>$pwd);
|
||||||
$conn = sqlsrv_connect( $server, $connectionInfo);
|
$conn = sqlsrv_connect( $server, $connectionInfo);
|
||||||
if( $conn === false )
|
if( $conn === false )
|
||||||
|
@ -17,6 +14,9 @@ if( $conn === false )
|
||||||
die( print_r( sqlsrv_errors(), true ));
|
die( print_r( sqlsrv_errors(), true ));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$tsql = "DISABLE TRIGGER uSalesOrderHeader ON Sales.SalesOrderHeader";
|
||||||
|
$stmt = sqlsrv_query($conn, $tsql);
|
||||||
|
|
||||||
/* Initiate transaction. */
|
/* Initiate transaction. */
|
||||||
/* Exit script if transaction cannot be initiated. */
|
/* Exit script if transaction cannot be initiated. */
|
||||||
if ( sqlsrv_begin_transaction( $conn ) === false )
|
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";
|
$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);
|
$stmt3 = sqlsrv_query($conn, $d_sql);
|
||||||
|
|
||||||
|
$tsql = "ENABLE TRIGGER uSalesOrderHeader ON Sales.SalesOrderHeader";
|
||||||
|
$stmt = sqlsrv_query($conn, $tsql);
|
||||||
|
|
||||||
/* Free statement and connection resources. */
|
/* Free statement and connection resources. */
|
||||||
sqlsrv_free_stmt( $stmt1);
|
sqlsrv_free_stmt( $stmt1);
|
||||||
sqlsrv_free_stmt( $stmt2);
|
sqlsrv_free_stmt( $stmt2);
|
||||||
|
|
|
@ -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=62 WHERE BusinessEntityID=8;
|
||||||
UPDATE HumanResources.Employee SET VacationHours=63 WHERE BusinessEntityID=9;
|
UPDATE HumanResources.Employee SET VacationHours=63 WHERE BusinessEntityID=9;
|
||||||
UPDATE HumanResources.Employee SET VacationHours=7 WHERE BusinessEntityID=11";
|
UPDATE HumanResources.Employee SET VacationHours=7 WHERE BusinessEntityID=11";
|
||||||
$stmt4=sqlsrv_query($conn, $r_sql);
|
$stmt=sqlsrv_query($conn, $r_sql);
|
||||||
sqlsrv_free_stmt( $stmt4 );
|
sqlsrv_free_stmt( $stmt );
|
||||||
|
|
||||||
/* Drop the stored procedure if it already exists. */
|
/* Drop the stored procedure if it already exists. */
|
||||||
$tsql1 = "IF OBJECT_ID('SubtractVacationHours', 'P') IS NOT NULL
|
dropProc($conn, "SubtractVacationHours");
|
||||||
DROP PROCEDURE SubtractVacationHours";
|
|
||||||
$stmt1 = sqlsrv_query($conn, $tsql1);
|
|
||||||
|
|
||||||
/* If the query fails, display errors and exit the script. */
|
|
||||||
if( $stmt1 === false)
|
|
||||||
{
|
|
||||||
DisplayErrors();
|
|
||||||
die;
|
|
||||||
}
|
|
||||||
/* Display any warnings. */
|
/* Display any warnings. */
|
||||||
DisplayWarnings();
|
DisplayWarnings();
|
||||||
|
|
||||||
/* Free the statement resources. */
|
|
||||||
sqlsrv_free_stmt( $stmt1 );
|
|
||||||
|
|
||||||
/* Create the stored procedure. */
|
/* Create the stored procedure. */
|
||||||
$tsql2 = "CREATE PROCEDURE SubtractVacationHours
|
$tsql2 = "CREATE PROCEDURE SubtractVacationHours
|
||||||
@BusinessEntityId int,
|
@BusinessEntityId int,
|
||||||
|
@ -69,10 +58,10 @@ $tsql2 = "CREATE PROCEDURE SubtractVacationHours
|
||||||
BEGIN
|
BEGIN
|
||||||
PRINT 'WARNING: Vacation hours are now less than zero.'
|
PRINT 'WARNING: Vacation hours are now less than zero.'
|
||||||
END;";
|
END;";
|
||||||
$stmt2 = sqlsrv_query( $conn, $tsql2 );
|
$stmt = sqlsrv_query( $conn, $tsql2 );
|
||||||
|
|
||||||
/* If the query fails, display errors and exit the script. */
|
/* If the query fails, display errors and exit the script. */
|
||||||
if( $stmt2 === false)
|
if( $stmt === false)
|
||||||
{
|
{
|
||||||
DisplayErrors();
|
DisplayErrors();
|
||||||
die;
|
die;
|
||||||
|
@ -81,7 +70,7 @@ if( $stmt2 === false)
|
||||||
DisplayWarnings();
|
DisplayWarnings();
|
||||||
|
|
||||||
/* Free the statement resources. */
|
/* Free the statement resources. */
|
||||||
sqlsrv_free_stmt( $stmt2 );
|
sqlsrv_free_stmt( $stmt );
|
||||||
|
|
||||||
/* Set up the array that maps employee ID to used vacation hours. */
|
/* Set up the array that maps employee ID to used vacation hours. */
|
||||||
$emp_hrs = array (7=>4, 8=>5, 9=>8, 11=>50);
|
$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. */
|
/* Define and prepare the query to substract used vacation hours. */
|
||||||
$tsql3 = "{call SubtractVacationHours(?, ?)}";
|
$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 the statement preparation fails, display errors and exit the script. */
|
||||||
if( $stmt3 === false)
|
if( $stmt === false)
|
||||||
{
|
{
|
||||||
DisplayErrors();
|
DisplayErrors();
|
||||||
die;
|
die;
|
||||||
|
@ -115,7 +104,7 @@ foreach(array_keys($emp_hrs) as $businessEntityId)
|
||||||
{
|
{
|
||||||
$vacationHrs = $emp_hrs[$businessEntityId];
|
$vacationHrs = $emp_hrs[$businessEntityId];
|
||||||
/* Execute the query. If it fails, display the errors. */
|
/* Execute the query. If it fails, display the errors. */
|
||||||
if( sqlsrv_execute($stmt3) === false)
|
if( sqlsrv_execute($stmt) === false)
|
||||||
{
|
{
|
||||||
DisplayErrors();
|
DisplayErrors();
|
||||||
die;
|
die;
|
||||||
|
@ -124,7 +113,7 @@ foreach(array_keys($emp_hrs) as $businessEntityId)
|
||||||
DisplayWarnings();
|
DisplayWarnings();
|
||||||
|
|
||||||
/*Move to the next result returned by the stored procedure. */
|
/*Move to the next result returned by the stored procedure. */
|
||||||
if( sqlsrv_next_result($stmt3) === false)
|
if( sqlsrv_next_result($stmt) === false)
|
||||||
{
|
{
|
||||||
DisplayErrors();
|
DisplayErrors();
|
||||||
die;
|
die;
|
||||||
|
@ -138,7 +127,9 @@ foreach(array_keys($emp_hrs) as $businessEntityId)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Free the statement*/
|
/* Free the statement*/
|
||||||
sqlsrv_free_stmt( $stmt3 );
|
sqlsrv_free_stmt( $stmt );
|
||||||
|
|
||||||
|
dropProc($conn, "SubtractVacationHours", false);
|
||||||
|
|
||||||
/* close connection resources. */
|
/* close connection resources. */
|
||||||
sqlsrv_close( $conn );
|
sqlsrv_close( $conn );
|
||||||
|
@ -169,10 +160,10 @@ function DisplayWarnings()
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
--EXPECTREGEX--
|
--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.
|
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 7 has 57 remaining vacation hours.
|
||||||
BusinessEntityId 8 has 57 remaining vacation hours.
|
BusinessEntityId 8 has 57 remaining vacation hours.
|
||||||
BusinessEntityId 9 has 55 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.
|
Error: \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]\[SQL Server\]The statement has been terminated.
|
|
@ -5,17 +5,9 @@ disables MARS support.
|
||||||
--FILE--
|
--FILE--
|
||||||
<?php
|
<?php
|
||||||
require('connect.inc');
|
require('connect.inc');
|
||||||
$connectionInfo = array( "Database"=>"$databaseName", "UID"=>"$uid", "PWD"=>"$pwd");
|
$connectionInfo = array("Database"=>$databaseName, "UID"=>$uid, "PWD"=>$pwd, 'MultipleActiveResultSets'=> false);
|
||||||
$conn = sqlsrv_connect( $server, $connectionInfo);
|
$conn = sqlsrv_connect( $server, $connectionInfo);
|
||||||
|
if( $conn === false ) {
|
||||||
/* 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 )
|
|
||||||
{
|
|
||||||
echo "Could not connect.\n";
|
echo "Could not connect.\n";
|
||||||
die( print_r( sqlsrv_errors(), true));
|
die( print_r( sqlsrv_errors(), true));
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,17 +57,18 @@ echo "<br>";
|
||||||
|
|
||||||
sqlsrv_free_stmt( $stmt);
|
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. */
|
/* Prepare with string type in parameter. */
|
||||||
$tsql = "UPDATE Sales.SalesOrderDetail
|
$tsql = "UPDATE Sales.SalesOrderDetail
|
||||||
SET OrderQty=(?)
|
SET OrderQty=(?)
|
||||||
WHERE CarrierTrackingNumber=(?)";
|
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
|
//Pass in parameters directly
|
||||||
$params = array(5, '8650-4A20-B1');
|
$params = array(5, '8650-4A20-B1');
|
||||||
$stmt = sqlsrv_prepare( $conn, $tsql, $params);
|
$stmt = sqlsrv_prepare( $conn, $tsql, $params);
|
||||||
|
@ -140,11 +141,13 @@ else
|
||||||
die( print_r( sqlsrv_errors(), true));
|
die( print_r( sqlsrv_errors(), true));
|
||||||
}
|
}
|
||||||
echo sqlsrv_rows_affected( $stmt)." rows affected.<br>";
|
echo sqlsrv_rows_affected( $stmt)." rows affected.<br>";
|
||||||
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. */
|
/* Free the statement and connection resources. */
|
||||||
//sqlsrv_free_stmt( $stmt);
|
sqlsrv_free_stmt( $stmt);
|
||||||
sqlsrv_close( $conn);
|
sqlsrv_close( $conn);
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
|
|
|
@ -17,17 +17,10 @@ if( $conn === false )
|
||||||
|
|
||||||
/*revert inserts from previous tests*/
|
/*revert inserts from previous tests*/
|
||||||
$d_sql = "DELETE FROM Production.ProductReview WHERE EmailAddress!='john@fourthcoffee.com' AND ProductID=709";
|
$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. */
|
/* Drop the stored procedure if it already exists. */
|
||||||
$tsql_dropSP = "IF OBJECT_ID('InsertProductReview', 'P') IS NOT NULL
|
dropProc($conn, 'InsertProductReview');
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Create the stored procedure. */
|
/* Create the stored procedure. */
|
||||||
$tsql_createSP = " CREATE PROCEDURE InsertProductReview
|
$tsql_createSP = " CREATE PROCEDURE InsertProductReview
|
||||||
|
@ -56,9 +49,9 @@ $tsql_createSP = " CREATE PROCEDURE InsertProductReview
|
||||||
SELECT * FROM Production.ProductReview
|
SELECT * FROM Production.ProductReview
|
||||||
WHERE ProductID = @ProductID;
|
WHERE ProductID = @ProductID;
|
||||||
END";
|
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";
|
echo "Error in executing statement 2.\n";
|
||||||
die( print_r( sqlsrv_errors(), true));
|
die( print_r( sqlsrv_errors(), true));
|
||||||
|
@ -86,8 +79,8 @@ $params = array(
|
||||||
);
|
);
|
||||||
|
|
||||||
/* Execute the query. */
|
/* Execute the query. */
|
||||||
$stmt3 = sqlsrv_query( $conn, $tsql_callSP, $params);
|
$stmt = sqlsrv_query( $conn, $tsql_callSP, $params);
|
||||||
if( $stmt3 === false)
|
if( $stmt === false)
|
||||||
{
|
{
|
||||||
echo "Error in executing statement 3.\n";
|
echo "Error in executing statement 3.\n";
|
||||||
die( print_r( sqlsrv_errors(), true));
|
die( print_r( sqlsrv_errors(), true));
|
||||||
|
@ -97,17 +90,17 @@ echo "<p>";
|
||||||
|
|
||||||
/* Consume the first result (rows affected by INSERT query in the
|
/* Consume the first result (rows affected by INSERT query in the
|
||||||
stored procedure) without calling sqlsrv_next_result. */
|
stored procedure) without calling sqlsrv_next_result. */
|
||||||
echo "Rows affectd: ".sqlsrv_rows_affected($stmt3)."-----\n";
|
echo "Rows affectd: ".sqlsrv_rows_affected($stmt)."-----\n";
|
||||||
|
|
||||||
echo "<p>";
|
echo "<p>";
|
||||||
|
|
||||||
/* Move to the next result and display results. */
|
/* Move to the next result and display results. */
|
||||||
$next_result = sqlsrv_next_result($stmt3);
|
$next_result = sqlsrv_next_result($stmt);
|
||||||
if( $next_result )
|
if( $next_result )
|
||||||
{
|
{
|
||||||
echo "<p>";
|
echo "<p>";
|
||||||
echo "\nReview information for product ID ".$productID.".---\n";
|
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 "<br>ReviewerName: ".$row['ReviewerName']."\n";
|
echo "<br>ReviewerName: ".$row['ReviewerName']."\n";
|
||||||
echo "<br>ReviewDate: ".date_format($row['ReviewDate'],
|
echo "<br>ReviewDate: ".date_format($row['ReviewDate'],
|
||||||
|
@ -127,13 +120,10 @@ else
|
||||||
die(print_r(sqlsrv_errors(), true));
|
die(print_r(sqlsrv_errors(), true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dropProc($conn, 'InsertProductReview', false);
|
||||||
|
|
||||||
/* Free statement and connection resources. */
|
/* Free statement and connection resources. */
|
||||||
sqlsrv_free_stmt( $stmt1 );
|
sqlsrv_free_stmt( $stmt );
|
||||||
sqlsrv_free_stmt( $stmt2 );
|
|
||||||
sqlsrv_free_stmt( $stmt3 );
|
|
||||||
sqlsrv_free_stmt( $stmt4 );
|
|
||||||
|
|
||||||
|
|
||||||
sqlsrv_close( $conn );
|
sqlsrv_close( $conn );
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
|
|
|
@ -15,6 +15,12 @@ if( $conn === false )
|
||||||
die( print_r( sqlsrv_errors(), true));
|
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. */
|
/* Set up the parameterized query. */
|
||||||
$tsql = "INSERT INTO Sales.SalesOrderDetail
|
$tsql = "INSERT INTO Sales.SalesOrderDetail
|
||||||
(SalesOrderID,
|
(SalesOrderID,
|
||||||
|
@ -29,12 +35,6 @@ $tsql = "INSERT INTO Sales.SalesOrderDetail
|
||||||
/* Set parameter values. */
|
/* Set parameter values. */
|
||||||
$params = array(75123, 5, 741, 1, 818.70, 0.00);
|
$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. */
|
/* Prepare and execute the query. */
|
||||||
$stmt = sqlsrv_query( $conn, $tsql, $params);
|
$stmt = sqlsrv_query( $conn, $tsql, $params);
|
||||||
if( $stmt )
|
if( $stmt )
|
||||||
|
@ -47,6 +47,10 @@ else
|
||||||
die( print_r( sqlsrv_errors(), true));
|
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. */
|
/* Free statement and connection resources. */
|
||||||
sqlsrv_free_stmt( $stmt);
|
sqlsrv_free_stmt( $stmt);
|
||||||
sqlsrv_close( $conn);
|
sqlsrv_close( $conn);
|
||||||
|
|
|
@ -13,14 +13,7 @@ if( $conn === false )
|
||||||
die( print_r( sqlsrv_errors(), true));
|
die( print_r( sqlsrv_errors(), true));
|
||||||
}
|
}
|
||||||
/* Drop the stored procedure if it already exists. */
|
/* Drop the stored procedure if it already exists. */
|
||||||
$tsql_dropSP = "IF OBJECT_ID('SubtractVacationHours', 'P') IS NOT NULL
|
dropProc($conn, 'SubtractVacationHours');
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Create the stored procedure. */
|
/* Create the stored procedure. */
|
||||||
$tsql_createSP = "CREATE PROCEDURE SubtractVacationHours
|
$tsql_createSP = "CREATE PROCEDURE SubtractVacationHours
|
||||||
|
@ -34,8 +27,8 @@ $tsql_createSP = "CREATE PROCEDURE SubtractVacationHours
|
||||||
FROM HumanResources.Employee
|
FROM HumanResources.Employee
|
||||||
WHERE BusinessEntityID = @BusinessEntityID)";
|
WHERE BusinessEntityID = @BusinessEntityID)";
|
||||||
|
|
||||||
$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";
|
echo "Error in executing statement 2.\n";
|
||||||
die( print_r( sqlsrv_errors(), true));
|
die( print_r( sqlsrv_errors(), true));
|
||||||
|
@ -62,26 +55,25 @@ $params = array(
|
||||||
);
|
);
|
||||||
|
|
||||||
/* Execute the query. */
|
/* Execute the query. */
|
||||||
$stmt3 = sqlsrv_query( $conn, $tsql_callSP, $params);
|
$stmt = sqlsrv_query( $conn, $tsql_callSP, $params);
|
||||||
if( $stmt3 === false )
|
if( $stmt === false )
|
||||||
{
|
{
|
||||||
echo "Error in executing statement 3.\n";
|
echo "Error in executing statement 3.\n";
|
||||||
die( print_r( sqlsrv_errors(), true));
|
die( print_r( sqlsrv_errors(), true));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Display the value of the output parameter $vacationHrs. */
|
/* Display the value of the output parameter $vacationHrs. */
|
||||||
sqlsrv_next_result($stmt3);
|
sqlsrv_next_result($stmt);
|
||||||
echo "Remaining vacation hours: ".$vacationHrs;
|
echo "Remaining vacation hours: ".$vacationHrs;
|
||||||
|
|
||||||
/* Revert the update in vacation hours */
|
/* Revert the update in vacation hours */
|
||||||
$r_sql = "UPDATE HumanResources.Employee SET VacationHours=48 WHERE BusinessEntityID=4";
|
$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. */
|
/*Free the statement and connection resources. */
|
||||||
sqlsrv_free_stmt( $stmt1);
|
sqlsrv_free_stmt( $stmt);
|
||||||
sqlsrv_free_stmt( $stmt2);
|
|
||||||
sqlsrv_free_stmt( $stmt3);
|
|
||||||
sqlsrv_free_stmt( $stmt4);
|
|
||||||
sqlsrv_close( $conn);
|
sqlsrv_close( $conn);
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
|
|
|
@ -16,14 +16,7 @@ if( $conn === false )
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Drop the stored procedure if it already exists. */
|
/* Drop the stored procedure if it already exists. */
|
||||||
$tsql_dropSP = "IF OBJECT_ID('GetEmployeeSalesYTD', 'P') IS NOT NULL
|
dropProc($conn, 'GetEmployeeSalesYTD');
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Create the stored procedure. */
|
/* Create the stored procedure. */
|
||||||
$tsql_createSP = " CREATE PROCEDURE GetEmployeeSalesYTD
|
$tsql_createSP = " CREATE PROCEDURE GetEmployeeSalesYTD
|
||||||
|
@ -35,8 +28,8 @@ $tsql_createSP = " CREATE PROCEDURE GetEmployeeSalesYTD
|
||||||
JOIN HumanResources.vEmployee AS e
|
JOIN HumanResources.vEmployee AS e
|
||||||
ON e.BusinessEntityID = sp.BusinessEntityID
|
ON e.BusinessEntityID = sp.BusinessEntityID
|
||||||
WHERE LastName = @SalesPerson";
|
WHERE LastName = @SalesPerson";
|
||||||
$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";
|
echo "Error in executing statement 2.\n";
|
||||||
die( print_r( sqlsrv_errors(), true));
|
die( print_r( sqlsrv_errors(), true));
|
||||||
|
@ -62,8 +55,8 @@ $params = array(
|
||||||
);
|
);
|
||||||
|
|
||||||
/* Execute the query. */
|
/* Execute the query. */
|
||||||
$stmt3 = sqlsrv_query( $conn, $tsql_callSP, $params);
|
$stmt = sqlsrv_query( $conn, $tsql_callSP, $params);
|
||||||
if( $stmt3 === false )
|
if( $stmt === false )
|
||||||
{
|
{
|
||||||
echo "Error in executing statement 3.\n";
|
echo "Error in executing statement 3.\n";
|
||||||
die( print_r( sqlsrv_errors(), true));
|
die( print_r( sqlsrv_errors(), true));
|
||||||
|
@ -72,10 +65,10 @@ if( $stmt3 === false )
|
||||||
/* Display the value of the output parameter $salesYTD. */
|
/* Display the value of the output parameter $salesYTD. */
|
||||||
echo "YTD sales for ".$lastName." are ". $salesYTD. ".";
|
echo "YTD sales for ".$lastName." are ". $salesYTD. ".";
|
||||||
|
|
||||||
|
dropProc($conn, 'GetEmployeeSalesYTD', false);
|
||||||
|
|
||||||
/*Free the statement and connection resources. */
|
/*Free the statement and connection resources. */
|
||||||
sqlsrv_free_stmt( $stmt1);
|
sqlsrv_free_stmt( $stmt);
|
||||||
sqlsrv_free_stmt( $stmt2);
|
|
||||||
sqlsrv_free_stmt( $stmt3);
|
|
||||||
sqlsrv_close( $conn);
|
sqlsrv_close( $conn);
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
|
|
|
@ -11,34 +11,32 @@ if ( $conn === false ) {
|
||||||
die( print_r( sqlsrv_errors(), true ));
|
die( print_r( sqlsrv_errors(), true ));
|
||||||
}
|
}
|
||||||
|
|
||||||
$stmt = sqlsrv_query( $conn, "DROP TABLE dbo.ScrollTest" );
|
$tableName = 'ScrollTest';
|
||||||
if ( $stmt !== false ) {
|
dropTable($conn, $tableName);
|
||||||
sqlsrv_free_stmt( $stmt );
|
|
||||||
}
|
|
||||||
|
|
||||||
$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 ) {
|
if ( $stmt === false ) {
|
||||||
die( print_r( sqlsrv_errors(), true ));
|
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 ) {
|
if ( $stmt === false ) {
|
||||||
die( print_r( sqlsrv_errors(), true ));
|
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 ) {
|
if ( $stmt === false ) {
|
||||||
die( print_r( sqlsrv_errors(), true ));
|
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 ) {
|
if ( $stmt === false ) {
|
||||||
die( print_r( sqlsrv_errors(), true ));
|
die( print_r( sqlsrv_errors(), true ));
|
||||||
}
|
}
|
||||||
|
|
||||||
$stmt = sqlsrv_query( $conn, "SELECT * FROM ScrollTest", array(), array( "Scrollable" => 'keyset' ));
|
$stmt = sqlsrv_query( $conn, "SELECT * FROM $tableName", array(), array( "Scrollable" => 'keyset' ));
|
||||||
// $stmt = sqlsrv_query( $conn, "SELECT * FROM ScrollTest", array(), array( "Scrollable" => 'dynamic' ));
|
// $stmt = sqlsrv_query( $conn, "SELECT * FROM $tableName", 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" => 'static' ));
|
||||||
|
|
||||||
$rows = sqlsrv_has_rows( $stmt );
|
$rows = sqlsrv_has_rows( $stmt );
|
||||||
if ( $rows != true ) {
|
if ( $rows != true ) {
|
||||||
|
@ -50,9 +48,9 @@ $field1 = sqlsrv_get_field( $stmt, 0 );
|
||||||
$field2 = sqlsrv_get_field( $stmt, 1 );
|
$field2 = sqlsrv_get_field( $stmt, 1 );
|
||||||
echo "\n$field1 $field2\n";
|
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
|
// 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 ) {
|
if ( $stmt2 !== false ) {
|
||||||
sqlsrv_free_stmt( $stmt2 );
|
sqlsrv_free_stmt( $stmt2 );
|
||||||
}
|
}
|
||||||
|
@ -62,6 +60,8 @@ $field1 = sqlsrv_get_field( $stmt, 0 );
|
||||||
$field2 = sqlsrv_get_field( $stmt, 1 );
|
$field2 = sqlsrv_get_field( $stmt, 1 );
|
||||||
echo "\n$field1 $field2\n";
|
echo "\n$field1 $field2\n";
|
||||||
|
|
||||||
|
dropTable($conn, $tableName, false);
|
||||||
|
|
||||||
sqlsrv_free_stmt( $stmt );
|
sqlsrv_free_stmt( $stmt );
|
||||||
sqlsrv_close( $conn );
|
sqlsrv_close( $conn );
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -32,4 +32,4 @@ else
|
||||||
sqlsrv_close( $conn);
|
sqlsrv_close( $conn);
|
||||||
?>
|
?>
|
||||||
--EXPECTREGEX--
|
--EXPECTREGEX--
|
||||||
CurrentDatabase: AdventureWorks.*<br>SQLServerVersion: 1[2-9].00.[0-9]{4}<br>SQLServerName: SQL.+<br>
|
CurrentDatabase: AdventureWorks201.<br>SQLServerVersion: 1[2-9].00.[0-9]{4}<br>SQLServerName: .+<br>
|
|
@ -15,13 +15,7 @@ call a stored procedure (SQLSRV Driver) and retrieve the errorNumber that is ret
|
||||||
}
|
}
|
||||||
|
|
||||||
// Drop the stored procedure if it already exists
|
// Drop the stored procedure if it already exists
|
||||||
$tsql_dropSP = "IF OBJECT_ID('sp_Test', 'P') IS NOT NULL
|
dropProc($conn, "sp_Test");
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the stored procedure
|
// Create the stored procedure
|
||||||
$tsql_createSP = "CREATE PROCEDURE sp_Test
|
$tsql_createSP = "CREATE PROCEDURE sp_Test
|
||||||
|
@ -31,8 +25,8 @@ call a stored procedure (SQLSRV Driver) and retrieve the errorNumber that is ret
|
||||||
SET @ErrorNumber = -1
|
SET @ErrorNumber = -1
|
||||||
SELECT 1,2,3
|
SELECT 1,2,3
|
||||||
END";
|
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";
|
echo "Error in executing statement 2.\n";
|
||||||
die (print_r (sqlsrv_errors(), true));
|
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
|
// Execute the query
|
||||||
$stmt3 = sqlsrv_query($conn, $tsql_callSP, $params);
|
$stmt = sqlsrv_query($conn, $tsql_callSP, $params);
|
||||||
if ($stmt3 === false) {
|
if ($stmt === false) {
|
||||||
echo "Error in executing statement 3.\n";
|
echo "Error in executing statement 3.\n";
|
||||||
die (print_r (sqlsrv_errors(), true));
|
die (print_r (sqlsrv_errors(), true));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display the value of the output parameter $errorNumber
|
// Display the value of the output parameter $errorNumber
|
||||||
sqlsrv_next_result($stmt3);
|
sqlsrv_next_result($stmt);
|
||||||
print("Error Number: $errorNumber\n\n");
|
print("Error Number: $errorNumber\n\n");
|
||||||
|
|
||||||
|
dropProc($conn, "sp_Test", false);
|
||||||
|
|
||||||
// Free the statement and connection resources. */
|
// Free the statement and connection resources. */
|
||||||
sqlsrv_free_stmt( $stmt1);
|
sqlsrv_free_stmt( $stmt);
|
||||||
sqlsrv_free_stmt( $stmt2);
|
|
||||||
sqlsrv_free_stmt( $stmt3);
|
|
||||||
sqlsrv_close( $conn);
|
sqlsrv_close( $conn);
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
|
|
Loading…
Reference in a new issue