Refactoring sqlsrv tests using a new AE namespace plus mostly cosmetic changes

This commit is contained in:
Jenny Tam 2017-10-04 14:22:56 -07:00
parent fae3e6539d
commit 39c4be46ec
195 changed files with 7216 additions and 8180 deletions

View file

@ -4,26 +4,24 @@ A test for a simple query
<?php require('skipif.inc'); ?>
--FILE--
<?php
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
sqlsrv_configure('WarningsReturnAsErrors', 0);
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
require( 'MsCommon.inc' );
require_once('MsCommon.inc');
$conn = Connect();
if (!$conn)
{
FatalError("Failed to connect");
$conn = connect();
if (!$conn) {
fatalError("Failed to connect");
}
$stmt = sqlsrv_query($conn, "SELECT * FROM [cd_info]");
if (! $stmt)
{
FatalError("Failed to select from cd_info");
if (! $stmt) {
fatalError("Failed to select from cd_info");
}
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
echo "Test successful<br/>\n";
?>
?>
--EXPECT--
Test successful<br/>
Test successful<br/>

View file

@ -4,59 +4,59 @@ scrollable results with no rows.
<?php require('skipif.inc'); ?>
--FILE--
<?php
sqlsrv_configure('WarningsReturnAsErrors', 0);
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
require( 'MsCommon.inc' );
require_once('MsCommon.inc');
$conn = Connect();
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true ));
$conn = connect();
if ($conn === false) {
die(print_r(sqlsrv_errors(), true));
}
$stmt = sqlsrv_query( $conn, "IF OBJECT_ID('ScrollTest', 'U') IS NOT NULL DROP TABLE ScrollTest" );
if( $stmt !== false ) { sqlsrv_free_stmt( $stmt ); }
$stmt = sqlsrv_query( $conn, "CREATE TABLE ScrollTest (id int, value char(10))" );
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
$stmt = sqlsrv_query($conn, "IF OBJECT_ID('ScrollTest', 'U') IS NOT NULL DROP TABLE ScrollTest");
if ($stmt !== false) {
sqlsrv_free_stmt($stmt);
}
sqlsrv_free_stmt( $stmt );
$stmt = sqlsrv_query( $conn, "SELECT * FROM ScrollTest", array(), array( "Scrollable" => 'static' ));
$rows = sqlsrv_has_rows( $stmt );
if( $rows != false ) {
FatalError( "Should be no rows present" );
$stmt = sqlsrv_query($conn, "CREATE TABLE ScrollTest (id int, value char(10))");
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query($conn, "SELECT * FROM ScrollTest", array(), array( "Scrollable" => 'static' ));
$rows = sqlsrv_has_rows($stmt);
if ($rows != false) {
fatalError("Should be no rows present");
};
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
$row = sqlsrv_fetch_array( $stmt );
print_r( $row );
if( $row === false ) {
print_r( sqlsrv_errors(), true );
$row = sqlsrv_fetch_array($stmt);
print_r($row);
if ($row === false) {
print_r(sqlsrv_errors(), true);
}
$stmt = sqlsrv_query( $conn, "SELECT * FROM ScrollTest" );
$rows = sqlsrv_has_rows( $stmt );
if( $rows != false ) {
FatalError( "Should be no rows present" );
$stmt = sqlsrv_query($conn, "SELECT * FROM ScrollTest");
$rows = sqlsrv_has_rows($stmt);
if ($rows != false) {
fatalError("Should be no rows present");
};
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
$row = sqlsrv_fetch_array( $stmt );
print_r( $row );
if( $row === false ) {
print_r( sqlsrv_errors(), true );
$row = sqlsrv_fetch_array($stmt);
print_r($row);
if ($row === false) {
print_r(sqlsrv_errors(), true);
}
$stmt = sqlsrv_query( $conn, "DROP TABLE ScrollTest" );
$stmt = sqlsrv_query($conn, "DROP TABLE ScrollTest");
echo "Test succeeded.\n";
?>

View file

@ -4,61 +4,63 @@ binding parameters, including output parameters, using the simplified syntax.
<?php require('skipif.inc'); ?>
--FILE--
<?php
set_time_limit(0);
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 0);
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
require( 'MsCommon.inc' );
require_once('MsCommon.inc');
$conn = Connect();
$conn = connect();
$stmt = sqlsrv_query( $conn, "IF OBJECT_ID('php_table_1_SERIL2', 'U') IS NOT NULL DROP TABLE [php_table_1_SERIL2]" );
if( $stmt !== false ) sqlsrv_free_stmt( $stmt );
$stmt = sqlsrv_query($conn, "CREATE TABLE [php_table_1_SERIL2] ([int] int, [varchar] varchar(512)) ");
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
sqlsrv_free_stmt( $stmt );
$stmt = sqlsrv_query($conn, "INSERT INTO [php_table_1_SERIL2] ([int], [varchar]) VALUES( 1, 'This is a test.' )" );
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$numRows1 = sqlsrv_rows_affected( $stmt );
if( $numRows1 === false ) {
die( print_r( sqlsrv_errors(), true ));
}
sqlsrv_free_stmt( $stmt );
$stmt = sqlsrv_query( $conn, "SELECT * FROM [php_table_1_SERIL2];SELECT * FROM [php_table_1_SERIL2]" );
$row = sqlsrv_fetch_array( $stmt );
if( $row === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$row = sqlsrv_fetch_array( $stmt );
if( $row === false ) {
die( print_r( sqlsrv_errors(), true ));
$stmt = sqlsrv_query($conn, "IF OBJECT_ID('php_table_1_SERIL2', 'U') IS NOT NULL DROP TABLE [php_table_1_SERIL2]");
if ($stmt !== false) {
sqlsrv_free_stmt($stmt);
}
$result = sqlsrv_next_result( $stmt );
if( $result === false ) {
die( print_r( sqlsrv_errors(), true ));
$stmt = sqlsrv_query($conn, "CREATE TABLE [php_table_1_SERIL2] ([int] int, [varchar] varchar(512)) ");
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
if( $result === null ) {
FatalError( "sqlsrv_next_result returned null" );
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query($conn, "INSERT INTO [php_table_1_SERIL2] ([int], [varchar]) VALUES( 1, 'This is a test.' )");
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
$row = sqlsrv_fetch_array( $stmt );
if( $row === false ) {
die( print_r( sqlsrv_errors(), true ));
$numRows1 = sqlsrv_rows_affected($stmt);
if ($numRows1 === false) {
die(print_r(sqlsrv_errors(), true));
}
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query($conn, "SELECT * FROM [php_table_1_SERIL2];SELECT * FROM [php_table_1_SERIL2]");
$row = sqlsrv_fetch_array($stmt);
if ($row === false) {
die(print_r(sqlsrv_errors(), true));
}
$row = sqlsrv_fetch_array($stmt);
if ($row === false) {
die(print_r(sqlsrv_errors(), true));
}
$stmt = sqlsrv_query( $conn, "DROP TABLE [php_table_1_SERIL2]" );
sqlsrv_free_stmt( $stmt );
sqlsrv_close( $conn );
$result = sqlsrv_next_result($stmt);
if ($result === false) {
die(print_r(sqlsrv_errors(), true));
}
if ($result === null) {
fatalError("sqlsrv_next_result returned null");
}
$row = sqlsrv_fetch_array($stmt);
if ($row === false) {
die(print_r(sqlsrv_errors(), true));
}
$stmt = sqlsrv_query($conn, "DROP TABLE [php_table_1_SERIL2]");
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
echo "Test succeeded.\n"
?>

View file

@ -4,14 +4,14 @@ binding parameters, including output parameters, using the simplified syntax.
<?php require('skipif.inc'); ?>
--FILE--
<?php
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
sqlsrv_configure('WarningsReturnAsErrors', 0);
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
require( 'MsCommon.inc' );
require_once('MsCommon.inc');
$conn = Connect();
if( !$conn ) {
FatalError( "sqlsrv_create failed." );
$conn = connect();
if (!$conn) {
fatalError("sqlsrv_create failed.");
}
$v1 = 1;
@ -19,46 +19,46 @@ binding parameters, including output parameters, using the simplified syntax.
$v3 = -1;
// this is a test to infer the PHP type to be integer and check it so that it matches
$stmt = sqlsrv_prepare( $conn, "{call test_out( ?, ?, ? )}", array( &$v1, &$v2, array( &$v3, SQLSRV_PARAM_OUT, null, SQLSRV_SQLTYPE_INT )));
$stmt = sqlsrv_prepare($conn, "{call test_out( ?, ?, ? )}", array( &$v1, &$v2, array( &$v3, SQLSRV_PARAM_OUT, null, SQLSRV_SQLTYPE_INT )));
$result = sqlsrv_execute( $stmt );
if( $result === false ) {
print_r( sqlsrv_errors() );
$result = sqlsrv_execute($stmt);
if ($result === false) {
print_r(sqlsrv_errors());
}
while( sqlsrv_next_result( $stmt ) != null );
while (sqlsrv_next_result($stmt) != null);
echo "$v3\n";
sqlsrv_free_stmt( $stmt );
sqlsrv_free_stmt($stmt);
// this is a test to see if we force the type to be integer when it's inferred and the variable is a string
$v3 = null;
$stmt = sqlsrv_prepare( $conn, "{call test_out( ?, ?, ? )}", array( &$v1, &$v2, array( &$v3, SQLSRV_PARAM_OUT, null, SQLSRV_SQLTYPE_INT )));
$stmt = sqlsrv_prepare($conn, "{call test_out( ?, ?, ? )}", array( &$v1, &$v2, array( &$v3, SQLSRV_PARAM_OUT, null, SQLSRV_SQLTYPE_INT )));
$result = sqlsrv_execute( $stmt );
if( $result === false ) {
print_r( sqlsrv_errors() );
$result = sqlsrv_execute($stmt);
if ($result === false) {
print_r(sqlsrv_errors());
}
while( sqlsrv_next_result( $stmt ) != null );
while (sqlsrv_next_result($stmt) != null);
echo "$v3\n";
sqlsrv_free_stmt( $stmt );
sqlsrv_free_stmt($stmt);
// For output parameters, if neither the php_type nor the sql_type is specified than the variable type is used to determine the php_type.
// php type or sql type is specified, than it is an error case.
$v3 = 3;
$stmt = sqlsrv_prepare( $conn, "{call test_out( ?, ?, ? )}", array( &$v1, &$v2, array( &$v3, SQLSRV_PARAM_OUT, null, null)));
$stmt = sqlsrv_prepare($conn, "{call test_out( ?, ?, ? )}", array( &$v1, &$v2, array( &$v3, SQLSRV_PARAM_OUT, null, null)));
$result = sqlsrv_execute( $stmt );
if( $result === false ) {
print_r( sqlsrv_errors() );
$result = sqlsrv_execute($stmt);
if ($result === false) {
print_r(sqlsrv_errors());
}
while( sqlsrv_next_result( $stmt ) != null );
while (sqlsrv_next_result($stmt) != null);
echo "$v3\n";
sqlsrv_free_stmt( $stmt );
sqlsrv_close( $conn );
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
?>
--EXPECT--
3

View file

@ -5,53 +5,63 @@ maximum size for both nonunicode and unicode data types.
--FILE--
<?php
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
require( 'MsCommon.inc' );
$conn = Connect();
if( !$conn ) {
die( print_r( sqlsrv_errors(), true ));
sqlsrv_configure('WarningsReturnAsErrors', 0);
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
require_once('MsCommon.inc');
$conn = connect();
if (!$conn) {
die(print_r(sqlsrv_errors(), true));
}
$stmt = sqlsrv_query( $conn, "IF OBJECT_ID('test_max_size', 'U') IS NOT NULL DROP TABLE test_max_size");
$stmt = sqlsrv_query( $conn, "CREATE TABLE test_max_size (id int, test_nvarchar nvarchar(4000), test_nchar nchar(4000), test_varchar varchar(8000), test_binary varbinary(8000))" );
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
dropTable($conn, 'test_max_size');
$stmt = sqlsrv_query($conn, "CREATE TABLE test_max_size (id int, test_nvarchar nvarchar(4000), test_nchar nchar(4000), test_varchar varchar(8000), test_binary varbinary(8000))");
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
$stmt = sqlsrv_query( $conn, "INSERT INTO test_max_size (id, test_nvarchar, test_nchar) VALUES (?, ?)",
array( 1, array( "this is a test", SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_NVARCHAR(8000))));
if( $stmt === false ) {
print_r( sqlsrv_errors() );
}
else {
FatalError( "Should have failed (1)." );
$stmt = sqlsrv_query(
$conn,
"INSERT INTO test_max_size (id, test_nvarchar, test_nchar) VALUES (?, ?)",
array( 1, array( "this is a test", SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_NVARCHAR(8000)))
);
if ($stmt === false) {
print_r(sqlsrv_errors());
} else {
fatalError("Should have failed (1).");
}
$stmt = sqlsrv_query( $conn, "INSERT INTO test_max_size (id, test_nchar) VALUES (?, ?)",
array( 2, array( "this is a test", SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_NCHAR(8000))));
if( $stmt === false ) {
print_r( sqlsrv_errors() );
}
else {
FatalError( "Should have failed (2)." );
$stmt = sqlsrv_query(
$conn,
"INSERT INTO test_max_size (id, test_nchar) VALUES (?, ?)",
array( 2, array( "this is a test", SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_NCHAR(8000)))
);
if ($stmt === false) {
print_r(sqlsrv_errors());
} else {
fatalError("Should have failed (2).");
}
$stmt = sqlsrv_query( $conn, "INSERT INTO test_max_size (id, test_varchar) VALUES (?, ?)",
array( 3, array( "this is a test", SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_VARCHAR(8000))));
if( $stmt === false ) {
die( print_r( sqlsrv_errors() ));
$stmt = sqlsrv_query(
$conn,
"INSERT INTO test_max_size (id, test_varchar) VALUES (?, ?)",
array( 3, array( "this is a test", SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_VARCHAR(8000)))
);
if ($stmt === false) {
die(print_r(sqlsrv_errors()));
}
$stmt = sqlsrv_query( $conn, "INSERT INTO test_max_size (id, test_binary) VALUES (?, ?)",
array( 4, array( "this is a test", SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_VARBINARY(8000))));
if( $stmt === false ) {
die( print_r( sqlsrv_errors() ));
$stmt = sqlsrv_query(
$conn,
"INSERT INTO test_max_size (id, test_binary) VALUES (?, ?)",
array( 4, array( "this is a test", SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_VARBINARY(8000)))
);
if ($stmt === false) {
die(print_r(sqlsrv_errors()));
}
$stmt = sqlsrv_query( $conn, "DROP TABLE test_max_size" );
dropTable($conn, 'test_max_size');
echo "Test succeeded.\n";
?>

View file

@ -4,54 +4,57 @@ inserting and retrieving UTF-8 text.
<?php require('skipif.inc'); ?>
--FILE--
<?php
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
sqlsrv_configure('WarningsReturnAsErrors', 0);
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
require( 'MsCommon.inc' );
$c = Connect();
require_once('MsCommon.inc');
$c = connect();
if( $c === false ) {
die( print_r( sqlsrv_errors(), true ));
if ($c === false) {
die(print_r(sqlsrv_errors(), true));
}
$s = sqlsrv_query( $c, "IF OBJECT_ID('utf8test', 'U') IS NOT NULL DROP TABLE utf8test" );
dropTable($c, 'utf8test');
// test a varchar, nvarchar non max, and nvarchar max
$s = sqlsrv_query( $c, "CREATE TABLE utf8test (c1 varchar(100), c2 nvarchar(100), c3 nvarchar(max))");
if( $s === false ) {
die( print_r( sqlsrv_errors(), true ));
$s = sqlsrv_query($c, "CREATE TABLE utf8test (c1 varchar(100), c2 nvarchar(100), c3 nvarchar(max))");
if ($s === false) {
die(print_r(sqlsrv_errors(), true));
}
$utf8 = pack( 'H*', 'efbbbfc5a6c4a5c4afc59d20c790c59f20e1baa120c5a5c499c5a1c5a720e1bb97c69220c399c5a4e282a32d3820c2a2d19be1baa7c599e1bab1c2a2c5a3e1bb81c59520c48fc78ec5a5e1baad' );
$utf8 = pack('H*', 'efbbbfc5a6c4a5c4afc59d20c790c59f20e1baa120c5a5c499c5a1c5a720e1bb97c69220c399c5a4e282a32d3820c2a2d19be1baa7c599e1bab1c2a2c5a3e1bb81c59520c48fc78ec5a5e1baad');
$s = sqlsrv_query( $c, "INSERT INTO utf8test (c1, c2, c3) VALUES (?,?,?)",
$s = sqlsrv_query(
$c,
"INSERT INTO utf8test (c1, c2, c3) VALUES (?,?,?)",
array(
array( &$utf8, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING('utf-8')),
array( &$utf8, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING('utf-8')),
array( &$utf8, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING('utf-8')) ));
if( $s === false ) {
die( print_r( sqlsrv_errors(), true ));
array( &$utf8, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING('utf-8')) )
);
if ($s === false) {
die(print_r(sqlsrv_errors(), true));
}
$s = sqlsrv_query( $c, 'SELECT * FROM utf8test' );
if( $s === false ) {
die( print_r( sqlsrv_errors(), true ));
$s = sqlsrv_query($c, 'SELECT * FROM utf8test');
if ($s === false) {
die(print_r(sqlsrv_errors(), true));
}
if( sqlsrv_fetch( $s ) === false ) {
die( print_r( sqlsrv_errors(), true ));
if (sqlsrv_fetch($s) === false) {
die(print_r(sqlsrv_errors(), true));
}
$u = sqlsrv_get_field( $s, 1, SQLSRV_PHPTYPE_STREAM( 'utf-8' ));
if( $u === false ) {
die( print_r( sqlsrv_errors(), true ));
$u = sqlsrv_get_field($s, 1, SQLSRV_PHPTYPE_STREAM('utf-8'));
if ($u === false) {
die(print_r(sqlsrv_errors(), true));
}
$utf8_2 = fread( $u, 10000 );
if( $utf8 != $utf8_2 ) {
FatalError( "round trip failed" );
$utf8_2 = fread($u, 10000);
if ($utf8 != $utf8_2) {
fatalError("round trip failed");
}
$stmt = sqlsrv_query( $c, "DROP TABLE utf8test" );
dropTable($c, 'utf8test');
echo "Test succeeded\n";

View file

@ -4,99 +4,99 @@ inserting UTF-8 text via a PHP and error conditions.
<?php require('skipif.inc'); ?>
--FILE--
<?php
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
sqlsrv_configure('WarningsReturnAsErrors', 0);
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
require( 'MsCommon.inc' );
$conn = Connect();
require_once('MsCommon.inc');
$conn = connect();
if( !$conn ) {
FatalError( "Failed to connect." );
if (!$conn) {
fatalError("Failed to connect.");
}
$stmt = sqlsrv_prepare( $conn, "IF OBJECT_ID('test_params', 'U') IS NOT NULL DROP TABLE test_params" );
sqlsrv_execute( $stmt );
sqlsrv_free_stmt( $stmt );
$stmt = sqlsrv_prepare( $conn, "CREATE TABLE test_params (id tinyint, name char(10), [double] float, stuff varchar(max))" );
sqlsrv_execute( $stmt );
sqlsrv_free_stmt( $stmt );
$stmt = sqlsrv_prepare($conn, "IF OBJECT_ID('test_params', 'U') IS NOT NULL DROP TABLE test_params");
sqlsrv_execute($stmt);
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_prepare($conn, "CREATE TABLE test_params (id tinyint, name char(10), [double] float, stuff varchar(max))");
sqlsrv_execute($stmt);
sqlsrv_free_stmt($stmt);
$f1 = 1;
$f2 = "testtestte";
$f3 = 12.0;
$f4 = fopen( "data://text/plain,This%20is%20some%20text%20meant%20to%20test%20binding%20parameters%20to%20streams", "r" );
$stmt = sqlsrv_prepare( $conn, "INSERT INTO test_params (id, name, [double], stuff) VALUES (?, ?, ?, ?)", array( &$f1, "testtestte", &$f3,
$f4 = fopen("data://text/plain,This%20is%20some%20text%20meant%20to%20test%20binding%20parameters%20to%20streams", "r");
$stmt = sqlsrv_prepare($conn, "INSERT INTO test_params (id, name, [double], stuff) VALUES (?, ?, ?, ?)", array( &$f1, "testtestte", &$f3,
array( &$f4, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM('utf-8') ))); //,
if( !$stmt ) {
var_dump( sqlsrv_errors() );
FatalError( "sqlsrv_prepare failed." );
if (!$stmt) {
var_dump(sqlsrv_errors());
fatalError("sqlsrv_prepare failed.");
}
$success = sqlsrv_execute( $stmt );
$success = sqlsrv_execute($stmt);
// test UTF-8 cutoff in the middle of a valid 3 byte UTF-8 char
$utf8 = str_repeat( "41", 8188 );
$utf8 = str_repeat("41", 8188);
$utf8 = $utf8 . "e38395";
$utf8 = pack( "H*", $utf8 );
$f4 = fopen( "data://text/plain," . $utf8, "r" );
$utf8 = pack("H*", $utf8);
$f4 = fopen("data://text/plain," . $utf8, "r");
$success = sqlsrv_execute( $stmt );
if( $success === false ) {
die( print_r( sqlsrv_errors(), true ));
$success = sqlsrv_execute($stmt);
if ($success === false) {
die(print_r(sqlsrv_errors(), true));
}
// test a 2 byte incomplete character
$utf8 = str_repeat( "41", 8188 );
$utf8 = str_repeat("41", 8188);
$utf8 = $utf8 . "dfa0";
$utf8 = pack( "H*", $utf8 );
$f4 = fopen( "data://text/plain," . $utf8, "r" );
$utf8 = pack("H*", $utf8);
$f4 = fopen("data://text/plain," . $utf8, "r");
$success = sqlsrv_execute( $stmt );
if( $success === false ) {
die( print_r( sqlsrv_errors(), true ));
$success = sqlsrv_execute($stmt);
if ($success === false) {
die(print_r(sqlsrv_errors(), true));
}
// test a 4 byte incomplete character
$utf8 = str_repeat( "41", 8186 );
$utf8 = str_repeat("41", 8186);
$utf8 = $utf8 . "f1a680bf";
$utf8 = pack( "H*", $utf8 );
$f4 = fopen( "data://text/plain," . $utf8, "r" );
$utf8 = pack("H*", $utf8);
$f4 = fopen("data://text/plain," . $utf8, "r");
$success = sqlsrv_execute( $stmt );
if( $success === false ) {
die( print_r( sqlsrv_errors(), true ));
$success = sqlsrv_execute($stmt);
if ($success === false) {
die(print_r(sqlsrv_errors(), true));
}
// test UTF-8 cutoff (really cutoff)
$utf8 = str_repeat( "41", 8188 );
$utf8 = str_repeat("41", 8188);
$utf8 = $utf8 . "e383";
$utf8 = pack( "H*", $utf8 );
$f4 = fopen( "data://text/plain," . $utf8, "r" );
$utf8 = pack("H*", $utf8);
$f4 = fopen("data://text/plain," . $utf8, "r");
$success = sqlsrv_execute( $stmt );
if( $success !== false ) {
FatalError( 'Should have failed with a cutoff UTF-8 string' );
$success = sqlsrv_execute($stmt);
if ($success !== false) {
fatalError('Should have failed with a cutoff UTF-8 string');
}
print_r( sqlsrv_errors() );
print_r(sqlsrv_errors());
// test UTF-8 invalid/corrupt stream
$utf8 = str_repeat( "41", 8188 );
$utf8 = str_repeat("41", 8188);
$utf8 = $utf8 . "e38395e38395";
$utf8 = substr_replace( $utf8, "fe", 1000, 2 );
$utf8 = pack( "H*", $utf8 );
$f4 = fopen( "data://text/plain," . $utf8, "r" );
$utf8 = substr_replace($utf8, "fe", 1000, 2);
$utf8 = pack("H*", $utf8);
$f4 = fopen("data://text/plain," . $utf8, "r");
$success = sqlsrv_execute( $stmt );
if( $success !== false ) {
FatalError( 'Should have failed with an invalid UTF-8 string' );
$success = sqlsrv_execute($stmt);
if ($success !== false) {
fatalError('Should have failed with an invalid UTF-8 string');
}
print_r( sqlsrv_errors() );
print_r(sqlsrv_errors());
$stmt = sqlsrv_query( $conn, "DROP TABLE test_params" );
$stmt = sqlsrv_query($conn, "DROP TABLE test_params");
sqlsrv_free_stmt( $stmt );
sqlsrv_close( $conn );
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
echo "Test succeeded\n";

View file

@ -5,40 +5,42 @@ warnings for non reference variables.
--FILE--
<?php
sqlsrv_configure( 'WarningsReturnAsErrors', false );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
sqlsrv_configure('WarningsReturnAsErrors', false);
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
require( 'MsCommon.inc' );
$conn = Connect();
if( !$conn ) {
FatalError( "sqlsrv_connect failed." );
require_once('MsCommon.inc');
$conn = connect();
if (!$conn) {
fatalError("sqlsrv_connect failed.");
}
$stmt = sqlsrv_query( $conn, "IF OBJECT_ID('test_empty_stream', 'U') IS NOT NULL DROP TABLE test_empty_stream" );
if( $stmt !== false ) sqlsrv_free_stmt( $stmt );
$stmt = sqlsrv_query($conn, "IF OBJECT_ID('test_empty_stream', 'U') IS NOT NULL DROP TABLE test_empty_stream");
if ($stmt !== false) {
sqlsrv_free_stmt($stmt);
}
$stmt = sqlsrv_query( $conn, "CREATE TABLE test_empty_stream (id int, varchar_stream varchar(max), varbinary_stream varbinary(max))");
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
$stmt = sqlsrv_query($conn, "CREATE TABLE test_empty_stream (id int, varchar_stream varchar(max), varbinary_stream varbinary(max))");
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
$f1 = 1;
$f2 = fopen( "data://text/plain,", "r" );
$stmt = sqlsrv_prepare( $conn, "INSERT INTO test_empty_stream (id, varchar_stream, varbinary_stream) VALUES (?, ?, ?)", array( $f1, array( $f2, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM('binary'), SQLSRV_SQLTYPE_VARCHAR('max') ),
fopen( "data://text/plain,This%20is%20some%20text%20meant%20to%20test%20binding%20parameters%20to%20streams", "r" )));
if( $stmt === false ) {
print_r( "sqlsrv_prepare failed." );
print_r( sqlsrv_errors() );
$f2 = fopen("data://text/plain,", "r");
$stmt = sqlsrv_prepare($conn, "INSERT INTO test_empty_stream (id, varchar_stream, varbinary_stream) VALUES (?, ?, ?)", array( $f1, array( $f2, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM('binary'), SQLSRV_SQLTYPE_VARCHAR('max') ),
fopen("data://text/plain,This%20is%20some%20text%20meant%20to%20test%20binding%20parameters%20to%20streams", "r")));
if ($stmt === false) {
print_r("sqlsrv_prepare failed.");
print_r(sqlsrv_errors());
}
$result = sqlsrv_execute($stmt);
if( $result === false ) {
print_r( "sqlsrv_execute(3) failed\n" );
print_r( sqlsrv_errors() );
if ($result === false) {
print_r("sqlsrv_execute(3) failed\n");
print_r(sqlsrv_errors());
}
$stmt = sqlsrv_query( $conn, "DROP TABLE test_empty_stream" );
sqlsrv_close( $conn );
$stmt = sqlsrv_query($conn, "DROP TABLE test_empty_stream");
sqlsrv_close($conn);
?>
--EXPECTREGEX--
sqlsrv_execute\(3\) failed
@ -64,4 +66,4 @@ Array
\[message\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]\[SQL Server\]Statement\(s\) could not be prepared\.
\)
\)
\)

View file

@ -5,48 +5,51 @@ Invalid UTF-16 coming from the server
--FILE--
<?php
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
sqlsrv_configure('WarningsReturnAsErrors', 0);
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
// For testing in Azure, can not switch databases
require( 'MsCommon.inc' );
$conn = Connect();
if( !$conn ) {
var_dump( sqlsrv_errors() );
require_once('MsCommon.inc');
$conn = connect();
if (!$conn) {
var_dump(sqlsrv_errors());
}
$s = sqlsrv_query( $conn, "IF OBJECT_ID('utf16invalid', 'U') IS NOT NULL DROP TABLE utf16invalid" );
$s = sqlsrv_query( $conn, "CREATE TABLE utf16invalid (id int identity, c1 nvarchar(100))");
if( $s === false ) {
die( print_r( sqlsrv_errors(), true ));
$s = sqlsrv_query($conn, "IF OBJECT_ID('utf16invalid', 'U') IS NOT NULL DROP TABLE utf16invalid");
$s = sqlsrv_query($conn, "CREATE TABLE utf16invalid (id int identity, c1 nvarchar(100))");
if ($s === false) {
die(print_r(sqlsrv_errors(), true));
}
// 0xdc00,0xdbff is an invalid surrogate pair
$invalid_utf16 = pack( "H*", '410042004300440000DCFFDB45004600' );
$invalid_utf16 = pack("H*", '410042004300440000DCFFDB45004600');
$s = sqlsrv_query( $conn, "INSERT INTO utf16invalid (c1) VALUES (?)",
$s = sqlsrv_query(
$conn,
"INSERT INTO utf16invalid (c1) VALUES (?)",
array(
array( &$invalid_utf16, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY)) ));
if( $s === false ) {
die( print_r( sqlsrv_errors(), true ));
array( &$invalid_utf16, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY)) )
);
if ($s === false) {
die(print_r(sqlsrv_errors(), true));
}
$s = sqlsrv_query( $conn, 'SELECT * FROM utf16invalid' );
if( $s === false ) {
die( print_r( sqlsrv_errors(), true ));
$s = sqlsrv_query($conn, 'SELECT * FROM utf16invalid');
if ($s === false) {
die(print_r(sqlsrv_errors(), true));
}
sqlsrv_fetch( $s );
sqlsrv_fetch($s);
$utf8 = sqlsrv_get_field( $s, 1, SQLSRV_PHPTYPE_STRING('utf-8') );
if( $utf8 !== false ) {
FatalError( 'sqlsrv_get_field should have failed with an error.' );
$utf8 = sqlsrv_get_field($s, 1, SQLSRV_PHPTYPE_STRING('utf-8'));
if ($utf8 !== false) {
fatalError('sqlsrv_get_field should have failed with an error.');
}
print_r( sqlsrv_errors() );
print_r(sqlsrv_errors());
$drop_proc = "DROP PROCEDURE Utf16InvalidOut";
$s = sqlsrv_query( $conn, $drop_proc );
$s = sqlsrv_query($conn, $drop_proc);
$create_proc = <<<PROC
CREATE PROCEDURE Utf16InvalidOut
@ -57,25 +60,28 @@ BEGIN
END;
PROC;
$s = sqlsrv_query( $conn, $create_proc );
if( $s === false ) {
die( print_r( sqlsrv_errors(), true ));
$s = sqlsrv_query($conn, $create_proc);
if ($s === false) {
die(print_r(sqlsrv_errors(), true));
}
$invalid_utf16_out = "";
$s = sqlsrv_query( $conn, "{call Utf16InvalidOut(?)}",
array( array( &$invalid_utf16_out, SQLSRV_PARAM_OUT, SQLSRV_PHPTYPE_STRING('utf-8'), SQLSRV_SQLTYPE_NVARCHAR(25)) ));
if( $s !== false ) {
$s = sqlsrv_query(
$conn,
"{call Utf16InvalidOut(?)}",
array( array( &$invalid_utf16_out, SQLSRV_PARAM_OUT, SQLSRV_PHPTYPE_STRING('utf-8'), SQLSRV_SQLTYPE_NVARCHAR(25)) )
);
if ($s !== false) {
echo "invalid utf16:<$invalid_utf16_out>\n";
FatalError( 'sqlsrv_query should have failed with an error' );
fatalError('sqlsrv_query should have failed with an error');
}
print_r( sqlsrv_errors() );
print_r(sqlsrv_errors());
sqlsrv_query( $conn, "DROP TABLE utf16invalid" );
sqlsrv_query( $conn, $drop_proc );
sqlsrv_query($conn, "DROP TABLE utf16invalid");
sqlsrv_query($conn, $drop_proc);
sqlsrv_close( $conn );
sqlsrv_close($conn);
echo "Test succeeded.\n";
?>

View file

@ -8,1339 +8,448 @@
*/
$useUTF8data = false;
require_once('MsHelper.inc');
require_once('MsSetup.inc');
function IsWindows()
$usingUTF8data = false;
function isWindows()
{
// This method returns TRUE when running in a Windows platform
// This method returns TRUE when running in a Windows platform
// The possible values are WIN32, WINNT and Windows
return (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN');
}
function UseUTF8Data()
function useUTF8Data()
{
global $useUTF8data;
return $useUTF8data;
global $usingUTF8data;
return $usingUTF8data;
}
function SetUTF8Data($val)
function setUTF8Data($val)
{
global $useUTF8data;
$useUTF8data = $val;
global $usingUTF8data;
$usingUTF8data = $val;
}
function TestMode()
function testMode()
{
$testMode = getenv('PHPT_EXEC');
return ($testMode ? true : false);
}
function TraceMode()
function traceMode()
{
include 'MsSetup.inc';
return ((!TestMode() && $traceEnabled) ? true : false);
global $traceEnabled;
return ((!testMode() && $traceEnabled) ? true : false);
}
function Trace($msg)
function trace($msg)
{
if (TraceMode())
{
if (traceMode()) {
echo $msg;
}
}
function TraceData($sqlType, $data)
/**
* This method prints the message when traceMode() is true
*
* @param  string  $msg
* @return void
*/
function traceData($sqlType, $data)
{
if (TraceMode())
{
if (traceMode()) {
$msg = strtoupper(" $sqlType:");
echo "$msg\t";
if (strlen($msg) <= 7)
{
if (strlen($msg) <= 7) {
echo "\t";
}
if (strlen($msg) <= 15)
{
if (strlen($msg) <= 15) {
echo "\t";
}
echo "$data\n"
;
echo "$data\n";
}
}
function IsMarsSupported()
function isMarsSupported()
{
include 'MsSetup.inc';
global $marsMode;
return ($marsMode ? true : false);
}
function IsDaasMode()
function isDaasMode()
{
include 'MsSetup.inc';
global $daasMode;
return ($daasMode ? true : false);
}
function IsAEQualified($conn)
// function isAEQualified($conn)
// {
// $msodbcsql_ver = sqlsrv_client_info($conn)['DriverVer'];
// $server_ver = sqlsrv_server_info($conn)['SQLServerVersion'];
// $msodbcsql_maj = explode(".", $msodbcsql_ver)[0];
// $msodbcsql_min = explode(".", $msodbcsql_ver)[1];
// if ($msodbcsql_maj < 17 || explode('.', $server_ver)[0] < 13) {
// return false;
// }
// return true;
// }
function startTest($testName)
{
$msodbcsql_ver = sqlsrv_client_info($conn)['DriverVer'];
$server_ver = sqlsrv_server_info($conn)['SQLServerVersion'];
$msodbcsql_maj = explode(".", $msodbcsql_ver)[0];
$msodbcsql_min = explode(".", $msodbcsql_ver)[1];
if ($msodbcsql_maj < 17 || explode('.', $server_ver)[0] < 13)
return false;
return true;
if (traceMode()) {
echo "Starting \"$testName\" test...\n\n";
}
}
function StartTest($testName)
/**
* This method signals the end of a test given its name
*
* @return void
*/
function endTest($testName)
{
include 'MsSetup.inc';
if (TraceMode())
{
echo "$PhpDriver: starting \"$testName\" test...\n\n";
}
if (!extension_loaded("sqlsrv"))
{
die("$PhpDriver cannot be loaded.");
}
// Set timezone
$tz = ini_get('date.timezone');
if (strcmp($tz, "") == 0)
{
date_default_timezone_set('America/Los_Angeles');
$tz = date_default_timezone_get();
}
Trace("Timezone: $tz.\n");
}
function EndTest($testName)
{
include 'MsSetup.inc';
if (TraceMode())
{
echo "\n$PhpDriver: ";
}
echo "Test \"$testName\" completed successfully.\n";
}
function Setup()
function setup()
{
set_time_limit(0);
sqlsrv_configure('LogSubsystems', SQLSRV_LOG_SYSTEM_OFF);
sqlsrv_configure('WarningsReturnAsErrors', 1);
}
function Configure($param, $expected)
function configure($param, $expected)
{
sqlsrv_configure($param, $expected);
$actual = sqlsrv_get_config($param);
if ($actual == $expected)
{
Trace("Set configuration parameter $param = $actual.\n");
}
else
{
die("Failed to set configuration parameter $param = $expected.");
if ($actual == $expected) {
trace("Set configuration parameter $param = $actual.\n");
} else {
die("Failed to set configuration parameter $param = $expected.");
}
}
function ConnectUTF8()
function connect($options = array())
{
return Connect(array( 'CharacterSet'=>'UTF-8' ));
}
include('MsSetup.inc');
function Connect($options = array())
{
include 'MsSetup.inc';
if (sizeof($options) > 0)
{
if (sizeof($options) > 0) {
$connectionOptions = array_merge($connectionOptions, $options);
}
Trace("Attempting connection to $server...");
trace("Attempting connection to $server...");
$conn = sqlsrv_connect($server, $connectionOptions);
if ($conn === false)
{
FatalError("Failed to connect to $server.");
if ($conn === false) {
fatalError("Failed to connect to $server.");
}
Trace(" successfully connected.\n\n");
trace(" successfully connected.\n\n");
return ($conn);
}
/**
* Connect to the database specified in MsSetup.inc; Column Encryption options automatically added when $keystore is not none
* @param array $options : connection attributes to pass to sqlsrv_connect
* @param bool $disableCE : flag for disabling column encryption even when keystore is NOT none
* for testing fetching encrypted data when connection column encryption is off
* @return connection resource
*/
function ae_connect( $options = array(), $disableCE = false )
function getTempTableName($table = '', $temporary = true)
{
require 'MsSetup.inc';
if ( sizeof( $options ) > 0 )
{
$connectionOptions = array_merge( $connectionOptions, $options );
}
if ( $keystore != "none" && !$disableCE )
{
$connectionOptions = array_merge( $connectionOptions, array( "ColumnEncryption" => "Enabled" ));
}
if ( $keystore == "ksp" && !$disableCE )
{
require( 'AE_Ksp.inc' );
$ksp_path = getKSPPath();
$ksp_options = array( "CEKeystoreProvider"=>$ksp_path, "CEKeystoreName"=>$ksp_name, "CEKeystoreEncryptKey"=>$encrypt_key );
$connectionOptions = array_merge( $connectionOptions, $ksp_options );
}
$conn = sqlsrv_connect( $server, $connectionOptions );
if ( $conn === false )
FatalError( "Failed to connect to $server." );
return $conn;
}
/**
* @return string CEK name depending on the connection keywords
*/
function getCekName()
{
require 'MsSetup.inc';
$cekName = '';
switch ( $keystore ) {
case "none":
$cekName = '';
break;
case "win":
$cekName = 'AEColumnKey';
break;
case "ksp":
$cekName = 'CustomCEK';
break;
case "akv":
$cekName = 'AKVColumnKey';
break;
default:
echo "getCekName: Invalid keystore name.\n";
}
return $cekName;
}
/**
* class for encapsulating column metadata needed for creating a table
*/
class columnMeta {
public $colName;
public $dataType; //a string that includes the size of the type if necessary (e.g., decimal(10,5))
public $encType; //randomized or deterministic; default is deterministic
public $options; //a string that is null by default (e.g. NOT NULL Identity (1,1) )
function __construct( $dataType, $colName = null, $options = null, $encType = "deterministic" )
{
if ( is_null( $colName ))
{
$this->colName = get_default_colname( $dataType );
}
else
{
$this->colName = $colName;
}
$this->dataType = $dataType;
$this->encType = $encType;
$this->options = $options;
}
/**
* @return string column definition for creating a table
*/
function getColDef()
{
require 'MsSetup.inc';
$append = " ";
// an identity column is not encrypted because a select query with identity column as the where clause is often run and the user want to have to bind parameter every time
if ( $keystore != "none" && stripos( $this->options, "identity" ) === false )
{
$cekName = getCekName();
if ( stripos( $this->dataType, "char" ) !== false )
$append .= "COLLATE Latin1_General_BIN2 ";
$append .= sprintf( "ENCRYPTED WITH (ENCRYPTION_TYPE = %s, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = $cekName) ", $this->encType );
}
$append .= $this->options;
$colDef = "[" . $this->colName . "] " . $this->dataType . $append;
return $colDef;
}
}
/**
* @return string default column name when a name is not provided in the columnMeta class
*/
function get_default_colname( $dataType )
{
$colName = "c_" . str_replace( ",", "_", str_replace( "(", "_", $dataType ));
$colName = rtrim( $colName, ")" );
return $colName;
}
/**
* Create a table
* @param object $conn : PDO connection object
* @param string $tbname : name of the table to be created
* @param array $columnMetaArr : array of columnMeta objects, which contain metadata for one column
*/
function create_table( $conn, $tbname, $columnMetaArr )
{
DropTable( $conn, $tbname );
$colDef = "";
foreach ( $columnMetaArr as $meta )
{
$colDef = $colDef . $meta->getColDef() . ", ";
}
$colDef = rtrim( $colDef, ", " );
$createSql = "CREATE TABLE $tbname ( $colDef )";
sqlsrv_query( $conn, $createSql );
}
/**
* class for encapsulating optional parameters for binding parameters in sqlsrv_prepare
*/
class bindParamOption {
public $index; //1-based index of the parameter
public $direction; //SQLSRV_PARAM_ constant indicating the parameter direction
public $phpType; //SQLSRV_PHPTYPE_ constant specifying the php type of the return values
public $sqlType; //SQLSRV_SQLTYPE_ constant specifying the SQL type of the input
function __construct( $index, $direction = null, $phpType = null, $sqlType = null )
{
$this->index = $index;
$this->direction = $direction;
$this->phpType = $phpType;
$this->sqlType = $sqlType;
}
/**
* @param resource $conn : connection resource
* @param mix $var : variable to bind to the SQL statement parameter
* @return array needed to bind parameter in sqlsrv_prepare
*/
function bindParamArr( $var )
{
// get the constant values of direction, phpType, and sqlType
$direction = null;
$phpType = null;
$sqlType = null;
if ( $this->direction )
$direction = constant( $this->direction );
if ( $this->phpType )
$phpType = constant( $this->phpType );
if ( $this->sqlType )
{
// parse out the datatype name, size, precision, and/or scale from a SQLSRV_SQLTYPE_ constant
$size = null;
$prec = null;
$scal = null;
$type_size = explode( "(", $this->sqlType );
$type = $type_size[0];
if ( count( $type_size ) > 1 )
{
$size = $type_size[1];
$prec_scal = explode( ",", $size );
if ( count( $prec_scal ) > 1 )
{
$prec = $prec_scal[0];
$scal = rtrim( $prec_scal[1], ")" );
$size = null;
}
}
// get the sqlType constant
if ( $prec && $scal )
$sqlType = call_user_func( $type, $prec, $scal );
elseif ( $size )
$sqlType = call_user_func( $type, $size );
else
$sqlType = constant( $type );
}
return array( $var, $direction, $phpType, $sqlType );
}
}
/**
* Insert a row into a table
* @param object $conn : PDO connection object
* @param string $tbname : name of the table for the row to be inserted
* @param array $inputs : an associative array column name and its value
* @param bool $r : true if the row was successfully inserted, otherwise false. Default value is null to make this parameter optional.
* $param string $api : SQLSRV API used for executing the insert query
* accepted values: "query", "queryParamsOp", "prepare", "prepareParamsOp"
* @param array $paramOption : an array of bindParamOptions. Should only be provided if $api is "perpareWithParamOp", if provided, has to be in the same order as $inputs
* @return object PDOStatement object of the insert statement
*/
function insert_row( $conn, $tbname, $inputs, &$r = null, $api = "query", $paramOption = array() )
{
require 'MsSetup.inc';
$stmt = null;
if ( $keystore == "none" && $api != "queryParamsOp" && $api != "prepareParamsOp" )
{
$insertSql = get_insertSql_complete( $tbname, $inputs );
switch ( $api ) {
case "query":
$stmt = sqlsrv_query( $conn, $insertSql );
break;
case "prepare":
$stmt = sqlsrv_prepare( $conn, $insertSql );
$r = sqlsrv_execute( $stmt );
break;
}
}
else
{
// if AE is on, must bind param
$insertSql = get_insertSql_placeholders( $tbname, $inputs );
$params = array();
if ( empty( $paramOption ))
{
foreach ( $inputs as $key => $value )
{
array_push($params, $inputs[$key] );
}
}
else
{
$i = 1;
foreach( $inputs as $key => $value )
{
$nooption = true;
foreach( $paramOption as $op )
{
if ( $op->index == $i )
{
array_push( $params, $op->bindParamArr( $inputs[$key] ));
$nooption = false;
$i++;
break;
}
}
if ( $nooption )
{
array_push( $params, $inputs[$key] );
$i++;
}
}
}
if ( $keystore != "none" || $api == "prepareParamsOp" )
{
$stmt = sqlsrv_prepare( $conn, $insertSql, $params );
$r = sqlsrv_execute( $stmt );
}
else
$stmt = sqlsrv_query( $conn, $insertSql, $params );
}
return $stmt;
}
/**
* @param string $tbname : name of the table for an insert sql
* @param array $input : associative array containing a key value pair of column name and data to put into an insert sql string
* @return string a complete insert sql string
*/
function get_insertSql_complete( $tbname, $inputs )
{
$colStr = "INSERT INTO $tbname (";
$valStr = "VALUES (";
if ( empty( $inputs ))
{
echo "get_insertSql_complete: inputs for inserting a row cannot be empty.\n";
return;
}
foreach( $inputs as $key => $value )
{
$colStr .= $key . ", ";
if ( is_null( $value ))
echo "get_insertSql_complete: value provided for input $value is null.\n";
elseif ( is_string( $value ))
$valStr .= "'" . $value . "', ";
else
$valStr .= $value . ", ";
}
$colStr = rtrim( $colStr, ", " ) . ") ";
$valStr = rtrim( $valStr, ", " ) . ") ";
$insertSql = $colStr . $valStr;
return $insertSql;
}
/**
* @param string $tbname : name of the table for an insert sql
* @param array $inputs : associative array containing a key value pair of column name and data to put into an insert sql string
* @return string an insert sql string with "?" placeholders for all values
*/
function get_insertSql_placeholders( $tbname, $inputs )
{
$colStr = "INSERT INTO $tbname (";
$valStr = "VALUES (";
if ( empty( $inputs ))
{
echo "get_insertSql_placeholders: inputs for inserting a row cannot be empty.\n";
return;
}
foreach( $inputs as $key => $value )
{
$colStr .= $key . ", ";
}
$colStr = rtrim( $colStr, ", " ) . ") ";
$valStr .= get_seq_placeholders( count( $inputs )) . ") ";
$insertSql = $colStr . $valStr;
return $insertSql;
}
/**
* @param string $spname : name of the stored procedure
* @param int $num : number of parameters needed for the stored procedure
* @return string a call stored procedure sql string with "?" placeholders for all parameters
*/
function get_callProcSql_placeholders( $spname, $num )
{
$callStr = "{CALL $spname (";
$callStr .= get_seq_placeholders( $num ) . ")} ";
return $callStr;
}
/**
* @param int $num : number of placeholders needed
* @return string a string containing $num number of repeated "?" placeholders delimited by ", "
*/
function get_seq_placeholders( $num )
{
if ( $num < 0 )
{
echo "get_seq_placeholders: num provided for creating a sequence of placeholders cannot be less than 0.\n";
return;
}
$placeholderStr = str_repeat( "?, ", $num );
$placeholderStr = rtrim( $placeholderStr, ", " );
return $placeholderStr;
}
/**
* Fetch all rows and all columns given a table name, and print them
* @param resource $conn : connection resource
* @param string $tbname : name of the table to fetch from
*/
function fetch_all( $conn, $tbname )
{
$sql = "SELECT * FROM $tbname";
$stmt = sqlsrv_query( $conn, $sql );
while ( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC ))
{
foreach ( $row as $key => $value )
{
if ( is_object( $value ) )
{
print "$key:\n";
foreach ( $value as $k =>$v )
{
print ( " $k: $v\n" );
}
}
else
print ( "$key: $value\n" );
}
}
}
/**
* @return bool false if $keystore specified in MsSetup.inc is none, otherwise return true
*/
function is_col_enc()
{
require 'MsSetup.inc';
if ( $keystore == "none" )
return false;
else
return true;
}
function GetTempTableName($table = '', $temporary = true)
{
// A temporary table name with the '#' prefix will be automatically
// dropped once the connection is closed. Otherwise, the caller
// A temporary table name with the '#' prefix will be automatically
// dropped once the connection is closed. Otherwise, the caller
// should take care of dropping the temp table afterwards.
$someNumber = rand(0, 1000);
$prefix = '';
if ($temporary)
if ($temporary) {
$prefix = '#';
if (strlen($table) == 0)
}
if (strlen($table) == 0) {
$table = 'php_test_table';
}
return $prefix . $table . '_' . $someNumber;
}
function GetTempProcName($proc = '', $temporary = true)
function getTempProcName($proc = '', $temporary = true)
{
// A temporary stored procedure name with the '#' prefix will be
// automatically dropped once the connection is closed. Otherwise,
// the caller should take care of dropping the temp procedure afterwards.
// A temporary stored procedure name with the '#' prefix will be
// automatically dropped once the connection is closed. Otherwise,
// the caller should take care of dropping the temp procedure afterwards.
$someNumber = rand(0, 1000);
$prefix = '';
if ($temporary)
if ($temporary) {
$prefix = '#';
if (strlen($proc) == 0)
$proc = 'php_test_proc';
}
if (strlen($proc) == 0) {
$proc = 'php_test_proc';
}
return $prefix . $proc . '_' . $someNumber;
}
function ExecuteQuery($conn, $query)
function executeQuery($conn, $query)
{
$stmt = sqlsrv_query($conn, $query);
if ($stmt === false)
{
FatalError("Query execution failed: $query");
if ($stmt === false) {
fatalError("Query execution failed: $query");
}
return ($stmt);
}
function PrepareQuery($conn, $query)
function prepareQuery($conn, $query)
{
$stmt = sqlsrv_prepare($conn, $query);
if ($stmt === false)
{
FatalError("Query preparation failed: $query");
if ($stmt === false) {
fatalError("Query preparation failed: $query");
}
return ($stmt);
}
function ExecuteQueryEx($conn, $query, $modeDirect)
function executeQueryEx($conn, $query, $modeDirect)
{
if ($modeDirect)
{ // direct execution
if ($modeDirect) { // direct execution
$stmt = sqlsrv_query($conn, $query);
}
else
{
$stmt = PrepareQuery($conn, $query);
} else {
$stmt = prepareQuery($conn, $query);
sqlsrv_execute($stmt);
}
return ($stmt);
}
function GetSqlType($k)
function createTable($conn, $tableName)
{
switch ($k)
{
case 1: return ("int");
case 2: return ("tinyint");
case 3: return ("smallint");
case 4: return ("bigint");
case 5: return ("bit");
case 6: return ("float");
case 7: return ("real");
case 8: return ("decimal(28,4)");
case 9: return ("numeric(32,4)");
case 10: return ("money");
case 11: return ("smallmoney");
case 12: return ("char(512)");
case 13: return ("varchar(512)");
case 14: return ("varchar(max)");
case 15: return ("nchar(512)");
case 16: return ("nvarchar(512)");
case 17: return ("nvarchar(max)");
case 18: return ("text");
case 19: return ("ntext");
case 20: return ("binary(512)");
case 21: return ("varbinary(512)");
case 22: return ("varbinary(max)");
case 23: return ("image");
case 24: return ("uniqueidentifier");
case 25: return ("datetime");
case 26: return ("smalldatetime");
case 27: return ("timestamp");
case 28: return ("xml");
default: break;
}
return ("udt");
}
function GetDriverType($k, $dataSize)
{
switch ($k)
{
case 1: return (SQLSRV_SQLTYPE_INT);
case 2: return (SQLSRV_SQLTYPE_TINYINT);
case 3: return (SQLSRV_SQLTYPE_SMALLINT);
case 4: return (SQLSRV_SQLTYPE_BIGINT);
case 5: return (SQLSRV_SQLTYPE_BIT);
case 6: return (SQLSRV_SQLTYPE_FLOAT);
case 7: return (SQLSRV_SQLTYPE_REAL);
case 8: return (SQLSRV_SQLTYPE_DECIMAL(28, 4));
case 9: return (SQLSRV_SQLTYPE_NUMERIC(32, 4));
case 10: return (SQLSRV_SQLTYPE_MONEY);
case 11: return (SQLSRV_SQLTYPE_SMALLMONEY);
case 12: return (SQLSRV_SQLTYPE_CHAR($dataSize));
case 13: return (SQLSRV_SQLTYPE_VARCHAR($dataSize));
case 14: return (SQLSRV_SQLTYPE_VARCHAR('max'));
case 15: return (SQLSRV_SQLTYPE_NCHAR($dataSize));
case 16: return (SQLSRV_SQLTYPE_NVARCHAR($dataSize));
case 17: return (SQLSRV_SQLTYPE_NVARCHAR('max'));
case 18: return (SQLSRV_SQLTYPE_TEXT);
case 19: return (SQLSRV_SQLTYPE_NTEXT);
case 20: return (SQLSRV_SQLTYPE_BINARY($dataSize));
case 21: return (SQLSRV_SQLTYPE_VARBINARY($dataSize));
case 22: return (SQLSRV_SQLTYPE_VARBINARY('max'));
case 23: return (SQLSRV_SQLTYPE_IMAGE);
case 24: return (SQLSRV_SQLTYPE_UNIQUEIDENTIFIER);
case 25: return (SQLSRV_SQLTYPE_DATETIME);
case 26: return (SQLSRV_SQLTYPE_SMALLDATETIME);
case 27: return (SQLSRV_SQLTYPE_TIMESTAMP);
case 28: return (SQLSRV_SQLTYPE_XML);
default: break;
}
return (SQLSRV_SQLTYPE_UDT);
}
function IsXml($k)
{
switch ($k)
{
case 28: return (true); // xml
default: break;
}
return (false);
}
function IsStreamable($k)
{
switch ($k)
{
case 12: return (true); // nchar(512)
case 13: return (true); // varchar(512)
case 14: return (true); // varchar(max)
case 15: return (true); // nchar(512)
case 16: return (true); // nvarchar(512)
case 17: return (true); // nvarchar(max)
case 18: return (true); // text
case 19: return (true); // ntext
case 20: return (true); // binary
case 21: return (true); // varbinary(512)
case 22: return (true); // varbinary(max)
case 23: return (true); // image
case 28: return (true); // xml
default: break;
}
return (false);
}
function IsNumeric($k)
{
switch ($k)
{
case 1: return (true); // int
case 2: return (true); // tinyint
case 3: return (true); // smallint
case 4: return (true); // bigint
case 5: return (true); // bit
case 6: return (true); // float
case 7: return (true); // real
case 8: return (true); // decimal(28,4)
case 9: return (true); // numeric(32,4)
case 10: return (true); // money
case 11: return (true); // smallmoney
default: break;
}
return (false);
}
function IsChar($k)
{
switch ($k)
{
case 12: return (true); // nchar(512)
case 13: return (true); // varchar(512)
case 14: return (true); // varchar(max)
case 15: return (true); // nchar(512)
case 16: return (true); // nvarchar(512)
case 17: return (true); // nvarchar(max)
case 18: return (true); // text
case 19: return (true); // ntext
case 28: return (true); // xml
default: break;
}
return (false);
}
function IsBinary($k)
{
switch ($k)
{
case 20: return (true); // binary
case 21: return (true); // varbinary(512)
case 22: return (true); // varbinary(max)
case 23: return (true); // image
default: break;
}
return (false);
}
function IsDateTime($k)
{
switch ($k)
{
case 25: return (true); // datetime
case 26: return (true); // smalldatetime
case 27: return (true); // timestamp
default: break;
}
return (false);
}
function IsUnicode($k)
{
switch ($k)
{
case 15: return (true); // nchar(512)
case 16: return (true); // nvarchar(512)
case 17: return (true); // nvarchar(max)
case 19: return (true); // ntext
default: break;
}
return (false);
}
function IsUpdatable($k)
{
switch ($k)
{
case 27: return (false); // timestamp
default: break;
}
return (true);
}
function IsLiteral($k)
{
switch ($k)
{
case 12: return (true); // nchar(512)
case 13: return (true); // varchar(512)
case 14: return (true); // varchar(max)
case 15: return (true); // nchar(512)
case 16: return (true); // nvarchar(512)
case 17: return (true); // nvarchar(max)
case 18: return (true); // text
case 19: return (true); // ntext
case 24: return (true); // uniqueidentifier
case 25: return (true); // datetime
case 26: return (true); // smalldatetime
case 28: return (true); // xml
default: break;
}
return (false);
}
function GetMetadata($k, $info)
{
if (strcasecmp($info, 'Name') == 0)
{
return (getColName($k));
}
if (strcasecmp($info, 'Size') == 0)
{
return (getColSize($k));
}
if (strcasecmp($info, 'Precision') == 0)
{
return (getColPrecision($k));
}
if (strcasecmp($info, 'Scale') == 0)
{
return (getColScale($k));
}
if (strcasecmp($info, 'Nullable') == 0)
{
return (getColNullable($k));
}
return ("");
}
function GetColName($k)
{
switch ($k)
{
case 1: return ("c1_int");
case 2: return ("c2_tinyint");
case 3: return ("c3_smallint");
case 4: return ("c4_bigint");
case 5: return ("c5_bit");
case 6: return ("c6_float");
case 7: return ("c7_real");
case 8: return ("c8_decimal");
case 9: return ("c9_numeric");
case 10: return ("c10_money");
case 11: return ("c11_smallmoney");
case 12: return ("c12_char");
case 13: return ("c13_varchar");
case 14: return ("c14_varchar_max");
case 15: return ("c15_nchar");
case 16: return ("c16_nvarchar");
case 17: return ("c17_nvarchar_max");
case 18: return ("c18_text");
case 19: return ("c19_ntext");
case 20: return ("c20_binary");
case 21: return ("c21_varbinary");
case 22: return ("c22_varbinary_max");
case 23: return ("c23_image");
case 24: return ("c24_uniqueidentifier");
case 25: return ("c25_datetime");
case 26: return ("c26_smalldatetime");
case 27: return ("c27_timestamp");
case 28: return ("c28_xml");
default: break;
}
return ("");
}
function GetColSize($k)
{
switch ($k)
{
case 12: return ("512");
case 13: return ("512");
case 14: return ("0");
case 15: return ("512");
case 16: return ("512");
case 17: return ("0");
case 18: return ("2147483647");
case 19: return ("1073741823");
case 20: return ("512");
case 21: return ("512");
case 22: return ("0)");
case 23: return ("2147483647");
case 24: return ("36");
//case 25: return ("23");
//case 26: return ("16");
case 27: return ("8");
case 28: return ("0");
default: break;
}
return ("");
}
function GetColPrecision($k)
{
switch ($k)
{
case 1: return ("10");
case 2: return ("3");
case 3: return ("5");
case 4: return ("19");
case 5: return ("1");
case 6: return ("53");
case 7: return ("24");
case 8: return ("28");
case 9: return ("32");
case 10: return ("19");
case 11: return ("10");
case 25: return ("23");
case 26: return ("16");
default: break;
}
return ("");
}
function GetColScale($k)
{
switch ($k)
{
case 8: return ("4");
case 9: return ("4");
case 10: return ("4");
case 11: return ("4");
case 25: return ("3");
case 26: return ("0");
default: break;
}
return ("");
}
function GetColNullable($k)
{
return (IsUpdatable($k) ? "1" : "0");
}
function GetSampleData($k)
{
switch ($k)
{
case 1: // int
return ("123456789");
case 2: // tinyint
return ("234");
case 3: // smallint
return ("5678");
case 4: // bigint
return ("123456789987654321");
case 5: // bit
return ("1");
case 6: // float
return ("123.456");
case 7: // real
return ("789.012");
case 8: // decimal
return ("12.34");
case 9: // numeric
return ("567.89");
case 10:// money
return ("321.54");
case 11:// smallmoney
return ("67.89");
case 12:// char
case 15:// nchar
return ("The quick brown fox jumps over the lazy dog");
case 13:// varchar
case 16:// nvarchar
return ("The quick brown fox jumps over the lazy dog 9876543210");
case 14:// varchar(max)
case 17:// nvarchar(max)
return ("The quick brown fox jumps over the lazy dog 0123456789");
case 18:// text
case 19:// ntext
return ("0123456789 The quick brown fox jumps over the lazy dog");
case 20:// binary
return ("0123456789");
case 21:// varbinary
return ("01234567899876543210");
case 22:// varbinary(max)
return ("98765432100123456789");
case 23:// image
return ("01234567899876543210");
case 24:// uniqueidentifier
return ("12345678-9012-3456-7890-123456789012");
case 25:// datetime
case 26:// smalldatetime
return (date("Y-m-d"));
case 27:// timestamp
return (null);
case 28:// xml
return ("<XmlTestData><Letters1>The quick brown fox jumps over the lazy dog</Letters1><Digits1>0123456789</Digits1></XmlTestData>");
default:
break;
}
return (null);
}
function CreateTable($conn, $tableName)
{
Trace("Creating table $tableName ...");
trace("Creating table $tableName ...");
$dataType = "[c1_int] int, [c2_tinyint] tinyint, [c3_smallint] smallint, [c4_bigint] bigint, [c5_bit] bit, [c6_float] float, [c7_real] real, [c8_decimal] decimal(28,4), [c9_numeric] numeric(32,4), [c10_money] money, [c11_smallmoney] smallmoney, [c12_char] char(512), [c13_varchar] varchar(512), [c14_varchar_max] varchar(max), [c15_nchar] nchar(512), [c16_nvarchar] nvarchar(512), [c17_nvarchar_max] nvarchar(max), [c18_text] text, [c19_ntext] ntext, [c20_binary] binary(512), [c21_varbinary] varbinary(512), [c22_varbinary_max] varbinary(max), [c23_image] image, [c24_uniqueidentifier] uniqueidentifier, [c25_datetime] datetime, [c26_smalldatetime] smalldatetime, [c27_timestamp] timestamp, [c28_xml] xml";
CreateTableEx($conn, $tableName, $dataType);
createTableEx($conn, $tableName, $dataType);
Trace(" completed successfully.\n");
trace(" completed successfully.\n");
}
function CreateTableEx($conn, $tableName, $dataType)
function createTableEx($conn, $tableName, $dataType)
{
$sql = "CREATE TABLE [$tableName] ($dataType)";
DropTable($conn,$tableName);
dropTable($conn, $tableName);
$stmt = sqlsrv_query($conn, $sql);
if ($stmt === false)
{
FatalError("Failed to create test table: ".$sql);
if ($stmt === false) {
fatalError("Failed to create test table: ".$sql);
}
sqlsrv_free_stmt($stmt);
}
function CreateTableIndex($conn, $tableName, $colIndex)
function createTableIndex($conn, $tableName, $colIndex)
{
include 'MsSetup.inc';
CreateTableIndexEx($conn, $tableName, $tableIndex, $colIndex);
createTableIndexEx($conn, $tableName, $tableIndex, $colIndex);
}
function CreateTableIndexEx($conn, $tableName, $tableIndex, $colIndex)
function createTableIndexEx($conn, $tableName, $tableIndex, $colIndex)
{
Trace("Creating table index for $tableName ...");
trace("Creating table index for $tableName ...");
$sqlIndex = "CREATE CLUSTERED INDEX [$tableIndex] ON [$tableName]($colIndex)";
$stmt = sqlsrv_query($conn, $sqlIndex);
if ($stmt === false)
{
FatalError("Failed to create clustered index for test table: ".$sqlIndex);
if ($stmt === false) {
fatalError("Failed to create clustered index for test table: ".$sqlIndex);
}
sqlsrv_free_stmt($stmt);
Trace(" completed successfully.\n");
trace(" completed successfully.\n");
}
function CreateUniqueIndex($conn, $tableName, $colIndex)
function createUniqueIndex($conn, $tableName, $colIndex)
{
include 'MsSetup.inc';
CreateUniqueIndexEx($conn, $tableName, $tableIndex, $colIndex);
createUniqueIndexEx($conn, $tableName, $tableIndex, $colIndex);
}
function CreateUniqueIndexEx($conn, $tableName, $tableIndex, $colIndex)
function createUniqueIndexEx($conn, $tableName, $tableIndex, $colIndex)
{
Trace("Creating unique table index for $tableName ...");
trace("Creating unique table index for $tableName ...");
$sqlIndex = "CREATE UNIQUE INDEX [$tableIndex] ON [$tableName]($colIndex)";
$stmt = sqlsrv_query($conn, $sqlIndex);
if ($stmt === false)
{
FatalError("Failed to create unique index for test table: ".$sqlIndex);
if ($stmt === false) {
fatalError("Failed to create unique index for test table: ".$sqlIndex);
}
sqlsrv_free_stmt($stmt);
Trace(" completed successfully.\n");
trace(" completed successfully.\n");
}
function DropTable($conn, $tableName)
function dropTable($conn, $tableName)
{
$stmt = sqlsrv_query($conn, "IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'" . $tableName . "') AND type in (N'U')) DROP TABLE $tableName");
if ($stmt === false)
{
}
else
{
if ($stmt === false) {
} else {
sqlsrv_free_stmt($stmt);
}
}
function SelectFromTable($conn, $tableName)
function selectFromTable($conn, $tableName)
{
return (SelectFromTableEx($conn, $tableName, null));
return (selectFromTableEx($conn, $tableName, null));
}
function SelectFromTableEx($conn, $tableName, $cond)
function selectFromTableEx($conn, $tableName, $cond)
{
if (($cond != null) && (strlen($cond) > 0))
{
return (SelectQuery($conn, "SELECT * FROM [$tableName] WHERE $cond"));
}
else
{
return (SelectQuery($conn, "SELECT * FROM [$tableName]"));
if (($cond != null) && (strlen($cond) > 0)) {
return (selectQuery($conn, "SELECT * FROM [$tableName] WHERE $cond"));
} else {
return (selectQuery($conn, "SELECT * FROM [$tableName]"));
}
}
function SelectQuery($conn, $query)
function selectQuery($conn, $query)
{
return (SelectQueryEx($conn, $query, null));
return (selectQueryEx($conn, $query, null));
}
function SelectQueryEx($conn, $query, $options)
function selectQueryEx($conn, $query, $options)
{
if ($options != null)
{
if ($options != null) {
$stmt = sqlsrv_query($conn, $query, null, $options);
}
else
{
} else {
$stmt = sqlsrv_query($conn, $query);
}
if ($stmt === false)
{
FatalError("Failed to query test table");
}
if ($stmt === false) {
fatalError("Failed to query test table");
}
$numFields = sqlsrv_num_fields($stmt);
if ($numFields <= 0)
{
if ($numFields <= 0) {
die("Unexpected number of fields: ".$numFields);
}
return ($stmt);
}
function RowCount($stmt)
function rowCount($stmt)
{
$rowCount = 0;
while (sqlsrv_fetch($stmt))
{
while (sqlsrv_fetch($stmt)) {
$rowCount++;
}
return ($rowCount);
}
function NumRows($conn, $tableName)
function numRows($conn, $tableName)
{
$stmt = SelectFromTable($conn, $tableName);
$rowCount = RowCount($stmt);
$rowCount = rowCount($stmt);
sqlsrv_free_stmt($stmt);
return ($rowCount);
}
function InsertQueryData($tableName, $index)
function insertQueryData($tableName, $index)
{
if (UseUTF8data())
{
if (UseUTF8data()) {
include_once 'MsData_UTF8.inc';
return (InsertQueryExUTF8($tableName, $index));
}
else
{
} else {
include_once 'MsData.inc';
return (InsertQueryEx($tableName, $index));
}
}
function InsertQuery($tableName)
function insertQuery($tableName)
{
return (InsertQueryData($tableName, rand(1, 20)));
return (insertQueryData($tableName, rand(1, 20)));
}
function InsertRows($conn, $tableName, $rowCount)
function insertRows($conn, $tableName, $rowCount)
{
Trace("Inserting $rowCount rows into $tableName ...");
trace("Inserting $rowCount rows into $tableName ...");
$count = 0;
for($i = 0; $i < $rowCount; $i++)
{
if (InsertRow($conn, $tableName))
{
for ($i = 0; $i < $rowCount; $i++) {
if (insertRow($conn, $tableName)) {
$count++;
}
}
Trace(" completed successfully.\n");
if ($count != $rowCount)
{
die("$count rows inserted instead of $rowCount\n");
trace(" completed successfully.\n");
if ($count != $rowCount) {
die("$count rows inserted instead of $rowCount\n");
}
return ($count);
}
function InsertRowsByRange($conn, $tableName, $minIndex, $maxIndex)
function insertRowsByRange($conn, $tableName, $minIndex, $maxIndex)
{
$rowCount = $maxIndex - $minIndex + 1;
if ($rowCount > 0)
{
Trace("Inserting $rowCount rows into $tableName ...");
for($i = $minIndex; $i <= $maxIndex; $i++)
{
InsertRowByIndex($conn, $tableName, $i);
if ($rowCount > 0) {
trace("Inserting $rowCount rows into $tableName ...");
for ($i = $minIndex; $i <= $maxIndex; $i++) {
insertRowByIndex($conn, $tableName, $i);
}
Trace(" completed successfully.\n");
}
trace(" completed successfully.\n");
}
}
function InsertRow($conn, $tableName)
function insertRow($conn, $tableName)
{
$query = InsertQuery($tableName);
$query = insertQuery($tableName);
$stmt = sqlsrv_query($conn, $query);
return (InsertCheck($stmt));
return (insertCheck($stmt));
}
function InsertRowEx($conn, $tableName, $dataCols, $dataValues, $dataOptions)
function insertRowEx($conn, $tableName, $dataCols, $dataValues, $dataOptions)
{
$stmt = sqlsrv_query($conn, "INSERT INTO [$tableName] ($dataCols) VALUES ($dataValues)", $dataOptions);
return (InsertCheck($stmt));
return (insertCheck($stmt));
}
function InsertRowByIndex($conn, $tableName, $index)
function insertRowByIndex($conn, $tableName, $index)
{
$query = InsertQueryData($tableName, $index);
$query = insertQueryData($tableName, $index);
$stmt = sqlsrv_query($conn, $query);
return (InsertCheck($stmt));
return (insertCheck($stmt));
}
function InsertStream($conn, $tableName, $dataCols, $dataValues, $dataOptions, $atExec)
function insertStream($conn, $tableName, $dataCols, $dataValues, $dataOptions, $atExec)
{
if ($atExec)
{
if ($atExec) {
$stmt = sqlsrv_query($conn, "INSERT INTO [$tableName] ($dataCols) VALUES ($dataValues)", $dataOptions, array('SendStreamParamsAtExec' => 1));
}
else
{
} else {
$stmt = sqlsrv_query($conn, "INSERT INTO [$tableName] ($dataCols) VALUES ($dataValues)", $dataOptions);
if ($stmt)
{
while (sqlsrv_send_stream_data($stmt))
{
if ($stmt) {
while (sqlsrv_send_stream_data($stmt)) {
}
}
}
return (InsertCheck($stmt));
return (insertCheck($stmt));
}
function InsertCheck($stmt)
function insertCheck($stmt)
{
if ($stmt === false)
{
FatalError("Failed to insert row into test table");
if ($stmt === false) {
fatalError("Failed to insert row into test table");
}
$numRows = sqlsrv_rows_affected($stmt);
sqlsrv_free_stmt($stmt);
if ($numRows != 1)
{
if ($numRows != 1) {
die("Unexpected row count at insert: ".$numRows);
}
return (true);
}
function GetInsertData($rowIndex, $colIndex, $skip)
function getInsertData($rowIndex, $colIndex, $skip)
{
$query = InsertQueryData("TestTable", $rowIndex);
$query = insertQueryData("TestTable", $rowIndex);
$data = strstr($query, "((");
$pos = 1;
if ($data === false)
{
if ($data === false) {
die("Failed to retrieve data on row $rowIndex");
}
$data = substr($data, 2);
while ($pos < ($colIndex - $skip))
{
while ($pos < ($colIndex - $skip)) {
$data = strstr($data, ", (");
$pos++;
if ($data === false)
{
if ($data === false) {
die("Failed to retrieve data on row $rowIndex, column $pos");
}
$data = substr($data, 3);
@ -1349,153 +458,130 @@ function GetInsertData($rowIndex, $colIndex, $skip)
// Is it's XML type, we can't use the closing bracket as the next delimiter
// because a bracket can be part of the xml data, unless the data is null
$pos = strpos($data, ")");
if ($pos === false)
{
if ($pos === false) {
die("Failed to isolate data on row $rowIndex, column $pos");
}
$tmp = substr($data, 0, $pos); // don't replace $data in case it's xml data
if (strcasecmp($tmp, "null") == 0 || strlen($tmp) == 0) // data can actually be blank for null
{
if (strcasecmp($tmp, "null") == 0 || strlen($tmp) == 0) { // data can actually be blank for null
$tmp = "";
}
else if (IsXml($colIndex))
{
} elseif (IsXml($colIndex)) {
$str = ">')"; // use the XML closing angle bracket as the delimiter
$pos = strpos($data, $str);
$tmp = substr($data, 0, $pos + 2);
$tmp = substr($data, 0, $pos + 2);
}
$data = $tmp; // update $data
if (IsUnicode($colIndex))
{ // N'data'
if (IsUnicode($colIndex)) { // N'data'
$data = substr($data, 2, strlen($data) - 3);
}
else if (IsLiteral($colIndex))
{ // 'data'
} elseif (IsLiteral($colIndex)) { // 'data'
$data = substr($data, 1, strlen($data) - 2);
}
else if (IsBinary($colIndex))
{ // 0xdata
} elseif (IsBinary($colIndex)) { // 0xdata
$data = substr($data, 2);
}
return (trim($data));
}
function CreateProc($conn, $procName, $procArgs, $procCode)
function createProc($conn, $procName, $procArgs, $procCode)
{
DropProc($conn,$procName);
dropProc($conn, $procName);
$stmt = sqlsrv_query($conn, "CREATE PROC [$procName] ($procArgs) AS BEGIN $procCode END");
if ($stmt === false)
{
FatalError("Failed to create test procedure");
if ($stmt === false) {
fatalError("Failed to create test procedure");
}
sqlsrv_free_stmt($stmt);
}
function DropProc($conn, $procName)
function dropProc($conn, $procName)
{
$stmt = sqlsrv_query($conn, "DROP PROC [$procName]");
if ($stmt === false)
{
}
else
{
if ($stmt === false) {
} else {
sqlsrv_free_stmt($stmt);
}
}
function CallProc($conn, $procName, $procArgs, $procValues)
function callProc($conn, $procName, $procArgs, $procValues)
{
$stmt = CallProcEx($conn, $procName, "", $procArgs, $procValues);
$stmt = callProcEx($conn, $procName, "", $procArgs, $procValues);
sqlsrv_free_stmt($stmt);
}
function CallProcEx($conn, $procName, $procPrefix, $procArgs, $procValues)
function callProcEx($conn, $procName, $procPrefix, $procArgs, $procValues)
{
$stmt = sqlsrv_query($conn, "{ $procPrefix CALL [$procName] ($procArgs)}", $procValues);
if ($stmt === false)
{
FatalError("Failed to call test procedure");
if ($stmt === false) {
fatalError("Failed to call test procedure");
}
return ($stmt);
}
function CreateFunc($conn, $funcName, $funcArgs, $retType, $funcCode)
function createFunc($conn, $funcName, $funcArgs, $retType, $funcCode)
{
DropFunc($conn,$funcName);
dropFunc($conn, $funcName);
$stmt = sqlsrv_query($conn, "CREATE FUNCTION [$funcName] ($funcArgs) RETURNS $retType AS BEGIN $funcCode END");
if ($stmt === false)
{
FatalError("Failed to create test function");
if ($stmt === false) {
fatalError("Failed to create test function");
}
sqlsrv_free_stmt($stmt);
}
function DropFunc($conn, $funcName)
function dropFunc($conn, $funcName)
{
$stmt = sqlsrv_query($conn, "DROP FUNCTION [$funcName]");
if ($stmt === false)
{
}
else
{
if ($stmt === false) {
} else {
sqlsrv_free_stmt($stmt);
}
}
function CallFunc($conn, $funcName, $funcArgs, $funcValues)
function callFunc($conn, $funcName, $funcArgs, $funcValues)
{
$stmt = sqlsrv_query($conn, "{ ? = CALL [$funcName]($funcArgs)}", $funcValues);
if ($stmt === false)
{
FatalError("Failed to call test function");
if ($stmt === false) {
fatalError("Failed to call test function");
}
sqlsrv_free_stmt($stmt);
}
function FatalError($errorMsg)
function fatalError($errorMsg)
{
SetUTF8Data(false);
handle_errors();
handleErrors();
die($errorMsg."\n");
}
function PrintErrors($message = "")
function printErrors($message = "")
{
if (strlen($message) > 0)
{
if (strlen($message) > 0) {
echo $message . "\n";
}
$errors = sqlsrv_errors(SQLSRV_ERR_ERRORS);
if(count($errors) == 0)
{
if (count($errors) == 0) {
$errors = sqlsrv_errors(SQLSRV_ERR_ALL);
}
$count = count($errors);
for($i = 0; $i < $count; $i++)
{
for ($i = 0; $i < $count; $i++) {
echo $errors[$i]['message'] . "\n";
}
}
function handle_errors()
function handleErrors()
{
$errors = sqlsrv_errors(SQLSRV_ERR_ERRORS);
$count = count($errors);
if($count == 0)
{
$errors = sqlsrv_errors(SQLSRV_ERR_ALL);
$count = 0;
$count = 0;
if (! empty($errors)) {
$count = count($errors);
}
if($count > 0)
{
for($i = 0; $i < $count; $i++)
{
trace ($errors[$i]['message']."\n");
} else {
$errors = sqlsrv_errors(SQLSRV_ERR_ALL);
if (! empty($errors)) {
$count = count($errors);
}
}
for ($i = 0; $i < $count; $i++) {
trace($errors[$i]['message']."\n");
}
}
?>
?>

View file

@ -0,0 +1,816 @@
<?php
/*
Microsoft SQL Server Driver for PHP - Unit Test Framework
Copyright (c) Microsoft Corporation. All rights reserved.
Description:
Helper classes and functions with Always Encrypted features incorporated.
*/
namespace AE {
require_once('MsSetup.inc');
/**
* class for encapsulating column metadata needed for creating a table
*/
class ColumnMeta
{
public $colName;
public $dataType; //a string that includes the size of the type if necessary (e.g., decimal(10,5))
public $encType; //randomized or deterministic; default is deterministic
public $options; //a string that is null by default (e.g. NOT NULL Identity (1,1) )
public function __construct($dataType, $colName = null, $options = null, $encType = "deterministic")
{
if (is_null($colName)) {
$this->colName = getDefaultColname($dataType);
} else {
$this->colName = $colName;
}
$this->dataType = $dataType;
$this->encType = $encType;
$this->options = $options;
}
/**
* @return string column definition for creating a table
*/
public function getColDef()
{
$append = " ";
// an identity column is not encrypted because a select query with identity column as the where clause is often run and the user want to have to bind parameter every time
// if ( $keystore != "none" && stripos( $this->options, "identity" ) === false )
if (isColEncrypted() && stripos($this->options, "identity") === false) {
$cekName = getCekName();
if (stripos($this->dataType, "char") !== false) {
$append .= "COLLATE Latin1_General_BIN2 ";
}
$append .= sprintf("ENCRYPTED WITH (ENCRYPTION_TYPE = %s, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = $cekName) ", $this->encType);
}
$append .= $this->options;
$colDef = "[" . $this->colName . "] " . $this->dataType . $append;
return $colDef;
}
}
/**
* class for encapsulating optional parameters for binding parameters in sqlsrv_prepare
*/
class BindParamOption
{
public $index; //1-based index of the parameter
public $direction; //SQLSRV_PARAM_ constant indicating the parameter direction
public $phpType; //SQLSRV_PHPTYPE_ constant specifying the php type of the return values
public $sqlType; //SQLSRV_SQLTYPE_ constant specifying the SQL type of the input
public function __construct($index, $direction = null, $phpType = null, $sqlType = null)
{
$this->index = $index;
$this->direction = $direction;
$this->phpType = $phpType;
$this->sqlType = $sqlType;
}
/**
* @param resource $conn : connection resource
* @param mix $var : variable to bind to the SQL statement parameter
* @return array needed to bind parameter in sqlsrv_prepare
*/
public function bindParamArr($var)
{
// get the constant values of direction, phpType, and sqlType
$direction = null;
$phpType = null;
$sqlType = null;
if ($this->direction) {
$direction = constant($this->direction);
}
if ($this->phpType) {
$phpType = constant($this->phpType);
}
if ($this->sqlType) {
// parse out the datatype name, size, precision, and/or scale from a SQLSRV_SQLTYPE_ constant
$size = null;
$prec = null;
$scal = null;
$type_size = explode("(", $this->sqlType);
$type = $type_size[0];
if (count($type_size) > 1) {
$size = $type_size[1];
$prec_scal = explode(",", $size);
if (count($prec_scal) > 1) {
$prec = $prec_scal[0];
$scal = rtrim($prec_scal[1], ")");
$size = null;
}
}
// get the sqlType constant
if ($prec && $scal) {
$sqlType = call_user_func($type, $prec, $scal);
} elseif ($size) {
$sqlType = call_user_func($type, $size);
} else {
$sqlType = constant($type);
}
}
return array( $var, $direction, $phpType, $sqlType );
}
}
/**
* @return string CEK name depending on the connection keywords
*/
function getCekName()
{
global $keystore;
$cekName = '';
switch ($keystore) {
case "none":
$cekName = '';
break;
case "win":
$cekName = 'AEColumnKey';
break;
case "ksp":
$cekName = 'CustomCEK';
break;
case "akv":
$cekName = 'AKVColumnKey';
break;
default:
echo "getCekName: Invalid keystore name.\n";
}
return $cekName;
}
/**
* @return string default column name when a name is not provided in the ColumnMeta class
*/
function getDefaultColname($dataType)
{
$colName = "c_" . str_replace(",", "_", str_replace("(", "_", $dataType));
$colName = rtrim($colName, ")");
return $colName;
}
/**
* @param string $tbname : name of the table for an insert sql
* @param array $input : associative array containing a key value pair of column name and data to put into an insert sql string
* @return string a complete insert sql string
*/
function getInsertSqlComplete($tbname, $inputs)
{
$colStr = "INSERT INTO $tbname (";
$valStr = "VALUES (";
if (empty($inputs)) {
echo "getInsertSqlComplete: inputs for inserting a row cannot be empty.\n";
return;
}
foreach ($inputs as $key => $value) {
$colStr .= $key . ", ";
if (is_null($value)) {
echo "getInsertSqlComplete: value provided for input $value is null.\n";
} elseif (is_string($value)) {
$valStr .= "'" . $value . "', ";
} else {
$valStr .= $value . ", ";
}
}
$colStr = rtrim($colStr, ", ") . ") ";
$valStr = rtrim($valStr, ", ") . ") ";
$insertSql = $colStr . $valStr;
return $insertSql;
}
/**
* @param string $tbname : name of the table for an insert sql
* @param array $inputs : associative array containing a key value pair of column name and data to put into an insert sql string
* @return string an insert sql string with "?" placeholders for all values
*/
function getInsertSqlPlaceholders($tbname, $inputs)
{
$colStr = "INSERT INTO $tbname (";
$valStr = "VALUES (";
if (empty($inputs)) {
echo "getInsertSqlPlaceholders: inputs for inserting a row cannot be empty.\n";
return;
}
foreach ($inputs as $key => $value) {
$colStr .= $key . ", ";
}
$colStr = rtrim($colStr, ", ") . ") ";
$valStr .= getSeqPlaceholders(count($inputs)) . ") ";
$insertSql = $colStr . $valStr;
return $insertSql;
}
/**
* @param string $spname : name of the stored procedure
* @param int $num : number of parameters needed for the stored procedure
* @return string a call stored procedure sql string with "?" placeholders for all parameters
*/
function getCallProcSqlPlaceholders($spname, $num)
{
$callStr = "{CALL $spname (";
$callStr .= getSeqPlaceholders($num) . ")} ";
return $callStr;
}
/**
* @param int $num : number of placeholders needed
* @return string a string containing $num number of repeated "?" placeholders delimited by ", "
*/
function getSeqPlaceholders($num)
{
if ($num <= 0) {
echo "getSeqPlaceholders: num provided for creating a sequence of placeholders cannot be less than 0.\n";
return;
}
$placeholderStr = str_repeat("?, ", $num);
$placeholderStr = rtrim($placeholderStr, ", ");
return $placeholderStr;
}
/**
* @return bool false if $keystore specified in MsSetup.inc is none or data not encrypted,
* otherwise return true
*/
function isColEncrypted()
{
global $keystore, $dataEncrypted;
if ($keystore == "none" || !$dataEncrypted) {
return false;
} else {
return true;
}
}
/**
* @return bool false if ODBC version is less than 17 or SQL Server older than 2016
*/
function isQualified($conn)
{
$msodbcsql_ver = sqlsrv_client_info($conn)['DriverVer'];
if (explode(".", $msodbcsql_ver)[0] < 17) {
return false;
}
$server_ver = sqlsrv_server_info($conn)['SQLServerVersion'];
if (explode('.', $server_ver)[0] < 13) {
return false;
}
return true;
}
/**
* Connect to the database specified in MsSetup.inc; Column Encryption options automatically added when $keystore is not none
* @param array $options : connection attributes to pass to sqlsrv_connect
* @param bool $disableCE : flag for disabling column encryption even when keystore is NOT none
* for testing fetching encrypted data when connection column encryption is off
* @return connection resource
*/
function connect($options = array(), $disableCE = false)
{
require('MsSetup.inc');
if (sizeof($options) > 0) {
$connectionOptions = array_merge($connectionOptions, $options);
}
if (!$disableCE) {
if (isColEncrypted()) {
$connectionOptions = array_merge($connectionOptions, array("ColumnEncryption" => "Enabled"));
}
if ($keystore == "ksp") {
require('AE_Ksp.inc');
$ksp_path = getKSPPath();
$ksp_options = array("CEKeystoreProvider"=>$ksp_path,
"CEKeystoreName"=>$ksp_name,
"CEKeystoreEncryptKey"=>$encrypt_key);
$connectionOptions = array_merge($connectionOptions, $ksp_options);
}
}
$conn = sqlsrv_connect($server, $connectionOptions);
if ($conn === false) {
fatalError("Failed to connect to $server.");
}
return $conn;
}
/**
* Create a table
* @param object $conn : sqlsrv connection object
* @param string $tbname : name of the table to be created
* @param array $columnMetaArr : array of ColumnMeta objects, which contain metadata for one column
*/
function createTable($conn, $tbname, $columnMetaArr)
{
dropTable($conn, $tbname);
$colDef = "";
foreach ($columnMetaArr as $meta) {
$colDef = $colDef . $meta->getColDef() . ", ";
}
$colDef = rtrim($colDef, ", ");
$createSql = "CREATE TABLE $tbname ( $colDef )";
sqlsrv_query($conn, $createSql);
}
/**
* Insert a row into a table
* @param object $conn : sqlsrv connection object
* @param string $tbname : name of the table for the row to be inserted
* @param array $inputs : an associative array column name and its value
* @param bool $r : true if the row was successfully inserted, otherwise false. Default value is null to make this parameter optional.
* $param string $api : SQLSRV API used for executing the insert query
* accepted values: "query", "queryParamsOp", "prepare", "prepareParamsOp"
* @param array $paramOption : an array of bindParamOptions. Should only be provided if $api is "perpareWithParamOp", if provided, has to be in the same order as $inputs
* @return object PDOStatement object of the insert statement
*/
function insertRow($conn, $tbname, $inputs, &$r = null, $api = "query", $paramOption = array())
{
require 'MsSetup.inc';
$stmt = null;
if ($keystore == "none" && $api != "queryParamsOp" && $api != "prepareParamsOp") {
$insertSql = getInsertSqlComplete($tbname, $inputs);
switch ($api) {
case "query":
$stmt = sqlsrv_query($conn, $insertSql);
break;
case "prepare":
$stmt = sqlsrv_prepare($conn, $insertSql);
$r = sqlsrv_execute($stmt);
break;
}
} else {
// if AE is on, must bind param
$insertSql = getInsertSqlPlaceholders($tbname, $inputs);
$params = array();
if (empty($paramOption)) {
foreach ($inputs as $key => $value) {
array_push($params, $inputs[$key]);
}
} else {
$i = 1;
foreach ($inputs as $key => $value) {
$nooption = true;
foreach ($paramOption as $op) {
if ($op->index == $i) {
array_push($params, $op->bindParamArr($inputs[$key]));
$nooption = false;
$i++;
break;
}
}
if ($nooption) {
array_push($params, $inputs[$key]);
$i++;
}
}
}
if ($keystore != "none" || $api == "prepareParamsOp") {
$stmt = sqlsrv_prepare($conn, $insertSql, $params);
$r = sqlsrv_execute($stmt);
} else {
$stmt = sqlsrv_query($conn, $insertSql, $params);
}
}
return $stmt;
}
/**
* Fetch all rows and all columns given a table name, and print them
* @param resource $conn : connection resource
* @param string $tbname : name of the table to fetch from
*/
function fetchAll($conn, $tbname)
{
$sql = "SELECT * FROM $tbname";
$stmt = sqlsrv_query($conn, $sql);
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
foreach ($row as $key => $value) {
if (is_object($value)) {
print "$key:\n";
foreach ($value as $k =>$v) {
print(" $k: $v\n");
}
} else {
print("$key: $value\n");
}
}
}
}
} // end of namespace AlwaysEncrypted
namespace {
function getSqlType($k)
{
switch ($k) {
case 1: return ("int");
case 2: return ("tinyint");
case 3: return ("smallint");
case 4: return ("bigint");
case 5: return ("bit");
case 6: return ("float");
case 7: return ("real");
case 8: return ("decimal(28,4)");
case 9: return ("numeric(32,4)");
case 10: return ("money");
case 11: return ("smallmoney");
case 12: return ("char(512)");
case 13: return ("varchar(512)");
case 14: return ("varchar(max)");
case 15: return ("nchar(512)");
case 16: return ("nvarchar(512)");
case 17: return ("nvarchar(max)");
case 18: return ("text");
case 19: return ("ntext");
case 20: return ("binary(512)");
case 21: return ("varbinary(512)");
case 22: return ("varbinary(max)");
case 23: return ("image");
case 24: return ("uniqueidentifier");
case 25: return ("datetime");
case 26: return ("smalldatetime");
case 27: return ("timestamp");
case 28: return ("xml");
default: break;
}
return ("udt");
}
function getDriverType($k, $dataSize)
{
switch ($k) {
case 1: return (SQLSRV_SQLTYPE_INT);
case 2: return (SQLSRV_SQLTYPE_TINYINT);
case 3: return (SQLSRV_SQLTYPE_SMALLINT);
case 4: return (SQLSRV_SQLTYPE_BIGINT);
case 5: return (SQLSRV_SQLTYPE_BIT);
case 6: return (SQLSRV_SQLTYPE_FLOAT);
case 7: return (SQLSRV_SQLTYPE_REAL);
case 8: return (SQLSRV_SQLTYPE_DECIMAL(28, 4));
case 9: return (SQLSRV_SQLTYPE_NUMERIC(32, 4));
case 10: return (SQLSRV_SQLTYPE_MONEY);
case 11: return (SQLSRV_SQLTYPE_SMALLMONEY);
case 12: return (SQLSRV_SQLTYPE_CHAR($dataSize));
case 13: return (SQLSRV_SQLTYPE_VARCHAR($dataSize));
case 14: return (SQLSRV_SQLTYPE_VARCHAR('max'));
case 15: return (SQLSRV_SQLTYPE_NCHAR($dataSize));
case 16: return (SQLSRV_SQLTYPE_NVARCHAR($dataSize));
case 17: return (SQLSRV_SQLTYPE_NVARCHAR('max'));
case 18: return (SQLSRV_SQLTYPE_TEXT);
case 19: return (SQLSRV_SQLTYPE_NTEXT);
case 20: return (SQLSRV_SQLTYPE_BINARY($dataSize));
case 21: return (SQLSRV_SQLTYPE_VARBINARY($dataSize));
case 22: return (SQLSRV_SQLTYPE_VARBINARY('max'));
case 23: return (SQLSRV_SQLTYPE_IMAGE);
case 24: return (SQLSRV_SQLTYPE_UNIQUEIDENTIFIER);
case 25: return (SQLSRV_SQLTYPE_DATETIME);
case 26: return (SQLSRV_SQLTYPE_SMALLDATETIME);
case 27: return (SQLSRV_SQLTYPE_TIMESTAMP);
case 28: return (SQLSRV_SQLTYPE_XML);
default: break;
}
return (SQLSRV_SQLTYPE_UDT);
}
function isXml($k)
{
switch ($k) {
case 28: return (true); // xml
default: break;
}
return (false);
}
function isStreamable($k)
{
switch ($k) {
case 12: return (true); // nchar(512)
case 13: return (true); // varchar(512)
case 14: return (true); // varchar(max)
case 15: return (true); // nchar(512)
case 16: return (true); // nvarchar(512)
case 17: return (true); // nvarchar(max)
case 18: return (true); // text
case 19: return (true); // ntext
case 20: return (true); // binary
case 21: return (true); // varbinary(512)
case 22: return (true); // varbinary(max)
case 23: return (true); // image
case 28: return (true); // xml
default: break;
}
return (false);
}
function isNumeric($k)
{
switch ($k) {
case 1: return (true); // int
case 2: return (true); // tinyint
case 3: return (true); // smallint
case 4: return (true); // bigint
case 5: return (true); // bit
case 6: return (true); // float
case 7: return (true); // real
case 8: return (true); // decimal(28,4)
case 9: return (true); // numeric(32,4)
case 10: return (true); // money
case 11: return (true); // smallmoney
default: break;
}
return (false);
}
function isChar($k)
{
switch ($k) {
case 12: return (true); // nchar(512)
case 13: return (true); // varchar(512)
case 14: return (true); // varchar(max)
case 15: return (true); // nchar(512)
case 16: return (true); // nvarchar(512)
case 17: return (true); // nvarchar(max)
case 18: return (true); // text
case 19: return (true); // ntext
case 28: return (true); // xml
default: break;
}
return (false);
}
function isBinary($k)
{
switch ($k) {
case 20: return (true); // binary
case 21: return (true); // varbinary(512)
case 22: return (true); // varbinary(max)
case 23: return (true); // image
default: break;
}
return (false);
}
function isDateTime($k)
{
switch ($k) {
case 25: return (true); // datetime
case 26: return (true); // smalldatetime
case 27: return (true); // timestamp
default: break;
}
return (false);
}
function isUnicode($k)
{
switch ($k) {
case 15: return (true); // nchar(512)
case 16: return (true); // nvarchar(512)
case 17: return (true); // nvarchar(max)
case 19: return (true); // ntext
default: break;
}
return (false);
}
function isUpdatable($k)
{
switch ($k) {
case 27: return (false); // timestamp
default: break;
}
return (true);
}
function isLiteral($k)
{
switch ($k) {
case 12: return (true); // nchar(512)
case 13: return (true); // varchar(512)
case 14: return (true); // varchar(max)
case 15: return (true); // nchar(512)
case 16: return (true); // nvarchar(512)
case 17: return (true); // nvarchar(max)
case 18: return (true); // text
case 19: return (true); // ntext
case 24: return (true); // uniqueidentifier
case 25: return (true); // datetime
case 26: return (true); // smalldatetime
case 28: return (true); // xml
default: break;
}
return (false);
}
function getMetadata($k, $info)
{
if (strcasecmp($info, 'Name') == 0) {
return (getColName($k));
}
if (strcasecmp($info, 'Size') == 0) {
return (getColSize($k));
}
if (strcasecmp($info, 'Precision') == 0) {
return (getColPrecision($k));
}
if (strcasecmp($info, 'Scale') == 0) {
return (getColScale($k));
}
if (strcasecmp($info, 'Nullable') == 0) {
return (getColNullable($k));
}
return ("");
}
function getColName($k)
{
switch ($k) {
case 1: return ("c1_int");
case 2: return ("c2_tinyint");
case 3: return ("c3_smallint");
case 4: return ("c4_bigint");
case 5: return ("c5_bit");
case 6: return ("c6_float");
case 7: return ("c7_real");
case 8: return ("c8_decimal");
case 9: return ("c9_numeric");
case 10: return ("c10_money");
case 11: return ("c11_smallmoney");
case 12: return ("c12_char");
case 13: return ("c13_varchar");
case 14: return ("c14_varchar_max");
case 15: return ("c15_nchar");
case 16: return ("c16_nvarchar");
case 17: return ("c17_nvarchar_max");
case 18: return ("c18_text");
case 19: return ("c19_ntext");
case 20: return ("c20_binary");
case 21: return ("c21_varbinary");
case 22: return ("c22_varbinary_max");
case 23: return ("c23_image");
case 24: return ("c24_uniqueidentifier");
case 25: return ("c25_datetime");
case 26: return ("c26_smalldatetime");
case 27: return ("c27_timestamp");
case 28: return ("c28_xml");
default: break;
}
return ("");
}
function getColSize($k)
{
switch ($k) {
case 12: return ("512");
case 13: return ("512");
case 14: return ("0");
case 15: return ("512");
case 16: return ("512");
case 17: return ("0");
case 18: return ("2147483647");
case 19: return ("1073741823");
case 20: return ("512");
case 21: return ("512");
case 22: return ("0)");
case 23: return ("2147483647");
case 24: return ("36");
//case 25: return ("23");
//case 26: return ("16");
case 27: return ("8");
case 28: return ("0");
default: break;
}
return ("");
}
function getColPrecision($k)
{
switch ($k) {
case 1: return ("10");
case 2: return ("3");
case 3: return ("5");
case 4: return ("19");
case 5: return ("1");
case 6: return ("53");
case 7: return ("24");
case 8: return ("28");
case 9: return ("32");
case 10: return ("19");
case 11: return ("10");
case 25: return ("23");
case 26: return ("16");
default: break;
}
return ("");
}
function getColScale($k)
{
switch ($k) {
case 8: return ("4");
case 9: return ("4");
case 10: return ("4");
case 11: return ("4");
case 25: return ("3");
case 26: return ("0");
default: break;
}
return ("");
}
function getColNullable($k)
{
return (isUpdatable($k) ? "1" : "0");
}
function getSampleData($k)
{
switch ($k) {
case 1: // int
return ("123456789");
case 2: // tinyint
return ("234");
case 3: // smallint
return ("5678");
case 4: // bigint
return ("123456789987654321");
case 5: // bit
return ("1");
case 6: // float
return ("123.456");
case 7: // real
return ("789.012");
case 8: // decimal
return ("12.34");
case 9: // numeric
return ("567.89");
case 10:// money
return ("321.54");
case 11:// smallmoney
return ("67.89");
case 12:// char
case 15:// nchar
return ("The quick brown fox jumps over the lazy dog");
case 13:// varchar
case 16:// nvarchar
return ("The quick brown fox jumps over the lazy dog 9876543210");
case 14:// varchar(max)
case 17:// nvarchar(max)
return ("The quick brown fox jumps over the lazy dog 0123456789");
case 18:// text
case 19:// ntext
return ("0123456789 The quick brown fox jumps over the lazy dog");
case 20:// binary
return ("0123456789");
case 21:// varbinary
return ("01234567899876543210");
case 22:// varbinary(max)
return ("98765432100123456789");
case 23:// image
return ("01234567899876543210");
case 24:// uniqueidentifier
return ("12345678-9012-3456-7890-123456789012");
case 25:// datetime
case 26:// smalldatetime
return (date("Y-m-d"));
case 27:// timestamp
return (null);
case 28:// xml
return ("<XmlTestData><Letters1>The quick brown fox jumps over the lazy dog</Letters1><Digits1>0123456789</Digits1></XmlTestData>");
default:
break;
}
return (null);
}
}
?>

View file

@ -8,11 +8,17 @@
*/
$PhpDriver = "Microsoft SQL Server Driver for PHP";
/*
$server = 'TARGET_SERVER';
$database = 'TARGET_DATABASE';
$userName = 'TARGET_USERNAME';
$userPassword = 'TARGET_PASSWORD';
*/
$server = 'SQL-2K16-01.galaxy.ad';
$database = 'php_test';
$userName = 'sa';
$userPassword = 'Moonshine4me';
$tableName = "php_test_table";
$tableIndex = "php_test_table_index";

View file

@ -6,7 +6,7 @@ Loads the PHP driver to check whether it is operational or not by checking if SQ
PHPT_EXEC=true
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function Info()
{
@ -14,17 +14,17 @@ function Info()
phpinfo();
$data = ob_get_contents();
ob_clean();
return $data;
}
$testName = "Driver Loading";
StartTest($testName);
startTest($testName);
preg_match ( '/sqlsrv support.*/', Info(), $matches );
var_dump( $matches );
preg_match('/sqlsrv support.*/', Info(), $matches);
var_dump($matches);
EndTest($testName);
endTest($testName);
?>
--EXPECT--
@ -32,4 +32,4 @@ array(1) {
[0]=>
string(25) "sqlsrv support => enabled"
}
Test "Driver Loading" completed successfully.
Test "Driver Loading" completed successfully.

View file

@ -1,8 +1,8 @@
--TEST--
Driver Setup Test
Driver setup Test
--DESCRIPTION--
Verifies the logging facility by checking the ability to set
and retrieve the values of “LogSubsystem” and "LogSeverity”
and retrieve the values of <EFBFBD>LogSubsystem<EFBFBD> and "LogSeverity<74>
parameters.
--ENV--
PHPT_EXEC=true
@ -10,51 +10,48 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function LoggingSetup()
{
$testName = "Driver Logging Setup";
StartTest($testName);
$testName = "Driver Logging setup";
startTest($testName);
Configure('LogSubsystems', -1);
Configure('LogSubsystems', 1);
Configure('LogSubsystems', 2);
Configure('LogSubsystems', 4);
Configure('LogSubsystems', 8);
Configure('LogSubsystems', 0);
configure('LogSubsystems', -1);
configure('LogSubsystems', 1);
configure('LogSubsystems', 2);
configure('LogSubsystems', 4);
configure('LogSubsystems', 8);
configure('LogSubsystems', 0);
Configure('LogSeverity', -1);
Configure('LogSeverity', 1);
Configure('LogSeverity', 2);
Configure('LogSeverity', 4);
Configure('LogSubsystems', SQLSRV_LOG_SYSTEM_OFF);
Configure('LogSeverity', SQLSRV_LOG_SEVERITY_ERROR);
configure('LogSeverity', -1);
configure('LogSeverity', 1);
configure('LogSeverity', 2);
configure('LogSeverity', 4);
EndTest($testName);
configure('LogSubsystems', SQLSRV_LOG_SYSTEM_OFF);
configure('LogSeverity', SQLSRV_LOG_SEVERITY_ERROR);
endTest($testName);
}
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
try
{
try {
LoggingSetup();
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
}
sqlsrv_configure('WarningsReturnAsError', 0);
Repro();
repro();
?>
--EXPECT--
Test "Driver Logging Setup" completed successfully.
Test "Driver Logging setup" completed successfully.

View file

@ -9,63 +9,49 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function ConnectionTest()
{
include 'MsSetup.inc';
$testName = "Connection";
StartTest($testName);
startTest($testName);
setup();
Setup();
// Invalid connection attempt => errors are expected
Trace("Invalid connection attempt (to a non-existing server) ....\n");
$conn1 = sqlsrv_connect('InvalidServerName');
if ($conn1 === false)
{
handle_errors();
}
else
{
if ($conn1 === false) {
handleErrors();
} else {
die("Invalid connection attempt should have failed.");
}
// Valid connection attempt => no errors are expected
Trace("\nValid connection attempt (to $server) ....\n");
$conn2 = Connect();
$conn2 = connect();
$errors = sqlsrv_errors(SQLSRV_ERR_ERRORS);
if (!empty($errors))
{
if (!empty($errors)) {
die("No errors were expected on valid connection attempts.");
}
sqlsrv_close($conn2);
EndTest($testName);
endTest($testName);
}
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
try
{
try {
ConnectionTest();
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
}
Repro();
repro();
?>
--EXPECT--
Test "Connection" completed successfully.

View file

@ -1,44 +1,38 @@
--TEST--
Client Info Test
--DESCRIPTION--
Verifies the functionality of "sqlsrv_client_info.
Verifies the functionality of "sqlsrv_client_info<EFBFBD>.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function ClientInfo()
{
include 'MsSetup.inc';
$testName = "Connection - Client Info";
StartTest($testName);
startTest($testName);
Setup();
$conn1 = Connect();
setup();
$conn1 = connect();
$clientinfo1 = sqlsrv_client_info($conn1);
$count1 = count($clientinfo1);
if ($count1 != 4)
{
if ($count1 != 4) {
die("Unexpected size for client_info array: ".$count1);
}
$driverName = 'DriverDllName';
$uname = php_uname();
if (IsWindows())
{
if (isWindows()) {
$driverName = 'DriverDllName';
}
else // other than Windows
{
} else { // other than Windows
$driverName = 'DriverName';
}
ShowInfo($clientinfo1, 'ExtensionVer');
ShowInfo($clientinfo1, $driverName);
ShowInfo($clientinfo1, 'DriverVer');
@ -46,35 +40,31 @@ function ClientInfo()
sqlsrv_close($conn1);
EndTest($testName);
endTest($testName);
}
function ShowInfo($clientInfo, $infoTag)
{
$info = $clientInfo[$infoTag];
Trace("$infoTag\t= $info\n");
trace("$infoTag\t= $info\n");
}
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
try
{
try {
ClientInfo();
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
}
Repro();
repro();
?>
--EXPECT--
Test "Connection - Client Info" completed successfully.
Test "Connection - Client Info" completed successfully.

View file

@ -1,29 +1,26 @@
--TEST--
Server Info Test
--DESCRIPTION--
Verifies the functionality of “sqlsrv_server_info”.
Verifies the functionality of <EFBFBD>sqlsrv_server_info<EFBFBD>.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function ServerInfo()
{
include 'MsSetup.inc';
$testName = "Connection - Server Info";
StartTest($testName);
startTest($testName);
Setup();
$conn1 = Connect();
setup();
$conn1 = connect();
$serverinfo1 = sqlsrv_server_info($conn1);
$count1 = count($serverinfo1);
if ($count1 != 3)
{
$serverinfo1 = sqlsrv_server_info($conn1);
$count1 = count($serverinfo1);
if ($count1 != 3) {
die("Unexpected size for server_info array: ".$count1);
}
@ -33,17 +30,15 @@ function ServerInfo()
sqlsrv_close($conn1);
EndTest($testName);
endTest($testName);
}
function ShowInfo($serverInfo, $infoTag)
{
$info = $serverInfo[$infoTag];
if (TraceMode())
{
if (traceMode()) {
echo "$infoTag\t";
if (strlen($infoTag) <= 15)
{
if (strlen($infoTag) <= 15) {
echo "\t";
}
echo "$info\n";
@ -51,23 +46,20 @@ function ShowInfo($serverInfo, $infoTag)
}
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
try
{
try {
ServerInfo();
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
}
Repro();
repro();
?>
--EXPECT--
Test "Connection - Server Info" completed successfully.
Test "Connection - Server Info" completed successfully.

View file

@ -9,82 +9,74 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function ConnectionClose()
{
include 'MsSetup.inc';
$testName = "Connection - Close";
StartTest($testName);
startTest($testName);
Setup();
setup();
$noRows = 5;
$conn1 = Connect();
CreateTable($conn1, $tableName);
InsertRows($conn1, $tableName, $noRows);
$conn1 = connect();
$tableName = 'TC24test';
createTable($conn1, $tableName);
insertRows($conn1, $tableName, $noRows);
// Close connection twice
for ($i = 0; $i < 2; $i++)
{
for ($i = 0; $i < 2; $i++) {
$ret = sqlsrv_close($conn1);
if ($ret === false)
{
if ($ret === false) {
die("Unexpected return for sqlsrv_close: $ret");
}
}
// Invalid Query
$stmt1 = sqlsrv_query($conn1, "SELECT * FROM [$tableName]");
if ($stmt1)
{
if ($stmt1) {
die("Select query should fail when connection is closed");
}
// Invalid Statement
$conn2 = Connect();
$stmt2 = SelectFromTable($conn2, $tableName);
$conn2 = connect();
$stmt2 = selectFromTable($conn2, $tableName);
sqlsrv_close($conn2);
if (sqlsrv_fetch($stmt2))
{
if (sqlsrv_fetch($stmt2)) {
die("Fetch should fail when connection is closed");
}
$conn3 = Connect();
DropTable($conn3, $tableName);
$conn3 = connect();
dropTable($conn3, $tableName);
sqlsrv_close($conn3);
EndTest($testName);
endTest($testName);
}
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
try
{
try {
ConnectionClose();
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
}
Repro();
repro();
?>
--EXPECTREGEX--
Warning: sqlsrv_close\(\): supplied resource is not a valid ss_sqlsrv_conn resource in .*TC24_Close.php on line 21
Warning: sqlsrv_close\(\): supplied resource is not a valid ss_sqlsrv_conn resource in .*TC24_Close.php on line 20
Warning: sqlsrv_query\(\): supplied resource is not a valid ss_sqlsrv_conn resource in .*TC24_Close.php on line 29
Warning: sqlsrv_query\(\): supplied resource is not a valid ss_sqlsrv_conn resource in .*TC24_Close.php on line 27
Warning: sqlsrv_fetch\(\): supplied resource is not a valid ss_sqlsrv_stmt resource in .*TC24_Close.php on line 39
Warning: sqlsrv_fetch\(\): supplied resource is not a valid ss_sqlsrv_stmt resource in .*TC24_Close.php on line 36
Test "Connection - Close" completed successfully.

View file

@ -1,7 +1,7 @@
--TEST--
Simple Query Test
--DESCRIPTION--
Basic verification of query statements (via "sqlsrv_query"):
Basic verification of query statements (via "sqlsrv_query"):
- Establish a connection
- Creates a table (including all 28 SQL types currently supported)
- Executes a SELECT query (on the empty table)
@ -13,58 +13,54 @@ PHPT_EXEC=true
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function SimpleQuery()
{
include 'MsSetup.inc';
$testName = "Statement - Simple Query";
StartTest($testName);
startTest($testName);
Setup();
$conn1 = Connect();
setup();
$tableName = 'TC31test';
CreateTable($conn1, $tableName);
$conn1 = connect();
Trace("Executing SELECT query on $tableName ...");
$stmt1 = SelectFromTable($conn1, $tableName);
$rows = RowCount($stmt1);;
createTable($conn1, $tableName);
trace("Executing SELECT query on $tableName ...");
$stmt1 = selectFromTable($conn1, $tableName);
$rows = rowCount($stmt1);
;
sqlsrv_free_stmt($stmt1);
Trace(" $rows rows retrieved.\n");
trace(" $rows rows retrieved.\n");
if ($rows > 0)
{
if ($rows > 0) {
die("Table $tableName, expected to be empty, has $rows rows.");
}
DropTable($conn1, $tableName);
dropTable($conn1, $tableName);
sqlsrv_close($conn1);
EndTest($testName);
endTest($testName);
}
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
try
{
try {
SimpleQuery();
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
}
Repro();
repro();
?>
--EXPECT--
Test "Statement - Simple Query" completed successfully.

View file

@ -9,96 +9,85 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function DeleteQuery()
{
include 'MsSetup.inc';
$testName = "Statement - Delete Query";
StartTest($testName);
startTest($testName);
Setup();
$conn1 = Connect();
setup();
$conn1 = connect();
$noRows = 10;
CreateTable($conn1, $tableName);
$noRowsInserted = InsertRows($conn1, $tableName, $noRows);
$tableName = 'TC32test';
createTable($conn1, $tableName);
$noRowsInserted = insertRows($conn1, $tableName, $noRows);
$row = 1;
$keyValue = "0";
while ($row <= $noRowsInserted)
{
$stmt1 = SelectFromTable($conn1, $tableName);
if (sqlsrv_fetch($stmt1) === false)
{
FatalError("Failed to retrieve 1st row of data from test table");
while ($row <= $noRowsInserted) {
$stmt1 = selectFromTable($conn1, $tableName);
if (sqlsrv_fetch($stmt1) === false) {
fatalError("Failed to retrieve 1st row of data from test table");
}
$keyValue = sqlsrv_get_field($stmt1, 0, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
sqlsrv_free_stmt($stmt1);
Trace("Deleting rows from $tableName ...");
trace("Deleting rows from $tableName ...");
$delRows = 1;
if (strlen($keyValue) == 0)
{
$stmt2 = ExecuteQuery($conn1, "DELETE TOP(1) FROM [$tableName]");
if (strlen($keyValue) == 0) {
$stmt2 = executeQuery($conn1, "DELETE TOP(1) FROM [$tableName]");
$cond = "(top row)";
}
else
{
} else {
$cond = "(c1_int = $keyValue)";
$stmt3 = SelectFromTableEx($conn1, $tableName, $cond);
$delRows = RowCount($stmt3);
$stmt3 = selectFromTableEx($conn1, $tableName, $cond);
$delRows = rowCount($stmt3);
sqlsrv_free_stmt($stmt3);
$stmt2 = ExecuteQuery($conn1, "DELETE FROM [$tableName] WHERE $cond");
$stmt2 = executeQuery($conn1, "DELETE FROM [$tableName] WHERE $cond");
}
$numRows1 = sqlsrv_rows_affected($stmt2);
sqlsrv_free_stmt($stmt2);
Trace(" $numRows1 row".(($numRows1 > 1) ? "s" : " ")." $cond.\n");
trace(" $numRows1 row".(($numRows1 > 1) ? "s" : " ")." $cond.\n");
if ($numRows1 != $delRows)
{
die("Unexpected row count at delete: $numRows1 instead of $delRows");
if ($numRows1 != $delRows) {
die("Unexpected row count at delete: $numRows1 instead of $delRows");
}
$row += $numRows1;
}
$stmt3 = ExecuteQuery($conn1, "DELETE TOP(1) FROM [$tableName]");
$stmt3 = executeQuery($conn1, "DELETE TOP(1) FROM [$tableName]");
$numRows2 = sqlsrv_rows_affected($stmt3);
sqlsrv_free_stmt($stmt3);
if ($numRows2 > 0)
{
if ($numRows2 > 0) {
die("Unexpected row count at delete: $numRows2");
}
DropTable($conn1, $tableName);
}
dropTable($conn1, $tableName);
sqlsrv_close($conn1);
EndTest($testName);
endTest($testName);
}
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
try
{
try {
DeleteQuery();
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
}
Repro();
repro();
?>
--EXPECT--
Test "Statement - Delete Query" completed successfully.
Test "Statement - Delete Query" completed successfully.

View file

@ -9,20 +9,19 @@ PHPT_EXEC=true
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function ComplexQuery()
{
include 'MsSetup.inc';
$testName = "Statement - Complex Query";
StartTest($testName);
startTest($testName);
Setup();
$conn1 = Connect();
setup();
$conn1 = connect();
$tableName = 'TC33test';
$dataTypes = "[c1_int] int IDENTITY, [c2_tinyint] tinyint, [c3_smallint] smallint, [c4_bigint] bigint, [c5_varchar] varchar(512)";
CreateTableEx($conn1, $tableName, $dataTypes);
createTableEx($conn1, $tableName, $dataTypes);
Execute($conn1, true, "SET IDENTITY_INSERT [$tableName] ON;");
Execute($conn1, true, "INSERT INTO [$tableName] (c1_int, c2_tinyint, c3_smallint, c4_bigint, c5_varchar) VALUES (-204401468, 168, 4787, 1583186637, 'î<ÄäC~zããa.Oa._ߣ*©<u_ßßCÃoa äãäÐßa+OühäobUa:zB_CÖ@~UÄz+ÃîÐ//Z@üo_:r,o¢ÃrßzoZß*ߪªå~ U¢a>£ÃZUÄ/ä_ZãðäåhüCã+/.obî|ößß,ð¢ðð:ÄÐ:*/>+/¢aö.öÄ<ð:>äO~*~ßÄzå¢<ª£ðý.O,>Ü,åbü@böhýC*<<hbÖä*o©¢h¢Ðüa+A/_@b/ÃBýBªß@ã~zÖZýC@äU_ßUßhvU*a@ÃðÄ:ªZAßAb£U_¢ßbãä:üåãorýÃߪ_ãÐÖªzãðåãoaü <ß~zZªaB.+åA¢ãÖ><î:/Ur î¢UßåOaÄ:a|++ª©.r~:/+ä|©ýo++v_@BZ:©©AßCð.©/Ab<,îß>UãÜÜöbb|ßÐߣ:î<<bîöa+,<_aÄ._ª>Ü<|ÖzÃz@>¢ª:a,CÜr__ª.<öÜCã+UÖU¢_üzü bÃ~ßo|, .î,b/U>äýaBZ@Ü£: bÖvýb>Ã/ÜÃ@üÖ/äb¢+r:Zß>ÐÜ|üu©ßZAC:Cßh *.ã£_ýîu|Urå.:aAUv@u>@<Öü.<ãZ böZAÜÖ£oüÐä*,ü:ðä')");
@ -30,8 +29,8 @@ function ComplexQuery()
Execute($conn1, false,"INSERT INTO [$tableName] (c1_int, c2_tinyint, c3_smallint, c4_bigint, c5_varchar) VALUES (1264768176, 111, 23449, 1421472052, 'uå©C@bðUOv~,©v,BZÜ*oh>zb_åÐä<@*OOå_Ö<ãuß/oßr <ðãbÜUßÜÃÖÄ~¢~£ bÜ©î.uÜТª:|_ÐüÄBÐbüåßÃv@,<CßOäv~:+,CZîvhC/oßUuößa<å>©/Ub,+AЩî:ÖrýB+~~ßßßãÜ+_<vO@ ßÃüÖîaCzÐîå@:rý.~vh~r.ÃbÃã©å_îCär BÖÜ:BbUväåöZ+|,CîaAöC,aîbb*UÜßßA hCu¢hOb ð|ßC.<C<.aBßvuÃÖå,AÐa>ABðöU/O<ÖãüªOãuߣ~uÖ+ßÄrbî/:ÖÖo /_ÃO:uÃzðUvã£Aã_BÐ/>UCr,Äå aÄÐaãvÖZ@ªr*_::~/+.å~ð©aÄßbz*z<~rU~O+Z|A<_Büß©¢ö ::.Übýüßr/örh¢:ääU äOA~Aîr<¢äv¢Ä+hC/vßoUª+Oãªã*ð¢Bö.Zbh/ä,åä>*öðßUßý>aªbBbvßãÖ/bã|ýÖ u.zý©~äðzÐU.UA*a*.¢>î rß ~Cüßaö+rª~ß@aã/ÐCß*a,ªÄbb<o+v.åu<£B<îBZßåu£/_>*~')");
Execute($conn1, true, "SET IDENTITY_INSERT [$tableName] ON;INSERT INTO [$tableName] (c1_int, c2_tinyint, c3_smallint, c4_bigint, c5_varchar) VALUES (-411114769, 198, 1378, 140345831, 'Ü@ßaörêA*ÐüßA>_hOüv@|h~O<¢+*ÃÐCbazÜaåZ/Öö:ýãuöÐaz£ÐAh+u+rß:| U*¢ªåßÄÐ_vî@@~ChÐö_å*AAýBö¢B,ßbßå.ÃB+u*CAvÜ,ã>ªßCU<åî©ürz¢@ör¢*Öub¢BåaÜ@ª.äBv¢o~ ßýo oîu/>ÜÐÄ,ð,ðaOÖå>ðC:öZ>ßåð©<ð¢+£r.bO.©,uAßr><ov:,ÄßîåÃ+å./||CUÜÜ_ÖĪh~<ã_å/hbý Ä©uBuß<Ö@boÖýBãCÜA/öÄ:© ßUü*ývuß.Bãååo_übýr_üß>ÐÃÜ£B¢AªvaîvýßCÜUß åvöuª><îÐUC*aÖU©rªhr+>|äýî|oðröУ<ª<Ö|AªohäAî_vu~:~£Ãhü+ÃBuÄð ü@Z+Ä@hÖî¢|@bU£_ü/£ |:¢zb>@Uß© Ãão Ö@ãÐBã_öBOBÄÐhCÜb~Ö>îü rýåüUzuãrbzß/ªîUÐð©uå.ß@£__vBb©/Ür¢Öuåz£ä*å£/*ÃO');SET IDENTITY_INSERT [$tableName] OFF;");
$stmt1 = SelectFromTable($conn1, $tableName);
$rowCount = RowCount($stmt1);
$stmt1 = selectFromTable($conn1, $tableName);
$rowCount = rowCount($stmt1);
sqlsrv_free_stmt($stmt1);
if ($rowCount != 2)
@ -39,25 +38,25 @@ function ComplexQuery()
die("Table $tableName has $rowCount rows instead of 2.");
}
DropTable($conn1, $tableName);
dropTable($conn1, $tableName);
sqlsrv_close($conn1);
EndTest($testName);
endTest($testName);
}
function Execute($conn, $expectedOutcome, $query)
{
Trace("Executing query ".ltrim(substr($query, 0, 40))." ... ");
trace("Executing query ".ltrim(substr($query, 0, 40))." ... ");
$stmt = ExecuteQueryEx($conn, $query, true);
if ($stmt === false)
{
Trace("failed.\n");
trace("failed.\n");
$actualOutcome = false;
}
else
{
Trace("succeeded.\n");
trace("succeeded.\n");
sqlsrv_free_stmt($stmt);
$actualOutcome = true;
}
@ -68,10 +67,10 @@ function Execute($conn, $expectedOutcome, $query)
}
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
try
{
@ -83,7 +82,7 @@ function Repro()
}
}
Repro();
repro();
?>
--EXPECT--

View file

@ -9,114 +9,101 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function PrepareAndExecute($noPasses)
{
include 'MsSetup.inc';
$testName = "Statement - Prepare and Execute";
StartTest($testName);
startTest($testName);
Setup();
$conn1 = Connect();
CreateTable($conn1, $tableName);
setup();
$conn1 = connect();
InsertRows($conn1, $tableName, 1);
$tableName = 'TC34test';
createTable($conn1, $tableName);
insertRows($conn1, $tableName, 1);
$values = array();
$fieldlVal = "";
// Prepare reference values
Trace("Execute a direct SELECT query on $tableName ...");
$stmt1 = SelectFromTable($conn1, $tableName);
trace("Execute a direct SELECT query on $tableName ...");
$stmt1 = selectFromTable($conn1, $tableName);
$numFields1 = sqlsrv_num_fields($stmt1);
sqlsrv_fetch($stmt1);
for ($i = 0; $i < $numFields1; $i++)
{
if (UseUTF8Data()){
for ($i = 0; $i < $numFields1; $i++) {
if (useUTF8Data()) {
$fieldVal = sqlsrv_get_field($stmt1, $i, SQLSRV_PHPTYPE_STRING('UTF-8'));
}
else{
} else {
$fieldVal = sqlsrv_get_field($stmt1, $i, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
}
if ($fieldVal === false)
{
FatalError("Failed to retrieve field $i");
if ($fieldVal === false) {
fatalError("Failed to retrieve field $i");
}
$values[$i] = $fieldVal;
}
sqlsrv_free_stmt($stmt1);
Trace(" $numFields1 fields retrieved.\n");
trace(" $numFields1 fields retrieved.\n");
// Prepare once and execute several times
Trace("Prepare a SELECT query on $tableName ...");
trace("Prepare a SELECT query on $tableName ...");
$stmt2 = PrepareQuery($conn1, "SELECT * FROM [$tableName]");
$numFields2 = sqlsrv_num_fields($stmt2);
Trace(" $numFields2 fields expected.\n");
if ($numFields2 != $numFields1)
{
SetUTF8Data(false);
trace(" $numFields2 fields expected.\n");
if ($numFields2 != $numFields1) {
setUTF8Data(false);
die("Incorrect number of fields: $numFields2");
}
for ($j = 0; $j < $noPasses; $j++)
{
Trace("Executing the prepared query ...");
for ($j = 0; $j < $noPasses; $j++) {
trace("Executing the prepared query ...");
sqlsrv_execute($stmt2);
sqlsrv_fetch($stmt2);
for ($i = 0; $i < $numFields2; $i++)
{
if (UseUTF8Data()){
for ($i = 0; $i < $numFields2; $i++) {
if (useUTF8Data()) {
$fieldVal = sqlsrv_get_field($stmt2, $i, SQLSRV_PHPTYPE_STRING('UTF-8'));
}
else{
} else {
$fieldVal = sqlsrv_get_field($stmt2, $i, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
}
if ($fieldVal === false)
{
FatalError("Failed to retrieve field $i");
if ($fieldVal === false) {
fatalError("Failed to retrieve field $i");
}
if ($values[$i] != $fieldVal)
{
SetUTF8Data(false);
if ($values[$i] != $fieldVal) {
setUTF8Data(false);
die("Incorrect value for field $i at iteration $j");
}
}
Trace(" $numFields2 fields verified.\n");
trace(" $numFields2 fields verified.\n");
}
sqlsrv_free_stmt($stmt2);
DropTable($conn1, $tableName);
dropTable($conn1, $tableName);
sqlsrv_close($conn1);
EndTest($testName);
endTest($testName);
}
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
if (! IsWindows())
{
SetUTF8Data(true);
if (! isWindows()) {
setUTF8Data(true);
}
try
{
try {
PrepareAndExecute(5);
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
SetUTF8Data(false);
setUTF8Data(false);
}
Repro();
repro();
?>
--EXPECT--
Test "Statement - Prepare and Execute" completed successfully.
Test "Statement - Prepare and Execute" completed successfully.

View file

@ -1,70 +1,63 @@
--TEST--
Statement Cancel Test
--DESCRIPTION--
Verifies that “sqlsrv_cancel” discards any pending data in current result set
Verifies that <EFBFBD>sqlsrv_cancel<EFBFBD> discards any pending data in current result set
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function Cancel()
{
include 'MsSetup.inc';
$testName = "Statement - Cancel";
StartTest($testName);
startTest($testName);
Setup();
$conn1 = Connect();
CreateTable($conn1, $tableName);
InsertRows($conn1, $tableName, 5);
setup();
$conn1 = connect();
Trace("Executing SELECT query on $tableName ...");
$stmt1 = SelectFromTable($conn1, $tableName);
if (sqlsrv_fetch($stmt1) === false)
{
FatalError("Failed to retrieve data from test table");
$tableName = 'TC35test';
createTable($conn1, $tableName);
insertRows($conn1, $tableName, 5);
trace("Executing SELECT query on $tableName ...");
$stmt1 = selectFromTable($conn1, $tableName);
if (sqlsrv_fetch($stmt1) === false) {
fatalError("Failed to retrieve data from test table");
}
Trace(" data fetched successfully.\n");
trace(" data fetched successfully.\n");
Trace("Cancel statement and attempt another fetch (expected to fail) ...\n");
trace("Cancel statement and attempt another fetch (expected to fail) ...\n");
sqlsrv_cancel($stmt1);
if (sqlsrv_fetch($stmt1) === false)
{
handle_errors();
}
else
{
if (sqlsrv_fetch($stmt1) === false) {
handleErrors();
} else {
die("No succesfull data fetch expectd after statement cancel");
}
DropTable($conn1, $tableName);
dropTable($conn1, $tableName);
sqlsrv_close($conn1);
EndTest($testName);
endTest($testName);
}
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
try
{
try {
Cancel();
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
}
Repro();
repro();
?>
--EXPECT--

View file

@ -10,72 +10,63 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function Close()
{
include 'MsSetup.inc';
$testName = "Statement - Close";
StartTest($testName);
startTest($testName);
Setup();
$conn1 = Connect();
CreateTable($conn1, $tableName);
setup();
$conn1 = connect();
$tableName = 'TC36test';
createTable($conn1, $tableName);
Trace("Executing SELECT query on $tableName ...");
$stmt1 = SelectFromTable($conn1, $tableName);
Trace(" successfull.\n");
trace("Executing SELECT query on $tableName ...");
$stmt1 = selectFromTable($conn1, $tableName);
trace(" successfull.\n");
sqlsrv_free_stmt($stmt1);
Trace("Attempting to retrieve the number of fields after statement was closed ...\n");
if (sqlsrv_num_fields($stmt1) === false)
{
handle_errors();
}
else
{
trace("Attempting to retrieve the number of fields after statement was closed ...\n");
if (sqlsrv_num_fields($stmt1) === false) {
handleErrors();
} else {
die("A closed statement cannot be reused.");
}
Trace("\nClosing the statement again (no error expected) ...\n");
if (sqlsrv_free_stmt($stmt1) === false)
{
FatalError("A statement can be closed multiple times.");
trace("\nClosing the statement again (no error expected) ...\n");
if (sqlsrv_free_stmt($stmt1) === false) {
fatalError("A statement can be closed multiple times.");
}
DropTable($conn1, $tableName);
dropTable($conn1, $tableName);
sqlsrv_close($conn1);
EndTest($testName);
endTest($testName);
}
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
try
{
try {
Close();
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
}
Repro();
repro();
?>
--EXPECTREGEX--
Warning: sqlsrv_num_fields\(\): supplied resource is not a valid ss_sqlsrv_stmt resource in .*TC36_Close.php on line 21
Warning: sqlsrv_free_stmt\(\): supplied resource is not a valid ss_sqlsrv_stmt resource in .*TC36_Close.php on line 32
Warning: sqlsrv_free_stmt\(\): supplied resource is not a valid ss_sqlsrv_stmt resource in .*TC36_Close.php on line 29
Test "Statement - Close" completed successfully.

View file

@ -1,8 +1,8 @@
--TEST--
Query Timeout Test
--DESCRIPTION--
Verifies the functionality of QueryTimeout option for both “sqlsrv_query”
and “sqlsrv_prepare”.
Verifies the functionality of QueryTimeout option for both <EFBFBD>sqlsrv_query<EFBFBD>
and <EFBFBD>sqlsrv_prepare<EFBFBD>.
Executes a batch query that is expected to time out because it includes
a request to delay the server execution (via WAITFOR DELAY) for a duration
longer than the query timeout.
@ -12,77 +12,66 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function QueryTimeout()
{
include 'MsSetup.inc';
$testName = "Statement - Query Timeout";
StartTest($testName);
startTest($testName);
Setup();
$conn1 = Connect();
CreateTable($conn1, $tableName);
setup();
$conn1 = connect();
$tableName = 'TC37test';
createTable($conn1, $tableName);
Trace("Executing batch queries requiring 3 seconds with 1 second timeout.\n");
trace("Executing batch queries requiring 3 seconds with 1 second timeout.\n");
$query = "WAITFOR DELAY '00:00:03'; SELECT * FROM [$tableName]";
$option = array('QueryTimeout' => 1);
// Test timeout with sqlsrv_query()
Trace("\tDirect execution ...");
trace("\tDirect execution ...");
$stmt1 = sqlsrv_query($conn1, $query, null, $option);
if ($stmt1 === false)
{
Trace(" query timed out (as expected).\n");
}
else
{
if ($stmt1 === false) {
trace(" query timed out (as expected).\n");
} else {
die("Query was expected to time out");
}
// Test timeout with sqlsrv_prepare()/sqlsrv_execute()
Trace("\tPrepared execution ...");
trace("\tPrepared execution ...");
$stmt2 = sqlsrv_prepare($conn1, $query, null, $option);
if ($stmt2 === false)
{
FatalError("Query preparation failed: $query");
if ($stmt2 === false) {
fatalError("Query preparation failed: $query");
}
$execOutcome = sqlsrv_execute($stmt2);
if ($execOutcome === false)
{
Trace(" query timed out (as expected).\n");
}
else
{
if ($execOutcome === false) {
trace(" query timed out (as expected).\n");
} else {
die("Query execution was expected to time out");
}
sqlsrv_free_stmt($stmt2);
DropTable($conn1, $tableName);
dropTable($conn1, $tableName);
sqlsrv_close($conn1);
EndTest($testName);
endTest($testName);
}
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
try
{
try {
QueryTimeout();
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
}
Repro();
repro();
?>
--EXPECT--

View file

@ -1,84 +1,82 @@
--TEST--
Invalid Query Test
--DESCRIPTION--
Verifies of "sqlsrv_query" response to invalid query attempts
Verifies of "sqlsrv_query" response to invalid query attempts
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function InvalidQuery()
{
include 'MsSetup.inc';
$testName = "Statement - Invalid Query";
StartTest($testName);
startTest($testName);
setup();
$conn1 = connect();
Setup();
$conn1 = Connect();
// Invalid Query
$stmt1 = sqlsrv_query($conn1, "INVALID QUERY");
if ($stmt1)
{
if ($stmt1) {
die("Invalid query should have failed.");
}
$dataType = "[c1] int, [c2] int";
CreateTableEx($conn1, $tableName, $dataType);
$tableName = 'TC38test';
createTableEx($conn1, $tableName, $dataType);
// Invalid PHPTYPE parameter
$stmt2 = sqlsrv_query($conn1, "INSERT INTO [$tableName] (c1, c2) VALUES (?, ?)",
array(1, array(2, SQLSRV_PARAM_IN, 'SQLSRV_PHPTYPE_UNKNOWN')));
if ($stmt2)
{
$stmt2 = sqlsrv_query(
$conn1,
"INSERT INTO [$tableName] (c1, c2) VALUES (?, ?)",
array(1, array(2, SQLSRV_PARAM_IN, 'SQLSRV_PHPTYPE_UNKNOWN'))
);
if ($stmt2) {
die("Insert query with invalid parameter should have failed.");
}
// Invalid option
$stmt3 = sqlsrv_query($conn1, "INSERT INTO [$tableName] (c1, c2) VALUES (?, ?)", array(1, 2),
array('doSomething' => 1));
if ($stmt3)
{
$stmt3 = sqlsrv_query(
$conn1,
"INSERT INTO [$tableName] (c1, c2) VALUES (?, ?)",
array(1, 2),
array('doSomething' => 1)
);
if ($stmt3) {
die("Insert query with invalid option should have failed.");
}
// Invalid select
DropTable($conn1, $tableName);
dropTable($conn1, $tableName);
$stmt4 = sqlsrv_query($conn1, "SELECT * FROM [$tableName]");
if ($stmt4)
{
if ($stmt4) {
die("Select query should have failed.");
}
sqlsrv_close($conn1);
EndTest($testName);
endTest($testName);
}
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
try
{
try {
InvalidQuery();
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
}
Repro();
repro();
?>
--EXPECT--
Test "Statement - Invalid Query" completed successfully.

View file

@ -8,23 +8,21 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function CursorTest($noRows1, $noRows2)
{
include 'MsSetup.inc';
$testName = "Statement - Cursor Mode";
StartTest($testName);
startTest($testName);
Setup();
$conn1 = Connect();
setup();
$conn1 = connect();
$cursor = "";
for ($k = 0; $k < 4; $k++)
{
switch ($k)
{
for ($k = 0; $k < 4; $k++) {
switch ($k) {
case 0: $cursor = SQLSRV_CURSOR_FORWARD; break;
case 1: $cursor = SQLSRV_CURSOR_STATIC; break;
case 2: $cursor = SQLSRV_CURSOR_DYNAMIC; break;
@ -36,89 +34,76 @@ function CursorTest($noRows1, $noRows2)
sqlsrv_close($conn1);
EndTest($testName);
endTest($testName);
}
function ScrollableFetch($conn, $tableName, $noRows1, $noRows2, $cursor)
{
$colIndex = "c27_timestamp";
CreateTable($conn, $tableName);
CreateUniqueIndex($conn, $tableName, $colIndex);
createTable($conn, $tableName);
createUniqueIndex($conn, $tableName, $colIndex);
$stmt1 = SelectFromTable($conn, $tableName);
if (sqlsrv_has_rows($stmt1))
{
$stmt1 = selectFromTable($conn, $tableName);
if (sqlsrv_has_rows($stmt1)) {
die("Table $tableName is expected to be empty...");
}
sqlsrv_free_stmt($stmt1);
$noRows = InsertRows($conn, $tableName, $noRows1);
$noRows = insertRows($conn, $tableName, $noRows1);
$query = "SELECT * FROM [$tableName] ORDER BY $colIndex";
$options = array('Scrollable' => $cursor);
$stmt2 = SelectQueryEx($conn, $query, $options);
if (!sqlsrv_has_rows($stmt2))
{
$stmt2 = selectQueryEx($conn, $query, $options);
if (!sqlsrv_has_rows($stmt2)) {
die("Table $tableName is not expected to be empty...");
}
if (($cursor == SQLSRV_CURSOR_STATIC) ||
($cursor == SQLSRV_CURSOR_KEYSET))
{
($cursor == SQLSRV_CURSOR_KEYSET)) {
$numRows = sqlsrv_num_rows($stmt2);
if ($numRows != $noRows)
{
die("Unexpected row count for $cursor: $numRows instead of $noRows\n");
if ($numRows != $noRows) {
die("Unexpected row count for $cursor: $numRows instead of $noRows\n");
}
}
while (($noRows > 0) && sqlsrv_fetch($stmt2))
{
while (($noRows > 0) && sqlsrv_fetch($stmt2)) {
// consume the result set
$noRows--;
}
if ($noRows2 > 0)
{
$extraRows = InsertRows($conn, $tableName, $noRows2);
if ($cursor == SQLSRV_CURSOR_DYNAMIC)
{
if ($noRows2 > 0) {
$extraRows = insertRows($conn, $tableName, $noRows2);
if ($cursor == SQLSRV_CURSOR_DYNAMIC) {
$noRows += $extraRows;
}
}
while (sqlsrv_fetch($stmt2))
{
while (sqlsrv_fetch($stmt2)) {
// consume the result set
$noRows--;
}
sqlsrv_free_stmt($stmt2);
if ($noRows != 0)
{
die("Unexpected row count for $cursor: $noRows\n");
if ($noRows != 0) {
die("Unexpected row count for $cursor: $noRows\n");
}
DropTable($conn, $tableName);
dropTable($conn, $tableName);
}
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
try
{
try {
CursorTest(10, 5);
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
}
Repro();
repro();
?>
--EXPECT--
Test "Statement - Cursor Mode" completed successfully.

View file

@ -12,81 +12,75 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function FetchMetadata()
{
include 'MsSetup.inc';
$testName = "Fetch - Metadata";
StartTest($testName);
startTest($testName);
Setup();
$conn1 = Connect();
CreateTable($conn1, $tableName);
setup();
$conn1 = connect();
createTable($conn1, $tableName);
InsertRow($conn1, $tableName);
insertRow($conn1, $tableName);
$stmt1 = SelectFromTable($conn1, $tableName);
$stmt1 = selectFromTable($conn1, $tableName);
$numFields = sqlsrv_num_fields($stmt1);
Trace("Expecting $numFields fields...\n");
trace("Expecting $numFields fields...\n");
$metadata = sqlsrv_field_metadata($stmt1);
$count = count($metadata);
if ($count != $numFields)
{
if ($count != $numFields) {
die("Unexpected metadata size: ".$count);
}
for ($k = 0; $k < $count; $k++)
{
Trace(" ".($k + 1)."\t");
for ($k = 0; $k < $count; $k++) {
trace(" ".($k + 1)."\t");
ShowMetadata($metadata, $k, 'Name');
ShowMetadata($metadata, $k, 'Size');
ShowMetadata($metadata, $k, 'Precision');
ShowMetadata($metadata, $k, 'Scale');
ShowMetadata($metadata, $k, 'Nullable');
Trace("\n");
trace("\n");
}
sqlsrv_free_stmt($stmt1);
DropTable($conn1, $tableName);
dropTable($conn1, $tableName);
sqlsrv_close($conn1);
EndTest($testName);
endTest($testName);
}
function ShowMetadata($mdArray, $field, $info)
{
$mdInfo = $mdArray[$field][$info];
$refInfo = GetMetadata($field + 1, $info);
Trace("[$info=$mdInfo]");
if ($mdInfo != $refInfo)
{
die ("Unexpected metadata value for $info in field ".($field + 1).": $mdInfo instead of $refInfo");
trace("[$info=$mdInfo]");
if ($mdInfo != $refInfo) {
die("Unexpected metadata value for $info in field ".($field + 1).": $mdInfo instead of $refInfo");
}
}
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
try
{
try {
FetchMetadata();
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
}
Repro();
repro();
?>
--EXPECT--

View file

@ -9,74 +9,67 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function FetchFields()
{
include 'MsSetup.inc';
$testName = "Fetch - Field";
StartTest($testName);
startTest($testName);
Setup();
if (! IsWindows())
$conn1 = ConnectUTF8();
else
$conn1 = Connect();
CreateTable($conn1, $tableName);
setup();
if (! isWindows()) {
$conn1 = connect(array( 'CharacterSet'=>'UTF-8' ));
} else {
$conn1 = connect();
}
createTable($conn1, $tableName);
$noRows = 10;
$noRowsInserted = InsertRows($conn1, $tableName, $noRows);
$noRowsInserted = insertRows($conn1, $tableName, $noRows);
$stmt1 = SelectFromTable($conn1, $tableName);
$stmt1 = selectFromTable($conn1, $tableName);
$numFields = sqlsrv_num_fields($stmt1);
Trace("Retrieving $noRowsInserted rows with $numFields fields each ...");
for ($i = 0; $i < $noRowsInserted; $i++)
{
trace("Retrieving $noRowsInserted rows with $numFields fields each ...");
for ($i = 0; $i < $noRowsInserted; $i++) {
$row = sqlsrv_fetch($stmt1);
if ($row === false)
{
FatalError("Row $i is missing");
if ($row === false) {
fatalError("Row $i is missing");
}
for ($j = 0; $j < $numFields; $j++)
{
for ($j = 0; $j < $numFields; $j++) {
$fld = sqlsrv_get_field($stmt1, $j);
if ($fld === false)
{
FatalError("Field $j of Row $i is missing\n");
if ($fld === false) {
fatalError("Field $j of Row $i is missing\n");
}
}
}
sqlsrv_free_stmt($stmt1);
Trace(" completed successfully.\n");
trace(" completed successfully.\n");
dropTable($conn1, $tableName);
DropTable($conn1, $tableName);
sqlsrv_close($conn1);
EndTest($testName);
endTest($testName);
}
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
try
{
try {
FetchFields();
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
}
Repro();
repro();
?>
--EXPECT--

View file

@ -7,72 +7,63 @@ PHPT_EXEC=true
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function FetchFields()
{
include 'MsSetup.inc';
$testName = "Fetch - Field Data";
StartTest($testName);
startTest($testName);
Setup();
$conn1 = Connect();
CreateTable($conn1, $tableName);
setup();
$conn1 = connect();
createTable($conn1, $tableName);
$startRow = 1;
$noRows = 20;
InsertRowsByRange($conn1, $tableName, $startRow, $startRow + $noRows - 1);
insertRowsByRange($conn1, $tableName, $startRow, $startRow + $noRows - 1);
$query = "SELECT * FROM [$tableName] ORDER BY c27_timestamp";
$stmt1 = SelectQuery($conn1, $query);
$stmt1 = selectQuery($conn1, $query);
$numFields = sqlsrv_num_fields($stmt1);
Trace("Retrieving $noRows rows with $numFields fields each ...");
for ($i = 0; $i < $noRows; $i++)
{
trace("Retrieving $noRows rows with $numFields fields each ...");
for ($i = 0; $i < $noRows; $i++) {
$row = sqlsrv_fetch($stmt1);
if ($row === false)
{
FatalError("Row $i is missing");
if ($row === false) {
fatalError("Row $i is missing");
}
$skipCount = 0;
for ($j = 0; $j < $numFields; $j++)
{
if (UseUTF8Data()){
for ($j = 0; $j < $numFields; $j++) {
if (useUTF8Data()) {
$fld = sqlsrv_get_field($stmt1, $j, SQLSRV_PHPTYPE_STRING('UTF-8'));
}
else{
} else {
$fld = sqlsrv_get_field($stmt1, $j, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
}
if ($fld === false)
{
FatalError("Field $j of Row $i is missing");
if ($fld === false) {
fatalError("Field $j of Row $i is missing");
}
$col = $j + 1;
if (!IsUpdatable($col))
{
if (!IsUpdatable($col)) {
$skipCount++;
}
else // should check data even if $fld is null
{
$data = GetInsertData($startRow + $i, $col, $skipCount);
if (!CheckData($col, $fld, $data))
{
SetUTF8Data(false);
} else { // should check data even if $fld is null
$data = getInsertData($startRow + $i, $col, $skipCount);
if (!CheckData($col, $fld, $data)) {
setUTF8Data(false);
die("Data corruption on row ".($startRow + $i)." column $col");
}
}
}
}
sqlsrv_free_stmt($stmt1);
Trace(" completed successfully.\n");
trace(" completed successfully.\n");
dropTable($conn1, $tableName);
DropTable($conn1, $tableName);
sqlsrv_close($conn1);
EndTest($testName);
endTest($testName);
}
@ -80,57 +71,46 @@ function CheckData($col, $actual, $expected)
{
$success = true;
if (IsNumeric($col))
{
if (floatval($actual) != floatval($expected))
{
if (IsNumeric($col)) {
if (floatval($actual) != floatval($expected)) {
$success = false;
}
}
else
{
} else {
$actual = trim($actual);
$len = strlen($expected);
if (IsDateTime($col))
{
if (IsDateTime($col)) {
$len = min(strlen("YYYY-MM-DD HH:mm:ss"), $len);
}
if (strncasecmp($actual, $expected, $len) != 0)
{
if (strncasecmp($actual, $expected, $len) != 0) {
$success = false;
}
}
if (!$success)
{
Trace("\nData error\nExpected:\n$expected\nActual:\n$actual\n");
if (!$success) {
trace("\nData error\nExpected:\n$expected\nActual:\n$actual\n");
}
return ($success);
}
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
if (! IsWindows())
{
SetUTF8Data(true);
if (! isWindows()) {
setUTF8Data(true);
}
try
{
try {
FetchFields();
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
SetUTF8Data(false);
setUTF8Data(false);
}
Repro();
repro();
?>
--EXPECT--

View file

@ -1,7 +1,7 @@
--TEST--
Fetch Array Test
--DESCRIPTION--
Verifies data retrieval via “sqlsrv_fetch_array”,
Verifies data retrieval via <EFBFBD>sqlsrv_fetch_array<EFBFBD>,
by checking all fetch type modes.
--ENV--
PHPT_EXEC=true
@ -9,65 +9,59 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function FetchRow($minFetchMode, $maxFetchMode)
{
include 'MsSetup.inc';
$testName = "Fetch - Array";
StartTest($testName);
startTest($testName);
if (!IsMarsSupported())
{
EndTest($testName);
if (!IsMarsSupported()) {
endTest($testName);
return;
}
Setup();
if (! IsWindows())
$conn1 = ConnectUTF8();
else
$conn1 = Connect();
CreateTable($conn1, $tableName);
setup();
if (! isWindows()) {
$conn1 = connect(array( 'CharacterSet'=>'UTF-8' ));
} else {
$conn1 = connect();
}
createTable($conn1, $tableName);
$noRows = 10;
$numFields = 0;
InsertRows($conn1, $tableName, $noRows);
insertRows($conn1, $tableName, $noRows);
for ($k = $minFetchMode; $k <= $maxFetchMode; $k++)
{
$stmt1 = SelectFromTable($conn1, $tableName);
$stmt2 = SelectFromTable($conn1, $tableName);
if ($numFields == 0)
{
for ($k = $minFetchMode; $k <= $maxFetchMode; $k++) {
$stmt1 = selectFromTable($conn1, $tableName);
$stmt2 = selectFromTable($conn1, $tableName);
if ($numFields == 0) {
$numFields = sqlsrv_num_fields($stmt1);
}
else
{
} else {
$count = sqlsrv_num_fields($stmt1);
if ($count != $numFields)
{
SetUTF8Data(false);
if ($count != $numFields) {
setUTF8Data(false);
die("Unexpected number of fields: $count");
}
}
switch ($k)
{
case 1: // fetch array - numeric mode
switch ($k) {
case 1: // fetch array - numeric mode
FetchArray($stmt1, $stmt2, SQLSRV_FETCH_NUMERIC, $noRows, $numFields);
break;
case 2: // fetch array - associative mode
case 2: // fetch array - associative mode
FetchArray($stmt1, $stmt2, SQLSRV_FETCH_ASSOC, $noRows, $numFields);
break;
case 3: // fetch array - both numeric & associative
case 3: // fetch array - both numeric & associative
FetchArray($stmt1, $stmt2, SQLSRV_FETCH_BOTH, $noRows, $numFields);
break;
default: // default
default: // default
FetchArray($stmt1, $stmt2, null, $noRows, $numFields);
break;
}
@ -76,62 +70,47 @@ function FetchRow($minFetchMode, $maxFetchMode)
sqlsrv_free_stmt($stmt2);
}
DropTable($conn1, $tableName);
dropTable($conn1, $tableName);
sqlsrv_close($conn1);
EndTest($testName);
endTest($testName);
}
function FetchArray($stmt, $stmtRef, $mode, $rows, $fields)
{
$size = $fields;
$fetchMode = $mode;
if ($fetchMode == SQLSRV_FETCH_NUMERIC)
{
Trace("\tRetrieving $rows arrays of size $size (Fetch Mode = NUMERIC) ...\n");
}
else if ($fetchMode == SQLSRV_FETCH_ASSOC)
{
Trace("\tRetrieving $rows arrays of size $size (Fetch Mode = ASSOCIATIVE) ...\n");
}
else if ($fetchMode == SQLSRV_FETCH_BOTH)
{
if ($fetchMode == SQLSRV_FETCH_NUMERIC) {
trace("\tRetrieving $rows arrays of size $size (Fetch Mode = NUMERIC) ...\n");
} elseif ($fetchMode == SQLSRV_FETCH_ASSOC) {
trace("\tRetrieving $rows arrays of size $size (Fetch Mode = ASSOCIATIVE) ...\n");
} elseif ($fetchMode == SQLSRV_FETCH_BOTH) {
$size = $fields * 2;
Trace("\tRetrieving $rows arrays of size $size (Fetch Mode = BOTH) ...\n");
}
else
{
trace("\tRetrieving $rows arrays of size $size (Fetch Mode = BOTH) ...\n");
} else {
$fetchMode = null;
$size = $fields * 2;
Trace("\tRetrieving $rows arrays of size $size (Fetch Mode = DEFAULT) ...\n");
trace("\tRetrieving $rows arrays of size $size (Fetch Mode = DEFAULT) ...\n");
}
for ($i = 0; $i < $rows; $i++)
{
if ($fetchMode == null)
{
for ($i = 0; $i < $rows; $i++) {
if ($fetchMode == null) {
$row = sqlsrv_fetch_array($stmt);
}
else
{
} else {
$row = sqlsrv_fetch_array($stmt, $fetchMode);
}
if ($row === false)
{
FatalError("Row $i is missing");
if ($row === false) {
fatalError("Row $i is missing");
}
$rowSize = count($row);
if ($rowSize != $size)
{
SetUTF8Data(false);
if ($rowSize != $size) {
setUTF8Data(false);
die("Row array has an incorrect size: ".$rowSize);
}
$rowRref = sqlsrv_fetch($stmtRef);
for ($j = 0; $j < $fields; $j++)
{
if (!CheckData($row, $stmtRef, $j, $fetchMode))
{
SetUTF8Data(false);
for ($j = 0; $j < $fields; $j++) {
if (!CheckData($row, $stmtRef, $j, $fetchMode)) {
setUTF8Data(false);
die("Data corruption on row ".($i + 1)." column ".($j + 1));
}
}
@ -147,70 +126,54 @@ function CheckData($row, $stmt, $index, $mode)
$actual = (($mode == SQLSRV_FETCH_ASSOC) ? $row[GetColName($col)] : $row[$index]);
$expected = null;
if (!IsUpdatable($col))
{
if (!IsUpdatable($col)) {
// do not check the timestamp
}
else if (IsNumeric($col) || IsDateTime($col))
{
} elseif (IsNumeric($col) || IsDateTime($col)) {
$expected = sqlsrv_get_field($stmt, $index);
if ($expected != $actual)
{
if ($expected != $actual) {
$success = false;
}
}
else if (IsBinary($col))
{
} elseif (IsBinary($col)) {
$expected = sqlsrv_get_field($stmt, $index, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
$actual = bin2hex($actual);
if (strcasecmp($actual, $expected) != 0)
{
if (strcasecmp($actual, $expected) != 0) {
$success = false;
}
}
else // if (IsChar($col))
{
if (UseUTF8Data()){
} else { // if (IsChar($col))
if (useUTF8Data()) {
$expected = sqlsrv_get_field($stmt, $index, SQLSRV_PHPTYPE_STRING('UTF-8'));
}
else{
} else {
$expected = sqlsrv_get_field($stmt, $index, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
}
if (strcmp($actual, $expected) != 0)
{
if (strcmp($actual, $expected) != 0) {
$success = false;
}
}
if (!$success)
{
Trace("\nData error\nExpected:\n$expected\nActual:\n$actual\n");
if (!$success) {
trace("\nData error\nExpected:\n$expected\nActual:\n$actual\n");
}
return ($success);
}
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
if (! IsWindows())
{
SetUTF8Data(true);
if (! isWindows()) {
setUTF8Data(true);
}
try
{
try {
FetchRow(1, 4);
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
SetUTF8Data(false);
setUTF8Data(false);
}
Repro();
repro();
?>
--EXPECT--

View file

@ -1,20 +1,19 @@
--TEST--
Fetch Object Test
--DESCRIPTION--
Verifies data retrieval via “sqlsrv_fetch_object”.
Verifies data retrieval via <EFBFBD>sqlsrv_fetch_object<EFBFBD>.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
class TestClass
{
function __construct($a1, $a2, $a3)
public function __construct($a1, $a2, $a3)
{
}
}
@ -23,84 +22,74 @@ function FetchRow($minFetchMode, $maxFetchMode)
include 'MsSetup.inc';
$testName = "Fetch - Object";
StartTest($testName);
startTest($testName);
Setup();
if (! IsWindows())
$conn1 = ConnectUTF8();
else
$conn1 = Connect();
CreateTable($conn1, $tableName);
setup();
if (! isWindows()) {
$conn1 = connect(array( 'CharacterSet'=>'UTF-8' ));
} else {
$conn1 = connect();
}
createTable($conn1, $tableName);
$noRows = 10;
$noRowsInserted = InsertRows($conn1, $tableName, $noRows);
$noRowsInserted = insertRows($conn1, $tableName, $noRows);
$actual = null;
$expected = null;
$numFields = 0;
for ($k = $minFetchMode; $k <= $maxFetchMode; $k++)
{
$stmt1 = SelectFromTable($conn1, $tableName);
if ($numFields == 0)
{
for ($k = $minFetchMode; $k <= $maxFetchMode; $k++) {
$stmt1 = selectFromTable($conn1, $tableName);
if ($numFields == 0) {
$numFields = sqlsrv_num_fields($stmt1);
}
else
{
} else {
$count = sqlsrv_num_fields($stmt1);
if ($count != $numFields)
{
if ($count != $numFields) {
die("Unexpected number of fields: $count");
}
}
switch ($k)
{
case 0: // fetch array (to retrieve reference values)
switch ($k) {
case 0: // fetch array (to retrieve reference values)
$expected = FetchArray($stmt1, $noRowsInserted, $numFields);
break;
case 1: // fetch object (without class)
case 1: // fetch object (without class)
$actual = FetchObject($stmt1, $noRowsInserted, $numFields, false);
CheckData($noRowsInserted, $numFields, $actual, $expected);
break;
case 2: // fetch object (with class)
case 2: // fetch object (with class)
$actual = FetchObject($stmt1, $noRowsInserted, $numFields, true);
CheckData($noRowsInserted, $numFields, $actual, $expected);
break;
default: // default
default: // default
break;
}
sqlsrv_free_stmt($stmt1);
}
DropTable($conn1, $tableName);
dropTable($conn1, $tableName);
sqlsrv_close($conn1);
EndTest($testName);
endTest($testName);
}
function FetchObject($stmt, $rows, $fields, $useClass)
{
Trace("\tRetrieving $rows objects with $fields fields each ...\n");
trace("\tRetrieving $rows objects with $fields fields each ...\n");
$values = array();
for ($i = 0; $i < $rows; $i++)
{
if ($useClass)
{
for ($i = 0; $i < $rows; $i++) {
if ($useClass) {
$obj = sqlsrv_fetch_object($stmt, "TestClass", array(1, 2, 3));
}
else
{
} else {
$obj = sqlsrv_fetch_object($stmt);
}
if ($obj === false)
{
FatalError("Row $i is missing");
if ($obj === false) {
fatalError("Row $i is missing");
}
$values[$i] = $obj;
}
@ -111,12 +100,10 @@ function FetchObject($stmt, $rows, $fields, $useClass)
function FetchArray($stmt, $rows, $fields)
{
$values = array();
for ($i = 0; $i < $rows; $i++)
{
for ($i = 0; $i < $rows; $i++) {
$row = sqlsrv_fetch_array($stmt);
if ($row === false)
{
FatalError("Row $i is missing");
if ($row === false) {
fatalError("Row $i is missing");
}
$values[$i] = $row;
}
@ -126,17 +113,13 @@ function FetchArray($stmt, $rows, $fields)
function CheckData($rows, $fields, $actualValues, $expectedValues)
{
if (($actualValues != null) && ($expectedValues != null))
{
for ($i = 0; $i < $rows; $i++)
{
for ($j = 0; $j < $fields; $j++)
{
if (($actualValues != null) && ($expectedValues != null)) {
for ($i = 0; $i < $rows; $i++) {
for ($j = 0; $j < $fields; $j++) {
$colName = GetColName($j + 1);
$actual = $actualValues[$i]->$colName;
$expected = $expectedValues[$i][$colName];
if ($actual != $expected)
{
if ($actual != $expected) {
die("Data corruption on row ".($i + 1)." column ".($j + 1).": $expected => $actual");
}
}
@ -146,22 +129,19 @@ function CheckData($rows, $fields, $actualValues, $expectedValues)
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
try
{
try {
FetchRow(0, 2);
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
}
Repro();
repro();
?>
--EXPECT--

View file

@ -1,121 +1,106 @@
--TEST--
Fetch Next Result Test
--DESCRIPTION--
Verifies the functionality of “sqlsvr_next_result”
Verifies the functionality of <EFBFBD>sqlsvr_next_result<EFBFBD>
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function FetchFields()
{
include 'MsSetup.inc';
$testName = "Fetch - Next Result";
StartTest($testName);
startTest($testName);
if (!IsMarsSupported())
{
EndTest($testName);
if (!IsMarsSupported()) {
endTest($testName);
return;
}
Setup();
$conn1 = Connect();
CreateTable($conn1, $tableName);
setup();
$conn1 = connect();
createTable($conn1, $tableName);
$noRows = 10;
InsertRows($conn1, $tableName, $noRows);
insertRows($conn1, $tableName, $noRows);
$stmt1 = SelectQuery($conn1, "SELECT * FROM [$tableName]");
$stmt2 = SelectQuery($conn1, "SELECT * FROM [$tableName]; SELECT * FROM [$tableName]");
if (sqlsrv_next_result($stmt2) === false)
{
FatalError("Failed to retrieve next result set");
$stmt1 = selectQuery($conn1, "SELECT * FROM [$tableName]");
$stmt2 = selectQuery($conn1, "SELECT * FROM [$tableName]; SELECT * FROM [$tableName]");
if (sqlsrv_next_result($stmt2) === false) {
fatalError("Failed to retrieve next result set");
}
$numFields1 = sqlsrv_num_fields($stmt1);
$numFields2 = sqlsrv_num_fields($stmt2);
if ($numFields1 != $numFields2)
{
SetUTF8Data(false);
if ($numFields1 != $numFields2) {
setUTF8Data(false);
die("Unexpected number of fields: $numField1 => $numFields2");
}
Trace("Retrieving $noRows rows with $numFields1 fields each ...");
for ($i = 0; $i < $noRows; $i++)
{
trace("Retrieving $noRows rows with $numFields1 fields each ...");
for ($i = 0; $i < $noRows; $i++) {
$row1 = sqlsrv_fetch($stmt1);
$row2 = sqlsrv_fetch($stmt2);
if (($row1 === false) || ($row2 === false))
{
FatalError("Row $i is missing");
if (($row1 === false) || ($row2 === false)) {
fatalError("Row $i is missing");
}
for ($j = 0; $j < $numFields1; $j++)
{
if (UseUTF8Data()){
for ($j = 0; $j < $numFields1; $j++) {
if (useUTF8Data()) {
$fld1 = sqlsrv_get_field($stmt1, $j, SQLSRV_PHPTYPE_STRING('UTF-8'));
$fld2 = sqlsrv_get_field($stmt2, $j, SQLSRV_PHPTYPE_STRING('UTF-8'));
}
else {
} else {
$fld1 = sqlsrv_get_field($stmt1, $j, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
$fld2 = sqlsrv_get_field($stmt2, $j, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
}
if (($fld1 === false) || ($fld2 === false))
{
FatalError("Field $j of Row $i is missing");
if (($fld1 === false) || ($fld2 === false)) {
fatalError("Field $j of Row $i is missing");
}
if ($fld1 != $fld2)
{
SetUTF8Data(false);
if ($fld1 != $fld2) {
setUTF8Data(false);
die("Data corruption on row ".($i + 1)." column ".($j + 1)." $fld1 => $fld2");
}
}
}
if (sqlsrv_next_result($stmt1) ||
sqlsrv_next_result($stmt2))
{
SetUTF8Data(false);
sqlsrv_next_result($stmt2)) {
setUTF8Data(false);
die("No more results were expected");
}
sqlsrv_free_stmt($stmt1);
sqlsrv_free_stmt($stmt2);
Trace(" completed successfully.\n");
trace(" completed successfully.\n");
dropTable($conn1, $tableName);
DropTable($conn1, $tableName);
sqlsrv_close($conn1);
EndTest($testName);
endTest($testName);
}
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
if (! IsWindows())
{
SetUTF8Data(true);
if (! isWindows()) {
setUTF8Data(true);
}
try
{
try {
FetchFields();
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
SetUTF8Data(false);
setUTF8Data(false);
}
Repro();
repro();
?>
--EXPECT--

View file

@ -9,23 +9,21 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function ParamQuery($minType, $maxType)
{
include 'MsSetup.inc';
$testName = "Parameterized Query";
StartTest($testName);
startTest($testName);
Setup();
$conn1 = Connect();
for ($k = $minType; $k <= $maxType; $k++)
{
setup();
$conn1 = connect();
for ($k = $minType; $k <= $maxType; $k++) {
$data = GetSampleData($k);
if ($data != null)
{
if ($data != null) {
$sqlType = GetSqlType($k);
$phpDriverType = GetDriverType($k, strlen($data));
$dataType = "[c1] int, [c2] $sqlType";
@ -34,60 +32,53 @@ function ParamQuery($minType, $maxType)
TraceData($sqlType, $data);
CreateQueryTable($conn1, $tableName, $dataType, "c1, c2", "?, ?", $dataOptions);
CheckData($conn1, $tableName, 2, $data);
DropTable($conn1, $tableName);
dropTable($conn1, $tableName);
}
}
}
sqlsrv_close($conn1);
EndTest($testName);
endTest($testName);
}
function CreateQueryTable($conn, $table, $dataType, $dataCols, $dataValues, $dataOptions)
{
CreateTableEx($conn, $table, $dataType);
InsertRowEx($conn, $table, $dataCols, $dataValues, $dataOptions);
createTableEx($conn, $table, $dataType);
insertRowEx($conn, $table, $dataCols, $dataValues, $dataOptions);
}
function CheckData($conn, $table, $cols, $expectedValue)
{
$stmt = SelectFromTable($conn, $table);
if (!sqlsrv_fetch($stmt))
{
$stmt = selectFromTable($conn, $table);
if (!sqlsrv_fetch($stmt)) {
die("Table $tableName was not expected to be empty.");
}
$numFields = sqlsrv_num_fields($stmt);
if ($numFields != $cols)
{
if ($numFields != $cols) {
die("Table $tableName was expected to have $cols fields.");
}
$actualValue = sqlsrv_get_field($stmt, 1, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
sqlsrv_free_stmt($stmt);
if (strncmp($actualValue, $expectedValue, strlen($expectedValue)) != 0)
{
if (strncmp($actualValue, $expectedValue, strlen($expectedValue)) != 0) {
die("Data corruption: $expectedValue => $actualValue.");
}
}
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
try
{
try {
ParamQuery(1, 28);
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
}
Repro();
repro();
?>
--EXPECT--

View file

@ -8,29 +8,30 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function FetchRow($noRows)
{
include 'MsSetup.inc';
$testName = "Fetch - Scrollable";
StartTest($testName);
startTest($testName);
Setup();
if (! IsWindows())
$conn1 = ConnectUTF8();
else
$conn1 = Connect();
CreateTable($conn1, $tableName);
setup();
if (! isWindows()) {
$conn1 = connect(array( 'CharacterSet'=>'UTF-8' ));
} else {
$conn1 = connect();
}
createTable($conn1, $tableName);
$noRowsInserted = InsertRows($conn1, $tableName, $noRows);
$noRowsInserted = insertRows($conn1, $tableName, $noRows);
$actual = null;
$expected = null;
// fetch array (to retrieve reference values)
$stmt1 = SelectFromTable($conn1, $tableName);
$stmt1 = selectFromTable($conn1, $tableName);
$numFields = sqlsrv_num_fields($stmt1);
$expected = FetchArray($stmt1, $noRowsInserted, $numFields);
sqlsrv_free_stmt($stmt1);
@ -39,49 +40,47 @@ function FetchRow($noRows)
// fetch object - FORWARD cursor
$options = array('Scrollable' => SQLSRV_CURSOR_FORWARD);
$stmt2 = SelectQueryEx($conn1, $query, $options);
$stmt2 = selectQueryEx($conn1, $query, $options);
$actual = FetchObject($stmt2, $noRowsInserted, $numFields, SQLSRV_SCROLL_NEXT);
sqlsrv_free_stmt($stmt2);
CheckData($noRowsInserted, $numFields, $actual, $expected);
// fetch object - STATIC cursor
$options = array('Scrollable' => SQLSRV_CURSOR_STATIC);
$stmt2 = SelectQueryEx($conn1, $query, $options);
$stmt2 = selectQueryEx($conn1, $query, $options);
$actual = FetchObject($stmt2, $noRowsInserted, $numFields, SQLSRV_SCROLL_RELATIVE);
sqlsrv_free_stmt($stmt2);
CheckData($noRowsInserted, $numFields, $actual, $expected);
// fetch object - DYNAMIC cursor
$options = array('Scrollable' => SQLSRV_CURSOR_DYNAMIC);
$stmt2 = SelectQueryEx($conn1, $query, $options);
$stmt2 = selectQueryEx($conn1, $query, $options);
$actual = FetchObject($stmt2, $noRowsInserted, $numFields, SQLSRV_SCROLL_ABSOLUTE);
sqlsrv_free_stmt($stmt2);
CheckData($noRowsInserted, $numFields, $actual, $expected);
// fetch object - KEYSET cursor
$options = array('Scrollable' => SQLSRV_CURSOR_KEYSET);
$stmt2 = SelectQueryEx($conn1, $query, $options);
$stmt2 = selectQueryEx($conn1, $query, $options);
$actual = FetchObject($stmt2, $noRowsInserted, $numFields, SQLSRV_SCROLL_PRIOR, 0);
sqlsrv_free_stmt($stmt2);
CheckData($noRowsInserted, $numFields, $actual, $expected);
DropTable($conn1, $tableName);
dropTable($conn1, $tableName);
sqlsrv_close($conn1);
EndTest($testName);
endTest($testName);
}
function FetchArray($stmt, $rows, $fields)
{
$values = array();
for ($i = 0; $i < $rows; $i++)
{
for ($i = 0; $i < $rows; $i++) {
$row = sqlsrv_fetch_array($stmt);
if ($row === false)
{
FatalError("Row $i is missing");
if ($row === false) {
fatalError("Row $i is missing");
}
$values[$i] = $row;
}
@ -91,43 +90,28 @@ function FetchArray($stmt, $rows, $fields)
function FetchObject($stmt, $rows, $fields, $dir)
{
Trace("\tRetrieving $rows objects with $fields fields each ...\n");
trace("\tRetrieving $rows objects with $fields fields each ...\n");
$values = array();
for ($i = 0; $i < $rows; $i++)
{
if ($dir == SQLSRV_SCROLL_NEXT)
{
for ($i = 0; $i < $rows; $i++) {
if ($dir == SQLSRV_SCROLL_NEXT) {
$obj = sqlsrv_fetch_object($stmt, null, null, $dir);
}
else if ($dir == SQLSRV_SCROLL_PRIOR)
{
if ($i == 0)
{
} elseif ($dir == SQLSRV_SCROLL_PRIOR) {
if ($i == 0) {
$obj = sqlsrv_fetch_object($stmt, null, null, SQLSRV_SCROLL_LAST);
}
else
{
} else {
$obj = sqlsrv_fetch_object($stmt, null, null, $dir);
}
}
else if ($dir == SQLSRV_SCROLL_ABSOLUTE)
{
} elseif ($dir == SQLSRV_SCROLL_ABSOLUTE) {
$obj = sqlsrv_fetch_object($stmt, null, null, $dir, $i);
}
else if ($dir == SQLSRV_SCROLL_RELATIVE)
{
} elseif ($dir == SQLSRV_SCROLL_RELATIVE) {
$obj = sqlsrv_fetch_object($stmt, null, null, $dir, 1);
}
if ($obj === false)
{
FatalError("Row $i is missing");
if ($obj === false) {
fatalError("Row $i is missing");
}
if ($dir == SQLSRV_SCROLL_PRIOR)
{
if ($dir == SQLSRV_SCROLL_PRIOR) {
$values[$rows - $i - 1] = $obj;
}
else
{
} else {
$values[$i] = $obj;
}
}
@ -136,17 +120,13 @@ function FetchObject($stmt, $rows, $fields, $dir)
function CheckData($rows, $fields, $actualValues, $expectedValues)
{
if (($actualValues != null) && ($expectedValues != null))
{
for ($i = 0; $i < $rows; $i++)
{
for ($j = 0; $j < $fields; $j++)
{
if (($actualValues != null) && ($expectedValues != null)) {
for ($i = 0; $i < $rows; $i++) {
for ($j = 0; $j < $fields; $j++) {
$colName = GetColName($j + 1);
$actual = $actualValues[$i]->$colName;
$expected = $expectedValues[$i][$colName];
if ($actual != $expected)
{
if ($actual != $expected) {
die("Data corruption on row ".($i + 1)." column ".($j + 1).": $expected => $actual");
}
}
@ -156,22 +136,19 @@ function CheckData($rows, $fields, $actualValues, $expectedValues)
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
try
{
try {
FetchRow(10);
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
}
Repro();
repro();
?>
--EXPECT--

View file

@ -9,97 +9,82 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function StreamRead($noRows, $startRow)
{
include 'MsSetup.inc';
$testName = "Stream - Read";
StartTest($testName);
startTest($testName);
Setup();
if (! IsWindows())
$conn1 = ConnectUTF8();
else
$conn1 = Connect();
setup();
if (! isWindows()) {
$conn1 = connect(array( 'CharacterSet'=>'UTF-8' ));
} else {
$conn1 = connect();
}
CreateTable($conn1, $tableName);
InsertRowsByRange($conn1, $tableName, $startRow, $startRow + $noRows - 1);
createTable($conn1, $tableName);
insertRowsByRange($conn1, $tableName, $startRow, $startRow + $noRows - 1);
$query = "SELECT * FROM [$tableName] ORDER BY c27_timestamp";
$stmt1 = SelectQuery($conn1, $query);
$stmt1 = selectQuery($conn1, $query);
$numFields = sqlsrv_num_fields($stmt1);
for ($row = 1; $row <= $noRows; $row++)
{
if (!sqlsrv_fetch($stmt1))
{
FatalError("Failed to fetch row ".$row);
for ($row = 1; $row <= $noRows; $row++) {
if (!sqlsrv_fetch($stmt1)) {
fatalError("Failed to fetch row ".$row);
}
Trace("\nStreaming row $row:\n");
trace("\nStreaming row $row:\n");
$skipCount = 0;
for ($j = 0; $j < $numFields; $j++)
{
for ($j = 0; $j < $numFields; $j++) {
$col = $j + 1;
if (!IsUpdatable($col))
{
if (!IsUpdatable($col)) {
$skipCount++;
}
if (IsStreamable($col))
{
if (IsStreamable($col)) {
VerifyStream($stmt1, $startRow + $row - 1, $j, $skipCount);
}
}
}
sqlsrv_free_stmt($stmt1);
DropTable($conn1, $tableName);
dropTable($conn1, $tableName);
sqlsrv_close($conn1);
EndTest($testName);
endTest($testName);
}
function VerifyStream($stmt, $row, $colIndex, $skip)
{
$col = $colIndex + 1;
if (IsStreamable($col))
{
if (IsStreamable($col)) {
$type = GetSqlType($col);
if (IsBinary($col))
{
if (IsBinary($col)) {
$stream = sqlsrv_get_field($stmt, $colIndex, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY));
}
else
{
if (UseUTF8Data()){
} else {
if (useUTF8Data()) {
$stream = sqlsrv_get_field($stmt, $colIndex, SQLSRV_PHPTYPE_STREAM('UTF-8'));
}
else{
} else {
$stream = sqlsrv_get_field($stmt, $colIndex, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_CHAR));
}
}
if ($stream === false)
{
FatalError("Failed to read field $col: $type");
}
else
{
if ($stream === false) {
fatalError("Failed to read field $col: $type");
} else {
$value = '';
if ($stream)
{
while (!feof($stream))
{
if ($stream) {
while (!feof($stream)) {
$value .= fread($stream, 8192);
}
fclose($stream);
$data = GetInsertData($row, $col, $skip);
if (!CheckData($col, $value, $data))
{
SetUTF8Data(false);
Trace("Data corruption on row $row column $col\n");
$data = getInsertData($row, $col, $skip);
if (!CheckData($col, $value, $data)) {
setUTF8Data(false);
trace("Data corruption on row $row column $col\n");
die("Data corruption on row $row column $col\n");
}
}
@ -113,31 +98,23 @@ function CheckData($col, $actual, $expected)
{
$success = true;
if (IsBinary($col))
{
if (IsBinary($col)) {
$actual = bin2hex($actual);
if (strncasecmp($actual, $expected, strlen($expected)) != 0)
{
if (strncasecmp($actual, $expected, strlen($expected)) != 0) {
$success = false;
}
}
else
{
if (strncasecmp($actual, $expected, strlen($expected)) != 0)
{
if ($col != 19)
{ // skip ntext
} else {
if (strncasecmp($actual, $expected, strlen($expected)) != 0) {
if ($col != 19) { // skip ntext
$pos = strpos($actual, $expected);
if (($pos === false) || ($pos > 1))
{
if (($pos === false) || ($pos > 1)) {
$success = false;
}
}
}
}
if (!$success)
{
Trace("\nData error\nExpected:\n$expected\nActual:\n$actual\n");
if (!$success) {
trace("\nData error\nExpected:\n$expected\nActual:\n$actual\n");
}
return ($success);
@ -145,31 +122,26 @@ function CheckData($col, $actual, $expected)
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
if (! IsWindows())
{
SetUTF8Data(true);
if (! isWindows()) {
setUTF8Data(true);
}
try
{
try {
StreamRead(20, 1);
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
SetUTF8Data(false);
setUTF8Data(false);
}
Repro();
repro();
?>
--EXPECT--
Test "Stream - Read" completed successfully.

View file

@ -11,22 +11,20 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function SendStream($minType, $maxType, $atExec)
{
include 'MsSetup.inc';
$testName = "Stream - ".($atExec ? "Send at Execution" : "Send after Execution");
StartTest($testName);
startTest($testName);
Setup();
$conn1 = Connect();
setup();
$conn1 = connect();
for ($k = $minType; $k <= $maxType; $k++)
{
switch ($k)
{
for ($k = $minType; $k <= $maxType; $k++) {
switch ($k) {
case 1: // int
case 2: // tinyint
case 3: // smallint
@ -97,8 +95,7 @@ function SendStream($minType, $maxType, $atExec)
break;
}
if ($data != null)
{
if ($data != null) {
$fname1 = fopen($fileName, "w");
fwrite($fname1, $data);
fclose($fname1);
@ -116,62 +113,55 @@ function SendStream($minType, $maxType, $atExec)
}
}
DropTable($conn1, $tableName);
dropTable($conn1, $tableName);
sqlsrv_close($conn1);
EndTest($testName);
endTest($testName);
}
function CreateQueryTable($conn, $table, $dataType, $dataCols, $dataValues, $dataOptions, $execMode)
{
CreateTableEx($conn, $table, $dataType);
InsertStream($conn, $table, $dataCols, $dataValues, $dataOptions, $execMode);
createTableEx($conn, $table, $dataType);
insertStream($conn, $table, $dataCols, $dataValues, $dataOptions, $execMode);
}
function CheckData($conn, $table, $cols, $expectedValue)
{
$stmt = SelectFromTable($conn, $table);
if (!sqlsrv_fetch($stmt))
{
FatalError("Table $tableName was not expected to be empty.");
$stmt = selectFromTable($conn, $table);
if (!sqlsrv_fetch($stmt)) {
fatalError("Table $tableName was not expected to be empty.");
}
$numFields = sqlsrv_num_fields($stmt);
if ($numFields != $cols)
{
if ($numFields != $cols) {
die("Table $tableName was expected to have $cols fields.");
}
$actualValue = sqlsrv_get_field($stmt, 1, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
sqlsrv_free_stmt($stmt);
if (strncmp($actualValue, $expectedValue, strlen($expectedValue)) != 0)
{
if (strncmp($actualValue, $expectedValue, strlen($expectedValue)) != 0) {
die("Data corruption: $expectedValue => $actualValue.");
}
}
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
try
{
try {
SendStream(12, 28, true); // send stream at execution
SendStream(12, 28, false); // send stream after execution
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
}
Repro();
repro();
?>
--EXPECT--
Test "Stream - Send at Execution" completed successfully.
Test "Stream - Send after Execution" completed successfully.

View file

@ -10,23 +10,23 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function CancelStream()
{
include 'MsSetup.inc';
$testName = "Stream - Cancel";
StartTest($testName);
startTest($testName);
Setup();
$conn1 = Connect();
setup();
$conn1 = connect();
$noRows = 5;
CreateTable($conn1, $tableName);
InsertRows($conn1, $tableName, $noRows);
createTable($conn1, $tableName);
insertRows($conn1, $tableName, $noRows);
$stmt1 = SelectFromTable($conn1, $tableName);
$stmt1 = selectFromTable($conn1, $tableName);
// Expired stream
$stream1 = GetStream($stmt1);
@ -39,40 +39,36 @@ function CancelStream()
CheckStream($stream2);
// Closed statement
$stmt2 = SelectFromTable($conn1, $tableName);
$stmt2 = selectFromTable($conn1, $tableName);
$stream3 = GetStream($stmt2);
sqlsrv_free_stmt($stmt2);
CheckStream($stream3);
DropTable($conn1, $tableName);
dropTable($conn1, $tableName);
sqlsrv_close($conn1);
EndTest($testName);
endTest($testName);
}
function GetStream($stmt)
{
$stream = null;
if (!sqlsrv_fetch($stmt))
{
FatalError("Failed to fetch row ".$row);
if (!sqlsrv_fetch($stmt)) {
fatalError("Failed to fetch row ".$row);
}
while ($stream == null)
{
while ($stream == null) {
$col = rand(11, 22); // select a streamable field
if (!IsStreamable($col + 1))
{
if (!IsStreamable($col + 1)) {
die("Failed to select a streamable field.");
}
$type = GetSqlType($col + 1);
Trace("Selected streamable type: $type ...\n");
trace("Selected streamable type: $type ...\n");
$stream = sqlsrv_get_field($stmt, $col, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY));
if ($stream === false)
{
FatalError("Failed to read field $col: $type");
if ($stream === false) {
fatalError("Failed to read field $col: $type");
}
}
@ -82,39 +78,32 @@ function GetStream($stmt)
function CheckStream($stream)
{
$bytesRead = 0;
try
{
try {
$value = fread($stream, 8192);
$bytesRread = strlen($value);
}
catch (Exception $e)
{
} catch (Exception $e) {
$bytesRead = 0;
Trace($e->getMessage());
trace($e->getMessage());
}
if ($bytesRead > 0)
{
if ($bytesRead > 0) {
die("Invalid stream should not return any data.");
}
}
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
try
{
try {
CancelStream();
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
}
Repro();
repro();
?>
--EXPECTREGEX--
@ -125,4 +114,3 @@ Repro();
|Warning: fread\(\): supplied argument is not a valid stream resource in .+\\TC53_StreamCancel.php on line 86|Warning: fread\(\): expects parameter 1 to be resource, null given in .+\\TC53_StreamCancel.php on line 86
Test "Stream - Cancel" completed successfully.

View file

@ -10,22 +10,20 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function SendStream($minType, $maxType)
{
include 'MsSetup.inc';
$testName = "Stream - Prepared Send";
StartTest($testName);
startTest($testName);
Setup();
$conn1 = Connect();
setup();
$conn1 = connect();
for ($k = $minType; $k <= $maxType; $k++)
{
switch ($k)
{
for ($k = $minType; $k <= $maxType; $k++) {
switch ($k) {
case 12: // char
case 13: // varchar
case 14: // varchar(max)
@ -62,18 +60,18 @@ function SendStream($minType, $maxType)
array(&$fname2, SQLSRV_PARAM_IN, null, $phpDriverType));
TraceData($sqlType, $data);
CreateTableEx($conn1, $tableName, $dataType);
createTableEx($conn1, $tableName, $dataType);
InsertData($conn1, $tableName, "c1, c2", "?, ?", $dataOptions);
CheckData($conn1, $tableName, 2, $data);
fclose($fname2);
}
DropTable($conn1, $tableName);
dropTable($conn1, $tableName);
sqlsrv_close($conn1);
EndTest($testName);
endTest($testName);
}
@ -81,69 +79,57 @@ function InsertData($conn, $tableName, $dataCols, $dataValues, $dataOptions)
{
$sql = "INSERT INTO [$tableName] ($dataCols) VALUES ($dataValues)";
$stmt = sqlsrv_prepare($conn, $sql, $dataOptions);
if ($stmt === false)
{
FatalError("Failed to prepare insert query: ".$sql);
if ($stmt === false) {
fatalError("Failed to prepare insert query: ".$sql);
}
$outcome = sqlsrv_execute($stmt);
if ($outcome === false)
{
FatalError("Failed to execute prepared query: ".$sql);
if ($outcome === false) {
fatalError("Failed to execute prepared query: ".$sql);
}
while (sqlsrv_send_stream_data($stmt))
{
while (sqlsrv_send_stream_data($stmt)) {
}
$numRows = sqlsrv_rows_affected($stmt);
sqlsrv_free_stmt($stmt);
if ($numRows != 1)
{
die("Unexpected row count at insert: ".$numRows);
if ($numRows != 1) {
die("Unexpected row count at insert: ".$numRows);
}
}
function CheckData($conn, $table, $cols, $expectedValue)
{
$stmt = SelectFromTable($conn, $table);
if (!sqlsrv_fetch($stmt))
{
FatalError("Table $tableName was not expected to be empty.");
$stmt = selectFromTable($conn, $table);
if (!sqlsrv_fetch($stmt)) {
fatalError("Table $tableName was not expected to be empty.");
}
$numFields = sqlsrv_num_fields($stmt);
if ($numFields != $cols)
{
if ($numFields != $cols) {
die("Table $tableName was expected to have $cols fields.");
}
$actualValue = sqlsrv_get_field($stmt, 1, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
sqlsrv_free_stmt($stmt);
if (strncmp($actualValue, $expectedValue, strlen($expectedValue)) != 0)
{
if (strncmp($actualValue, $expectedValue, strlen($expectedValue)) != 0) {
die("Data corruption: $expectedValue => $actualValue.");
}
}
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
try
{
try {
SendStream(12, 23);
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
}
Repro();
repro();
?>
--EXPECTREGEX--
Test "Stream - Prepared Send" completed successfully.

View file

@ -8,57 +8,49 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function StreamScroll($noRows, $startRow)
{
include 'MsSetup.inc';
$testName = "Stream - Scrollable";
StartTest($testName);
startTest($testName);
Setup();
if (! IsWindows())
$conn1 = ConnectUTF8();
else
$conn1 = Connect();
setup();
if (! isWindows()) {
$conn1 = connect(array( 'CharacterSet'=>'UTF-8' ));
} else {
$conn1 = connect();
}
CreateTable($conn1, $tableName);
InsertRowsByRange($conn1, $tableName, $startRow, $startRow + $noRows - 1);
createTable($conn1, $tableName);
insertRowsByRange($conn1, $tableName, $startRow, $startRow + $noRows - 1);
$query = "SELECT * FROM [$tableName] ORDER BY c27_timestamp";
$options = array('Scrollable' => SQLSRV_CURSOR_STATIC);
$stmt1 = SelectQueryEx($conn1, $query, $options);
$stmt1 = selectQueryEx($conn1, $query, $options);
$numFields = sqlsrv_num_fields($stmt1);
$row = $noRows;
while ($row >= 1)
{
if ($row == $noRows)
{
if (!sqlsrv_fetch($stmt1, SQLSRV_SCROLL_LAST))
{
FatalError("Failed to fetch row ".$row);
while ($row >= 1) {
if ($row == $noRows) {
if (!sqlsrv_fetch($stmt1, SQLSRV_SCROLL_LAST)) {
fatalError("Failed to fetch row ".$row);
}
} else {
if (!sqlsrv_fetch($stmt1, SQLSRV_SCROLL_PRIOR)) {
fatalError("Failed to fetch row ".$row);
}
}
else
{
if (!sqlsrv_fetch($stmt1, SQLSRV_SCROLL_PRIOR))
{
FatalError("Failed to fetch row ".$row);
}
}
Trace("\nStreaming row $row:\n");
trace("\nStreaming row $row:\n");
$skipCount = 0;
for ($j = 0; $j < $numFields; $j++)
{
for ($j = 0; $j < $numFields; $j++) {
$col = $j + 1;
if (!IsUpdatable($col))
{
if (!IsUpdatable($col)) {
$skipCount++;
}
if (IsStreamable($col))
{
if (IsStreamable($col)) {
VerifyStream($stmt1, $startRow + $row - 1, $j, $skipCount);
}
}
@ -66,52 +58,41 @@ function StreamScroll($noRows, $startRow)
}
sqlsrv_free_stmt($stmt1);
DropTable($conn1, $tableName);
dropTable($conn1, $tableName);
sqlsrv_close($conn1);
EndTest($testName);
endTest($testName);
}
function VerifyStream($stmt, $row, $colIndex, $skip)
{
$col = $colIndex + 1;
if (IsStreamable($col))
{
if (IsStreamable($col)) {
$type = GetSqlType($col);
if (IsBinary($col))
{
if (IsBinary($col)) {
$stream = sqlsrv_get_field($stmt, $colIndex, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY));
} else {
if (useUTF8Data()) {
$stream = sqlsrv_get_field($stmt, $colIndex, SQLSRV_PHPTYPE_STREAM('UTF-8'));
} else {
$stream = sqlsrv_get_field($stmt, $colIndex, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_CHAR));
}
}
else
{
if (UseUTF8Data()){
$stream = sqlsrv_get_field($stmt, $colIndex, SQLSRV_PHPTYPE_STREAM('UTF-8'));
}
else{
$stream = sqlsrv_get_field($stmt, $colIndex, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_CHAR));
}
}
if ($stream === false)
{
FatalError("Failed to read field $col: $type");
}
else
{
if ($stream === false) {
fatalError("Failed to read field $col: $type");
} else {
$value = '';
if ($stream)
{
while (!feof($stream))
{
if ($stream) {
while (!feof($stream)) {
$value .= fread($stream, 8192);
}
fclose($stream);
$data = GetInsertData($row, $col, $skip);
if (!CheckData($col, $value, $data))
{
Trace("Data corruption on row $row column $col\n");
SetUTF8Data(false);
$data = getInsertData($row, $col, $skip);
if (!CheckData($col, $value, $data)) {
trace("Data corruption on row $row column $col\n");
setUTF8Data(false);
die("Data corruption on row $row column $col\n");
}
}
@ -125,32 +106,24 @@ function CheckData($col, $actual, $expected)
{
$success = true;
if (IsBinary($col))
{
if (IsBinary($col)) {
$actual = bin2hex($actual);
if (strncasecmp($actual, $expected, strlen($expected)) != 0)
{
if (strncasecmp($actual, $expected, strlen($expected)) != 0) {
$success = false;
}
}
else
{
if (strncasecmp($actual, $expected, strlen($expected)) != 0)
{
if ($col != 19)
{
} else {
if (strncasecmp($actual, $expected, strlen($expected)) != 0) {
if ($col != 19) {
// skip ntext
$pos = strpos($actual, $expected);
if (($pos === false) || ($pos > 1))
{
if (($pos === false) || ($pos > 1)) {
$success = false;
}
}
}
}
if (!$success)
{
Trace("\nData error\nExpected:\n$expected\nActual:\n$actual\n");
if (!$success) {
trace("\nData error\nExpected:\n$expected\nActual:\n$actual\n");
}
return ($success);
@ -158,29 +131,24 @@ function CheckData($col, $actual, $expected)
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
if (! IsWindows())
{
SetUTF8Data(true);
if (! isWindows()) {
setUTF8Data(true);
}
try
{
try {
StreamScroll(20, 1);
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
SetUTF8Data(false);
setUTF8Data(false);
}
Repro();
repro();
?>
--EXPECT--
Test "Stream - Scrollable" completed successfully.

View file

@ -11,98 +11,82 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function Transaction()
{
include 'MsSetup.inc';
$testName = "Transaction - Execution";
StartTest($testName);
startTest($testName);
Setup();
$conn1 = Connect();
CreateTable($conn1, $tableName);
setup();
$conn1 = connect();
createTable($conn1, $tableName);
$noRows = 10;
ExecTransaction($conn1, false, $tableName, $noRows); // rollback
ExecTransaction($conn1, true, $tableName, $noRows); // submit
DropTable($conn1, $tableName);
dropTable($conn1, $tableName);
sqlsrv_close($conn1);
EndTest($testName);
endTest($testName);
}
function ExecTransaction($conn, $mode, $tableName, $noRows)
{
if ($mode === true)
{
Trace("\nSUBMIT sequence:\n\t");
}
else
{
Trace("\nROLLBACK sequence:\n\t");
if ($mode === true) {
trace("\nSUBMIT sequence:\n\t");
} else {
trace("\nROLLBACK sequence:\n\t");
}
sqlsrv_begin_transaction($conn);
$noRowsInserted = InsertRows($conn, $tableName, $noRows);
if ($mode === true)
{
Trace("\tTransaction submit...");
$noRowsInserted = insertRows($conn, $tableName, $noRows);
if ($mode === true) {
trace("\tTransaction submit...");
sqlsrv_commit($conn);
}
else
{
Trace("\tTransaction rollback...");
} else {
trace("\tTransaction rollback...");
sqlsrv_rollback($conn);
}
$rowCount = 0;
$stmt = SelectFromTable($conn, $tableName);
while (sqlsrv_fetch($stmt))
{
$stmt = selectFromTable($conn, $tableName);
while (sqlsrv_fetch($stmt)) {
$rowCount++;
}
sqlsrv_free_stmt($stmt);
Trace(" rows effectively inserted: $rowCount.\n");
if ($mode === true)
{ // commit: expected to fetch all inserted rows
if ($rowCount != $noRowsInserted)
{
trace(" rows effectively inserted: $rowCount.\n");
if ($mode === true) { // commit: expected to fetch all inserted rows
if ($rowCount != $noRowsInserted) {
die("An incorrect number of rows was fetched. Expected: ".$noRows);
}
}
else
{ // rollback: no row should have been inserted
if ($rowCount > 0)
{
} else { // rollback: no row should have been inserted
if ($rowCount > 0) {
die("No row should have been fetched after rollback");
}
}
}
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
try
{
try {
Transaction();
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
}
Repro();
repro();
?>
--EXPECT--
Test "Transaction - Execution" completed successfully.

View file

@ -9,62 +9,62 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function Transaction()
{
include 'MsSetup.inc';
$testName = "Transaction - Disconnect";
StartTest($testName);
startTest($testName);
Setup();
$conn1 = Connect();
CreateTable($conn1, $tableName);
setup();
$conn1 = connect();
createTable($conn1, $tableName);
$noRows = 10;
// Insert rows and disconnect before the transaction is commited (implicit rollback)
Trace("\nBegin transaction...\n");
trace("\nBegin transaction...\n");
sqlsrv_begin_transaction($conn1);
InsertRows($conn1, $tableName, $noRows);
Trace("Disconnect prior to commit...\n\n");
insertRows($conn1, $tableName, $noRows);
trace("Disconnect prior to commit...\n\n");
sqlsrv_close($conn1);
// Insert rows and commit the transaction
$conn2 = Connect();
Trace("Begin transaction...\n");
$conn2 = connect();
trace("Begin transaction...\n");
sqlsrv_begin_transaction($conn2);
$noRowsInserted = InsertRows($conn2, $tableName, $noRows);
Trace("Transaction commit...\n");
$noRowsInserted = insertRows($conn2, $tableName, $noRows);
trace("Transaction commit...\n");
sqlsrv_commit($conn2);
$rowCount = 0;
$stmt1 = SelectFromTable($conn2, $tableName);
$stmt1 = selectFromTable($conn2, $tableName);
while (sqlsrv_fetch($stmt1))
{
$rowCount++;
}
sqlsrv_free_stmt($stmt1);
Trace("\nRows effectively inserted through both transactions: ".$rowCount."\n");
trace("\nRows effectively inserted through both transactions: ".$rowCount."\n");
if ($rowCount != $noRowsInserted)
{
die("An incorrect number of rows was fetched. Expected: ".$noRowsInserted);
}
DropTable($conn2, $tableName);
dropTable($conn2, $tableName);
sqlsrv_close($conn2);
EndTest($testName);
endTest($testName);
}
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
try
{
@ -76,9 +76,8 @@ function Repro()
}
}
Repro();
repro();
?>
--EXPECT--
Test "Transaction - Disconnect" completed successfully.

View file

@ -13,33 +13,31 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function Transaction($steps)
{
include 'MsSetup.inc';
$testName = "Transaction - Boundaries";
StartTest($testName);
startTest($testName);
Setup();
$conn1 = Connect();
$conn2 = Connect();
CreateTable($conn1, $tableName);
setup();
$conn1 = connect();
$conn2 = connect();
createTable($conn1, $tableName);
$noRows1 = 2; // inserted rows
$noRows2 = 3;
$noRows = 0; // expected rows
for ($k = 0; $k < $steps; $k++)
{
switch ($k)
{
for ($k = 0; $k < $steps; $k++) {
switch ($k) {
case 0: // nested commit
sqlsrv_begin_transaction($conn1);
sqlsrv_begin_transaction($conn2);
InsertRows($conn1, $tableName, $noRows1);
InsertRows($conn2, $tableName, $noRows2);
insertRows($conn1, $tableName, $noRows1);
insertRows($conn2, $tableName, $noRows2);
sqlsrv_commit($conn2);
sqlsrv_commit($conn1);
$noRows += ($noRows1 + $noRows2);
@ -48,8 +46,8 @@ function Transaction($steps)
case 1: // nested rollback
sqlsrv_begin_transaction($conn1);
sqlsrv_begin_transaction($conn2);
InsertRows($conn1, $tableName, $noRows1);
InsertRows($conn2, $tableName, $noRows2);
insertRows($conn1, $tableName, $noRows1);
insertRows($conn2, $tableName, $noRows2);
sqlsrv_rollback($conn2);
sqlsrv_rollback($conn1);
break;
@ -57,8 +55,8 @@ function Transaction($steps)
case 2: // nested commit & rollback
sqlsrv_begin_transaction($conn1);
sqlsrv_begin_transaction($conn2);
InsertRows($conn1, $tableName, $noRows1);
InsertRows($conn2, $tableName, $noRows2);
insertRows($conn1, $tableName, $noRows1);
insertRows($conn2, $tableName, $noRows2);
sqlsrv_rollback($conn2);
sqlsrv_commit($conn1);
$noRows += $noRows1;
@ -66,19 +64,19 @@ function Transaction($steps)
case 3: // interleaved commit
sqlsrv_begin_transaction($conn1);
InsertRows($conn1, $tableName, $noRows1);
insertRows($conn1, $tableName, $noRows1);
sqlsrv_begin_transaction($conn2);
sqlsrv_commit($conn1);
InsertRows($conn2, $tableName, $noRows2);
insertRows($conn2, $tableName, $noRows2);
sqlsrv_commit($conn2);
$noRows += ($noRows1 + $noRows2);
break;
case 4: // interleaved insert
sqlsrv_begin_transaction($conn1);
InsertRows($conn1, $tableName, $noRows1);
insertRows($conn1, $tableName, $noRows1);
sqlsrv_begin_transaction($conn2);
InsertRows($conn2, $tableName, $noRows2);
insertRows($conn2, $tableName, $noRows2);
sqlsrv_commit($conn1);
sqlsrv_commit($conn2);
$noRows += ($noRows1 + $noRows2);
@ -87,18 +85,18 @@ function Transaction($steps)
case 5: // interleaved insert & commit
sqlsrv_begin_transaction($conn1);
sqlsrv_begin_transaction($conn2);
InsertRows($conn1, $tableName, $noRows1);
insertRows($conn1, $tableName, $noRows1);
sqlsrv_commit($conn1);
InsertRows($conn2, $tableName, $noRows2);
insertRows($conn2, $tableName, $noRows2);
sqlsrv_commit($conn2);
$noRows += ($noRows1 + $noRows2);
break;
case 6: // interleaved execution with commit & rollback
sqlsrv_begin_transaction($conn1);
InsertRows($conn1, $tableName, $noRows1);
insertRows($conn1, $tableName, $noRows1);
sqlsrv_begin_transaction($conn2);
InsertRows($conn2, $tableName, $noRows2);
insertRows($conn2, $tableName, $noRows2);
sqlsrv_commit($conn2);
sqlsrv_rollback($conn1);
$noRows += $noRows2;
@ -106,60 +104,55 @@ function Transaction($steps)
case 7: // mixed execution
sqlsrv_begin_transaction($conn1);
InsertRows($conn1, $tableName, $noRows1);
InsertRows($conn2, $tableName, $noRows2);
insertRows($conn1, $tableName, $noRows1);
insertRows($conn2, $tableName, $noRows2);
sqlsrv_commit($conn1);
$noRows += ($noRows1 + $noRows2);
break;
default:// no transaction
InsertRows($conn1, $tableName, $noRows1);
InsertRows($conn2, $tableName, $noRows2);
insertRows($conn1, $tableName, $noRows1);
insertRows($conn2, $tableName, $noRows2);
$noRows += ($noRows1 + $noRows2);
break;
}
}
$rowCount = 0;
$stmt1 = SelectFromTable($conn1, $tableName);
while (sqlsrv_fetch($stmt1))
{
$stmt1 = selectFromTable($conn1, $tableName);
while (sqlsrv_fetch($stmt1)) {
$rowCount++;
}
sqlsrv_free_stmt($stmt1);
Trace("Row insertion attempts through all the transactions: ".$steps * ($noRows1 + $noRows2)."\n");
Trace("Rows effectively inserted through all the transactions: ".$rowCount."\n");
if ($rowCount != $noRows)
{
trace("Row insertion attempts through all the transactions: ".$steps * ($noRows1 + $noRows2)."\n");
trace("Rows effectively inserted through all the transactions: ".$rowCount."\n");
if ($rowCount != $noRows) {
die("An incorrect number of rows was fetched. Expected: ".$noRows);
}
DropTable($conn1, $tableName);
dropTable($conn1, $tableName);
sqlsrv_close($conn1);
sqlsrv_close($conn2);
EndTest($testName);
endTest($testName);
}
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
try
{
try {
Transaction(9);
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
}
Repro();
repro();
?>
--EXPECT--

View file

@ -10,23 +10,21 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function Transaction($minType, $maxType)
{
include 'MsSetup.inc';
$testName = "Transaction - Stored Proc";
StartTest($testName);
startTest($testName);
Setup();
$conn1 = Connect();
setup();
$conn1 = connect();
$colName = "c1";
for ($k = $minType; $k <= $maxType; $k++)
{
switch ($k)
{
for ($k = $minType; $k <= $maxType; $k++) {
switch ($k) {
case 20: // binary
case 21: // varbinary
case 22: // varbinary(max)
@ -36,46 +34,42 @@ function Transaction($minType, $maxType)
$data = GetSampleData($k);
break;
}
if ($data != null)
{
if ($data != null) {
$sqlType = GetSqlType($k);
CreateTableEx($conn1, $tableName, "[$colName] $sqlType");
createTableEx($conn1, $tableName, "[$colName] $sqlType");
CreateTransactionProc($conn1, $tableName, $colName, $procName, $sqlType);
$noRows = ExecTransactionProc($conn1, $procName, $data, true);
if ($noRows != 1)
{
if ($noRows != 1) {
die("$sqlType: Incorrect row count after commit: $noRows");
}
$noRows = ExecTransactionProc($conn1, $procName, $data, false);
if ($noRows != 2)
{
if ($noRows != 2) {
die("$sqlType: Incorrect row count after rollback: $noRows");
}
$noRows = NumRows($conn1, $tableName);
if ($noRows != 1)
{
$noRows = numRows($conn1, $tableName);
if ($noRows != 1) {
die("$sqlType: Incorrect total row count: $noRows");
}
DropProc($conn1, $procName);
DropTable($conn1, $tableName);
dropProc($conn1, $procName);
dropTable($conn1, $tableName);
}
}
}
sqlsrv_close($conn1);
EndTest($testName);
endTest($testName);
}
function CreateTransactionProc($conn, $tableName, $colName, $procName, $sqlType)
{
$procArgs = "@p1 $sqlType, @p2 INT OUTPUT";
$procCode = "SET NOCOUNT ON; INSERT INTO [$tableName] ($colName) VALUES (@p1) SET @p2 = (SELECT COUNT(*) FROM [$tableName])";
CreateProc($conn, $procName, $procArgs, $procCode);
$procCode = "SET NOCOUNT ON; INSERT INTO [$tableName] ($colName) VALUES (@p1) SET @p2 = (SELECT COUNT(*) FROM [$tableName])";
createProc($conn, $procName, $procArgs, $procCode);
}
function ExecTransactionProc($conn, $procName, $data, $commitMode)
@ -84,13 +78,10 @@ function ExecTransactionProc($conn, $procName, $data, $commitMode)
$callArgs = array(array($data, SQLSRV_PARAM_IN), array(&$retValue, SQLSRV_PARAM_OUT));
sqlsrv_begin_transaction($conn);
$stmt = CallProc($conn, $procName, "?, ?", $callArgs);
if ($commitMode === true)
{ // commit
$stmt = callProc($conn, $procName, "?, ?", $callArgs);
if ($commitMode === true) { // commit
sqlsrv_commit($conn);
}
else
{ // rollback
} else { // rollback
sqlsrv_rollback($conn);
}
@ -99,24 +90,20 @@ function ExecTransactionProc($conn, $procName, $data, $commitMode)
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
try
{
try {
Transaction(1, 28);
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
}
Repro();
repro();
?>
--EXPECT--
Test "Transaction - Stored Proc" completed successfully.

View file

@ -8,7 +8,7 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function StoredProc()
{
@ -18,10 +18,10 @@ function StoredProc()
$data1 = "Microsoft SQL Server ";
$data2 = "Driver for PHP";
StartTest($testName);
startTest($testName);
Setup();
$conn1 = Connect();
setup();
$conn1 = connect();
ExecProc($conn1, $procName, "CHAR", $data1, $data2);
ExecProc($conn1, $procName, "VARCHAR", $data1, $data2);
@ -30,7 +30,7 @@ function StoredProc()
sqlsrv_close($conn1);
EndTest($testName);
endTest($testName);
}
function ExecProc($conn, $procName, $sqlType, $inValue1, $inValue2)
@ -51,33 +51,29 @@ function ExecProc($conn, $procName, $sqlType, $inValue1, $inValue2)
array($inValue2, SQLSRV_PARAM_IN));
CreateProc($conn, $procName, $procArgs, $procCode);
CallProc($conn, $procName, "?, ?, ?", $callArgs);
DropProc($conn, $procName);
createProc($conn, $procName, $procArgs, $procCode);
callProc($conn, $procName, "?, ?, ?", $callArgs);
dropProc($conn, $procName);
if (strncmp($actual, $expected, strlen($expected)) != 0)
{
if (strncmp($actual, $expected, strlen($expected)) != 0) {
die("Data corruption: $expected => $actual.");
}
}
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
try
{
try {
StoredProc();
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
}
Repro();
repro();
?>
--EXPECT--

View file

@ -8,7 +8,7 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function StoredFunc()
{
@ -18,10 +18,10 @@ function StoredFunc()
$data1 = "Microsoft SQL Server ";
$data2 = "Driver for PHP";
StartTest($testName);
startTest($testName);
Setup();
$conn1 = Connect();
setup();
$conn1 = connect();
ExecFunc($conn1, $procName, "CHAR", $data1, $data2);
ExecFunc($conn1, $procName, "VARCHAR", $data1, $data2);
@ -30,7 +30,7 @@ function StoredFunc()
sqlsrv_close($conn1);
EndTest($testName);
endTest($testName);
}
function ExecFunc($conn, $funcName, $sqlType, $inValue1, $inValue2)
@ -52,32 +52,28 @@ function ExecFunc($conn, $funcName, $sqlType, $inValue1, $inValue2)
CreateFunc($conn, $funcName, $funcArgs, $sqlTypeOut, $funcCode);
CallFunc($conn, $funcName, "?, ?", $callArgs);
DropFunc($conn, $funcName);
callFunc($conn, $funcName, "?, ?", $callArgs);
dropFunc($conn, $funcName);
if (strncmp($actual, $expected, strlen($expected)) != 0)
{
if (strncmp($actual, $expected, strlen($expected)) != 0) {
die("Data corruption: $expected => $actual.");
}
}
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
try
{
try {
StoredFunc();
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
}
Repro();
repro();
?>
--EXPECT--

View file

@ -8,17 +8,17 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function StoredProc()
{
include 'MsSetup.inc';
$testName = "Stored Proc Call";
StartTest($testName);
startTest($testName);
Setup();
$conn1 = Connect();
setup();
$conn1 = connect();
$step = 0;
$dataStr = "The quick brown fox jumps over the lazy dog.";
@ -26,42 +26,37 @@ function StoredProc()
// Scenario #1: using a null buffer
$step++;
if (!ExecProc1($conn1, $procName, $dataStr, 40, 0))
{
if (!ExecProc1($conn1, $procName, $dataStr, 40, 0)) {
die("Execution failure at step $step.");
}
// Scenario #2: using a pre-allocated buffer
$step++;
if (!ExecProc1($conn1, $procName, $dataStr, 25, 1))
{
if (!ExecProc1($conn1, $procName, $dataStr, 25, 1)) {
die("Execution failure at step $step.");
}
// Scenario #3: specifying an exact return size
$step++;
if (!ExecProc1($conn1, $procName, $dataStr, 0, 2))
{
if (!ExecProc1($conn1, $procName, $dataStr, 0, 2)) {
die("Execution failure at step $step.");
}
// Scenario #4: specifying a larger return size
$step++;
if (!ExecProc1($conn1, $procName, $dataStr, 50, 2))
{
if (!ExecProc1($conn1, $procName, $dataStr, 50, 2)) {
die("Execution failure at step $step.");
}
// Scenario #5: returning a value
$step++;
if (!ExecProc2($conn1, $procName, $dataInt))
{
if (!ExecProc2($conn1, $procName, $dataInt)) {
die("Execution failure at step $step.");
}
sqlsrv_close($conn1);
EndTest($testName);
endTest($testName);
}
function ExecProc1($conn, $procName, $dataIn, $extraSize, $phpInit)
@ -73,11 +68,9 @@ function ExecProc1($conn, $procName, $dataIn, $extraSize, $phpInit)
$procArgs = "@p1 VARCHAR($len) OUTPUT";
$procCode = "SET @p1 = '$inValue'";
if ($phpInit == 1)
{
if ($phpInit == 1) {
$outValue = "";
for ($i = 0; $i < $len; $i++)
{ // fill the buffer with "A"
for ($i = 0; $i < $len; $i++) { // fill the buffer with "A"
$outValue = $outValue."A";
}
}
@ -85,13 +78,12 @@ function ExecProc1($conn, $procName, $dataIn, $extraSize, $phpInit)
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
SQLSRV_SQLTYPE_VARCHAR($lenData + 1)));
CreateProc($conn, $procName, $procArgs, $procCode);
CallProc($conn, $procName, "?", $callArgs);
DropProc($conn, $procName);
createProc($conn, $procName, $procArgs, $procCode);
callProc($conn, $procName, "?", $callArgs);
dropProc($conn, $procName);
if ($inValue != trim($outValue))
{
Trace("Data corruption: [$inValue] => [$outValue]\n");
if ($inValue != trim($outValue)) {
trace("Data corruption: [$inValue] => [$outValue]\n");
return (false);
}
return (true);
@ -102,44 +94,40 @@ function ExecProc2($conn, $procName, $dataIn)
{
$procArgs = "@p1 INT";
$procCode = "SET NOCOUNT ON; SELECT 199 IF @p1 = 0 RETURN 11 ELSE RETURN 22";
$retValue = -1;
$retValue = -1;
$callArgs = array(array(&$retValue, SQLSRV_PARAM_OUT), array($dataIn, SQLSRV_PARAM_IN));
CreateProc($conn, $procName, $procArgs, $procCode);
$stmt = CallProcEx($conn, $procName, "? = ", "?", $callArgs);
DropProc($conn, $procName);
createProc($conn, $procName, $procArgs, $procCode);
$stmt = callProcEx($conn, $procName, "? = ", "?", $callArgs);
dropProc($conn, $procName);
$row = sqlsrv_fetch_array($stmt);
$count = count($row);
sqlsrv_next_result($stmt);
sqlsrv_next_result($stmt);
sqlsrv_free_stmt($stmt);
if (($row === false) || ($count <= 0) || ($row[0] != 199) ||
(($retValue != 11) && ($retValue != 22)))
{
Trace("Row count = $count, Returned value = $retValue\n");
(($retValue != 11) && ($retValue != 22))) {
trace("Row count = $count, Returned value = $retValue\n");
return (false);
}
return (true);
}
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
try
{
try {
StoredProc();
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
}
Repro();
repro();
?>
--EXPECT--

View file

@ -10,22 +10,20 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function ProcQuery($minType, $maxType)
{
include 'MsSetup.inc';
$testName = "Stored Proc Query";
StartTest($testName);
startTest($testName);
Setup();
$conn1 = Connect();
setup();
$conn1 = connect();
for ($k = $minType; $k <= $maxType; $k++)
{
switch ($k)
{
for ($k = $minType; $k <= $maxType; $k++) {
switch ($k) {
case 1: // TINYINT
ExecProcQuery($conn1, $procName, "TINYINT", 11, 12, 23);
break;
@ -69,53 +67,47 @@ function ProcQuery($minType, $maxType)
default:// default
break;
}
}
}
sqlsrv_close($conn1);
EndTest($testName);
endTest($testName);
}
function ExecProcQuery($conn, $procName, $dataType, $inData1, $inData2, $outData)
{
$procArgs = "@p1 $dataType, @p2 $dataType, @p3 $dataType OUTPUT";
$procCode = "SELECT @p3 = CONVERT($dataType, @p1 + @p2)";
CreateProc($conn, $procName, $procArgs, $procCode);
createProc($conn, $procName, $procArgs, $procCode);
$callArgs = "?, ?, ?";
$callResult = 0.0;
$callValues = array($inData1, $inData2, array(&$callResult, SQLSRV_PARAM_OUT));
CallProc($conn, $procName, $callArgs, $callValues);
DropProc($conn, $procName);
callProc($conn, $procName, $callArgs, $callValues);
dropProc($conn, $procName);
TraceData($dataType, "".$inData1." + ".$inData2." = ".$callResult);
if ($callResult != $outData)
{
if ($callResult != $outData) {
die("Expected result for ".$dataType." was ".$outData);
}
}
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
try
{
try {
ProcQuery(1, 10);
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
}
Repro();
repro();
?>
--EXPECT--
Test "Stored Proc Query" completed successfully.

View file

@ -9,31 +9,28 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function StoredProcRoundtrip($minType, $maxType)
{
include 'MsSetup.inc';
$testName = "Stored Proc Roundtrip";
StartTest($testName);
startTest($testName);
Setup();
$conn1 = Connect();
setup();
$conn1 = connect();
$data = "The quick brown fox jumps over the lazy dog 0123456789";
$dataSize = strlen($data);
for ($i = $minType; $i <= $maxType; $i++)
{
for ($i = $minType; $i <= $maxType; $i++) {
$dataTypeIn = GetSqlType($i);
$phpTypeIn = GetDriverType($i, $dataSize);
for ($j = $minType; $j <= $maxType; $j++)
{
for ($j = $minType; $j <= $maxType; $j++) {
$k = $j;
switch ($j)
{ // avoid LOB types as output
switch ($j) { // avoid LOB types as output
case 14: // varchar(max)
case 18: // text
$k = 13; // varchar
@ -46,17 +43,17 @@ function StoredProcRoundtrip($minType, $maxType)
default:
break;
}
$dataTypeOut = GetSqlType($k);
$phpTypeOut = GetDriverType($k, 512);
ExecProcRoundtrip($conn1, $procName, $dataTypeIn, $dataTypeOut, $phpTypeIn, $phpTypeOut, $data);
}
}
}
sqlsrv_close($conn1);
EndTest($testName);
endTest($testName);
}
@ -64,42 +61,38 @@ function ExecProcRoundtrip($conn, $procName, $dataTypeIn, $dataTypeOut, $phpType
{
$procArgs = "@p1 $dataTypeIn, @p2 $dataTypeOut OUTPUT";
$procCode = "SELECT @p2 = CONVERT($dataTypeOut, @p1)";
CreateProc($conn, $procName, $procArgs, $procCode);
createProc($conn, $procName, $procArgs, $procCode);
$callArgs = "?, ?";
$callResult = "";
$callValues = array(array($dataIn, SQLSRV_PARAM_IN, null, $phpTypeIn),
$callValues = array(array($dataIn, SQLSRV_PARAM_IN, null, $phpTypeIn),
array(&$callResult, SQLSRV_PARAM_OUT, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), $phpTypeOut));
CallProc($conn, $procName, $callArgs, $callValues);
DropProc($conn, $procName);
callProc($conn, $procName, $callArgs, $callValues);
dropProc($conn, $procName);
$dataOut = trim($callResult);
if (strncmp($dataOut, $dataIn, strlen($dataIn)) != 0)
{
if (strncmp($dataOut, $dataIn, strlen($dataIn)) != 0) {
TraceData($dataTypeIn."=>".$dataTypeOut, "\n In: [".$dataIn."]\nOut: [".$dataOut."]");
die("Unexpected result for ".$dataTypeIn."=>".$dataTypeOut);
}
}
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
try
{
try {
StoredProcRoundtrip(12, 19);
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
}
Repro();
repro();
?>
--EXPECT--
Test "Stored Proc Roundtrip" completed successfully.
Test "Stored Proc Roundtrip" completed successfully.

View file

@ -8,7 +8,7 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function StoredProc()
{
@ -18,10 +18,10 @@ function StoredProc()
$data1 = "Microsoft SQL Server ";
$data2 = "Driver for PHP";
StartTest($testName);
startTest($testName);
Setup();
$conn1 = Connect();
setup();
$conn1 = connect();
ExecProc($conn1, $procName, "VARCHAR(32)", SQLSRV_SQLTYPE_VARCHAR(32), "ABC");
ExecProc($conn1, $procName, "FLOAT", SQLSRV_SQLTYPE_FLOAT, 3.2);
@ -29,7 +29,7 @@ function StoredProc()
sqlsrv_close($conn1);
EndTest($testName);
endTest($testName);
}
function ExecProc($conn, $procName, $sqlType, $sqlTypeEx, $initData)
@ -41,33 +41,29 @@ function ExecProc($conn, $procName, $sqlType, $sqlTypeEx, $initData)
$callArgs = array(array(&$data, SQLSRV_PARAM_OUT, null, $sqlTypeEx));
CreateProc($conn, $procName, $procArgs, $procCode);
CallProc($conn, $procName, "?", $callArgs);
DropProc($conn, $procName);
createProc($conn, $procName, $procArgs, $procCode);
callProc($conn, $procName, "?", $callArgs);
dropProc($conn, $procName);
if ($data != null)
{
if ($data != null) {
die("Data corruption: [$data] instead of null.");
}
}
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
try
{
try {
StoredProc();
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
}
Repro();
repro();
?>
--EXPECT--

View file

@ -9,65 +9,56 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function BugRepro()
{
include 'MsSetup.inc';
$testName = "Regression VSTS 611146";
StartTest($testName);
startTest($testName);
Setup();
$conn1 = Connect();
setup();
$conn1 = connect();
// empty parameter array
$s = sqlsrv_query( $conn1, "select ?", array( array() ));
if( $s !== false )
{
die( "Should have failed." );
}
else
{
$s = sqlsrv_query($conn1, "select ?", array( array() ));
if ($s !== false) {
die("Should have failed.");
} else {
$arr = sqlsrv_errors();
print_r( $arr[0][2] );
print_r( "\n" );
print_r($arr[0][2]);
print_r("\n");
}
// unknown direction
$s = sqlsrv_query( $conn1, "select ?", array( array( 1, 1000 ) ));
if( $s !== false )
{
die( "Should have failed." );
}
else
{
$s = sqlsrv_query($conn1, "select ?", array( array( 1, 1000 ) ));
if ($s !== false) {
die("Should have failed.");
} else {
$arr = sqlsrv_errors();
print_r( $arr[0][2] );
print_r( "\n" );
print_r($arr[0][2]);
print_r("\n");
}
EndTest($testName);
endTest($testName);
}
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
try
{
try {
BugRepro();
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
}
Repro();
repro();
?>
--EXPECT--

View file

@ -9,62 +9,58 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function BugRepro()
{
include 'MsSetup.inc';
$testName = "Regression VSTS 846501";
StartTest($testName);
startTest($testName);
Setup();
$conn1 = Connect();
setup();
$conn1 = connect();
// empty parameter array
$s = sqlsrv_query( $conn1, "DROP TABLE test_bq" );
$s = sqlsrv_query( $conn1, "CREATE TABLE test_bq (id INT IDENTITY NOT NULL, test_varchar_max varchar(max))" );
if( $s === false ) {
die( print_r( sqlsrv_errors(), true ));
$s = sqlsrv_query($conn1, "DROP TABLE test_bq");
$s = sqlsrv_query($conn1, "CREATE TABLE test_bq (id INT IDENTITY NOT NULL, test_varchar_max varchar(max))");
if ($s === false) {
die(print_r(sqlsrv_errors(), true));
}
$s = sqlsrv_query( $conn1, "CREATE CLUSTERED INDEX [idx_test_int] ON test_bq (id)" );
if( $s === false ) {
die( print_r( sqlsrv_errors(), true ));
$s = sqlsrv_query($conn1, "CREATE CLUSTERED INDEX [idx_test_int] ON test_bq (id)");
if ($s === false) {
die(print_r(sqlsrv_errors(), true));
}
$s = sqlsrv_query( $conn1, "INSERT INTO test_bq (test_varchar_max) VALUES ('ABCD')" );
if( $s === false ) {
die( print_r( sqlsrv_errors(), true ));
$s = sqlsrv_query($conn1, "INSERT INTO test_bq (test_varchar_max) VALUES ('ABCD')");
if ($s === false) {
die(print_r(sqlsrv_errors(), true));
}
$tsql = "select test_varchar_max from test_bq";
$result = sqlsrv_query( $conn1, $tsql, array(), array( "Scrollable" => SQLSRV_CURSOR_CLIENT_BUFFERED ));
$result = sqlsrv_query($conn1, $tsql, array(), array( "Scrollable" => SQLSRV_CURSOR_CLIENT_BUFFERED ));
while($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_BOTH))
{
while ($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_BOTH)) {
print $row['test_varchar_max']."\n";
}
sqlsrv_query( $conn1, "DROP TABLE test_bq" );
EndTest($testName);
sqlsrv_query($conn1, "DROP TABLE test_bq");
endTest($testName);
}
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
try
{
try {
BugRepro();
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
}
Repro();
repro();
?>
--EXPECT--

View file

@ -9,31 +9,29 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function MemCheck($noPasses, $noRows1, $noRows2, $startStep, $endStep)
{
include 'MsSetup.inc';
$testName = "Memory Leakage Check";
StartTest($testName);
startTest($testName);
Setup();
setup();
Trace("Execution setup: $noPasses passes over a table with $noRows1 => ".($noRows1 + $noRows2)." rows.\n");
trace("Execution setup: $noPasses passes over a table with $noRows1 => ".($noRows1 + $noRows2)." rows.\n");
// The data added into the table has some UTF-8 characters in it.
// The fetch functions in the switch block below fail if we don't
// The fetch functions in the switch block below fail if we don't
// set the encoding to UTF-8. We can set the UTF-8 option elsewhere
// (in the options for sqlsrv_fetch for example) but it is easier
// to simply call ConnectUTF8().
$conn1 = ConnectUTF8();
SetUTF8Data(true);
CreateTable($conn1, $tableName);
$noRowsInserted = InsertRows($conn1, $tableName, $noRows1);
// to simply call connect(array( 'CharacterSet'=>'UTF-8' )).
$conn1 = connect(array( 'CharacterSet'=>'UTF-8' ));
setUTF8Data(true);
$tableName = 'TC81test';
createTable($conn1, $tableName);
$noRowsInserted = insertRows($conn1, $tableName, $noRows1);
// Calibration
// when fetching DateTime in the test, the DateTime PHP extension is used, and memory is allocated when this
@ -42,28 +40,26 @@ function MemCheck($noPasses, $noRows1, $noRows2, $startStep, $endStep)
$date = new DateTime();
unset($date);
$phpLeak = RunTest($noPasses, 0, $tableName, $conn1, false, true, 0);
Trace("\n0. Calibration\t - PHP memory leak: $phpLeak bytes\n");
trace("\n0. Calibration\t - PHP memory leak: $phpLeak bytes\n");
// Preliminary Execution
Trace("\nPreliminary Execution:\n");
trace("\nPreliminary Execution:\n");
$drvLeak = ExecTest(1, $noRows1, $startStep, $endStep, $tableName, $conn1, false, true, $phpLeak);
$totalLeak = 0;
// Connection & Query
$start = Max($startStep, 1);
$end = Min($endStep, 3);
Trace("\nConnection & Direct Query Execution:\n");
trace("\nConnection & Direct Query Execution:\n");
$leak = ExecTest($noPasses, $noRows1, $start, $end, $tableName, $conn1, false, true, $phpLeak) - $drvLeak;
if ($leak > $totalLeak)
{
if ($leak > $totalLeak) {
$totalLeak = $leak;
}
Trace("\nPrepared Query Execution:\n");
trace("\nPrepared Query Execution:\n");
$start = Max($startStep, 2);
$leak = ExecTest($noPasses, $noRows1, $start, $end, $tableName, $conn1, true, true, $phpLeak) - $drvLeak;
if ($leak > $totalLeak)
{
if ($leak > $totalLeak) {
$totalLeak = $leak;
}
@ -73,10 +69,8 @@ function MemCheck($noPasses, $noRows1, $noRows2, $startStep, $endStep)
$end = Min($endStep, 7);
$prepared = false;
$release = false;
for ($j = 0; $j < 8; $j++)
{
switch ($j)
{
for ($j = 0; $j < 8; $j++) {
switch ($j) {
case 0:
$prepared = false;
$release = true;
@ -98,7 +92,7 @@ function MemCheck($noPasses, $noRows1, $noRows2, $startStep, $endStep)
break;
case 4:
InsertRows($conn1, $tableName, $noRows2);
insertRows($conn1, $tableName, $noRows2);
$noRows = $noRows1 + $noRows2;
$prepared = false;
$release = false;
@ -123,42 +117,34 @@ function MemCheck($noPasses, $noRows1, $noRows2, $startStep, $endStep)
break;
}
if ($prepared)
{
Trace("\nPrepared Query");
if ($prepared) {
trace("\nPrepared Query");
} else {
trace("\nDirect Query");
}
else
{
Trace("\nDirect Query");
}
if ($release)
{
Trace(" with statement release:\n");
}
else
{
Trace(" without statement release:\n");
if ($release) {
trace(" with statement release:\n");
} else {
trace(" without statement release:\n");
}
$leak = ExecTest($noPasses, $noRows, $start, $end, $tableName, $conn1, $prepared, $release, $phpLeak) - $drvLeak;
if ($leak > $totalLeak)
{
if ($leak > $totalLeak) {
$totalLeak = $leak;
}
}
sqlsrv_close($conn1);
$conn2 = Connect();
DropTable($conn2, $tableName);
$conn2 = connect();
dropTable($conn2, $tableName);
sqlsrv_close($conn2);
SetUTF8Data(false);
setUTF8Data(false);
if ($totalLeak > 0)
{
if ($totalLeak > 0) {
die("Memory leaks detected: $totalLeak bytes\n");
}
EndTest($testName);
endTest($testName);
}
function GetConnection()
@ -173,23 +159,17 @@ function ExecQuery($conn, $tableName, $prepared)
$selectQuery = "SELECT * FROM [$tableName]";
$stmt = null;
if ($prepared)
{
if ($prepared) {
$stmt = sqlsrv_prepare($conn, $selectQuery);
}
else
{
} else {
$stmt = sqlsrv_query($conn, $selectQuery);
}
if ($stmt === false)
{
FatalError("Query execution failed: $selectQuery");
if ($stmt === false) {
fatalError("Query execution failed: $selectQuery");
}
if ($prepared)
{
if (!sqlsrv_execute($stmt))
{
FatalError("Query execution failed: $selectQuery");
if ($prepared) {
if (!sqlsrv_execute($stmt)) {
fatalError("Query execution failed: $selectQuery");
}
}
@ -201,47 +181,43 @@ function ExecTest($noPasses, $noRows, $startStep, $endStep, $tableName, $conn, $
$leak = 0;
// Execution
for ($i = $startStep; $i <= $endStep; $i++)
{
switch ($i)
{
for ($i = $startStep; $i <= $endStep; $i++) {
switch ($i) {
case 1: // connection only
Trace("$i. Connection\t - ");
trace("$i. Connection\t - ");
break;
case 2: // query with no release
Trace("$i. Query\t - ");
trace("$i. Query\t - ");
break;
case 3: // query with release
Trace("$i. Query Freed\t - ");
trace("$i. Query Freed\t - ");
break;
case 4: // fetch
Trace("$i. Simple Fetch\t - ");
trace("$i. Simple Fetch\t - ");
break;
case 5: // fetch fields
Trace("$i. Fetch Fields\t - ");
trace("$i. Fetch Fields\t - ");
break;
case 6: // fetch array
Trace("$i. Fetch Array\t - ");
trace("$i. Fetch Array\t - ");
break;
case 7: // fetch object
Trace("$i. Fetch Object\t - ");
trace("$i. Fetch Object\t - ");
break;
default:
break;
}
$memLeak = RunTest($noPasses, $noRows, $tableName, $conn, $prepared, $release, $i) - $phpLeak;
Trace("Driver memory leak: $memLeak bytes\n");
if ($memLeak > 0)
{
if ($leak <= 0)
{
trace("Driver memory leak: $memLeak bytes\n");
if ($memLeak > 0) {
if ($leak <= 0) {
$leak = $memLeak;
echo intval($leak) . " leaking\n";
}
@ -254,8 +230,7 @@ function ExecTest($noPasses, $noRows, $startStep, $endStep, $tableName, $conn, $
function RunTest($noPasses, $noRows, $tableName, $conn, $prepared, $release, $mode)
{
$memStart = memory_get_usage();
for ($k = 1; $k <= $noPasses; $k++)
{
for ($k = 1; $k <= $noPasses; $k++) {
$conn2 = null;
$stmt = null;
$fld = null;
@ -263,8 +238,7 @@ function RunTest($noPasses, $noRows, $tableName, $conn, $prepared, $release, $mo
$numFields = 0;
$i = 0;
switch ($mode)
{
switch ($mode) {
case 0: // calibration
break;
@ -284,16 +258,13 @@ function RunTest($noPasses, $noRows, $tableName, $conn, $prepared, $release, $mo
case 4: // fetch
$stmt = ExecQuery($conn, $tableName, $prepared);
while (sqlsrv_fetch($stmt))
{
while (sqlsrv_fetch($stmt)) {
$rowCount++;
}
if ($release)
{
if ($release) {
sqlsrv_free_stmt($stmt);
}
if ($rowCount != $noRows)
{
if ($rowCount != $noRows) {
die("$rowCount rows retrieved instead of $noRows\n");
}
break;
@ -301,57 +272,46 @@ function RunTest($noPasses, $noRows, $tableName, $conn, $prepared, $release, $mo
case 5: // fetch fields
$stmt = ExecQuery($conn, $tableName, $prepared);
$numFields = sqlsrv_num_fields($stmt);
while (sqlsrv_fetch($stmt))
{
while (sqlsrv_fetch($stmt)) {
$rowCount++;
for ($i = 0; $i < $numFields; $i++)
{
for ($i = 0; $i < $numFields; $i++) {
$fld = sqlsrv_get_field($stmt, $i);
if ($fld === false)
{
if ($fld === false) {
die("Field $i of row $rowCount is missing");
}
unset($fld);
}
}
if ($release)
{
if ($release) {
sqlsrv_free_stmt($stmt);
}
if ($rowCount != $noRows)
{
if ($rowCount != $noRows) {
die("$rowCount rows retrieved instead of $noRows\n");
}
break;
case 6: // fetch array
$stmt = ExecQuery($conn, $tableName, $prepared);
While (sqlsrv_fetch_array($stmt))
{
while (sqlsrv_fetch_array($stmt)) {
$rowCount++;
}
if ($release)
{
if ($release) {
sqlsrv_free_stmt($stmt);
}
if ($rowCount != $noRows)
{
if ($rowCount != $noRows) {
die("$rowCount rows retrieved instead of $noRows\n");
}
break;
case 7: // fetch object
$stmt = ExecQuery($conn, $tableName, $prepared);
While (sqlsrv_fetch_object($stmt))
{
while (sqlsrv_fetch_object($stmt)) {
$rowCount++;
}
if ($release)
{
if ($release) {
sqlsrv_free_stmt($stmt);
}
if ($rowCount != $noRows)
{
if ($rowCount != $noRows) {
die("$rowCount rows retrieved instead of $noRows\n");
}
break;
@ -365,28 +325,25 @@ function RunTest($noPasses, $noRows, $tableName, $conn, $prepared, $release, $mo
unset($stmt);
}
$memEnd = memory_get_usage();
Trace( intval($memEnd) . " - " . intval($memStart) . "\n" );
trace(intval($memEnd) . " - " . intval($memStart) . "\n");
return ($memEnd - $memStart);
}
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
try
{
try {
MemCheck(20, 10, 15, 1, 7);
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
}
Repro();
repro();
?>
--EXPECT--

View file

@ -8,19 +8,19 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function StoredProcCheck()
{
include 'MsSetup.inc';
$testName = "ResultSet with Stored Proc";
StartTest($testName);
startTest($testName);
Setup();
setup();
$conn1 = Connect();
$conn1 = connect();
$table1 = $tableName."_1";
$table2 = $tableName."_2";
@ -43,66 +43,59 @@ function StoredProcCheck()
INSERT INTO [$table2] (DataID, DataNo) values (@p1, @p2)
SELECT @p4=(SELECT Intro from [$table3] WHERE DataID=@p1) ";
CreateTableEx($conn1, $table1, "DataID int, ExecTime datetime, DataNo nchar(32), DataRef nvarchar(64)");
CreateTableEx($conn1, $table2, "DataID int, DataNo nchar(32)");
CreateTableEx($conn1, $table3, "DataID int, Intro nvarchar(max)");
CreateProc($conn1, $procName, $procArgs, $procCode);
createTableEx($conn1, $table1, "DataID int, ExecTime datetime, DataNo nchar(32), DataRef nvarchar(64)");
createTableEx($conn1, $table2, "DataID int, DataNo nchar(32)");
createTableEx($conn1, $table3, "DataID int, Intro nvarchar(max)");
createProc($conn1, $procName, $procArgs, $procCode);
$stmt1 = sqlsrv_query($conn1, "INSERT INTO [$table3] (DataID, Intro) VALUES (1, 'Test Value 1')");
InsertCheck($stmt1);
insertCheck($stmt1);
$stmt2 = sqlsrv_query($conn1, "INSERT INTO [$table3] (DataID, Intro) VALUES (2, 'Test Value 2')");
InsertCheck($stmt2);
insertCheck($stmt2);
$stmt3 = sqlsrv_query($conn1, "INSERT INTO [$table3] (DataID, Intro) VALUES (3, 'Test Value 3')");
InsertCheck($stmt3);
insertCheck($stmt3);
$stmt4 = CallProcEx($conn1, $procName, "", "?, ?, ?, ?", $callArgs);
$stmt4 = callProcEx($conn1, $procName, "", "?, ?, ?, ?", $callArgs);
$result = sqlsrv_next_result($stmt4);
while ($result != null)
{
if( $result === false )
{
FatalError("Failed to execute sqlsrv_next_result");
while ($result != null) {
if ($result === false) {
fatalError("Failed to execute sqlsrv_next_result");
}
$result = sqlsrv_next_result($stmt4);
}
sqlsrv_free_stmt($stmt4);
DropProc($conn1, $procName);
dropProc($conn1, $procName);
echo "$introText\n";
DropTable($conn1, $table1);
DropTable($conn1, $table2);
DropTable($conn1, $table3);
dropTable($conn1, $table1);
dropTable($conn1, $table2);
dropTable($conn1, $table3);
sqlsrv_close($conn1);
EndTest($testName);
endTest($testName);
}
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
try
{
try {
StoredProcCheck();
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
}
Repro();
repro();
?>
--EXPECT--
Test Value 1
Test "ResultSet with Stored Proc" completed successfully.

View file

@ -8,25 +8,24 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function ComplexInsert($count)
{
include 'MsSetup.inc';
$testName = "Complex Insert Query";
StartTest($testName);
startTest($testName);
Setup();
setup();
$conn1 = Connect();
$conn1 = connect();
$tableName = 'TC83test';
dropTable($conn1, $tableName);
DropTable($conn1, $tableName);
$data = "a1='1', a2='2', a3='3', a4='4', a5='5', a6='6'";
$querySelect = "SELECT COUNT(*) FROM [$tableName]";
$queryInsert =
$queryInsert =
" SELECT $data INTO [$tableName]
DECLARE @i int
SET @i=1
@ -38,11 +37,12 @@ function ComplexInsert($count)
END
";
$stmt1 = ExecuteQuery($conn1, $queryInsert);
while (sqlsrv_next_result($stmt1) != NULL) {};
$stmt1 = executeQuery($conn1, $queryInsert);
while (sqlsrv_next_result($stmt1) != null) {
};
sqlsrv_free_stmt($stmt1);
$stmt2 = ExecuteQuery($conn1, $querySelect);
$stmt2 = executeQuery($conn1, $querySelect);
$row = sqlsrv_fetch_array($stmt2);
sqlsrv_free_stmt($stmt2);
@ -50,31 +50,26 @@ function ComplexInsert($count)
sqlsrv_close($conn1);
EndTest($testName);
endTest($testName);
}
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
try
{
try {
ComplexInsert(160);
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
}
Repro();
repro();
?>
--EXPECT--
160 rows attempted; actual rows created = 160
Test "Complex Insert Query" completed successfully.

View file

@ -8,19 +8,17 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function LargeColumnNameTest($columnName, $expectfail)
{
include 'MsSetup.inc';
setup();
Setup();
$conn = Connect();
$conn = connect();
$tableName = "LargeColumnNameTest";
DropTable($conn, $tableName);
dropTable($conn, $tableName);
sqlsrv_query($conn, "CREATE TABLE [$tableName] ([$columnName] int)");
@ -28,61 +26,52 @@ function LargeColumnNameTest($columnName, $expectfail)
$stmt = sqlsrv_query($conn, "SELECT * from [$tableName]");
if ( null == $stmt )
{
if (null == $stmt) {
echo "$";
echo "stmt = null";
echo "\n";
}
else
{
if ( null == sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC) )
{
if (!$expectfail)
FatalError("Possible regression: Unable to retrieve inserted value.");
} else {
if (null == sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
if (!$expectfail) {
fatalError("Possible regression: Unable to retrieve inserted value.");
}
}
sqlsrv_free_stmt($stmt);
}
DropTable($conn, $tableName);
dropTable($conn, $tableName);
sqlsrv_close($conn);
}
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
$testName = "PHP - Large Column Name Test";
StartTest($testName);
startTest($testName);
$columnName = "a";
try
{
for ($a = 1; $a <= 129; $a++)
{
try {
for ($a = 1; $a <= 129; $a++) {
LargeColumnNameTest($columnName, $a > 128);
$columnName .= "A";
}
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
EndTest($testName);
endTest($testName);
}
Repro();
repro();
?>
--EXPECT--
$stmt = null

View file

@ -8,19 +8,17 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function LargeColumnNameTest($columnName, $expectfail)
{
include 'MsSetup.inc';
setup();
Setup();
$conn = ConnectUTF8();
$conn = connect(array( 'CharacterSet'=>'UTF-8' ));
$tableName = "LargeColumnNameTest";
DropTable($conn, $tableName);
dropTable($conn, $tableName);
sqlsrv_query($conn, "CREATE TABLE [$tableName] ([$columnName] int)");
@ -28,58 +26,48 @@ function LargeColumnNameTest($columnName, $expectfail)
$stmt = sqlsrv_query($conn, "SELECT * from [$tableName]");
if ( null == $stmt )
{
if (null == $stmt) {
echo "$";
echo "stmt = null";
echo "\n";
}
else
{
if ( null == sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC) )
{
if (!$expectfail)
FatalError("Possible regression: Unable to retrieve inserted value.");
} else {
if (null == sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
if (!$expectfail) {
fatalError("Possible regression: Unable to retrieve inserted value.");
}
}
sqlsrv_free_stmt($stmt);
}
sqlsrv_close($conn);
}
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
$testName = "PHP - Large Unicode Column Name Test";
StartTest($testName);
startTest($testName);
$columnName = "银";
try
{
for ($a = 1; $a <= 129; $a++)
{
try {
for ($a = 1; $a <= 129; $a++) {
LargeColumnNameTest($columnName, $a > 128);
$columnName .= "银";
}
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
EndTest($testName);
endTest($testName);
}
Repro();
repro();
?>
--EXPECT--
$stmt = null

View file

@ -8,19 +8,17 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function LargeColumnNameTest($columnName, $expectfail)
{
include 'MsSetup.inc';
setup();
Setup();
$conn = ConnectUTF8();
$conn = connect(array( 'CharacterSet'=>'UTF-8' ));
$tableName = "LargeColumnNameTest";
DropTable($conn, $tableName);
dropTable($conn, $tableName);
sqlsrv_query($conn, "CREATE TABLE [$tableName] ([$columnName] int)");
@ -28,58 +26,49 @@ function LargeColumnNameTest($columnName, $expectfail)
$stmt = sqlsrv_query($conn, "SELECT * from [$tableName]");
if ( null == $stmt )
{
if (null == $stmt) {
echo "$";
echo "stmt = null";
echo "\n";
}
else
{
if ( null == sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC) )
{
if (!$expectfail)
FatalError("Possible regression: Unable to retrieve inserted value.");
} else {
if (null == sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
if (!$expectfail) {
fatalError("Possible regression: Unable to retrieve inserted value.");
}
}
sqlsrv_free_stmt($stmt);
}
sqlsrv_close($conn);
}
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
$testName = "PHP - Large Unicode Column Name Test";
StartTest($testName);
startTest($testName);
$columnName = "银";
try
{
for ($a = 1; $a <= 129; $a++)
{
try {
for ($a = 1; $a <= 129; $a++) {
LargeColumnNameTest($columnName, $a > 128);
$columnName .= "银";
}
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
EndTest($testName);
endTest($testName);
}
Repro();
repro();
?>
--EXPECT--
$stmt = null

View file

@ -8,27 +8,26 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function MaxOutputParamsTest($buffer, $phptype, $sqltype, $expected)
{
include 'MsSetup.inc';
setup();
Setup();
$conn = connect();
$conn = Connect();
dropProc($conn, "EXEC_TEST");
DropProc($conn, "EXEC_TEST");
CreateProc(
createProc(
$conn,
"EXEC_TEST",
"@OUT varchar(80) output",
"SET NOCOUNT ON; select @OUT = '$expected'; return (0)
");
"
);
$outstr = $buffer;
$sql = "execute EXEC_TEST ?";
$stmt = sqlsrv_prepare($conn, $sql, array(array( &$outstr, SQLSRV_PARAM_OUT, $phptype, $sqltype)));
@ -37,8 +36,7 @@ function MaxOutputParamsTest($buffer, $phptype, $sqltype, $expected)
echo "Expected: $expected Received: $outstr\n";
if ($outstr !== $expected)
{
if ($outstr !== $expected) {
print_r(sqlsrv_errors(SQLSRV_ERR_ALL));
return(-1);
}
@ -53,37 +51,35 @@ function MaxOutputParamsTest($buffer, $phptype, $sqltype, $expected)
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
$failed = null;
$testName = "PHP - Max Output Params Test";
StartTest($testName);
startTest($testName);
try
{
try {
$failed |= MaxOutputParamsTest("ab", SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_VARCHAR('MAX'), "abc");
$failed |= MaxOutputParamsTest(null, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_VARCHAR('10'), "abc");
$failed |= MaxOutputParamsTest(null, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_VARCHAR('MAX'), "abc");
$failed |= MaxOutputParamsTest(null, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_VARCHAR('MAX'), "abc");
$failed |= MaxOutputParamsTest("abc", SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), null, "abc");
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
if ($failed)
FatalError("Possible Regression: Value returned as VARCHAR(MAX) truncated");
if ($failed) {
fatalError("Possible Regression: Value returned as VARCHAR(MAX) truncated");
}
EndTest($testName);
endTest($testName);
}
Repro();
repro();
?>
--EXPECT--
Expected: abc Received: abc
@ -91,4 +87,4 @@ Expected: abc Received: abc
Expected: abc Received: abc
Expected: abc Received: abc
Expected: abc Received: abc
Test "PHP - Max Output Params Test" completed successfully.
Test "PHP - Max Output Params Test" completed successfully.

View file

@ -8,57 +8,57 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function InsertNullsTest($phptype, $sqltype)
{
include 'MsSetup.inc';
$outvar = null;
$failed = false;
Setup();
setup();
$conn = Connect();
$conn = connect();
DropTable($conn, $tableName);
$tableName = 'TC86test';
dropTable($conn, $tableName);
CreateTable($conn, $tableName);
createTable($conn, $tableName);
$stmt = sqlsrv_query($conn, <<<SQL
$stmt = sqlsrv_query(
$conn,
<<<SQL
SELECT [TABLE_NAME],[COLUMN_NAME],[IS_NULLABLE] FROM [INFORMATION_SCHEMA].[COLUMNS] WHERE [TABLE_NAME] = '$tableName'
SQL
);
if ($stmt === false)
{
FatalError("Could not query for column information on table $tableName");
if ($stmt === false) {
fatalError("Could not query for column information on table $tableName");
}
while ($row = sqlsrv_fetch($stmt))
{
while ($row = sqlsrv_fetch($stmt)) {
$tableName = sqlsrv_get_field($stmt, 0);
$columnName = sqlsrv_get_field($stmt, 1);
$nullable = sqlsrv_get_field($stmt, 2);
Trace($columnName . ": " . $nullable . "\n");
if (($nullable == 'YES') && (strpos($columnName, "binary") !== false))
{
$stmt2 = sqlsrv_prepare($conn, "INSERT INTO [$tableName] ([" . $columnName . "]) VALUES (?)",
array(array( null, SQLSRV_PARAM_IN, $phptype, $sqltype)) );
trace($columnName . ": " . $nullable . "\n");
if (!sqlsrv_execute($stmt2))
{
if (($nullable == 'YES') && (strpos($columnName, "binary") !== false)) {
$stmt2 = sqlsrv_prepare(
$conn,
"INSERT INTO [$tableName] ([" . $columnName . "]) VALUES (?)",
array(array( null, SQLSRV_PARAM_IN, $phptype, $sqltype))
);
if (!sqlsrv_execute($stmt2)) {
print_r(sqlsrv_errors(SQLSRV_ERR_ALL));
$failed = true;
}
}
}
DropTable($conn, $tableName);
dropTable($conn, $tableName);
return $failed;
}
@ -66,34 +66,32 @@ SQL
//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{
$failed = null;
$testName = "PHP - Insert Nulls";
StartTest($testName);
startTest($testName);
try
{
try {
$failed |= InsertNullsTest(SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY), null);
$failed |= InsertNullsTest(null, SQLSRV_SQLTYPE_VARBINARY('10'));
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
if ($failed)
FatalError("Possible Regression: Could not insert NULL");
EndTest($testName);
if ($failed) {
fatalError("Possible Regression: Could not insert NULL");
}
endTest($testName);
}
Repro();
repro();
?>
--EXPECT--

View file

@ -4,71 +4,70 @@ Fix for 168256.
<?php require('skipif.inc'); ?>
--FILE--
<?php
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
sqlsrv_configure('WarningsReturnAsErrors', 0);
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
require( 'MsCommon.inc' );
require_once('MsCommon.inc');
$connectionInfo = array( "Database"=>"test");
if( !($conn = Connect()))
{
FatalError("Could not connect");
if (!($conn = Connect())) {
fatalError("Could not connect");
}
$tsql = "SELECT OrderQty, UnitPrice FROM [168256]";
// default fetch_array (both)
$stmt = sqlsrv_query( $conn, $tsql);
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
$stmt = sqlsrv_query($conn, $tsql);
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
for($i = 0; $i < 10; $i++){
$row = sqlsrv_fetch_array( $stmt );
for ($i = 0; $i < 10; $i++) {
$row = sqlsrv_fetch_array($stmt);
print_r($row);
}
sqlsrv_free_stmt( $stmt);
sqlsrv_free_stmt($stmt);
// fetch array with numeric indices
$stmt = sqlsrv_query( $conn, $tsql);
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
$stmt = sqlsrv_query($conn, $tsql);
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
for($i = 0; $i < 10; $i++){
$row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_NUMERIC );
for ($i = 0; $i < 10; $i++) {
$row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_NUMERIC);
print_r($row);
}
sqlsrv_free_stmt( $stmt);
sqlsrv_free_stmt($stmt);
// fetch array with name indices
$stmt = sqlsrv_query( $conn, $tsql);
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
$stmt = sqlsrv_query($conn, $tsql);
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
for($i = 0; $i < 10; $i++){
$row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC );
for ($i = 0; $i < 10; $i++) {
$row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC);
print_r($row);
}
sqlsrv_free_stmt( $stmt);
sqlsrv_free_stmt($stmt);
// fetch array with both indices
$stmt = sqlsrv_query( $conn, $tsql);
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
$stmt = sqlsrv_query($conn, $tsql);
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
for($i = 0; $i < 10; $i++){
$row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_BOTH );
for ($i = 0; $i < 10; $i++) {
$row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_BOTH);
print_r($row);
}
sqlsrv_free_stmt( $stmt);
sqlsrv_free_stmt($stmt);
sqlsrv_close( $conn );
sqlsrv_close($conn);
?>
--EXPECT--
Array

View file

@ -4,28 +4,27 @@ Fix for 168256.
<?php require('skipif.inc'); ?>
--FILE--
<?php
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
sqlsrv_configure('WarningsReturnAsErrors', 0);
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
require( 'MsCommon.inc' );
if( !($conn = Connect()))
{
FatalError("Could not connect");
require_once('MsCommon.inc');
if (!($conn = Connect())) {
fatalError("Could not connect");
}
$tsql = "SELECT OrderQty, UnitPrice FROM [168256]";
$stmt = sqlsrv_query( $conn, $tsql);
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
$stmt = sqlsrv_query($conn, $tsql);
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
for($i = 0; $i < 10; $i++){
$row = sqlsrv_fetch_array( $stmt);
for ($i = 0; $i < 10; $i++) {
$row = sqlsrv_fetch_array($stmt);
print_r($row);
}
sqlsrv_free_stmt( $stmt);
sqlsrv_close( $conn );
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
?>
--EXPECT--
Array

View file

@ -4,43 +4,47 @@ fix for 182741.
<?php require('skipif.inc'); ?>
--FILE--
<?php
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
sqlsrv_configure('WarningsReturnAsErrors', 0);
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
require( 'MsCommon.inc' );
require_once('MsCommon.inc');
$conn = Connect();
if( !$conn ) {
FatalError("Could not connect");
if (!$conn) {
fatalError("Could not connect");
}
$stmt = sqlsrv_query( $conn, "IF OBJECT_ID('182741', 'U') IS NOT NULL DROP TABLE [182741]" );
if( $stmt !== false )
sqlsrv_free_stmt( $stmt );
$stmt = sqlsrv_query( $conn, "CREATE TABLE [182741] ([int_type] int, [text_type] text, [ntext_type] ntext, [image_type] image)");
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
$stmt = sqlsrv_query($conn, "IF OBJECT_ID('182741', 'U') IS NOT NULL DROP TABLE [182741]");
if ($stmt !== false) {
sqlsrv_free_stmt($stmt);
}
sqlsrv_free_stmt( $stmt );
$stmt = sqlsrv_query( $conn, "INSERT INTO [182741] ([int_type], [text_type], [ntext_type], [image_type]) VALUES(?, ?, ?, ?)",
$stmt = sqlsrv_query($conn, "CREATE TABLE [182741] ([int_type] int, [text_type] text, [ntext_type] ntext, [image_type] image)");
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query(
$conn,
"INSERT INTO [182741] ([int_type], [text_type], [ntext_type], [image_type]) VALUES(?, ?, ?, ?)",
array( 1, array( "Test Data", SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR)),
array( "Test Data", SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR)),
array( "Test Data", SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY))));
array( "Test Data", SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY)))
);
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
sqlsrv_query( $conn, "DROP TABLE [182741]" );
sqlsrv_free_stmt( $stmt );
sqlsrv_close( $conn );
sqlsrv_query($conn, "DROP TABLE [182741]");
echo "Test succeeded.";
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
echo "Test succeeded.";
?>
--EXPECT--
Test succeeded.

View file

@ -1,116 +1,111 @@
--TEST--
verify github issue52 is fixed.
--DESCRIPTION--
This test only works in previous versions of SQL Servers. Full-text search features are
This test only works in previous versions of SQL Servers. Full-text search features are
deprecated starting in SQL Server 2016.
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
require_once 'MsCommon.inc';
sqlsrv_configure('WarningsReturnAsErrors', 0);
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
require_once('MsCommon.inc');
$conn = Connect();
$server_info = sqlsrv_server_info( $conn);
if( $server_info )
{
$server_info = sqlsrv_server_info($conn);
if ($server_info) {
// check SQL Server version
$version = substr($server_info['SQLServerVersion'], 0, 2);
if ($version >= 13)
{
if ($version >= 13) {
echo "Full-text search feature deprecated.\n";
return;
}
}
}
$tableName = 'test_Fulltext';
$dataType = 'Pagename varchar(20) not null primary key,URL varchar(30) not null,Description text null,Keywords varchar(4000) null';
#===================================
if($conn)
{
if ($conn) {
echo "Connection established.<br/>";
CreateTableEx($conn, $tableName, $dataType);
PopulateTable($conn,$tableName);
createTableEx($conn, $tableName, $dataType);
PopulateTable($conn, $tableName);
EnableFullText($conn, $tableName);
sleep(5);
FetchData($conn, $tableName);
DisableFullText($conn,$tableName);
FetchData($conn,$tableName);
}
else
{
DisableFullText($conn, $tableName);
FetchData($conn, $tableName);
} else {
echo "Connection could not be established.\n";
die(print_r(sqlsrv_errors(),true));
die(print_r(sqlsrv_errors(), true));
}
sqlsrv_close($conn);
#====================================================================
function FetchData($conn, $tableName){
function FetchData($conn, $tableName)
{
$query = "SELECT * FROM $tableName WHERE freetext(description,'Magazine')";
$rtn_qry = sqlsrv_query($conn,$query);
if(!$rtn_qry)
{
var_dump( sqlsrv_errors() );
die( "sqlsrv_query(6) failed." );
$rtn_qry = sqlsrv_query($conn, $query);
if (!$rtn_qry) {
var_dump(sqlsrv_errors());
die("sqlsrv_query(6) failed.");
}
while(sqlsrv_fetch($rtn_qry))
{
$id = sqlsrv_get_field( $rtn_qry, 0, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
while (sqlsrv_fetch($rtn_qry)) {
$id = sqlsrv_get_field($rtn_qry, 0, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
echo "$id <br/>";
$id1 = sqlsrv_get_field( $rtn_qry, 1, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
$id1 = sqlsrv_get_field($rtn_qry, 1, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
echo "$id1 <br/>";
$id2 = sqlsrv_get_field( $rtn_qry, 2, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
$id2 = sqlsrv_get_field($rtn_qry, 2, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
echo "$id2 <br/>";
$id3 = sqlsrv_get_field( $rtn_qry, 3, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
$id3 = sqlsrv_get_field($rtn_qry, 3, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
echo "$id3 <br/>";
}
}
function PopulateTable($conn,$tableName){
function PopulateTable($conn, $tableName)
{
$dataCols = 'Pagename,URL,Description,Keywords';
$row1 = "'home.asp','home.asp','This is the home page','home,SQL'";
$row2 = "'PAGETWO.asp','/page2/pagetwo.asp','NT Magazine is great','second'";
$row3 = "'pagethree.asp','/page3/pagethree.asp','SQL Magazine is the greatest','third'";
$dataValues = array($row1, $row2, $row3);
foreach($dataValues as $value)
{
InsertRowEx($conn, $tableName, $dataCols, $value, null);
foreach ($dataValues as $value) {
insertRowEx($conn, $tableName, $dataCols, $value, null);
}
}
function EnableFullText($conn,$tableName){
function EnableFullText($conn, $tableName)
{
echo "Enabling full-text index ... ";
$catalogName = "fulltext_".$tableName."_catalog";
#if the fulltext catalog exists, drop it;
dropCatalog($conn, $catalogName);
$sql = $query = "CREATE UNIQUE INDEX ui_ukJobCand ON $tableName(Pagename); CREATE FULLTEXT CATALOG $catalogName as default; CREATE FULLTEXT INDEX ON $tableName(URL, Description, Keywords) KEY INDEX ui_ukJobCand with stoplist = SYSTEM";
$outcome = sqlsrv_query($conn, $sql);
if(!$outcome){
if (!$outcome) {
die("Failed to enable FULLTEXT INDEX on $tableName");
}
echo "completed successfully.\n";
}
function DisableFullText($conn,$tableName){
function DisableFullText($conn, $tableName)
{
echo "\n Disabling full-text index ... ";
$sql = "DROP FULLTEXT INDEX ON $tableName";
$outcome = sqlsrv_query($conn, $sql);
if(!$outcome){
if (!$outcome) {
die("Failed to drop the FULLTEXT INDEX on $tableName");
}
echo "completed successfully.\n";
}
#================helpers=====================
function dropCatalog($conn, $catalogName){
function dropCatalog($conn, $catalogName)
{
$catalogExists="IF EXISTS (SELECT 1 FROM sys.fulltext_catalogs WHERE [name] = '$catalogName')
DROP FULLTEXT CATALOG $catalogName";
$outcome = sqlsrv_query($conn, $catalogExists);
if(!$outcome){
if (!$outcome) {
die("Failed to drop the $catalogName");
}
}
@ -119,4 +114,4 @@ function dropCatalog($conn, $catalogName){
--EXPECTREGEX--
(Full-text search feature deprecated.|.*Connection established(.*Magazine.*)*
.*Disabling full-text index ... completed successfully..*
.*["message"].*Cannot use a CONTAINS or FREETEXT predicate on table or indexed view.* not full-text indexed.*)
.*["message"].*Cannot use a CONTAINS or FREETEXT predicate on table or indexed view.* not full-text indexed.*)

View file

@ -1,16 +1,15 @@
<?php
if(! extension_loaded( "sqlsrv" ) )
die( "skip extension not loaded" );
require_once( "MsCommon.inc" );
$conn = ae_connect();
if( ! $conn )
{
echo( "Error: could not connect during SKIPIF!" );
if (! extension_loaded("sqlsrv")) {
die("skip extension not loaded");
}
require_once('MsCommon.inc');
$conn = connect();
if (! $conn) {
echo("Error: could not connect during SKIPIF!");
} elseif (AE\isColEncrypted() && !AE\isQualified($conn)) {
die("skip - AE feature not supported in the current environment.");
}
else if(! IsAEQualified( $conn ) )
{
die( "skip - AE feature not supported in the current environment." );
}
?>

View file

@ -4,101 +4,107 @@ new SQL Server 2008 date types.
<?php require('skipif.inc'); ?>
--FILE--
<?php
date_default_timezone_set('America/Los_Angeles');
sqlsrv_configure('WarningsReturnAsErrors', 0);
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
sqlsrv_configure('LogSubsystems', SQLSRV_LOG_SYSTEM_OFF);
date_default_timezone_set( 'America/Los_Angeles' );
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
sqlsrv_configure( 'LogSubsystems', SQLSRV_LOG_SYSTEM_OFF );
require( 'MsCommon.inc' );
require_once('MsCommon.inc');
// For testing in Azure, can not switch databases
$conn = Connect(array( 'ReturnDatesAsStrings' => true ));
$conn = connect(array( 'ReturnDatesAsStrings' => true ));
if( !$conn ) {
FatalError("Could not connect");
if (!$conn) {
fatalError("Could not connect");
}
$stmt = sqlsrv_query( $conn, "IF OBJECT_ID('2008_date_types', 'U') IS NOT NULL DROP TABLE [2008_date_types]" );
$stmt = sqlsrv_query($conn, "IF OBJECT_ID('2008_date_types', 'U') IS NOT NULL DROP TABLE [2008_date_types]");
$stmt = sqlsrv_query( $conn, "CREATE TABLE [2008_date_types] (id int, [c1_date] date, [c2_time] time, [c3_datetimeoffset] datetimeoffset, [c4_datetime2] datetime2)" );
if( $stmt === false ) {
FatalError("Create table failed");
$stmt = sqlsrv_query($conn, "CREATE TABLE [2008_date_types] (id int, [c1_date] date, [c2_time] time, [c3_datetimeoffset] datetimeoffset, [c4_datetime2] datetime2)");
if ($stmt === false) {
fatalError("Create table failed");
}
// insert new date time types as strings (this works now)
$stmt = sqlsrv_query( $conn, "INSERT INTO [2008_date_types] (id, [c1_date], [c2_time], [c3_datetimeoffset], [c4_datetime2])" .
$stmt = sqlsrv_query(
$conn,
"INSERT INTO [2008_date_types] (id, [c1_date], [c2_time], [c3_datetimeoffset], [c4_datetime2])" .
" VALUES (?, ?, ?, ?, ?)",
array( rand(0,99999),
array( rand(0, 99999),
array( strftime('%Y-%m-%d'), SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING('utf-8'), SQLSRV_SQLTYPE_DATE ),
array( strftime( '%H:%M:%S' ), SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING( 'utf-8' ), SQLSRV_SQLTYPE_TIME ),
array( date_format( date_create(), 'Y-m-d H:i:s.u P'), SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING('utf-8'), SQLSRV_SQLTYPE_DATETIMEOFFSET ),
array( date_format( date_create(), 'Y-m-d H:i:s.u'), SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING('utf-8'), SQLSRV_SQLTYPE_DATETIME2 )));
if( $stmt === false ) {
FatalError("Insert 1 failed");
array( strftime('%H:%M:%S'), SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING('utf-8'), SQLSRV_SQLTYPE_TIME ),
array( date_format(date_create(), 'Y-m-d H:i:s.u P'), SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING('utf-8'), SQLSRV_SQLTYPE_DATETIMEOFFSET ),
array( date_format(date_create(), 'Y-m-d H:i:s.u'), SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING('utf-8'), SQLSRV_SQLTYPE_DATETIME2 ))
);
if ($stmt === false) {
fatalError("Insert 1 failed");
}
// insert new date time types as DateTime objects (this works now)
$stmt = sqlsrv_query( $conn, "INSERT INTO [2008_date_types] (id, [c1_date], [c2_time], [c3_datetimeoffset], [c4_datetime2])" .
$stmt = sqlsrv_query(
$conn,
"INSERT INTO [2008_date_types] (id, [c1_date], [c2_time], [c3_datetimeoffset], [c4_datetime2])" .
" VALUES (?, ?, ?, ?, ?)",
array( rand(0,99999),
array( rand(0, 99999),
array( date_create(), SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_DATETIME, SQLSRV_SQLTYPE_DATE ),
array( date_create(), SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_DATETIME, SQLSRV_SQLTYPE_TIME ),
array( date_create(), SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_DATETIME, SQLSRV_SQLTYPE_DATETIMEOFFSET ),
array( date_create(), SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_DATETIME, SQLSRV_SQLTYPE_DATETIME2 )));
if( $stmt === false ) {
FatalError("Insert 2 failed");
array( date_create(), SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_DATETIME, SQLSRV_SQLTYPE_DATETIME2 ))
);
if ($stmt === false) {
fatalError("Insert 2 failed");
}
// insert new date time types as default DateTime objects with no type information (this works now)
$stmt = sqlsrv_query( $conn, "INSERT INTO [2008_date_types] (id, [c1_date], [c2_time], [c3_datetimeoffset], [c4_datetime2])" .
" VALUES (?, ?, ?, ?, ?)",
array( rand(0,99999), date_create(), date_create(), date_create(), date_create()));
if( $stmt === false ) {
FatalError("Insert 3 failed");
$stmt = sqlsrv_query(
$conn,
"INSERT INTO [2008_date_types] (id, [c1_date], [c2_time], [c3_datetimeoffset], [c4_datetime2])" .
" VALUES (?, ?, ?, ?, ?)",
array( rand(0, 99999), date_create(), date_create(), date_create(), date_create())
);
if ($stmt === false) {
fatalError("Insert 3 failed");
}
// insert new date time types as strings with no type information (this works)
$stmt = sqlsrv_query( $conn, "INSERT INTO [2008_date_types] (id, [c1_date], [c2_time], [c3_datetimeoffset], [c4_datetime2])" .
$stmt = sqlsrv_query(
$conn,
"INSERT INTO [2008_date_types] (id, [c1_date], [c2_time], [c3_datetimeoffset], [c4_datetime2])" .
" VALUES (?, ?, ?, ?, ?)",
array( rand(0,99999), strftime('%Y-%m-%d'), strftime( '%H:%M:%S' ), date_format( date_create(), 'Y-m-d H:i:s.u P'), date_format( date_create(), 'Y-m-d H:i:s.u P')));
if( $stmt === false ) {
FatalError("Insert 4 failed");
array( rand(0, 99999), strftime('%Y-%m-%d'), strftime('%H:%M:%S'), date_format(date_create(), 'Y-m-d H:i:s.u P'), date_format(date_create(), 'Y-m-d H:i:s.u P'))
);
if ($stmt === false) {
fatalError("Insert 4 failed");
}
// retrieve date time fields as strings (this works)
$stmt = sqlsrv_query( $conn, "SELECT * FROM [2008_date_types]" );
while( sqlsrv_fetch( $stmt )) {
for( $i = 0; $i < sqlsrv_num_fields( $stmt ); ++$i ) {
$fld = sqlsrv_get_field( $stmt, $i, SQLSRV_PHPTYPE_STRING( SQLSRV_ENC_CHAR ));
$stmt = sqlsrv_query($conn, "SELECT * FROM [2008_date_types]");
while (sqlsrv_fetch($stmt)) {
for ($i = 0; $i < sqlsrv_num_fields($stmt); ++$i) {
$fld = sqlsrv_get_field($stmt, $i, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
echo "field $i = $fld\n";
}
}
// retrieve date time fields as default (should come back as DateTime objects) (this works now)
$stmt = sqlsrv_query( $conn, "SELECT * FROM [2008_date_types]" );
if( $stmt === false ) {
FatalError("Select from table failed");
$stmt = sqlsrv_query($conn, "SELECT * FROM [2008_date_types]");
if ($stmt === false) {
fatalError("Select from table failed");
}
while( $row = sqlsrv_fetch_array( $stmt )) {
var_dump( $row );
while ($row = sqlsrv_fetch_array($stmt)) {
var_dump($row);
}
// retrieve date itme fields as DateTime objects
$stmt = sqlsrv_query( $conn, "SELECT * FROM [2008_date_types]" );
while( sqlsrv_fetch( $stmt )) {
for( $i = 1; $i < sqlsrv_num_fields( $stmt ); ++$i ) {
$fld = sqlsrv_get_field( $stmt, $i, SQLSRV_PHPTYPE_DATETIME );
$str = date_format( $fld, 'Y-m-d H:i:s.u P' );
$stmt = sqlsrv_query($conn, "SELECT * FROM [2008_date_types]");
while (sqlsrv_fetch($stmt)) {
for ($i = 1; $i < sqlsrv_num_fields($stmt); ++$i) {
$fld = sqlsrv_get_field($stmt, $i, SQLSRV_PHPTYPE_DATETIME);
$str = date_format($fld, 'Y-m-d H:i:s.u P');
echo "field $i = $str\n";
}
}
print_r( sqlsrv_field_metadata( $stmt ));
print_r(sqlsrv_field_metadata($stmt));
sqlsrv_close( $conn );
sqlsrv_close($conn);
?>
--EXPECTREGEX--

View file

@ -9,49 +9,52 @@ steps to reproduce the issue:
4 - call sp.
--FILE--
<?php
require_once("MsCommon.inc");
require_once('MsCommon.inc');
$conn = Connect();
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true ));
$conn = connect();
if ($conn === false) {
die(print_r(sqlsrv_errors(), true));
}
//----------------Main---------------------------
$procName = GetTempProcName();
createSP($conn, $procName);
sqlsrv_configure( 'WarningsReturnAsErrors', true );
sqlsrv_configure('WarningsReturnAsErrors', true);
executeSP($conn, $procName);
sqlsrv_configure( 'WarningsReturnAsErrors', false );
sqlsrv_configure('WarningsReturnAsErrors', false);
executeSP($conn, $procName);
echo "Done";
//-------------------functions-------------------
function createSP($conn, $procName){
$sp_sql="create proc $procName @p1 integer, @p2 integer, @p3 integer output
function createSP($conn, $procName)
{
$sp_sql="create proc $procName @p1 integer, @p2 integer, @p3 integer output
as
begin
select @p3 = @p1 + @p2
print @p3
end
";
$stmt = sqlsrv_query($conn, $sp_sql);
if ($stmt === false) { FatalError("Failed to create stored procedure"); }
$stmt = sqlsrv_query($conn, $sp_sql);
if ($stmt === false) {
fatalError("Failed to create stored procedure");
}
}
function executeSP($conn, $procName){
$expected = 3;
$v1 = 1;
$v2 = 2;
$v3 = 'str';
$stmt = sqlsrv_query( $conn, "{call $procName( ?, ?, ? )}", array( $v1, $v2, array( &$v3, SQLSRV_PARAM_OUT )));
if( $stmt === false ) {
print_r( sqlsrv_errors(), true );
}
if ( $v3 != $expected ) {
FatalError("The expected value is $expected, actual value is $v3\n");
}
function executeSP($conn, $procName)
{
$expected = 3;
$v1 = 1;
$v2 = 2;
$v3 = 'str';
$stmt = sqlsrv_query($conn, "{call $procName( ?, ?, ? )}", array( $v1, $v2, array( &$v3, SQLSRV_PARAM_OUT )));
if ($stmt === false) {
print_r(sqlsrv_errors(), true);
}
if ($v3 != $expected) {
fatalError("The expected value is $expected, actual value is $v3\n");
}
}
?>
--EXPECT--
Done
Done

View file

@ -4,67 +4,73 @@ LOB types as strings.
<?php require('skipif.inc'); ?>
--FILE--
<?php
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
require( 'MsCommon.inc' );
$conn = Connect();
if( !$conn ) {
FatalError( "Failed to connect." );
sqlsrv_configure('WarningsReturnAsErrors', 0);
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
require_once('MsCommon.inc');
$conn = connect();
if (!$conn) {
fatalError("Failed to connect.");
}
sqlsrv_query($conn, "IF OBJECT_ID('PhpCustomerTable', 'U') IS NOT NULL DROP TABLE [PhpCustomerTable]" );
sqlsrv_query($conn, "CREATE TABLE [PhpCustomerTable] ([Id] int NOT NULL Identity (100,2) PRIMARY KEY, [Field2] text, [Field3] image, [Field4] ntext, [Field5] varbinary(max), [Field6] varchar(max), [Field7] nvarchar(max))" );
sqlsrv_query($conn, "INSERT [PhpCustomerTable] ([Field2], [Field3], [Field4], [Field5], [Field6], [Field7]) VALUES ('This is field 2.', 0x010203, 'This is field 4.', 0x040506, 'This is field 6.', 'This is field 7.' )" );
sqlsrv_query($conn, "IF OBJECT_ID('PhpCustomerTable', 'U') IS NOT NULL DROP TABLE [PhpCustomerTable]");
sqlsrv_query($conn, "CREATE TABLE [PhpCustomerTable] ([Id] int NOT NULL Identity (100,2) PRIMARY KEY, [Field2] text, [Field3] image, [Field4] ntext, [Field5] varbinary(max), [Field6] varchar(max), [Field7] nvarchar(max))");
sqlsrv_query($conn, "INSERT [PhpCustomerTable] ([Field2], [Field3], [Field4], [Field5], [Field6], [Field7]) VALUES ('This is field 2.', 0x010203, 'This is field 4.', 0x040506, 'This is field 6.', 'This is field 7.' )");
$stmt = sqlsrv_query($conn, "SELECT * FROM [PhpCustomerTable]");
sqlsrv_fetch( $stmt );
sqlsrv_fetch($stmt);
$v = sqlsrv_get_field( $stmt, 0, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR) );
if(!$v)
print( 'Failed to get text field' );
else {
$v = sqlsrv_get_field($stmt, 0, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
if (!$v) {
print('Failed to get text field');
} else {
echo "$v<br/>\n";
}
$v = sqlsrv_get_field( $stmt, 1, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR) );
if(!$v)
print( 'Failed to get text field' );
$v = sqlsrv_get_field($stmt, 1, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
if (!$v) {
print('Failed to get text field');
}
echo "$v<br/>\n";
$v = sqlsrv_get_field( $stmt, 2, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR) );
if(!$v)
die( 'Failed to get image field]' );
$v = sqlsrv_get_field($stmt, 2, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
if (!$v) {
die('Failed to get image field]');
}
echo "$v<br/>\n";
$v = sqlsrv_get_field( $stmt, 3, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR) );
if(!$v)
print( 'Failed to get ntext field' );
$v = sqlsrv_get_field($stmt, 3, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
if (!$v) {
print('Failed to get ntext field');
}
echo "$v<br/>\n";
$v = sqlsrv_get_field( $stmt, 4, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR) );
if(!$v)
print( 'Failed to get varbinary(max) field' );
$v = sqlsrv_get_field($stmt, 4, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
if (!$v) {
print('Failed to get varbinary(max) field');
}
echo "$v<br/>\n";
$v = sqlsrv_get_field( $stmt, 5, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR) );
if(!$v)
print( 'Failed to get varchar(max) field' );
$v = sqlsrv_get_field($stmt, 5, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
if (!$v) {
print('Failed to get varchar(max) field');
}
echo "$v<br/>\n";
$v = sqlsrv_get_field( $stmt, 6, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR) );
if(!$v)
print( 'Failed to get nvarchar(max) field' );
$v = sqlsrv_get_field($stmt, 6, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
if (!$v) {
print('Failed to get nvarchar(max) field');
}
echo "$v<br/>\n";
sqlsrv_free_stmt( $stmt );
sqlsrv_close( $conn );
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
echo "Test successful."
?>

View file

@ -6,49 +6,46 @@ Bind params using sqlsrv_prepare without any sql_type specified
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
include 'AEData.inc';
require_once('MsCommon.inc');
require_once('AEData.inc');
date_default_timezone_set("Canada/Pacific");
$dataTypes = array( "date", "datetime", "datetime2", "smalldatetime", "time", "datetimeoffset" );
$conn = ae_connect();
$conn = AE\connect();
foreach ( $dataTypes as $dataType ) {
foreach ($dataTypes as $dataType) {
echo "\nTesting $dataType: \n";
// create table
$tbname = GetTempTableName( "", false );
$colMetaArr = array( new columnMeta( $dataType, "c_det" ), new columnMeta( $dataType, "c_rand", null, "randomized" ));
create_table( $conn, $tbname, $colMetaArr );
$tbname = GetTempTableName("", false);
$colMetaArr = array( new AE\ColumnMeta($dataType, "c_det"), new AE\ColumnMeta($dataType, "c_rand", null, "randomized"));
AE\createTable($conn, $tbname, $colMetaArr);
// insert a row
$inputValues = array_slice( ${explode( "(", $dataType )[0] . "_params"}, 1, 2 );
$inputValues = array_slice(${explode("(", $dataType)[0] . "_params"}, 1, 2);
$r;
$stmt = insert_row( $conn, $tbname, array( $colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r );
if ( $r === false ) {
is_incompatible_types_error( $dataType, "default type" );
}
else {
$stmt = AE\insertRow($conn, $tbname, array( $colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r);
if ($r === false) {
is_incompatible_types_error($dataType, "default type");
} else {
echo "****Encrypted default type is compatible with encrypted $dataType****\n";
if ( $dataType != "time" )
fetch_all( $conn, $tbname );
else
{
if ($dataType != "time") {
AE\fetchAll($conn, $tbname);
} else {
$sql = "SELECT * FROM $tbname";
$stmt = sqlsrv_query( $conn, $sql );
$row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC );
foreach ( $row as $key => $value )
{
$stmt = sqlsrv_query($conn, $sql);
$row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC);
foreach ($row as $key => $value) {
//var_dump( $row );
$t = $value->format( 'H:i:s' );
$t = $value->format('H:i:s');
print "$key: $t\n";
}
}
}
DropTable( $conn, $tbname );
dropTable($conn, $tbname);
}
sqlsrv_free_stmt( $stmt );
sqlsrv_close( $conn );
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
?>
--EXPECT--

View file

@ -6,67 +6,59 @@ Bind params using sqlsrv_prepare without any sql_type specified
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
include 'AEData.inc';
require_once('MsCommon.inc');
require_once('AEData.inc');
use AE\ColumnMeta;
$dataTypes = array( "smallmoney", "money" );
$conn = ae_connect();
$conn = AE\connect();
foreach ( $dataTypes as $dataType ) {
foreach ($dataTypes as $dataType) {
echo "\nTesting $dataType: \n";
$success = true;
// create table
$tbname = GetTempTableName( "", false );
$colMetaArr = array( new columnMeta( $dataType, "c_det" ), new columnMeta( $dataType, "c_rand", null, "randomized" ));
create_table( $conn, $tbname, $colMetaArr );
$tbname = GetTempTableName("", false);
$colMetaArr = array( new AE\ColumnMeta($dataType, "c_det"), new AE\ColumnMeta($dataType, "c_rand", null, "randomized"));
AE\createTable($conn, $tbname, $colMetaArr);
// insert a row
$inputValues = array_slice( ${explode( "(", $dataType )[0] . "_params"}, 1, 2 );
$inputValues = array_slice(${explode("(", $dataType)[0] . "_params"}, 1, 2);
$r;
$stmt = insert_row( $conn, $tbname, array( $colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r );
if ( !is_col_enc() )
{
if ( $r === false )
{
$stmt = AE\insertRow($conn, $tbname, array( $colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r);
if (!AE\isColEncrypted()) {
if ($r === false) {
echo "Default type should be compatible with $dataType.\n";
$success = false;
}
else
{
} else {
$sql = "SELECT * FROM $tbname";
$stmt = sqlsrv_query( $conn, $sql );
$row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC );
if ( $row["c_det"] != $inputValues[0] || $row["c_rand"] != $inputValues[1] )
{
$stmt = sqlsrv_query($conn, $sql);
$row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC);
if ($row["c_det"] != $inputValues[0] || $row["c_rand"] != $inputValues[1]) {
echo "Incorrect output retrieved for datatype $dataType and sqlType $sqlType.\n";
$success = false;
}
}
}
else
{
if ( $r === false )
{
if ( sqlsrv_errors()[0]['SQLSTATE'] != 22018 )
{
} else {
if ($r === false) {
if (sqlsrv_errors()[0]['SQLSTATE'] != 22018) {
echo "Incorrect error returned.\n";
$success = false;
}
}
else
{
} else {
echo "$dataType is not compatible with any type.\n";
$success = false;
}
}
if ( $success )
if ($success) {
echo "Test successfully done.\n";
DropTable( $conn, $tbname );
}
dropTable($conn, $tbname);
}
sqlsrv_free_stmt( $stmt );
sqlsrv_close( $conn );
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
?>
--EXPECT--

View file

@ -6,35 +6,34 @@ Bind params using sqlsrv_prepare without any sql_type specified
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
include 'AEData.inc';
require_once('MsCommon.inc');
require_once('AEData.inc');
$dataTypes = array( "bit", "tinyint", "smallint", "int", "bigint", "decimal(18,5)", "numeric(10,5)", "float", "real" );
$conn = ae_connect();
$conn = AE\connect();
foreach ( $dataTypes as $dataType ) {
foreach ($dataTypes as $dataType) {
echo "\nTesting $dataType: \n";
// create table
$tbname = GetTempTableName( "", false );
$colMetaArr = array( new columnMeta( $dataType, "c_det" ), new columnMeta( $dataType, "c_rand", null, "randomized" ));
create_table( $conn, $tbname, $colMetaArr );
$tbname = GetTempTableName("", false);
$colMetaArr = array( new AE\ColumnMeta($dataType, "c_det"), new AE\ColumnMeta($dataType, "c_rand", null, "randomized"));
AE\createTable($conn, $tbname, $colMetaArr);
// insert a row
$inputValues = array_slice( ${explode( "(", $dataType )[0] . "_params"}, 1, 2 );
$inputValues = array_slice(${explode("(", $dataType)[0] . "_params"}, 1, 2);
$r;
$stmt = insert_row( $conn, $tbname, array( $colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r );
if ( $r === false ) {
is_incompatible_types_error( $dataType, "default type" );
}
else {
$stmt = AE\insertRow($conn, $tbname, array( $colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r);
if ($r === false) {
is_incompatible_types_error($dataType, "default type");
} else {
echo "****Encrypted default type is compatible with encrypted $dataType****\n";
fetch_all( $conn, $tbname );
AE\fetchAll($conn, $tbname);
}
DropTable( $conn, $tbname );
dropTable($conn, $tbname);
}
sqlsrv_free_stmt( $stmt );
sqlsrv_close( $conn );
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
?>
--EXPECT--

View file

@ -6,65 +6,61 @@ Retrieving SQL query contains encrypted filter
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
date_default_timezone_set("Canada/Pacific");
$conn = ae_connect();
$conn = AE\connect();
// Create the table
$tbname = 'Patients';
$colMetaArr = array( new columnMeta( "int", "PatientId", "IDENTITY(1,1)" ),
new columnMeta( "char(11)", "SSN"),
new columnMeta( "nvarchar(50)", "FirstName", "NULL" ),
new columnMeta( "nvarchar(50)", "LastName", "NULL"),
new columnMeta( "date", "BirthDate", null, "randomized" ));
create_table( $conn, $tbname, $colMetaArr );
$colMetaArr = array( new AE\ColumnMeta("int", "PatientId", "IDENTITY(1,1)"),
new AE\ColumnMeta("char(11)", "SSN"),
new AE\ColumnMeta("nvarchar(50)", "FirstName", "NULL"),
new AE\ColumnMeta("nvarchar(50)", "LastName", "NULL"),
new AE\ColumnMeta("date", "BirthDate", null, "randomized"));
AE\createTable($conn, $tbname, $colMetaArr);
// insert a row
$SSN = "795-73-9838";
$inputs = array( "SSN" => $SSN, "FirstName" => "Catherine", "LastName" => "Abel", "BirthDate" => "1996-10-19" );
$stmt = insert_row( $conn, $tbname, $inputs );
$stmt = AE\insertRow($conn, $tbname, $inputs);
echo "Retrieving plaintext data:\n";
$selectSql = "SELECT SSN, FirstName, LastName, BirthDate FROM $tbname WHERE SSN = ?";
$stmt = sqlsrv_prepare( $conn, $selectSql, array( $SSN ));
sqlsrv_execute( $stmt );
$decrypted_row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC );
foreach ( $decrypted_row as $key => $value )
{
if ( !is_object( $value ))
$stmt = sqlsrv_prepare($conn, $selectSql, array( $SSN ));
sqlsrv_execute($stmt);
$decrypted_row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC);
foreach ($decrypted_row as $key => $value) {
if (!is_object($value)) {
print "$key: $value\n";
else
{
} else {
print "$key:\n";
foreach ( $value as $dateKey => $dateValue )
{
foreach ($value as $dateKey => $dateValue) {
print " $dateKey: $dateValue\n";
}
}
}
sqlsrv_free_stmt( $stmt );
sqlsrv_free_stmt($stmt);
//for AE only
echo "\nChecking ciphertext data:\n";
if ( is_col_enc() )
{
$conn1 = ae_connect( null, true );
if (AE\isColEncrypted()) {
$conn1 = connect(null, true);
$selectSql = "SELECT SSN, FirstName, LastName, BirthDate FROM $tbname";
$stmt = sqlsrv_query( $conn1, $selectSql );
$encrypted_row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC );
foreach( $encrypted_row as $key => $value )
{
if ( ctype_print( $value ))
$stmt = sqlsrv_query($conn1, $selectSql);
$encrypted_row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC);
foreach ($encrypted_row as $key => $value) {
if (ctype_print($value)) {
print "Error: expected a binary array for $key!\n";
}
}
sqlsrv_free_stmt( $stmt );
sqlsrv_close( $conn1 );
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn1);
}
DropTable( $conn, $tbname );
sqlsrv_close( $conn );
dropTable($conn, $tbname);
sqlsrv_close($conn);
echo "Done";

View file

@ -4,65 +4,65 @@ Test for inserting encrypted fixed size types data and retrieve both encrypted a
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
date_default_timezone_set("Canada/Pacific");
$conn = ae_connect();
$conn = AE\connect();
$testPass = true;
// Create the table
$tbname = 'FixedSizeAnalysis';
$colMetaArr = array( new columnMeta( "tinyint", "TinyIntData" ),
new columnMeta( "smallint", "SmallIntData" ),
new columnMeta( "int", "IntData" ),
new columnMeta( "bigint", "BigIntData" ),
new columnMeta( "decimal(38,0)", "DecimalData" ),
new columnMeta( "bit", "BitData" ),
new columnMeta( "datetime", "DateTimeData" ),
new columnMeta( "datetime2", "DateTime2Data" ));
create_table( $conn, $tbname, $colMetaArr );
$colMetaArr = array( new AE\ColumnMeta("tinyint", "TinyIntData"),
new AE\ColumnMeta("smallint", "SmallIntData"),
new AE\ColumnMeta("int", "IntData"),
new AE\ColumnMeta("bigint", "BigIntData"),
new AE\ColumnMeta("decimal(38,0)", "DecimalData"),
new AE\ColumnMeta("bit", "BitData"),
new AE\ColumnMeta("datetime", "DateTimeData"),
new AE\ColumnMeta("datetime2", "DateTime2Data"));
AE\createTable($conn, $tbname, $colMetaArr);
// insert a row
$inputs = array( "TinyIntData" => 255,
"SmallIntData" => 32767,
"IntData" => 2147483647,
"BigIntData" => 92233720368547,
"DecimalData" => 79228162514264,
"BitData" => 1,
"DateTimeData" => '9999-12-31 23:59:59.997',
$inputs = array( "TinyIntData" => 255,
"SmallIntData" => 32767,
"IntData" => 2147483647,
"BigIntData" => 92233720368547,
"DecimalData" => 79228162514264,
"BitData" => 1,
"DateTimeData" => '9999-12-31 23:59:59.997',
"DateTime2Data" => '9999-12-31 23:59:59.9999999');
$r;
$stmt = insert_row( $conn, $tbname, $inputs, $r );
if ( $r === false ) {
var_dump( sqlsrv_errors() );
$stmt = AE\insertRow($conn, $tbname, $inputs, $r);
if ($r === false) {
var_dump(sqlsrv_errors());
}
print "Decrypted values:\n";
fetch_all( $conn, $tbname );
AE\fetchAll($conn, $tbname);
sqlsrv_free_stmt( $stmt );
sqlsrv_free_stmt($stmt);
// for AE only
if ( is_col_enc() )
{
$conn1 = ae_connect( null, true );
if (AE\isColEncrypted()) {
$conn1 = connect(null, true);
$selectSql = "SELECT * FROM $tbname";
$stmt = sqlsrv_query( $conn1, $selectSql );
if ( $stmt === false )
var_dump( sqlsrv_errors() );
$encrypted_row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC );
foreach( $encrypted_row as $key => $value )
{
if ( ctype_print( $value ))
print "Error: expected a binary array for $key!\n";
$stmt = sqlsrv_query($conn1, $selectSql);
if ($stmt === false) {
var_dump(sqlsrv_errors());
}
sqlsrv_free_stmt( $stmt );
sqlsrv_close( $conn1 );
$encrypted_row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC);
foreach ($encrypted_row as $key => $value) {
if (ctype_print($value)) {
print "Error: expected a binary array for $key!\n";
}
}
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn1);
}
DropTable( $conn, $tbname );
sqlsrv_close( $conn );
dropTable($conn, $tbname);
sqlsrv_close($conn);
echo "Done\n";
@ -83,4 +83,4 @@ DateTime2Data:
date: 9999-12-31 23:59:59.1000000
timezone_type: 3
timezone: Canada/Pacific
Done
Done

View file

@ -4,63 +4,57 @@ Test for inserting encrypted nvarchar data of variable lengths and retrieving en
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
$conn = ae_connect();
$conn = AE\connect();
$testPass = true;
// Create the table
$tbname = 'NVarcharAnalysis';
$colMetaArr = array( new columnMeta( "int", "CharCount", "IDENTITY(0,1)" ), new columnMeta( "nvarchar(1000)" ));
create_table( $conn, $tbname, $colMetaArr );
$colMetaArr = array( new AE\ColumnMeta("int", "CharCount", "IDENTITY(0,1)"), new AE\ColumnMeta("nvarchar(1000)"));
AE\createTable($conn, $tbname, $colMetaArr);
// insert 1000 rows
for ( $i = 0; $i < 1000; $i++ )
{
$data = str_repeat( "*", $i );
$stmt = insert_row( $conn, $tbname, array( get_default_colname( "nvarchar(1000)" ) => $data ));
for ($i = 0; $i < 1000; $i++) {
$data = str_repeat("*", $i);
$stmt = AE\insertRow($conn, $tbname, array( AE\getDefaultColname("nvarchar(1000)") => $data ));
}
$selectSql = "SELECT * FROM $tbname";
$stmt = sqlsrv_query( $conn, $selectSql );
while ( $decrypted_row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC ))
{
if ( $decrypted_row[ 'CharCount' ] != strlen( $decrypted_row[ get_default_colname( "nvarchar(1000)" ) ] ))
{
$stmt = sqlsrv_query($conn, $selectSql);
while ($decrypted_row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
if ($decrypted_row[ 'CharCount' ] != strlen($decrypted_row[ AE\getDefaultColname("nvarchar(1000)") ])) {
$rowInd = $decrypted_row[ 'CharCount' ] + 1;
echo "Failed to decrypted at row $rowInd\n";
$testPass = false;
}
}
sqlsrv_free_stmt( $stmt );
sqlsrv_free_stmt($stmt);
// for AE only
if ( is_col_enc() )
{
$conn1 = ae_connect( null, true );
$stmt = sqlsrv_query( $conn1, $selectSql );
while ( $encrypted_row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC ))
{
if ( $encrypted_row[ 'CharCount' ] == strlen( $encrypted_row[ get_default_colname( "nvarchar(1000)" ) ] ))
{
if (AE\isColEncrypted()) {
$conn1 = connect(null, true);
$stmt = sqlsrv_query($conn1, $selectSql);
while ($encrypted_row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
if ($encrypted_row[ 'CharCount' ] == strlen($encrypted_row[ AE\getDefaultColname("nvarchar(1000)") ])) {
$rowInd = $encrypted_row[ 'CharCount' ] + 1;
echo "Failed to encrypted at row $rowInd\n";
$testPass = false;
}
}
sqlsrv_free_stmt( $stmt );
sqlsrv_close( $conn1 );
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn1);
}
DropTable( $conn, $tbname );
sqlsrv_close( $conn );
dropTable($conn, $tbname);
sqlsrv_close($conn);
if ( $testPass ) {
if ($testPass) {
echo "Test successfully done.\n";
}
?>
--EXPECT--
Test successfully done.
Test successfully done.

View file

@ -4,62 +4,56 @@ Test for inserting encrypted varchar data of variable lengths and retrieving enc
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
$conn = ae_connect();
$conn = AE\connect();
$testPass = true;
// Create the table
$tbname = 'VarcharAnalysis';
$colMetaArr = array( new columnMeta( "int", "CharCount", "IDENTITY(0,1)" ), new columnMeta( "varchar(1000)" ));
create_table( $conn, $tbname, $colMetaArr );
$colMetaArr = array( new AE\ColumnMeta("int", "CharCount", "IDENTITY(0,1)"), new AE\ColumnMeta("varchar(1000)"));
AE\createTable($conn, $tbname, $colMetaArr);
// insert 1000 rows
for ( $i = 0; $i < 1000; $i++ )
{
$data = str_repeat( "*", $i );
$stmt = insert_row( $conn, $tbname, array( get_default_colname( "varchar(1000)" ) => $data ));
for ($i = 0; $i < 1000; $i++) {
$data = str_repeat("*", $i);
$stmt = AE\insertRow($conn, $tbname, array( AE\getDefaultColname("varchar(1000)") => $data ));
}
$selectSql = "SELECT * FROM $tbname";
$stmt = sqlsrv_query( $conn, $selectSql );
while ( $decrypted_row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC ))
{
if ( $decrypted_row[ 'CharCount' ] != strlen( $decrypted_row[ get_default_colname( "varchar(1000)" ) ] ))
{
$stmt = sqlsrv_query($conn, $selectSql);
while ($decrypted_row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
if ($decrypted_row[ 'CharCount' ] != strlen($decrypted_row[ AE\getDefaultColname("varchar(1000)") ])) {
$rowInd = $decrypted_row[ 'CharCount' ] + 1;
echo "Failed to decrypted at row $rowInd\n";
$testPass = false;
}
}
sqlsrv_free_stmt( $stmt );
sqlsrv_free_stmt($stmt);
// for AE only
if ( is_col_enc() )
{
$conn1 = ae_connect( null, true );
$stmt = sqlsrv_query( $conn1, $selectSql );
while ( $encrypted_row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC ))
{
if ( $encrypted_row[ 'CharCount' ] == strlen( $encrypted_row[ get_default_colname( "varchar(1000)" ) ] ))
{
if (AE\isColEncrypted()) {
$conn1 = connect(null, true);
$stmt = sqlsrv_query($conn1, $selectSql);
while ($encrypted_row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
if ($encrypted_row[ 'CharCount' ] == strlen($encrypted_row[ AE\getDefaultColname("varchar(1000)") ])) {
$rowInd = $encrypted_row[ 'CharCount' ] + 1;
echo "Failed to encrypted at row $rowInd\n";
$testPass = false;
}
}
sqlsrv_free_stmt( $stmt );
sqlsrv_close( $conn1 );
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn1);
}
DropTable( $conn, $tbname );
sqlsrv_close( $conn );
dropTable($conn, $tbname);
sqlsrv_close($conn);
if ( $testPass ) {
if ($testPass) {
echo "Test successfully done.\n";
}
?>
--EXPECT--
Test successfully done.
Test successfully done.

View file

@ -6,12 +6,12 @@ Bind params using sqlsrv_prepare with all sql_type
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
include 'AEData.inc';
require_once('MsCommon.inc');
require_once('AEData.inc');
date_default_timezone_set("Canada/Pacific");
$dataTypes = array( "date", "datetime", "datetime2", "smalldatetime", "time", "datetimeoffset" );
// this is a list of implicit datatype conversion that SQL Server allows (https://docs.microsoft.com/en-us/sql/t-sql/data-types/data-type-conversion-database-engine)
$compatList = array( "date" => array( "SQLSRV_SQLTYPE_CHAR", "SQLSRV_SQLTYPE_VARCHAR", "SQLSRV_SQLTYPE_NCHAR", "SQLSRV_SQLTYPE_NVARCHAR", "SQLSRV_SQLTYPE_DATETIME", "SQLSRV_SQLTYPE_SMALLDATETIME", "SQLSRV_SQLTYPE_DATE", "SQLSRV_SQLTYPE_DATETIMEOFFSET", "SQLSRV_SQLTYPE_DATETIME2" ),
"datetime" => array( "SQLSRV_SQLTYPE_CHAR", "SQLSRV_SQLTYPE_VARCHAR", "SQLSRV_SQLTYPE_NCHAR", "SQLSRV_SQLTYPE_NVARCHAR", "SQLSRV_SQLTYPE_DATETIME", "SQLSRV_SQLTYPE_SMALLDATETIME", "SQLSRV_SQLTYPE_DATE", "SQLSRV_SQLTYPE_TIME", "SQLSRV_SQLTYPE_DATETIMEOFFSET", "SQLSRV_SQLTYPE_DATETIME2" ),
@ -20,79 +20,69 @@ $compatList = array( "date" => array( "SQLSRV_SQLTYPE_CHAR", "SQLSRV_SQLTYPE_VAR
"time" => array( "SQLSRV_SQLTYPE_CHAR", "SQLSRV_SQLTYPE_VARCHAR", "SQLSRV_SQLTYPE_NCHAR", "SQLSRV_SQLTYPE_NVARCHAR", "SQLSRV_SQLTYPE_DATETIME", "SQLSRV_SQLTYPE_SMALLDATETIME", "SQLSRV_SQLTYPE_TIME", "SQLSRV_SQLTYPE_DATETIMEOFFSET", "SQLSRV_SQLTYPE_DATETIME2" ),
"datetimeoffset" => array("SQLSRV_SQLTYPE_CHAR", "SQLSRV_SQLTYPE_VARCHAR", "SQLSRV_SQLTYPE_NCHAR", "SQLSRV_SQLTYPE_NVARCHAR", "SQLSRV_SQLTYPE_DATETIME", "SQLSRV_SQLTYPE_SMALLDATETIME", "SQLSRV_SQLTYPE_DATE", "SQLSRV_SQLTYPE_TIME", "SQLSRV_SQLTYPE_DATETIMEOFFSET", "SQLSRV_SQLTYPE_DATETIME2") );
$conn = ae_connect();
$conn = AE\connect();
foreach ( $dataTypes as $dataType ) {
foreach ($dataTypes as $dataType) {
echo "\nTesting $dataType: \n";
$success = true;
// create table
$tbname = GetTempTableName( "", false );
$colMetaArr = array( new columnMeta( $dataType, "c_det" ), new columnMeta( $dataType, "c_rand", null, "randomized" ));
create_table( $conn, $tbname, $colMetaArr );
$tbname = GetTempTableName("", false);
$colMetaArr = array( new AE\ColumnMeta($dataType, "c_det"), new AE\ColumnMeta($dataType, "c_rand", null, "randomized"));
AE\createTable($conn, $tbname, $colMetaArr);
// test each SQLSRV_SQLTYPE_ constants
foreach ( $sqlTypes as $sqlType )
{
foreach ($sqlTypes as $sqlType) {
// insert a row
$inputValues = array_slice( ${explode( "(", $dataType )[0] . "_params"}, 1, 2 );
$sqlType = get_default_size_prec( $sqlType );
$paramOp = array( new bindParamOption( 1, null, null, $sqlType ), new bindParamOption( 2, null, null, $sqlType ));
$inputValues = array_slice(${explode("(", $dataType)[0] . "_params"}, 1, 2);
$sqlType = get_default_size_prec($sqlType);
$paramOp = array( new AE\BindParamOption(1, null, null, $sqlType), new AE\BindParamOption(2, null, null, $sqlType));
$r;
$stmt = insert_row( $conn, $tbname, array( $colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r, "prepareParamsOp", $paramOp );
if ( !is_col_enc() )
{
if ( $r === false )
{
$stmt = AE\insertRow($conn, $tbname, array( $colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r, "prepareParamsOp", $paramOp);
if (!AE\isColEncrypted()) {
if ($r === false) {
$isCompatible = false;
foreach ( $compatList[$dataType] as $compatType )
{
if ( $compatType == $sqlType )
foreach ($compatList[$dataType] as $compatType) {
if ($compatType == $sqlType) {
$isCompatible = true;
}
}
// 22018 is the SQLSTATE for any incompatible conversion errors
if ( $isCompatible && sqlsrv_errors()[0]['SQLSTATE'] == 22018 )
{
echo "$sqlType should be compatible with $dataType\n";
$success = false;
}
}
}
else
{
if ( $r === false )
{
// always encrypted only allow sqlType that is identical to the encrypted column datatype
if ( "SQLSRV_SQLTYPE_" . strtoupper( $dataType ) == $sqlType )
{
if ($isCompatible && sqlsrv_errors()[0]['SQLSTATE'] == 22018) {
echo "$sqlType should be compatible with $dataType\n";
$success = false;
}
}
else
{
$sql = "SELECT * FROM $tbname";
$stmt = sqlsrv_query( $conn, $sql );
$row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC );
if ( $row["c_det"] != new DateTime( $inputValues[0] ) || $row["c_rand"] != new DateTime( $inputValues[1] ))
{
echo "Incorrect output retrieved for datatype $dataType and sqlType $sqlType.\n";
var_dump( $inputValues );
var_dump( $row );
} else {
if ($r === false) {
// always encrypted only allow sqlType that is identical to the encrypted column datatype
if ("SQLSRV_SQLTYPE_" . strtoupper($dataType) == $sqlType) {
echo "$sqlType should be compatible with $dataType\n";
$success = false;
}
}
} else {
$sql = "SELECT * FROM $tbname";
$stmt = sqlsrv_query($conn, $sql);
$row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC);
if ($row["c_det"] != new DateTime($inputValues[0]) || $row["c_rand"] != new DateTime($inputValues[1])) {
echo "Incorrect output retrieved for datatype $dataType and sqlType $sqlType.\n";
var_dump($inputValues);
var_dump($row);
$success = false;
}
}
}
sqlsrv_query( $conn, "TRUNCATE TABLE $tbname" );
sqlsrv_query($conn, "TRUNCATE TABLE $tbname");
}
if ( $success )
if ($success) {
echo "Test successfully done.\n";
DropTable( $conn, $tbname );
}
dropTable($conn, $tbname);
}
sqlsrv_free_stmt( $stmt );
sqlsrv_close( $conn );
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
?>
--EXPECT--

View file

@ -6,8 +6,8 @@ Bind params using sqlsrv_prepare with all sql_type
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
include 'AEData.inc';
require_once('MsCommon.inc');
require_once('AEData.inc');
$dataTypes = array( "smallmoney", "money" );
@ -15,61 +15,55 @@ $dataTypes = array( "smallmoney", "money" );
$compatList = array( "smallmoney" => array( "SQLSRV_SQLTYPE_BINARY", "SQLSRV_SQLTYPE_VARBINARY", "SQLSRV_SQLTYPE_CHAR", "SQLSRV_SQLTYPE_VARCHAR", "SQLSRV_SQLTYPE_NCHAR", "SQLSRV_SQLTYPE_NVARCHAR", "SQLSRV_SQLTYPE_DATETIME", "SQLSRV_SQLTYPE_SMALLDATETIME", "SQLSRV_SQLTYPE_DECIMAL(18,5)", "SQLSRV_SQLTYPE_NUMERIC(10,5)", "SQLSRV_SQLTYPE_FLOAT", "SQLSRV_SQLTYPE_REAL", "SQLSRV_SQLTYPE_BIGINT", "SQLSRV_SQLTYPE_INT", "SQLSRV_SQLTYPE_SMALLINT", "SQLSRV_SQLTYPE_TINYINT", "SQLSRV_SQLTYPE_MONEY", "SQLSRV_SQLTYPE_SMALLMONEY", "SQLSRV_SQLTYPE_BIT", "SQLSRV_SQLTYPE_TIMESTAMP" ),
"money" => array( "SQLSRV_SQLTYPE_BINARY", "SQLSRV_SQLTYPE_VARBINARY", "SQLSRV_SQLTYPE_CHAR", "SQLSRV_SQLTYPE_VARCHAR", "SQLSRV_SQLTYPE_NCHAR", "SQLSRV_SQLTYPE_NVARCHAR", "SQLSRV_SQLTYPE_DATETIME", "SQLSRV_SQLTYPE_SMALLDATETIME", "SQLSRV_SQLTYPE_DECIMAL(18,5)", "SQLSRV_SQLTYPE_NUMERIC(10,5)", "SQLSRV_SQLTYPE_FLOAT", "SQLSRV_SQLTYPE_REAL", "SQLSRV_SQLTYPE_BIGINT", "SQLSRV_SQLTYPE_INT", "SQLSRV_SQLTYPE_SMALLINT", "SQLSRV_SQLTYPE_TINYINT", "SQLSRV_SQLTYPE_MONEY", "SQLSRV_SQLTYPE_SMALLMONEY", "SQLSRV_SQLTYPE_BIT", "SQLSRV_SQLTYPE_TIMESTAMP" ));
$conn = ae_connect();
$conn = AE\connect();
foreach ( $dataTypes as $dataType ) {
foreach ($dataTypes as $dataType) {
echo "\nTesting $dataType: \n";
$success = true;
// create table
$tbname = GetTempTableName( "", false );
$colMetaArr = array( new columnMeta( $dataType, "c_det" ), new columnMeta( $dataType, "c_rand", null, "randomized" ));
create_table( $conn, $tbname, $colMetaArr );
$tbname = GetTempTableName("", false);
$colMetaArr = array( new AE\ColumnMeta($dataType, "c_det"), new AE\ColumnMeta($dataType, "c_rand", null, "randomized"));
AE\createTable($conn, $tbname, $colMetaArr);
// test each SQLSRV_SQLTYPE_ constants
foreach ( $sqlTypes as $sqlType )
{
foreach ($sqlTypes as $sqlType) {
// insert a row
$inputValues = array_slice( ${explode( "(", $dataType )[0] . "_params"}, 1, 2 );
$sqlType = get_default_size_prec( $sqlType );
$paramOp = array( new bindParamOption( 1, null, null, $sqlType ), new bindParamOption( 2, null, null, $sqlType ));
$inputValues = array_slice(${explode("(", $dataType)[0] . "_params"}, 1, 2);
$sqlType = get_default_size_prec($sqlType);
$paramOp = array( new AE\BindParamOption(1, null, null, $sqlType), new AE\BindParamOption(2, null, null, $sqlType));
$r;
$stmt = insert_row( $conn, $tbname, array( $colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r, "prepareParamsOp", $paramOp );
if ( !is_col_enc() )
{
if ( $r === false )
{
$stmt = AE\insertRow($conn, $tbname, array( $colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r, "prepareParamsOp", $paramOp);
if (!AE\isColEncrypted()) {
if ($r === false) {
$isCompatible = false;
foreach ( $compatList[$dataType] as $compatType )
{
if ( stripos( $compatType, $sqlType ) !== false )
foreach ($compatList[$dataType] as $compatType) {
if (stripos($compatType, $sqlType) !== false) {
$isCompatible = true;
}
}
// 22018 is the SQLSTATE for any incompatible conversion errors
if ( $isCompatible && sqlsrv_errors()[0]['SQLSTATE'] == 22018 )
{
if ($isCompatible && sqlsrv_errors()[0]['SQLSTATE'] == 22018) {
echo "$sqlType should be compatible with $dataType\n";
$success = false;
}
}
}
else
{
if ( $r !== false )
{
}
} else {
if ($r !== false) {
echo "$dataType should not be compatible with any type.\n";
$success = false;
}
}
}
sqlsrv_query( $conn, "TRUNCATE TABLE $tbname" );
sqlsrv_query($conn, "TRUNCATE TABLE $tbname");
}
if ( $success )
if ($success) {
echo "Test successfully done.\n";
DropTable( $conn, $tbname );
}
dropTable($conn, $tbname);
}
sqlsrv_free_stmt( $stmt );
sqlsrv_close( $conn );
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
?>
--EXPECT--

View file

@ -6,8 +6,8 @@ Bind params using sqlsrv_prepare with all sql_type
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
include 'AEData.inc';
require_once('MsCommon.inc');
require_once('AEData.inc');
$dataTypes = array( "bit", "tinyint", "smallint", "int", "bigint", "decimal(18,5)", "numeric(10,5)", "float", "real" );
@ -23,88 +23,74 @@ $compatList = array( "bit" => array( "SQLSRV_SQLTYPE_BINARY", "SQLSRV_SQLTYPE_VA
"real" => array( "SQLSRV_SQLTYPE_BINARY", "SQLSRV_SQLTYPE_VARBINARY", "SQLSRV_SQLTYPE_CHAR", "SQLSRV_SQLTYPE_VARCHAR", "SQLSRV_SQLTYPE_NCHAR", "SQLSRV_SQLTYPE_NVARCHAR", "SQLSRV_SQLTYPE_DATETIME", "SQLSRV_SQLTYPE_SMALLDATETIME", "SQLSRV_SQLTYPE_DECIMAL(18,5)", "SQLSRV_SQLTYPE_NUMERIC(10,5)", "SQLSRV_SQLTYPE_FLOAT", "SQLSRV_SQLTYPE_REAL", "SQLSRV_SQLTYPE_BIGINT", "SQLSRV_SQLTYPE_INT", "SQLSRV_SQLTYPE_SMALLINT", "SQLSRV_SQLTYPE_TINYINT", "SQLSRV_SQLTYPE_MONEY", "SQLSRV_SQLTYPE_SMALLMONEY", "SQLSRV_SQLTYPE_BIT" ));
$epsilon = 0.0001;
$conn = ae_connect();
$conn = AE\connect();
foreach ( $dataTypes as $dataType ) {
foreach ($dataTypes as $dataType) {
echo "\nTesting $dataType: \n";
$success = true;
// create table
$tbname = GetTempTableName( "", false );
$colMetaArr = array( new columnMeta( $dataType, "c_det" ), new columnMeta( $dataType, "c_rand", null, "randomized" ));
create_table( $conn, $tbname, $colMetaArr );
$tbname = GetTempTableName("", false);
$colMetaArr = array( new AE\ColumnMeta($dataType, "c_det"), new AE\ColumnMeta($dataType, "c_rand", null, "randomized"));
AE\createTable($conn, $tbname, $colMetaArr);
// test each SQLSRV_SQLTYPE_ constants
foreach ( $sqlTypes as $sqlType )
{
foreach ($sqlTypes as $sqlType) {
// insert a row
$inputValues = array_slice( ${explode( "(", $dataType )[0] . "_params"}, 1, 2 );
$sqlType = get_default_size_prec( $sqlType );
$paramOp = array( new bindParamOption( 1, null, null, $sqlType ), new bindParamOption( 2, null, null, $sqlType ));
$inputValues = array_slice(${explode("(", $dataType)[0] . "_params"}, 1, 2);
$sqlType = get_default_size_prec($sqlType);
$paramOp = array( new AE\BindParamOption(1, null, null, $sqlType), new AE\BindParamOption(2, null, null, $sqlType));
$r;
$stmt = insert_row( $conn, $tbname, array( $colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r, "prepareParamsOp", $paramOp );
if ( !is_col_enc() )
{
if ( $r === false )
{
$stmt = AE\insertRow($conn, $tbname, array( $colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r, "prepareParamsOp", $paramOp);
if (!AE\isColEncrypted()) {
if ($r === false) {
$isCompatibleible = false;
foreach ( $compatList[$dataType] as $compatType )
{
if ( stripos( $compatType, $sqlType ) !== false )
foreach ($compatList[$dataType] as $compatType) {
if (stripos($compatType, $sqlType) !== false) {
$isCompatibleible = true;
}
}
// 22018 is the SQLSTATE for any incompatible conversion errors
if ( $isCompatibleible && sqlsrv_errors()[0]['SQLSTATE'] == 22018 )
{
echo "$sqlType should be compatible with $dataType\n";
$success = false;
}
}
}
else
{
if ( $r === false )
{
// always encrypted only allow sqlType that is identical to the encrypted column datatype
if ( stripos( "SQLSRV_SQLTYPE_" . $dataType, $sqlType ) !== false )
{
if ($isCompatibleible && sqlsrv_errors()[0]['SQLSTATE'] == 22018) {
echo "$sqlType should be compatible with $dataType\n";
$success = false;
}
}
else
{
} else {
if ($r === false) {
// always encrypted only allow sqlType that is identical to the encrypted column datatype
if (stripos("SQLSRV_SQLTYPE_" . $dataType, $sqlType) !== false) {
echo "$sqlType should be compatible with $dataType\n";
$success = false;
}
} else {
$sql = "SELECT * FROM $tbname";
$stmt = sqlsrv_query( $conn, $sql );
$row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC );
if ( $dataType == "float" || $dataType == "real" )
{
if ( abs( $row["c_det"] - $inputValues[0] ) > $epsilon || abs( $row["c_rand"] - $inputValues[1] ) > $epsilon )
{
$stmt = sqlsrv_query($conn, $sql);
$row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC);
if ($dataType == "float" || $dataType == "real") {
if (abs($row["c_det"] - $inputValues[0]) > $epsilon || abs($row["c_rand"] - $inputValues[1]) > $epsilon) {
echo "Incorrect output retrieved for datatype $dataType and sqlType $sqlType.\n";
$success = false;
}
} else {
if ($row["c_det"] != $inputValues[0] || $row["c_rand"] != $inputValues[1]) {
echo "Incorrect output retrieved for datatype $dataType and sqlType $sqlType.\n";
$success = false;
}
}
else
{
if ( $row["c_det"] != $inputValues[0] || $row["c_rand"] != $inputValues[1] )
{
echo "Incorrect output retrieved for datatype $dataType and sqlType $sqlType.\n";
$success = false;
}
}
}
}
}
sqlsrv_query( $conn, "TRUNCATE TABLE $tbname" );
sqlsrv_query($conn, "TRUNCATE TABLE $tbname");
}
if ( $success )
if ($success) {
echo "Test successfully done.\n";
DropTable( $conn, $tbname );
}
dropTable($conn, $tbname);
}
sqlsrv_free_stmt( $stmt );
sqlsrv_close( $conn );
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
?>
--EXPECT--

View file

@ -6,8 +6,8 @@ Bind params using sqlsrv_prepare with all sql_type
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
include 'AEData.inc';
require_once('MsCommon.inc');
require_once('AEData.inc');
$dataTypes = array( "char(5)", "varchar(max)", "nchar(5)", "nvarchar(max)" );
@ -17,74 +17,65 @@ $compatList = array( "char(5)" => array( "SQLSRV_SQLTYPE_CHAR(5)", "SQLSRV_SQLTY
"nchar(5)" => array( "SQLSRV_SQLTYPE_CHAR(5)", "SQLSRV_SQLTYPE_VARCHAR", "SQLSRV_SQLTYPE_NCHAR(5)", "SQLSRV_SQLTYPE_NVARCHAR", "SQLSRV_SQLTYPE_DECIMAL", "SQLSRV_SQLTYPE_NUMERIC", "SQLSRV_SQLTYPE_NTEXT", "SQLSRV_SQLTYPE_TEXT", "SQLSRV_SQLTYPE_XML" ),
"nvarchar(max)" => array( "SQLSRV_SQLTYPE_CHAR(5)", "SQLSRV_SQLTYPE_VARCHAR", "SQLSRV_SQLTYPE_NCHAR(5)", "SQLSRV_SQLTYPE_NVARCHAR", "SQLSRV_SQLTYPE_DECIMAL", "SQLSRV_SQLTYPE_NUMERIC", "SQLSRV_SQLTYPE_NTEXT", "SQLSRV_SQLTYPE_TEXT", "SQLSRV_SQLTYPE_XML" ));
$conn = ae_connect();
$conn = AE\connect();
foreach ( $dataTypes as $dataType ) {
foreach ($dataTypes as $dataType) {
echo "\nTesting $dataType: \n";
$success = true;
// create table
$tbname = GetTempTableName( "", false );
$colMetaArr = array( new columnMeta( $dataType, "c_det" ), new columnMeta( $dataType, "c_rand", null, "randomized" ));
create_table( $conn, $tbname, $colMetaArr );
$tbname = GetTempTableName("", false);
$colMetaArr = array( new AE\ColumnMeta($dataType, "c_det"), new AE\ColumnMeta($dataType, "c_rand", null, "randomized"));
AE\createTable($conn, $tbname, $colMetaArr);
// test each SQLSRV_SQLTYPE_ constants
foreach ( $sqlTypes as $sqlType )
{
foreach ($sqlTypes as $sqlType) {
// insert a row
$inputValues = array_slice( ${explode( "(", $dataType )[0] . "_params"}, 1, 2 );
$sqlType = get_default_size_prec( $sqlType );
$paramOp = array( new bindParamOption( 1, null, null, $sqlType ), new bindParamOption( 2, null, null, $sqlType ));
$inputValues = array_slice(${explode("(", $dataType)[0] . "_params"}, 1, 2);
$sqlType = get_default_size_prec($sqlType);
$paramOp = array( new AE\BindParamOption(1, null, null, $sqlType), new AE\BindParamOption(2, null, null, $sqlType));
$r;
$stmt = insert_row( $conn, $tbname, array( $colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r, "prepareParamsOp", $paramOp );
if ( $r === false )
{
if ( !is_col_enc() )
{
$stmt = AE\insertRow($conn, $tbname, array( $colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r, "prepareParamsOp", $paramOp);
if ($r === false) {
if (!AE\isColEncrypted()) {
$isCompatible = false;
foreach ( $compatList[$dataType] as $compatType )
{
if ( stripos( $compatType, $sqlType ) !== false )
foreach ($compatList[$dataType] as $compatType) {
if (stripos($compatType, $sqlType) !== false) {
$isCompatible = true;
}
}
// 22018 is the SQLSTATE for any incompatible conversion errors
if ( $isCompatible && sqlsrv_errors()[0]['SQLSTATE'] == 22018 )
{
if ($isCompatible && sqlsrv_errors()[0]['SQLSTATE'] == 22018) {
echo "$sqlType should be compatible with $dataType\n";
$success = false;
}
}
else
{
} else {
// always encrypted only allow sqlType that is identical to the encrypted column datatype
if ( stripos( "SQLSRV_SQLTYPE_" . $dataType, $sqlType ) !== false )
{
if (stripos("SQLSRV_SQLTYPE_" . $dataType, $sqlType) !== false) {
echo "$sqlType should be compatible with $dataType\n";
$success = false;
}
}
}
else
{
} else {
$sql = "SELECT * FROM $tbname";
$stmt = sqlsrv_query( $conn, $sql );
$row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC );
if ( $row["c_det"] != $inputValues[0] || $row["c_rand"] != $inputValues[1] )
{
$stmt = sqlsrv_query($conn, $sql);
$row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC);
if ($row["c_det"] != $inputValues[0] || $row["c_rand"] != $inputValues[1]) {
echo "Incorrect output retrieved for datatype $dataType and sqlType $sqlType.\n";
$success = false;
}
}
sqlsrv_query( $conn, "TRUNCATE TABLE $tbname" );
sqlsrv_query($conn, "TRUNCATE TABLE $tbname");
}
if ( $success )
if ($success) {
echo "Test successfully done.\n";
DropTable( $conn, $tbname );
}
dropTable($conn, $tbname);
}
sqlsrv_free_stmt( $stmt );
sqlsrv_close( $conn );
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
?>
--EXPECT--

View file

@ -6,35 +6,34 @@ Bind params using sqlsrv_prepare without any sql_type specified
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
include 'AEData.inc';
require_once('MsCommon.inc');
require_once('AEData.inc');
$dataTypes = array( "char(5)", "varchar(max)", "nchar(5)", "nvarchar(max)" );
$conn = ae_connect();
$conn = AE\connect();
foreach ( $dataTypes as $dataType ) {
foreach ($dataTypes as $dataType) {
echo "\nTesting $dataType: \n";
// create table
$tbname = GetTempTableName( "", false );
$colMetaArr = array( new columnMeta( $dataType, "c_det" ), new columnMeta( $dataType, "c_rand", null, "randomized" ));
create_table( $conn, $tbname, $colMetaArr );
$tbname = GetTempTableName("", false);
$colMetaArr = array( new AE\ColumnMeta($dataType, "c_det"), new AE\ColumnMeta($dataType, "c_rand", null, "randomized"));
AE\createTable($conn, $tbname, $colMetaArr);
// insert a row
$inputValues = array_slice( ${explode( "(", $dataType )[0] . "_params"}, 1, 2 );
$inputValues = array_slice(${explode("(", $dataType)[0] . "_params"}, 1, 2);
$r;
$stmt = insert_row( $conn, $tbname, array( $colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r );
if ( $r === false ) {
is_incompatible_types_error( $dataType, "default type" );
}
else {
$stmt = AE\insertRow($conn, $tbname, array( $colMetaArr[0]->colName => $inputValues[0], $colMetaArr[1]->colName => $inputValues[1] ), $r);
if ($r === false) {
is_incompatible_types_error($dataType, "default type");
} else {
echo "****Encrypted default type is compatible with encrypted $dataType****\n";
fetch_all( $conn, $tbname );
AE\fetchAll($conn, $tbname);
}
DropTable( $conn, $tbname );
dropTable($conn, $tbname);
}
sqlsrv_free_stmt( $stmt );
sqlsrv_close( $conn );
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
?>
--EXPECT--

View file

@ -4,17 +4,17 @@ Test for binding output parameter of encrypted values for a sample emplolyee tab
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
$conn = ae_connect();
$conn = AE\connect();
$tbname = 'employee';
$colMetaArr = array( new columnMeta( "int", "PersonID", "NOT NULL Identity (1,1)" ),
new columnMeta( "varchar(255)", "FirstName", "NOT NULL" ),
new columnMeta( "varchar(255)", "LastName" ),
new columnMeta( "varchar(255)", "Address" ),
new columnMeta( "varchar(255)", "City" ));
create_table( $conn, $tbname, $colMetaArr );
$colMetaArr = array( new AE\ColumnMeta("int", "PersonID", "NOT NULL Identity (1,1)"),
new AE\ColumnMeta("varchar(255)", "FirstName", "NOT NULL"),
new AE\ColumnMeta("varchar(255)", "LastName"),
new AE\ColumnMeta("varchar(255)", "Address"),
new AE\ColumnMeta("varchar(255)", "City"));
AE\createTable($conn, $tbname, $colMetaArr);
// Create a Store Procedure
$spname = 'InOutRet_Params';
@ -25,7 +25,7 @@ $createSpSql = "CREATE PROCEDURE $spname (
SELECT @MatchingRecs=count(*) FROM $tbname WHERE
PersonID=@pPersonID;
RETURN 100";
sqlsrv_query( $conn, $createSpSql );
sqlsrv_query($conn, $createSpSql);
// Create a select Store Procedure
$sspname = 'getInfo';
@ -34,20 +34,19 @@ $selectSpSql = "CREATE PROCEDURE $sspname (
@Address varchar(255) OUTPUT, @City varchar(255) OUTPUT, @PersonID int) AS
SELECT @FirstName = FirstName, @LastName = LastName, @Address = Address, @City = City
FROM $tbname WHERE PersonID=@PersonID";
sqlsrv_query( $conn, $selectSpSql );
sqlsrv_query($conn, $selectSpSql);
// Insert data
$firstNameParams = array( 'Luke', 'Tahir', 'Gwen', 'Mike', 'Sarah' );
$lastNameParams = array( 'Duke', 'Chaudry', 'Wheeler', 'Leibskind', 'Ackerman' );
$addressParams = array( '2130 Boars Nest', '83 First Street', '842 Vine Ave.', '33 Elm St.', '440 U.S. 11' );
$cityParams = array( 'Hazard Co', 'Brooklyn', 'New York', 'Binghamton', 'Roselle' );
for ( $i = 0; $i < 5; $i++ )
{
for ($i = 0; $i < 5; $i++) {
$inputs = array( "FirstName" => $firstNameParams[$i],
"LastName" => $lastNameParams[$i],
"Address" => $addressParams[$i],
"City" => $cityParams[$i] );
$stmt = insert_row( $conn, $tbname, $inputs );
$stmt = AE\insertRow($conn, $tbname, $inputs);
}
// call Store Procedure
@ -55,42 +54,40 @@ $callSpSql = "{? = CALL $spname (?, ?)}";
$retParam = 0;
$pPersonID = 1;
$cbOutParam = 0;
$stmt = sqlsrv_prepare( $conn, $callSpSql, array( array( &$retParam, SQLSRV_PARAM_OUT ), array( $pPersonID, SQLSRV_PARAM_IN ), array( &$cbOutParam, SQLSRV_PARAM_OUT )));
sqlsrv_execute( $stmt );
sqlsrv_next_result( $stmt );
if ( sqlsrv_errors() )
{
var_dump( sqlsrv_errors() );
$stmt = sqlsrv_prepare($conn, $callSpSql, array( array( &$retParam, SQLSRV_PARAM_OUT ), array( $pPersonID, SQLSRV_PARAM_IN ), array( &$cbOutParam, SQLSRV_PARAM_OUT )));
sqlsrv_execute($stmt);
sqlsrv_next_result($stmt);
if (sqlsrv_errors()) {
var_dump(sqlsrv_errors());
}
print ( "retParam: " . $retParam . "\n" );
print ( "pPersonID: " . $pPersonID . "\n" );
print ( "cbOutParam: " . $cbOutParam . "\n" );
print("retParam: " . $retParam . "\n");
print("pPersonID: " . $pPersonID . "\n");
print("cbOutParam: " . $cbOutParam . "\n");
// Retrieve all data through output params
$outSql = get_callProcSql_placeholders( $sspname, 5 );
$outSql = AE\getCallProcSqlPlaceholders($sspname, 5);
$firstNameOut = '';
$lastNameOut = '';
$addressOut = '';
$cityOut = '';
$pPersonID = 2;
$stmt = sqlsrv_prepare( $conn, $outSql, array( array( &$firstNameOut, SQLSRV_PARAM_OUT ), array( &$lastNameOut, SQLSRV_PARAM_OUT ), array( &$addressOut, SQLSRV_PARAM_OUT ), array( &$cityOut, SQLSRV_PARAM_OUT ), array( $pPersonID, SQLSRV_PARAM_IN )));
sqlsrv_execute( $stmt );
if ( sqlsrv_errors() )
{
var_dump( sqlsrv_errors() );
$stmt = sqlsrv_prepare($conn, $outSql, array( array( &$firstNameOut, SQLSRV_PARAM_OUT ), array( &$lastNameOut, SQLSRV_PARAM_OUT ), array( &$addressOut, SQLSRV_PARAM_OUT ), array( &$cityOut, SQLSRV_PARAM_OUT ), array( $pPersonID, SQLSRV_PARAM_IN )));
sqlsrv_execute($stmt);
if (sqlsrv_errors()) {
var_dump(sqlsrv_errors());
}
print ( "firstNameOut: " . $firstNameOut . "\n" );
print ( "lastNameOut: " . $lastNameOut . "\n" );
print ( "addressOut: " . $addressOut . "\n" );
print ( "cityOut: " . $cityOut . "\n" );
print ( "pPersonID: " . $pPersonID . "\n" );
print("firstNameOut: " . $firstNameOut . "\n");
print("lastNameOut: " . $lastNameOut . "\n");
print("addressOut: " . $addressOut . "\n");
print("cityOut: " . $cityOut . "\n");
print("pPersonID: " . $pPersonID . "\n");
sqlsrv_query( $conn, "DROP PROCEDURE $spname" );
sqlsrv_query( $conn, "DROP PROCEDURE $sspname" );
sqlsrv_query( $conn, "DROP TABLE $tbname" );
sqlsrv_free_stmt( $stmt );
sqlsrv_close( $conn );
sqlsrv_query($conn, "DROP PROCEDURE $spname");
sqlsrv_query($conn, "DROP PROCEDURE $sspname");
sqlsrv_query($conn, "DROP TABLE $tbname");
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
?>
--EXPECT--
@ -101,4 +98,4 @@ firstNameOut: Tahir
lastNameOut: Chaudry
addressOut: 83 First Street
cityOut: Brooklyn
pPersonID: 2
pPersonID: 2

View file

@ -4,80 +4,79 @@ Test for binding output parameter of encrypted values for all types
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
$conn = ae_connect();
$conn = AE\connect();
// Create the table
$tbname = GetTempTableName( "", false );
$colMetaArr = array( new columnMeta( "int", "c1_int" ),
new columnMeta( "smallint", "c2_smallint" ),
new columnMeta( "tinyint", "c3_tinyint" ),
new columnMeta( "bit", "c4_bit" ),
new columnMeta( "bigint", "c5_bigint" ),
new columnMeta( "decimal(18,5)", "c6_decimal" ),
new columnMeta( "numeric(10,5)", "c7_numeric" ),
new columnMeta( "float", "c8_float" ),
new columnMeta( "real", "c9_real" ),
new columnMeta( "date", "c10_date" ),
new columnMeta( "datetime", "c11_datetime" ),
new columnMeta( "datetime2", "c12_datetime2" ),
new columnMeta( "datetimeoffset", "c13_datetimeoffset" ),
new columnMeta( "time", "c14_time" ),
new columnMeta( "char(5)", "c15_char" ),
new columnMeta( "varchar(max)", "c16_varchar" ),
new columnMeta( "nchar(5)", "c17_nchar" ),
new columnMeta( "nvarchar(max)", "c18_nvarchar" ));
create_table( $conn, $tbname, $colMetaArr );
$tbname = GetTempTableName("", false);
$colMetaArr = array( new AE\ColumnMeta("int", "c1_int"),
new AE\ColumnMeta("smallint", "c2_smallint"),
new AE\ColumnMeta("tinyint", "c3_tinyint"),
new AE\ColumnMeta("bit", "c4_bit"),
new AE\ColumnMeta("bigint", "c5_bigint"),
new AE\ColumnMeta("decimal(18,5)", "c6_decimal"),
new AE\ColumnMeta("numeric(10,5)", "c7_numeric"),
new AE\ColumnMeta("float", "c8_float"),
new AE\ColumnMeta("real", "c9_real"),
new AE\ColumnMeta("date", "c10_date"),
new AE\ColumnMeta("datetime", "c11_datetime"),
new AE\ColumnMeta("datetime2", "c12_datetime2"),
new AE\ColumnMeta("datetimeoffset", "c13_datetimeoffset"),
new AE\ColumnMeta("time", "c14_time"),
new AE\ColumnMeta("char(5)", "c15_char"),
new AE\ColumnMeta("varchar(max)", "c16_varchar"),
new AE\ColumnMeta("nchar(5)", "c17_nchar"),
new AE\ColumnMeta("nvarchar(max)", "c18_nvarchar"));
AE\createTable($conn, $tbname, $colMetaArr);
// Create a Store Procedure
$spname = 'selectAllColumns';
$spSql = "CREATE PROCEDURE $spname (
@c1_int int OUTPUT, @c2_smallint smallint OUTPUT,
@c3_tinyint tinyint OUTPUT, @c4_bit bit OUTPUT,
@c1_int int OUTPUT, @c2_smallint smallint OUTPUT,
@c3_tinyint tinyint OUTPUT, @c4_bit bit OUTPUT,
@c5_bigint bigint OUTPUT, @c6_decimal decimal(18,5) OUTPUT,
@c7_numeric numeric(10,5) OUTPUT, @c8_float float OUTPUT,
@c7_numeric numeric(10,5) OUTPUT, @c8_float float OUTPUT,
@c9_real real OUTPUT, @c10_date date OUTPUT,
@c11_datetime datetime OUTPUT, @c12_datetime2 datetime2 OUTPUT,
@c13_datetimeoffset datetimeoffset OUTPUT, @c14_time time OUTPUT,
@c15_char char(5) OUTPUT, @c16_varchar varchar(max) OUTPUT,
@c17_nchar nchar(5) OUTPUT, @c18_nvarchar nvarchar(max) OUTPUT) AS
SELECT @c1_int = c1_int, @c2_smallint = c2_smallint,
@c3_tinyint = c3_tinyint, @c4_bit = c4_bit,
@c5_bigint = c5_bigint, @c6_decimal = c6_decimal,
@c7_numeric = c7_numeric, @c8_float = c8_float,
@c9_real = c9_real, @c10_date = c10_date,
SELECT @c1_int = c1_int, @c2_smallint = c2_smallint,
@c3_tinyint = c3_tinyint, @c4_bit = c4_bit,
@c5_bigint = c5_bigint, @c6_decimal = c6_decimal,
@c7_numeric = c7_numeric, @c8_float = c8_float,
@c9_real = c9_real, @c10_date = c10_date,
@c11_datetime = c11_datetime, @c12_datetime2 = c12_datetime2,
@c13_datetimeoffset = c13_datetimeoffset, @c14_time = c14_time,
@c15_char = c15_char, @c16_varchar = c16_varchar,
@c17_nchar = c17_nchar, @c18_nvarchar = c18_nvarchar
FROM $tbname";
sqlsrv_query( $conn, $spSql );
sqlsrv_query($conn, $spSql);
// Insert data
$inputs = array( "c1_int" => 2147483647,
"c2_smallint" => 32767,
"c3_tinyint" => 255,
"c4_bit" => 1,
"c5_bigint" => 922337203685479936,
"c6_decimal" => 9223372036854.80000,
"c7_numeric" => 21474.83647,
$inputs = array( "c1_int" => 2147483647,
"c2_smallint" => 32767,
"c3_tinyint" => 255,
"c4_bit" => 1,
"c5_bigint" => 922337203685479936,
"c6_decimal" => 9223372036854.80000,
"c7_numeric" => 21474.83647,
"c8_float" => 9223372036.8548,
"c9_real" => 2147.483,
"c10_date" => '9999-12-31',
"c11_datetime" => '9999-12-31 23:59:59.997',
"c12_datetime2" => '9999-12-31 23:59:59.9999999',
"c13_datetimeoffset" => '9999-12-31 23:59:59.9999999 +14:00',
"c14_time" => '23:59:59.9999999',
"c15_char" => 'th, n',
"c16_varchar" => 'This large row size can cause errors (such as error 512) during some normal operations, such as a clustered index key update, or sorts of the full column set, which users cannot anticipate until performing an operation.',
"c17_nchar" => 'th Un',
"c9_real" => 2147.483,
"c10_date" => '9999-12-31',
"c11_datetime" => '9999-12-31 23:59:59.997',
"c12_datetime2" => '9999-12-31 23:59:59.9999999',
"c13_datetimeoffset" => '9999-12-31 23:59:59.9999999 +14:00',
"c14_time" => '23:59:59.9999999',
"c15_char" => 'th, n',
"c16_varchar" => 'This large row size can cause errors (such as error 512) during some normal operations, such as a clustered index key update, or sorts of the full column set, which users cannot anticipate until performing an operation.',
"c17_nchar" => 'th Un',
"c18_nvarchar" => 'When prefixing a string constant with the letter N, the implicit conversion will result in a Unicode string if the constant to convert does not exceed the max length for a Unicode string data type (4,000).' );
$stmt = insert_row( $conn, $tbname, $inputs );
$stmt = AE\insertRow($conn, $tbname, $inputs);
// Call store procedure
$outSql = get_callProcSql_placeholders( $spname, count( $inputs ));
$outSql = AE\getCallProcSqlPlaceholders($spname, count($inputs));
$intOut = 0;
$smallintOut = 0;
@ -97,49 +96,49 @@ $charOut = '';
$varcharOut = '';
$ncharOut = '';
$nvarcharOut = '';
$stmt = sqlsrv_prepare( $conn, $outSql, array( array( &$intOut, SQLSRV_PARAM_OUT ),
array( &$smallintOut, SQLSRV_PARAM_OUT ),
array( &$tinyintOut, SQLSRV_PARAM_OUT ),
array( &$bitOut, SQLSRV_PARAM_OUT ),
array( &$bigintOut, SQLSRV_PARAM_OUT ),
array( &$decimalOut, SQLSRV_PARAM_OUT ),
array( &$numericOut, SQLSRV_PARAM_OUT ),
array( &$floatOut, SQLSRV_PARAM_OUT ),
array( &$realOut, SQLSRV_PARAM_OUT ),
array( &$dateOut, SQLSRV_PARAM_OUT ),
array( &$datetimeOut, SQLSRV_PARAM_OUT ),
array( &$datetime2Out, SQLSRV_PARAM_OUT ),
array( &$datetimeoffsetOut, SQLSRV_PARAM_OUT ),
array( &$timeOut, SQLSRV_PARAM_OUT ),
array( &$charOut, SQLSRV_PARAM_OUT ),
array( &$varcharOut, SQLSRV_PARAM_OUT ),
array( &$ncharOut, SQLSRV_PARAM_OUT ),
$stmt = sqlsrv_prepare($conn, $outSql, array( array( &$intOut, SQLSRV_PARAM_OUT ),
array( &$smallintOut, SQLSRV_PARAM_OUT ),
array( &$tinyintOut, SQLSRV_PARAM_OUT ),
array( &$bitOut, SQLSRV_PARAM_OUT ),
array( &$bigintOut, SQLSRV_PARAM_OUT ),
array( &$decimalOut, SQLSRV_PARAM_OUT ),
array( &$numericOut, SQLSRV_PARAM_OUT ),
array( &$floatOut, SQLSRV_PARAM_OUT ),
array( &$realOut, SQLSRV_PARAM_OUT ),
array( &$dateOut, SQLSRV_PARAM_OUT ),
array( &$datetimeOut, SQLSRV_PARAM_OUT ),
array( &$datetime2Out, SQLSRV_PARAM_OUT ),
array( &$datetimeoffsetOut, SQLSRV_PARAM_OUT ),
array( &$timeOut, SQLSRV_PARAM_OUT ),
array( &$charOut, SQLSRV_PARAM_OUT ),
array( &$varcharOut, SQLSRV_PARAM_OUT ),
array( &$ncharOut, SQLSRV_PARAM_OUT ),
array( &$nvarcharOut, SQLSRV_PARAM_OUT )));
sqlsrv_execute( $stmt );
sqlsrv_execute($stmt);
print ( "intOut: " . $intOut . "\n" );
print ( "smallintOut: " . $smallintOut . "\n" );
print ( "tinyintOut: " . $tinyintOut . "\n" );
print ( "bitOut: " . $bitOut . "\n" );
print ( "bigintOut: " . $bigintOut . "\n" );
print ( "decimalOut: " . $decimalOut . "\n" );
print ( "numericOut: " . $numericOut . "\n" );
print ( "floatOut: " . $floatOut . "\n" );
print ( "realOut: " . $realOut . "\n" );
print ( "dateOut: " . $dateOut . "\n" );
print ( "datetimeOut: " . $datetimeOut . "\n" );
print ( "datetime2Out: " . $datetime2Out . "\n" );
print ( "datetimeoffsetOut: " . $datetimeoffsetOut . "\n" );
print ( "timeOut: " . $timeOut . "\n" );
print ( "charOut: " . $charOut . "\n" );
print ( "varcharOut: " . $varcharOut . "\n" );
print ( "ncharOut: " . $ncharOut . "\n" );
print ( "nvarcharOut: " . $nvarcharOut . "\n" );
print("intOut: " . $intOut . "\n");
print("smallintOut: " . $smallintOut . "\n");
print("tinyintOut: " . $tinyintOut . "\n");
print("bitOut: " . $bitOut . "\n");
print("bigintOut: " . $bigintOut . "\n");
print("decimalOut: " . $decimalOut . "\n");
print("numericOut: " . $numericOut . "\n");
print("floatOut: " . $floatOut . "\n");
print("realOut: " . $realOut . "\n");
print("dateOut: " . $dateOut . "\n");
print("datetimeOut: " . $datetimeOut . "\n");
print("datetime2Out: " . $datetime2Out . "\n");
print("datetimeoffsetOut: " . $datetimeoffsetOut . "\n");
print("timeOut: " . $timeOut . "\n");
print("charOut: " . $charOut . "\n");
print("varcharOut: " . $varcharOut . "\n");
print("ncharOut: " . $ncharOut . "\n");
print("nvarcharOut: " . $nvarcharOut . "\n");
sqlsrv_query( $conn, "DROP PROCEDURE $spname" );
sqlsrv_query( $conn, "DROP TABLE $tbname" );
sqlsrv_free_stmt( $stmt );
sqlsrv_close( $conn );
sqlsrv_query($conn, "DROP PROCEDURE $spname");
sqlsrv_query($conn, "DROP TABLE $tbname");
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
?>
--EXPECTREGEX--
@ -160,4 +159,4 @@ timeOut: 23:59:59\.9999999
charOut: th\, n
varcharOut: This large row size can cause errors \(such as error 512\) during some normal operations\, such as a clustered index key update\, or sorts of the full column set\, which users cannot anticipate until performing an operation\.
ncharOut: th Un
nvarcharOut: When prefixing a string constant with the letter N\, the implicit conversion will result in a Unicode string if the constant to convert does not exceed the max length for a Unicode string data type \(4,000\)\.
nvarcharOut: When prefixing a string constant with the letter N\, the implicit conversion will result in a Unicode string if the constant to convert does not exceed the max length for a Unicode string data type \(4,000\)\.

View file

@ -30,7 +30,7 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
/**
* main function called by repro to set up the test, iterate through the given datatypes and test the output param.
@ -42,39 +42,37 @@ function main($minType, $maxType)
$testName = "BindParam - OutputParam";
$tableName = "test_Datatypes_Output";
$columnNames = array( "c1","c2" );
StartTest($testName);
startTest($testName);
Setup();
$conn = Connect();
for ($k = $minType; $k <= $maxType; $k++)
{
if ($k == 18 || $k == 19)
{
// skip text and ntext types; not supported as output params
setup();
$conn = connect();
for ($k = $minType; $k <= $maxType; $k++) {
if ($k == 18 || $k == 19) {
// skip text and ntext types; not supported as output params
continue;
}
$sqlType = GetSqlType($k);
// for each data type create a table with two columns, 1: dataType id 2: data type
$dataType = "[$columnNames[0]] int, [$columnNames[1]] $sqlType";
CreateTableEx($conn, $tableName, $dataType);
createTableEx($conn, $tableName, $dataType);
// data to populate the table, false since we don't want to initialize a variable using this data.
$data = GetData($k, false);
TraceData($sqlType, $data);
$dataValues = array($k, $data);
InsertRowNoOption( $conn, $tableName, $columnNames, $dataValues );
InsertRowNoOption($conn, $tableName, $columnNames, $dataValues);
ExecProc($conn, $tableName, $columnNames, $k, $data, $sqlType);
}
DropTable($conn, $tableName, $k);
dropTable($conn, $tableName, $k);
sqlsrv_close($conn);
EndTest($testName);
endTest($testName);
}
/**
@ -88,29 +86,29 @@ function main($minType, $maxType)
*/
function ExecProc($conn, $tableName, $columnNames, $k, $data, $sqlType)
{
$phpDriverType = GetDriverType($k, strlen($data));
$spArgs = "@p1 int, @p2 $sqlType OUTPUT";
$spCode = "SET @p2 = ( SELECT c2 FROM $tableName WHERE c1 = @p1 )";
$procName = "testBindOutSp";
CreateProc( $conn, $procName, $spArgs, $spCode );
$callArgs = "?, ?";
//get data to initialize $callResult variable, this variable should be different than inserted data in the table
$initData = GetData( $k , true);
$callResult = $initData;
$params = array( array( $k, SQLSRV_PARAM_IN ),
$phpDriverType = GetDriverType($k, strlen($data));
$spArgs = "@p1 int, @p2 $sqlType OUTPUT";
$spCode = "SET @p2 = ( SELECT c2 FROM $tableName WHERE c1 = @p1 )";
$procName = "testBindOutSp";
createProc($conn, $procName, $spArgs, $spCode);
$callArgs = "?, ?";
//get data to initialize $callResult variable, this variable should be different than inserted data in the table
$initData = GetData($k, true);
$callResult = $initData;
$params = array( array( $k, SQLSRV_PARAM_IN ),
array( &$callResult, SQLSRV_PARAM_OUT, null, $phpDriverType ));
CallProc($conn, $procName, $callArgs, $params);
// check if it is updated
if( $callResult === $initData ){
die("the result should be different");
}
DropProc($conn, $procName);
callProc($conn, $procName, $callArgs, $params);
// check if it is updated
if ($callResult === $initData) {
die("the result should be different");
}
dropProc($conn, $procName);
}
/**
@ -118,14 +116,14 @@ function ExecProc($conn, $tableName, $columnNames, $k, $data, $sqlType)
* @param $conn
* @param $tableName
* @param $columnNames array containig the column names
* @param $dataValues array of values to be insetred in the table
* @param $dataValues array of values to be insetred in the table
*/
function InsertRowNoOption( $conn, $tableName, $columnNames, $dataValues )
function InsertRowNoOption($conn, $tableName, $columnNames, $dataValues)
{
$tsql = "INSERT INTO [$tableName] ($columnNames[0], $columnNames[1]) VALUES (?, ?)";
$stmt = sqlsrv_query( $conn, $tsql, $dataValues );
if( false === $stmt ){
print_r( sqlsrv_errors() );
$tsql = "INSERT INTO [$tableName] ($columnNames[0], $columnNames[1]) VALUES (?, ?)";
$stmt = sqlsrv_query($conn, $tsql, $dataValues);
if (false === $stmt) {
print_r(sqlsrv_errors());
}
}
@ -134,39 +132,37 @@ function InsertRowNoOption( $conn, $tableName, $columnNames, $dataValues )
* @param $k data type id, this id of each datatype are the same as the one in the MsCommon.inc file
* @param $initData boolean parameter, if true it means the returned data value is used to initialize a variable.
*/
function GetData( $k , $initData)
function GetData($k, $initData)
{
if(false == $initData)
{
switch ($k)
{
if (false == $initData) {
switch ($k) {
case 1: // int
return(123456789);
case 2: // tinyint
return(234);
case 3: // smallint
return(5678);
case 4: // bigint
return(123456789987654321);
case 5: // bit
return (1);
case 6: // float
return (123.456);
case 7: // real
return (789.012);
case 8: // decimal(28,4)
case 9: // numeric(32,4)
case 10: // money
case 11: // smallmoney
return(987.0123);
case 12: // char(512)
case 13: // varchar(512)
case 14: // varchar(max)
@ -175,28 +171,24 @@ function GetData( $k , $initData)
case 17: // nvarchar(max)
case 18: // text
case 19: // ntext - deprecated
return("HelloWorld");
return("HelloWorld");
case 20: // binary(512)
case 21: // varbinary(512)
case 22: // varbinary(max)
return(0x0001e240); //123456
default:
return(null);
} // switch
}
else
{
switch ($k)
{
return(null);
} // switch
} else {
switch ($k) {
case 1: // int
case 2: // tinyint
case 3: // smallint
case 4: // bigint
case 5: // bit
return (0);
case 6: // float
case 7: // real
case 8: // decimal(28,4)
@ -204,7 +196,7 @@ function GetData( $k , $initData)
case 10: // money
case 11: // smallmoney
return(00.00);
case 12: // char(512)
case 13: // varchar(512)
case 14: // varchar(max)
@ -214,17 +206,16 @@ function GetData( $k , $initData)
case 18: // text
case 19: // ntext
return("default");
case 20: // binary(512)
case 21: // varbinary(512)
case 22: // varbinary(max)
return(0x0);
default:
return(null);
} // switch
}
}
//--------------------------------------------------------------------
@ -233,12 +224,9 @@ function GetData( $k , $initData)
//--------------------------------------------------------------------
function Repro()
{
try
{
try {
main(1, 22);
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
}
@ -248,4 +236,4 @@ Repro();
?>
--EXPECTREGEX--
Test "BindParam - OutputParam" completed successfully.
Test "BindParam - OutputParam" completed successfully.

View file

@ -5,35 +5,33 @@ Verify the Binary and Char encoding output when binding output string with SQLST
--FILE--
<?php
require( 'MsCommon.inc' );
require_once('MsCommon.inc');
$conn = Connect();
if( $conn === false )
{
FatalError("Could not connect");
if ($conn === false) {
fatalError("Could not connect");
}
$stmt = sqlsrv_query( $conn, "IF OBJECT_ID('BindStringTest', 'U') IS NOT NULL DROP TABLE BindStringTest" );
$stmt = sqlsrv_query( $conn, "IF OBJECT_ID('uspPerson', 'P') IS NOT NULL DROP PROCEDURE uspPerson");
if( $stmt === false )
{
echo "Error in executing statement 1.\n";
die( print_r( sqlsrv_errors(), true));
$stmt = sqlsrv_query($conn, "IF OBJECT_ID('BindStringTest', 'U') IS NOT NULL DROP TABLE BindStringTest");
$stmt = sqlsrv_query($conn, "IF OBJECT_ID('uspPerson', 'P') IS NOT NULL DROP PROCEDURE uspPerson");
if ($stmt === false) {
echo "Error in executing statement 1.\n";
die(print_r(sqlsrv_errors(), true));
}
$stmt = sqlsrv_query( $conn, "CREATE TABLE BindStringTest (PersonID int, Name nvarchar(50))" );
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
$stmt = sqlsrv_query($conn, "CREATE TABLE BindStringTest (PersonID int, Name nvarchar(50))");
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
$stmt = sqlsrv_query( $conn, "INSERT INTO BindStringTest (PersonID, Name) VALUES (10, N'Miller')" );
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
$stmt = sqlsrv_query($conn, "INSERT INTO BindStringTest (PersonID, Name) VALUES (10, N'Miller')");
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
$stmt = sqlsrv_query( $conn, "INSERT INTO BindStringTest (PersonID, Name) VALUES (11, N'JSmith')" );
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$stmt = sqlsrv_query($conn, "INSERT INTO BindStringTest (PersonID, Name) VALUES (11, N'JSmith')");
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
$tsql_createSP = "CREATE PROCEDURE uspPerson
@id int, @return nvarchar(50) OUTPUT
@ -42,12 +40,11 @@ $tsql_createSP = "CREATE PROCEDURE uspPerson
SET NOCOUNT ON;
SET @return = (SELECT Name FROM BindStringTest WHERE PersonID = @id)
END";
$stmt = sqlsrv_query( $conn, $tsql_createSP);
if( $stmt === false )
{
echo "Error in executing statement 2.\n";
die( print_r( sqlsrv_errors(), true));
$stmt = sqlsrv_query($conn, $tsql_createSP);
if ($stmt === false) {
echo "Error in executing statement 2.\n";
die(print_r(sqlsrv_errors(), true));
}
$tsql_callSP = "{call uspPerson( ? , ?)}";
@ -59,43 +56,41 @@ echo "NVARCHAR(32)\n";
echo "---------Encoding char-----------\n";
$id = 10;
$return = "";
$params = array(
$params = array(
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
SQLSRV_SQLTYPE_NVARCHAR(32)
));
if( $stmt = sqlsrv_query($conn, $tsql_callSP, $params) === false)
{
print_r( sqlsrv_errors(), true);
if ($stmt = sqlsrv_query($conn, $tsql_callSP, $params) === false) {
print_r(sqlsrv_errors(), true);
}
$expectedLength = 6;
$expectedValue = "Miller";
$actualLength = strlen($return);
$actualValue = $return;
compareResults ( $expectedLength, $expectedValue, $actualLength, $actualValue );
compareResults($expectedLength, $expectedValue, $actualLength, $actualValue);
echo "---------Encoding binary---------\n";
$id = 10;
$return = "";
$params = array(
$params = array(
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY),
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY),
SQLSRV_SQLTYPE_NVARCHAR(32)
));
if( $stmt = sqlsrv_query($conn, $tsql_callSP, $params) == false)
{
print_r( sqlsrv_errors(), true);
}
if ($stmt = sqlsrv_query($conn, $tsql_callSP, $params) == false) {
print_r(sqlsrv_errors(), true);
}
$expectedLength = 12;
$expectedValue = "M\0i\0l\0l\0e\0r\0";
$actualLength = strlen($return);
$actualValue = $return;
compareResults ( $expectedLength, $expectedValue, $actualLength, $actualValue );
compareResults($expectedLength, $expectedValue, $actualLength, $actualValue);
//***********************************************************************************************
echo "\n\n";
@ -103,44 +98,42 @@ echo "NVARCHAR(50)\n";
echo "---------Encoding char-----------\n";
$id = 10;
$return = "";
$params = array(
$params = array(
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
SQLSRV_SQLTYPE_NVARCHAR(50)
));
if( $stmt = sqlsrv_query($conn, $tsql_callSP, $params) === false)
{
print_r( sqlsrv_errors(), true);
if ($stmt = sqlsrv_query($conn, $tsql_callSP, $params) === false) {
print_r(sqlsrv_errors(), true);
}
$expectedLength = 6;
$expectedValue = "Miller";
$actualLength = strlen($return);
$actualValue = $return;
compareResults ( $expectedLength, $expectedValue, $actualLength, $actualValue );
compareResults($expectedLength, $expectedValue, $actualLength, $actualValue);
echo "---------Encoding binary---------\n";
$id = 10;
$return = "";
$params = array(
$params = array(
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY),
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY),
SQLSRV_SQLTYPE_NVARCHAR(50)
));
if( $stmt = sqlsrv_query($conn, $tsql_callSP, $params) == false)
{
print_r( sqlsrv_errors(), true);
}
if ($stmt = sqlsrv_query($conn, $tsql_callSP, $params) == false) {
print_r(sqlsrv_errors(), true);
}
$expectedLength = 12;
$expectedValue = "M\0i\0l\0l\0e\0r\0";
$actualLength = strlen($return);
$actualValue = $return;
compareResults ( $expectedLength, $expectedValue, $actualLength, $actualValue );
compareResults($expectedLength, $expectedValue, $actualLength, $actualValue);
//***********************************************************************************************
echo "\n\n";
@ -150,43 +143,41 @@ $id = 10;
$return = "";
$params = array(
$params = array(
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
SQLSRV_SQLTYPE_NVARCHAR(1)
));
if( $stmt = sqlsrv_query($conn, $tsql_callSP, $params) === false)
{
echo "Statement should fail\n";
if ($stmt = sqlsrv_query($conn, $tsql_callSP, $params) === false) {
echo "Statement should fail\n";
}
$expectedLength = 1;
$expectedValue = "M";
$actualValue = $return;
$actualLength = strlen($return);
compareResults ( $expectedLength, $expectedValue, $actualLength, $actualValue );
compareResults($expectedLength, $expectedValue, $actualLength, $actualValue);
echo "---------Encoding binary---------\n";
$id = 10;
$return = "";
$params = array(
$params = array(
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY),
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY),
SQLSRV_SQLTYPE_NVARCHAR(1)
));
if( $stmt = sqlsrv_query($conn, $tsql_callSP, $params) == false)
{
echo "Statement should fail\n";
}
if ($stmt = sqlsrv_query($conn, $tsql_callSP, $params) == false) {
echo "Statement should fail\n";
}
$expectedLength = 2;
$expectedValue = "M\0";
$actualLength = strlen($return);
$actualValue = $return;
compareResults ( $expectedLength, $expectedValue, $actualLength, $actualValue );
compareResults($expectedLength, $expectedValue, $actualLength, $actualValue);
//***********************************************************************************************
echo "\n\n";
@ -194,43 +185,41 @@ echo "NCHAR(32)\n";
echo "---------Encoding char-----------\n";
$id = 10;
$return = "";
$params = array(
$params = array(
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
SQLSRV_SQLTYPE_NCHAR(32)
));
if( $stmt = sqlsrv_query($conn, $tsql_callSP, $params) === false)
{
print_r( sqlsrv_errors(), true);
if ($stmt = sqlsrv_query($conn, $tsql_callSP, $params) === false) {
print_r(sqlsrv_errors(), true);
}
$expectedLength = 32;
$expectedValue = "Miller ";
$actualLength = strlen($return);
$actualValue = $return;
compareResults ( $expectedLength, $expectedValue, $actualLength, $actualValue );
compareResults($expectedLength, $expectedValue, $actualLength, $actualValue);
echo "---------Encoding binary---------\n";
$id = 10;
$return = "";
$params = array(
$params = array(
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY),
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY),
SQLSRV_SQLTYPE_NCHAR(32)
));
if( $stmt = sqlsrv_query($conn, $tsql_callSP, $params) == false)
{
print_r( sqlsrv_errors(), true);
}
if ($stmt = sqlsrv_query($conn, $tsql_callSP, $params) == false) {
print_r(sqlsrv_errors(), true);
}
$expectedLength = 64;
$expectedValue = "M\0i\0l\0l\0e\0r\0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0";
$actualLength = strlen($return);
$actualValue = $return;
compareResults ( $expectedLength, $expectedValue, $actualLength, $actualValue );
compareResults($expectedLength, $expectedValue, $actualLength, $actualValue);
//***********************************************************************************************
echo "\n\n";
@ -238,135 +227,129 @@ echo "NCHAR(0)\n";
echo "---------Encoding char-----------\n";
$id = 10;
$return = "";
$params = array(
$params = array(
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
SQLSRV_SQLTYPE_NCHAR(0)
));
if( $stmt = sqlsrv_query($conn, $tsql_callSP, $params) === false)
{
echo "Statement should fail\n";
if ($stmt = sqlsrv_query($conn, $tsql_callSP, $params) === false) {
echo "Statement should fail\n";
}
$expectedLength = 0;
$expectedValue = "";
$actualLength = strlen($return);
$actualValue = $return;
compareResults ( $expectedLength, $expectedValue, $actualLength, $actualValue );
compareResults($expectedLength, $expectedValue, $actualLength, $actualValue);
echo "---------Encoding binary---------\n";
$id = 10;
$return = "";
$params = array(
$params = array(
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY),
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY),
SQLSRV_SQLTYPE_NCHAR(0)
));
if( $stmt = sqlsrv_query($conn, $tsql_callSP, $params) == false)
{
echo "Statement should fail\n";
}
if ($stmt = sqlsrv_query($conn, $tsql_callSP, $params) == false) {
echo "Statement should fail\n";
}
$expectedLength = 0;
$expectedValue = "";
$actualLength = strlen($return);
$actualValue = $return;
compareResults ( $expectedLength, $expectedValue, $actualLength, $actualValue );
compareResults($expectedLength, $expectedValue, $actualLength, $actualValue);
//***********************************************************************************************
echo "\n\n";
echo "NCHAR(50)\n";
echo "NCHAR(50)\n";
echo "---------Encoding char-----------\n";
$id = 10;
$return = "";
$params = array(
$params = array(
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
SQLSRV_SQLTYPE_NCHAR(50)
));
if( $stmt = sqlsrv_query($conn, $tsql_callSP, $params) === false)
{
print_r( sqlsrv_errors(), true);
if ($stmt = sqlsrv_query($conn, $tsql_callSP, $params) === false) {
print_r(sqlsrv_errors(), true);
}
$expectedLength = 50;
$expectedValue = "Miller ";
$actualLength = strlen($return);
$actualValue = $return;
compareResults ( $expectedLength, $expectedValue, $actualLength, $actualValue );
compareResults($expectedLength, $expectedValue, $actualLength, $actualValue);
echo "---------Encoding binary---------\n";
$id = 10;
$return = "";
$params = array(
$params = array(
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY),
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY),
SQLSRV_SQLTYPE_NCHAR(50)
));
if( $stmt = sqlsrv_query($conn, $tsql_callSP, $params) == false)
{
print_r( sqlsrv_errors(), true);
}
if ($stmt = sqlsrv_query($conn, $tsql_callSP, $params) == false) {
print_r(sqlsrv_errors(), true);
}
$expectedLength = 100;
$expectedValue = "M\0i\0l\0l\0e\0r\0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0";
$actualLength = strlen($return);
$actualValue = $return;
compareResults ( $expectedLength, $expectedValue, $actualLength, $actualValue );
compareResults($expectedLength, $expectedValue, $actualLength, $actualValue);
//***********************************************************************************************
// NCHAR 1: less than length of the returned value
// NCHAR 1: less than length of the returned value
echo "\n\n";
echo "NCHAR(1)\n";
echo "---------Encoding char-----------\n";
$id = 10;
$return = "";
$params = array(
$params = array(
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
SQLSRV_SQLTYPE_NCHAR(1)
));
if( $stmt = sqlsrv_query($conn, $tsql_callSP, $params) === false)
{
print_r( sqlsrv_errors(), true);
if ($stmt = sqlsrv_query($conn, $tsql_callSP, $params) === false) {
print_r(sqlsrv_errors(), true);
}
$expectedLength = 1;
$expectedValue = "M";
$actualValue = $return;
$actualLength = strlen($return);
compareResults ( $expectedLength, $expectedValue, $actualLength, $actualValue );
compareResults($expectedLength, $expectedValue, $actualLength, $actualValue);
echo "---------Encoding binary---------\n";
$id = 10;
$return = "";
$params = array(
$params = array(
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY),
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY),
SQLSRV_SQLTYPE_NCHAR(1)
));
if( $stmt = sqlsrv_query($conn, $tsql_callSP, $params) == false)
{
print_r( sqlsrv_errors(), true);
}
if ($stmt = sqlsrv_query($conn, $tsql_callSP, $params) == false) {
print_r(sqlsrv_errors(), true);
}
$expectedLength = 2;
$expectedValue = "M\0";
$actualValue = $return;
$actualLength = strlen($return);
compareResults ( $expectedLength, $expectedValue, $actualLength, $actualValue );
compareResults($expectedLength, $expectedValue, $actualLength, $actualValue);
sqlsrv_query( $conn, "DROP TABLE BindStringTest" );
sqlsrv_query( $conn, "DROP PROCEDURE uspPerson");
sqlsrv_query($conn, "DROP TABLE BindStringTest");
sqlsrv_query($conn, "DROP PROCEDURE uspPerson");
sqlsrv_close($conn);
@ -379,22 +362,17 @@ $status = true;
* @param $actualLength The length of the actual value
* @param $actualValue The actual value
*/
function compareResults ( $expectedLength, $expectedValue, $actualLength, $actualValue )
function compareResults($expectedLength, $expectedValue, $actualLength, $actualValue)
{
$match = false;
if ( $expectedLength == $actualLength)
{
if ( strncmp ( $actualValue, $expectedValue, $expectedLength ) == 0 )
{
if ($expectedLength == $actualLength) {
if (strncmp($actualValue, $expectedValue, $expectedLength) == 0) {
$match = true;
}
}
if ( !$match )
{
echo "The actual result is different from the expected one \n";
}
else
{
if (!$match) {
echo "The actual result is different from the expected one \n";
} else {
echo "The actual result is the same as the expected one \n";
}
}
@ -450,4 +428,4 @@ NCHAR(1)
---------Encoding char-----------
The actual result is the same as the expected one
---------Encoding binary---------
The actual result is the same as the expected one
The actual result is the same as the expected one

View file

@ -5,45 +5,42 @@ Read, Update, Insert from a SQLSRV stream with buffered query
--FILE--
<?php
require( 'MsCommon.inc' );
require_once('MsCommon.inc');
$conn = Connect();
if( !$conn ) {
FatalError("Could not connect");
$conn = connect();
if (!$conn) {
fatalError("Could not connect");
}
$query = "IF OBJECT_ID('PhpCustomerTable', 'U') IS NOT NULL DROP TABLE [PhpCustomerTable]";
$stmt = sqlsrv_prepare( $conn, $query, array(), array("Scrollable"=>SQLSRV_CURSOR_CLIENT_BUFFERED));
$stmt = sqlsrv_prepare($conn, $query, array(), array("Scrollable"=>SQLSRV_CURSOR_CLIENT_BUFFERED));
if(!$stmt)
{
if (!$stmt) {
echo "Statement could not be prepared.\n";
die( print_r( sqlsrv_errors(),true));
die(print_r(sqlsrv_errors(), true));
}
sqlsrv_execute( $stmt );
sqlsrv_execute($stmt);
$query = "CREATE TABLE [PhpCustomerTable] ([Id] int NOT NULL Identity (100,2) PRIMARY KEY, [Field2] text, [Field3] image, [Field4] ntext, [Field5] varbinary(max), [Field6] varchar(max), [Field7] nvarchar(max))";
$stmt = sqlsrv_prepare( $conn, $query, array(), array("Scrollable"=>SQLSRV_CURSOR_CLIENT_BUFFERED));
$stmt = sqlsrv_prepare($conn, $query, array(), array("Scrollable"=>SQLSRV_CURSOR_CLIENT_BUFFERED));
if(!$stmt)
{
if (!$stmt) {
echo "Statement could not be prepared.\n";
die( print_r( sqlsrv_errors(),true));
die(print_r(sqlsrv_errors(), true));
}
sqlsrv_execute( $stmt );
sqlsrv_execute($stmt);
$query = "INSERT [PhpCustomerTable] ([Field2], [Field3], [Field4], [Field5], [Field6], [Field7]) VALUES ('This is field 2.', 0x010203, 'This is field 4.', 0x040506, 'This is field 6.', 'This is field 7.' )";
$stmt = sqlsrv_prepare( $conn, $query, array(), array("Scrollable"=>SQLSRV_CURSOR_CLIENT_BUFFERED));
$stmt = sqlsrv_prepare($conn, $query, array(), array("Scrollable"=>SQLSRV_CURSOR_CLIENT_BUFFERED));
if(!$stmt)
{
if (!$stmt) {
echo "Statement could not be prepared.\n";
die( print_r( sqlsrv_errors(),true));
die(print_r(sqlsrv_errors(), true));
}
sqlsrv_execute( $stmt );
sqlsrv_execute($stmt);
$f2 = fopen('php://memory', 'a');
fwrite($f2, 'Update field 2.');
@ -68,166 +65,137 @@ rewind($f7);
$query = "UPDATE [PhpCustomerTable] SET [Field2]=? WHERE [Field7]='This is field 7.'";
$params = array(array(&$f2, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_TEXT));
$stmt = sqlsrv_prepare( $conn, $query, $params, array("Scrollable"=>SQLSRV_CURSOR_CLIENT_BUFFERED));
$stmt = sqlsrv_prepare($conn, $query, $params, array("Scrollable"=>SQLSRV_CURSOR_CLIENT_BUFFERED));
if(!$stmt)
{
if (!$stmt) {
echo "Statement could not be prepared.\n";
die( print_r( sqlsrv_errors(),true));
die(print_r(sqlsrv_errors(), true));
}
sqlsrv_execute( $stmt );
sqlsrv_execute($stmt);
sqlsrv_free_stmt($stmt);
$query = "UPDATE [PhpCustomerTable] SET [Field3]=? WHERE [Field7]='This is field 7.'";
$params = array(array(&$f3, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_IMAGE));
$stmt = sqlsrv_prepare( $conn, $query, $params, array("Scrollable"=>SQLSRV_CURSOR_CLIENT_BUFFERED));
$stmt = sqlsrv_prepare($conn, $query, $params, array("Scrollable"=>SQLSRV_CURSOR_CLIENT_BUFFERED));
if(!$stmt)
{
if (!$stmt) {
echo "Statement could not be prepared.\n";
die( print_r( sqlsrv_errors(),true));
die(print_r(sqlsrv_errors(), true));
}
sqlsrv_execute( $stmt );
sqlsrv_free_stmt( $stmt );
sqlsrv_execute($stmt);
sqlsrv_free_stmt($stmt);
$query = "UPDATE [PhpCustomerTable] SET [Field4]=? WHERE [Field7]='This is field 7.'";
$params = array(array(&$f4, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_NTEXT));
$stmt = sqlsrv_prepare( $conn, $query, $params, array("Scrollable"=>SQLSRV_CURSOR_CLIENT_BUFFERED));
$stmt = sqlsrv_prepare($conn, $query, $params, array("Scrollable"=>SQLSRV_CURSOR_CLIENT_BUFFERED));
if(!$stmt)
{
if (!$stmt) {
echo "Statement could not be prepared.\n";
die( print_r( sqlsrv_errors(),true));
die(print_r(sqlsrv_errors(), true));
}
sqlsrv_execute( $stmt );
sqlsrv_free_stmt( $stmt );
sqlsrv_execute($stmt);
sqlsrv_free_stmt($stmt);
$query = "UPDATE [PhpCustomerTable] SET [Field5]=? WHERE [Field7]='This is field 7.'";
$params = array(array(&$f5, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_VARBINARY('max')));
$stmt = sqlsrv_prepare( $conn, $query, $params, array("Scrollable"=>SQLSRV_CURSOR_CLIENT_BUFFERED));
$stmt = sqlsrv_prepare($conn, $query, $params, array("Scrollable"=>SQLSRV_CURSOR_CLIENT_BUFFERED));
if(!$stmt)
{
if (!$stmt) {
echo "Statement could not be prepared.\n";
die( print_r( sqlsrv_errors(),true));
die(print_r(sqlsrv_errors(), true));
}
sqlsrv_execute( $stmt );
sqlsrv_free_stmt( $stmt );
sqlsrv_execute($stmt);
sqlsrv_free_stmt($stmt);
$query = "UPDATE [PhpCustomerTable] SET [Field6]=? WHERE [Field7]='This is field 7.'";
$params = array(array(&$f6, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_VARCHAR('MAX')));
$stmt = sqlsrv_prepare( $conn, $query, $params, array("Scrollable"=>SQLSRV_CURSOR_CLIENT_BUFFERED));
$stmt = sqlsrv_prepare($conn, $query, $params, array("Scrollable"=>SQLSRV_CURSOR_CLIENT_BUFFERED));
if(!$stmt)
{
if (!$stmt) {
echo "Statement could not be prepared.\n";
die( print_r( sqlsrv_errors(),true));
die(print_r(sqlsrv_errors(), true));
}
sqlsrv_execute( $stmt );
sqlsrv_free_stmt( $stmt );
sqlsrv_execute($stmt);
sqlsrv_free_stmt($stmt);
$query = "UPDATE [PhpCustomerTable] SET [Field7]=? WHERE [Field7]='This is field 7.'";
$params = array(array(&$f7, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_NVARCHAR('MAX')));
$stmt = sqlsrv_prepare( $conn, $query, $params, array("Scrollable"=>SQLSRV_CURSOR_CLIENT_BUFFERED));
$stmt = sqlsrv_prepare($conn, $query, $params, array("Scrollable"=>SQLSRV_CURSOR_CLIENT_BUFFERED));
if(!$stmt)
{
if (!$stmt) {
echo "Statement could not be prepared.\n";
die( print_r( sqlsrv_errors(),true));
die(print_r(sqlsrv_errors(), true));
}
sqlsrv_execute( $stmt );
sqlsrv_free_stmt( $stmt );
sqlsrv_execute($stmt);
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query($conn, "SELECT * FROM [PhpCustomerTable]", array(), array("Scrollable"=>SQLSRV_CURSOR_CLIENT_BUFFERED));
if(!$stmt)
{
if (!$stmt) {
echo "Statement could not be prepared.\n";
die( print_r( sqlsrv_errors(),true));
die(print_r(sqlsrv_errors(), true));
}
sqlsrv_fetch( $stmt );
sqlsrv_fetch($stmt);
$field = sqlsrv_get_field( $stmt, 0, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR) );
if(!$field)
{
print( "Failed to get text field\n" );
}
else
{
$field = str_replace("\0","",$field);
$field = sqlsrv_get_field($stmt, 0, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
if (!$field) {
print("Failed to get text field\n");
} else {
$field = str_replace("\0", "", $field);
print("$field\n");
}
$field = sqlsrv_get_field( $stmt, 1, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR) );
if(!$field)
{
print( "Failed to get text field\n" );
}
else
{
$field = sqlsrv_get_field($stmt, 1, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
if (!$field) {
print("Failed to get text field\n");
} else {
print("$field\n");
}
$field = sqlsrv_get_field( $stmt, 2, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR) );
if(!$field)
{
print( "Failed to get image field\n" );
}
else
{
$field = sqlsrv_get_field($stmt, 2, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
if (!$field) {
print("Failed to get image field\n");
} else {
print("$field\n");
}
$field = sqlsrv_get_field( $stmt, 3, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR) );
if(!$field)
{
print( "Failed to get ntext field\n" );
}
else
{
$field = sqlsrv_get_field($stmt, 3, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
if (!$field) {
print("Failed to get ntext field\n");
} else {
print("$field\n");
}
$field = sqlsrv_get_field( $stmt, 4, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR) );
if(!$field)
{
print( "Failed to get varbinary(max) field\n" );
}
else
{
$field = sqlsrv_get_field($stmt, 4, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
if (!$field) {
print("Failed to get varbinary(max) field\n");
} else {
print("$field\n");
}
$field = sqlsrv_get_field( $stmt, 5, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR) );
if(!$field)
{
print( "Failed to get varchar(max) field\n" );
}
else
{
$field = sqlsrv_get_field($stmt, 5, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
if (!$field) {
print("Failed to get varchar(max) field\n");
} else {
print("$field\n");
}
$field = sqlsrv_get_field( $stmt, 6, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR) );
if(!$field)
{
print( "Failed to get nvarchar(max) field\n" );
}
else
{
$field = sqlsrv_get_field($stmt, 6, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
if (!$field) {
print("Failed to get nvarchar(max) field\n");
} else {
print("$field\n");
}
sqlsrv_query( $conn, "DROP TABLE [PhpCustomerTable]" );
sqlsrv_query($conn, "DROP TABLE [PhpCustomerTable]");
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
@ -240,4 +208,4 @@ Update field 2.
Update field 4.
323633343237
Update field 6.
Update field 7.
Update field 7.

View file

@ -1,5 +1,5 @@
--TEST--
Fetch array of extended ASCII data using a scrollable buffered cursor
Fetch array of extended ASCII data using a scrollable buffered cursor
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
@ -7,8 +7,10 @@ Fetch array of extended ASCII data using a scrollable buffered cursor
require_once("MsCommon.inc");
// Connect
$conn = ConnectUTF8();
if( !$conn ) { die( print_r( sqlsrv_errors(), true)); }
$conn = connect(array( 'CharacterSet'=>'UTF-8' ));
if (!$conn) {
die(print_r(sqlsrv_errors(), true));
}
// Create table
$tableName = '#exAsciiTest';
@ -16,16 +18,18 @@ $query = "CREATE TABLE $tableName (ID CHAR(10))";
$stmt = sqlsrv_query($conn, $query);
// Insert data
$query = "INSERT INTO $tableName VALUES ('Aå_Ð×Æ×Ø_B')";
$query = "INSERT INTO $tableName VALUES ('Aå_Ð×Æ×Ø_B')";
$stmt = sqlsrv_query($conn, $query);
if (! $stmt)
die(print_r( sqlsrv_errors(), true));
if (! $stmt) {
die(print_r(sqlsrv_errors(), true));
}
// Fetch data
$query = "SELECT * FROM $tableName";
$stmt = sqlsrv_query($conn, $query, [], array("Scrollable"=>"buffered"));
if (! $stmt)
die(print_r( sqlsrv_errors(), true));
if (! $stmt) {
die(print_r(sqlsrv_errors(), true));
}
// Fetch
$row = sqlsrv_fetch_array($stmt);

View file

@ -11,11 +11,11 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
require( 'MsCommon.inc' );
require_once('MsCommon.inc');
$conn = Connect();
if( !$conn ) {
FatalError("Could not connect");
if (!$conn) {
fatalError("Could not connect");
}
$tsql = <<<SQL
@ -25,7 +25,7 @@ SELECT 'bit_true'=@bit_true, 'bit_false'=@bit_false, 'bit_cast_true'=@bit_cast_t
'int_true'=@int_true, 'direct_true'=?, 'direct_false'=?,
'direct_bit_cast_true'=CAST(? AS bit)
SQL;
$stmt = sqlsrv_query($conn,$tsql,[true,false,true,true,true,false,true]);
$stmt = sqlsrv_query($conn, $tsql, [true,false,true,true,true,false,true]);
$row = sqlsrv_fetch_object($stmt);
var_dump($row);
@ -49,4 +49,4 @@ object(stdClass)#1 (7) {
int(0)
["direct_bit_cast_true"]=>
int(1)
}
}

View file

@ -11,11 +11,11 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
require( 'MsCommon.inc' );
require_once('MsCommon.inc');
$conn = Connect();
if( !$conn ) {
FatalError("Could not connect");
if (!$conn) {
fatalError("Could not connect");
}
$tsql = <<<SQL
@ -25,7 +25,7 @@ SELECT 'bit_true'=@bit_true, 'bit_false'=@bit_false, 'bit_cast_true'=@bit_cast_t
'int_true'=@int_true, 'direct_true'=?, 'direct_false'=?,
'direct_bit_cast_true'=CAST(? AS bit)
SQL;
$stmt = sqlsrv_query($conn,$tsql,[1,0,1,1,1,0,1]);
$stmt = sqlsrv_query($conn, $tsql, [1,0,1,1,1,0,1]);
$row = sqlsrv_fetch_object($stmt);
var_dump($row);
@ -49,4 +49,4 @@ object(stdClass)#1 (7) {
int(0)
["direct_bit_cast_true"]=>
int(1)
}
}

View file

@ -11,11 +11,11 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
require( 'MsCommon.inc' );
require_once('MsCommon.inc');
$conn = Connect();
if( !$conn ) {
FatalError("Could not connect");
if (!$conn) {
fatalError("Could not connect");
}
$tsql = <<<SQL
@ -25,7 +25,7 @@ SELECT 'bit_true'=@bit_true, 'bit_false'=@bit_false, 'bit_cast_true'=@bit_cast_t
'int_true'=@int_true, 'direct_true'=?, 'direct_false'=?,
'direct_bit_cast_true'=CAST(? AS bit)
SQL;
$stmt = sqlsrv_query($conn,$tsql,[true,false,true,true,true,false,true]);
$stmt = sqlsrv_query($conn, $tsql, [true,false,true,true,true,false,true]);
$row = sqlsrv_fetch_object($stmt);
var_dump($row);
@ -49,4 +49,4 @@ object(stdClass)#1 (7) {
int(0)
["direct_bit_cast_true"]=>
int(1)
}
}

View file

@ -10,11 +10,11 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
require( 'MsCommon.inc' );
require_once('MsCommon.inc');
$conn = Connect();
if( !$conn ) {
FatalError("Could not connect");
$conn = connect();
if (!$conn) {
fatalError("Could not connect");
}
$stmt = sqlsrv_query($conn, "IF OBJECT_ID('testBoolean', 'P') IS NOT NULL DROP PROCEDURE testBoolean");
@ -57,4 +57,4 @@ sqlsrv_close($conn);
int(1)
int(0)
int(1)
int(1)
int(1)

View file

@ -10,11 +10,11 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
require( 'MsCommon.inc' );
require_once('MsCommon.inc');
$conn = Connect();
if( !$conn ) {
FatalError("Could not connect");
fatalError("Could not connect");
}
$stmt = sqlsrv_query($conn, "IF OBJECT_ID('testBoolean', 'P') IS NOT NULL DROP PROCEDURE testBoolean");
@ -57,4 +57,4 @@ sqlsrv_close($conn);
bool(true)
bool(false)
bool(true)
bool(true)
bool(true)

View file

@ -12,11 +12,11 @@ PHPT_EXEC=true
<?php
/* Fails on PHP 7, producing 1's and 2's instead of 0's and 1's. */
require( 'MsCommon.inc' );
require_once('MsCommon.inc');
$conn = Connect();
if( !$conn ) {
FatalError("Could not connect");
if (!$conn) {
fatalError("Could not connect");
}
$stmt = sqlsrv_query($conn, "IF OBJECT_ID('testBoolean', 'P') IS NOT NULL DROP PROCEDURE testBoolean");
@ -59,4 +59,4 @@ sqlsrv_close($conn);
int(1)
int(0)
int(1)
int(1)
int(1)

View file

@ -12,11 +12,11 @@ PHPT_EXEC=true
<?php
/* Fails on PHP 7, producing 1's and 2's instead of 0's and 1's. */
require( 'MsCommon.inc' );
require_once('MsCommon.inc');
$conn = Connect();
if( !$conn ) {
FatalError("Could not connect");
if (!$conn) {
fatalError("Could not connect");
}
$stmt = sqlsrv_query($conn, "IF OBJECT_ID('testBoolean', 'P') IS NOT NULL DROP PROCEDURE testBoolean");
@ -59,4 +59,4 @@ sqlsrv_close($conn);
bool(true)
bool(false)
bool(true)
bool(true)
bool(true)

View file

@ -1,28 +1,29 @@
--TEST--
Free statement twice
Free statement twice
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function CloseTwice()
{
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
{
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
// Connect
$conn = Connect();
if( !$conn ) { FatalError("Could not connect.\n"); }
$tableName = GetTempTableName();
$conn = connect();
if (!$conn) {
fatalError("Could not connect.\n");
}
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_tinyint] tinyint)");
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query($conn, "SELECT * FROM $tableName");
sqlsrv_free_stmt($stmt);
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
$tableName = GetTempTableName();
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_tinyint] tinyint)");
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query($conn, "SELECT * FROM $tableName");
sqlsrv_free_stmt($stmt);
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
}
//--------------------------------------------------------------------
@ -31,17 +32,14 @@ function CloseTwice()
//--------------------------------------------------------------------
function Repro()
{
StartTest("sqlsrv_close_twice");
try
{
startTest("sqlsrv_close_twice");
try {
CloseTwice();
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
echo "\nDone\n";
EndTest("sqlsrv_close_twice");
endTest("sqlsrv_close_twice");
}
Repro();

View file

@ -1,37 +1,36 @@
--TEST--
Test sqlsrv_commit method.
--SKIPIF--
<?php require_once ('skipif.inc'); ?>
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
require( 'MsCommon.inc' );
require_once('MsCommon.inc');
$conn = Connect();
if( !$conn ) {
FatalError("Could not connect");
$conn = connect();
if (!$conn) {
fatalError("Could not connect");
}
$stmt1 = sqlsrv_query( $conn, "IF OBJECT_ID('Products', 'U') IS NOT NULL DROP TABLE Products" );
$stmt1 = sqlsrv_query( $conn, "CREATE TABLE Products (ProductID int PRIMARY KEY, ProductName nvarchar(40), CategoryID int, UnitPrice money)" );
if( $stmt1 === false ) {
die( print_r( sqlsrv_errors(), true ));
$stmt1 = sqlsrv_query($conn, "IF OBJECT_ID('Products', 'U') IS NOT NULL DROP TABLE Products");
$stmt1 = sqlsrv_query($conn, "CREATE TABLE Products (ProductID int PRIMARY KEY, ProductName nvarchar(40), CategoryID int, UnitPrice money)");
if ($stmt1 === false) {
die(print_r(sqlsrv_errors(), true));
}
sqlsrv_free_stmt($stmt1);
$stmt2 = sqlsrv_query( $conn, "INSERT INTO Products (ProductID, ProductName, CategoryID, UnitPrice) VALUES (1, 'TestProduct2', 2, '13.55')" );
$stmt3 = sqlsrv_query( $conn, "SELECT * FROM Products WHERE CategoryID = 2" );
$stmt2 = sqlsrv_query($conn, "INSERT INTO Products (ProductID, ProductName, CategoryID, UnitPrice) VALUES (1, 'TestProduct2', 2, '13.55')");
$stmt3 = sqlsrv_query($conn, "SELECT * FROM Products WHERE CategoryID = 2");
if ( $stmt2 && $stmt3 )
{
sqlsrv_commit( $conn );
if ($stmt2 && $stmt3) {
sqlsrv_commit($conn);
echo "Commit successful";
}
$stmt1 = sqlsrv_query( $conn, "DROP TABLE Products" );
$stmt1 = sqlsrv_query($conn, "DROP TABLE Products");
sqlsrv_free_stmt($stmt1);
sqlsrv_free_stmt($stmt2);
sqlsrv_free_stmt($stmt3);
?>
--EXPECT--
Commit successful
Commit successful

View file

@ -2,66 +2,65 @@
Test a complex query with IDENTITY_INSERT
--FILE--
<?php
include 'MsCommon.inc';
require_once('MsCommon.inc');
function ComplexQuery()
{
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
// Connect
$conn = Connect(array("CharacterSet"=>"UTF-8"));
if( !$conn ) { FatalError("Could not connect.\n"); }
$conn = connect(array("CharacterSet"=>"UTF-8"));
if (!$conn) {
fatalError("Could not connect.\n");
}
$tableName = GetTempTableName();
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int IDENTITY, [c2_tinyint] tinyint, [c3_smallint] smallint, [c4_bigint] bigint, [c5_varchar] varchar(512))");
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int IDENTITY, [c2_tinyint] tinyint, [c3_smallint] smallint, [c4_bigint] bigint, [c5_varchar] varchar(512))");
sqlsrv_free_stmt($stmt);
$noExpectedRows = 0;
$noActualRows = 0;
$stmt = sqlsrv_query($conn, "SET IDENTITY_INSERT $tableName ON;");
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query($conn, "SET IDENTITY_INSERT $tableName ON;");
sqlsrv_free_stmt($stmt);
$noExpectedRows++;
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_tinyint, c3_smallint, c4_bigint, c5_varchar) VALUES (1324944463, 105, 18521, 2022363960, 'üv£ª©*@*rãCaC|/ä*,,@ý©bvªäîCUBão_+ßZhUªî¢~ÖÜ/ª@ä+ßßar~Özr,aß/,bCaü<ÖÐhÐbß<î/ðzãý+bÜ:Zßöüª@BÖUß<U@¢Ö<hÖhubÄrÐÃ*.å|a/,ª¢ßOa@oubýãýý£îZ~,ä¢î|+ª¢rZUCrOu,B£åß|:£ªîoBärÐA/BzOoß<bvu~ßuîCãߢ¢îýA@aðuAa,UÐ.>Ußaåab|¢ª¢|ü£/ÃßzzuªãA.ªZUöß<©a>OzübBüÜ|bZ./öbvß*rbö>ß©r//~ÖCÜhð¢bßz:¢Ä+_Ã__£ý£Uýh:v¢bý,©Ü£©,A:Zh>ßåvö+Ä>Ã.ßvC|:Ü*Üü*åz|b.©©üAý@uU.oOÜýAÜÐÜð©OB|rrîbU<övoUßäZÃÖ<ÄåªAÄ.Ua*ÖOªB,åîzB:ÜhövÖZhýðüC')");
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query($conn, "SET IDENTITY_INSERT $tableName OFF;");
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_tinyint, c3_smallint, c4_bigint, c5_varchar) VALUES (-1554807493, 253, -12809, -1698802997, 'ßöîÄ@v+oß+î|ruý*Ü¢ãÖ~.*ArABªßOBzUU£ßUuÜ<ðýr|b~_äaü/OÖzv.¢ä>>OÜ+¢vªzöªoB_ä+ߪrÜö£>U~ãÖð~ðýur,ÖvZh¢ªZ>vªUäåîz,>ÃräðäýðO_ä*a,ö+üÐß~bÃü¢<<+îýÐöäªO/zA+:îZ,öBÐü<î£îåhBÖzßÄ~,:>bð<~aÐãö¢*¢våvÃÐåî@a<vBãßÖä媢<üa.u:>_Äu£öa~våu>¢Bã©å:Aßã£Üvåö+aä£U<bUu*rv+@U_|ð@+v@Üßb|,.ªäÖ/*êýÄ¢¢Ö/+ä><¢b@|zbãÖ@ÃãUb|ÄB£©,~ßð©ðUßöZÜöî£Zz<>åäZßð©ßaÖÖ¢bð£ßÄ>îÃÃ.~z>h_ý~ÜrüÖBruß+ª©CB©O>rå,Chro,£ßbZ_ß©,ÃUu|ßåüÄ/ý*åu|~Ö.ßZUoä:~A~CZhðU|öZ:ä/£Ä*î©ÄhävhbrzîÐ@.rãß©@uÜ©~>ÖÜööCÄzÜCü+>oZÄÜ/ABßA_b|b¢bÜh<|uBr.B*rü>aCª|AÄ©@öÖßÖ~Ö<rÐ,ä@©|££.C.üå¢/rbªßî')");
$errors = sqlsrv_errors(SQLSRV_ERR_ALL);
$count1 = count($errors);
$e = $errors[0];
$value1 = $e['message'];
print "$value1\n";
$value2 = $e['code'];
print "$value2\n";
$value3 = $e['SQLSTATE'];
print "$value3\n";
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_tinyint, c3_smallint, c4_bigint, c5_varchar) VALUES (1324944463, 105, 18521, 2022363960, 'üv£ª©*@*rãCaC|/ä*,,@ý©bvªäîCUBão_+ßZhUªî¢~ÖÜ/ª@ä+ßßar~Özr,aß/,bCaü<ÖÐhÐbß<î/ðzãý+bÜ:Zßöüª@BÖUß<U@¢Ö<hÖhubÄrÐÃ*.å|a/,ª¢ßOa@oubýãýý£îZ~,ä¢î|+ª¢rZUCrOu,B£åß|:£ªîoBärÐA/BzOoß<bvu~ßuîCãߢ¢îýA@aðuAa,UÐ.>Ußaåab|¢ª¢|ü£/ÃßzzuªãA.ªZUöß<©a>OzübBüÜ|bZ./öbvß*rbö>ß©r//~ÖCÜhð¢bßz:¢Ä+_Ã__£ý£Uýh:v¢bý,©Ü£©,A:Zh>ßåvö+Ä>Ã.ßvC|:Ü*Üü*åz|b.©©üAý@uU.oOÜýAÜÐÜð©OB|rrîbU<övoUßäZÃÖ<ÄåªAÄ.Ua*ÖOªB,åîzB:ÜhövÖZhýðüC')");
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query($conn, "SET IDENTITY_INSERT $tableName OFF;");
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_tinyint, c3_smallint, c4_bigint, c5_varchar) VALUES (-1554807493, 253, -12809, -1698802997, 'ßöîÄ@v+oß+î|ruý*Ü¢ãÖ~.*ArABªßOBzUU£ßUuÜ<ðýr|b~_äaü/OÖzv.¢ä>>OÜ+¢vªzöªoB_ä+ߪrÜö£>U~ãÖð~ðýur,ÖvZh¢ªZ>vªUäåîz,>ÃräðäýðO_ä*a,ö+üÐß~bÃü¢<<+îýÐöäªO/zA+:îZ,öBÐü<î£îåhBÖzßÄ~,:>bð<~aÐãö¢*¢våvÃÐåî@a<vBãßÖä媢<üa.u:>_Äu£öa~våu>¢Bã©å:Aßã£Üvåö+aä£U<bUu*rv+@U_|ð@+v@Üßb|,.ªäÖ/*êýÄ¢¢Ö/+ä><¢b@|zbãÖ@ÃãUb|ÄB£©,~ßð©ðUßöZÜöî£Zz<>åäZßð©ßaÖÖ¢bð£ßÄ>îÃÃ.~z>h_ý~ÜrüÖBruß+ª©CB©O>rå,Chro,£ßbZ_ß©,ÃUu|ßåüÄ/ý*åu|~Ö.ßZUoä:~A~CZhðU|öZ:ä/£Ä*î©ÄhävhbrzîÐ@.rãß©@uÜ©~>ÖÜööCÄzÜCü+>oZÄÜ/ABßA_b|b¢bÜh<|uBr.B*rü>aCª|AÄ©@öÖßÖ~Ö<rÐ,ä@©|££.C.üå¢/rbªßî')");
$errors = sqlsrv_errors(SQLSRV_ERR_ALL);
$count1 = count($errors);
$e = $errors[0];
$value1 = $e['message'];
print "$value1\n";
$value2 = $e['code'];
print "$value2\n";
$value3 = $e['SQLSTATE'];
print "$value3\n";
$noExpectedRows++;
$stmt = sqlsrv_query($conn, "SET IDENTITY_INSERT $tableName ON;INSERT INTO $tableName (c1_int, c2_tinyint, c3_smallint, c4_bigint, c5_varchar) VALUES (1994559593, 129, -8455, -236232445, 'ߣ*ÐO+ö+<ã:>üoîzÄ¢zz~Ãýö|vUå>|CÄUü~>buÃv<ä~Ö+.ü*ªbuî_bBC©.oîCbåîÐÖUa~/U>öAäÐBu~ozîZ/zrOOä:ß©bßo.ü©A¢höÖoßÖü>r+A/ßaªrß:ª@|bhhªª/oå<Ö:rüa+oC¢~uÄü>/.ãbOöª_b@bbߢ|uzߪ֢~uäýub©ãaZäC£ÄrÖ,üöäu+Ãîö|||,U.BråãoýbüåöÃburöoî+>öä©î,u_öb©@C:ÜåÜîÜåAÖzýbð|Z<Ãý.£rîZ|/z@¢£AýZ,ßuZ*:b.AzТä¢üßöbvbväð|<**~Uv.Ð*Ä©B*ýCUöa¢åO©Ãß*ÃÃ|ÜðA@îÃßaB<hÜîaZoöå>öüahUUA+ߣ_u|~äö.©hr£oBo<äãüO+_å<OЪÖßßväzA,~u~Obbî@ßÃãÜää©,.bO:C£Ü,äUO¢åå**hÐ~UZ©ðh<abß*üÖîC.äßh~Uð<r*ßäv£î*@¢Cv/BÖhAüB~ýAå@Z@<a_O|<©ßb*CZO,o:ã+¢£ÃZC©B¢o+>O:Z~Üoîßzb£ª£A.AÖÜÄ._O_å£ß');SET IDENTITY_INSERT $tableName OFF;");
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query($conn, "SET IDENTITY_INSERT $tableName ON;INSERT INTO $tableName (c1_int, c2_tinyint, c3_smallint, c4_bigint, c5_varchar) VALUES (1994559593, 129, -8455, -236232445, 'ߣ*ÐO+ö+<ã:>üoîzÄ¢zz~Ãýö|vUå>|CÄUü~>buÃv<ä~Ö+.ü*ªbuî_bBC©.oîCbåîÐÖUa~/U>öAäÐBu~ozîZ/zrOOä:ß©bßo.ü©A¢höÖoßÖü>r+A/ßaªrß:ª@|bhhªª/oå<Ö:rüa+oC¢~uÄü>/.ãbOöª_b@bbߢ|uzߪ֢~uäýub©ãaZäC£ÄrÖ,üöäu+Ãîö|||,U.BråãoýbüåöÃburöoî+>öä©î,u_öb©@C:ÜåÜîÜåAÖzýbð|Z<Ãý.£rîZ|/z@¢£AýZ,ßuZ*:b.AzТä¢üßöbvbväð|<**~Uv.Ð*Ä©B*ýCUöa¢åO©Ãß*ÃÃ|ÜðA@îÃßaB<hÜîaZoöå>öüahUUA+ߣ_u|~äö.©hr£oBo<äãüO+_å<OЪÖßßväzA,~u~Obbî@ßÃãÜää©,.bO:C£Ü,äUO¢åå**hÐ~UZ©ðh<abß*üÖîC.äßh~Uð<r*ßäv£î*@¢Cv/BÖhAüB~ýAå@Z@<a_O|<©ßb*CZO,o:ã+¢£ÃZC©B¢o+>O:Z~Üoîßzb£ª£A.AÖÜÄ._O_å£ß');SET IDENTITY_INSERT $tableName OFF;");
sqlsrv_free_stmt($stmt);
echo "Number of rows inserted: $noExpectedRows\n";
$stmt = sqlsrv_query($conn, "SELECT * FROM $tableName");
while ($result = sqlsrv_fetch($stmt))
{
$stmt = sqlsrv_query($conn, "SELECT * FROM $tableName");
while ($result = sqlsrv_fetch($stmt)) {
$noActualRows++;
}
sqlsrv_free_stmt($stmt);
sqlsrv_free_stmt($stmt);
echo "Number of rows fetched: $noActualRows\n";
if ($noActualRows != $noExpectedRows)
{
if ($noActualRows != $noExpectedRows) {
echo("Number of rows does not match expected value\n");
}
sqlsrv_close($conn);
sqlsrv_close($conn);
}
//--------------------------------------------------------------------
@ -70,19 +69,16 @@ function ComplexQuery()
//--------------------------------------------------------------------
function Repro()
{
StartTest("sqlsrv_statement_complex_query");
startTest("sqlsrv_statement_complex_query");
echo "\nTest begins...\n";
try
{
try {
ComplexQuery();
}
catch (Exception $e)
{
} catch (Exception $e) {
echo $e->getMessage();
}
echo "\nDone\n";
EndTest("sqlsrv_statement_complex_query");
endTest("sqlsrv_statement_complex_query");
}
Repro();

View file

@ -3,136 +3,134 @@ sqlsrv_configure.
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
<?php
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
sqlsrv_configure('WarningsReturnAsErrors', 0);
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
// test negative cases first
// must have two parameters
$result = sqlsrv_configure( "WarningsReturnAsErrors" );
if( $result ) {
FatalError( "sqlsrv_configure(1) should have failed." );
$result = sqlsrv_configure("WarningsReturnAsErrors");
if ($result) {
fatalError("sqlsrv_configure(1) should have failed.");
}
// warnings_return_as_errors the only supported option
$result = sqlsrv_configure( "blahblahblah", 1 );
if( $result ) {
FatalError( "sqlsrv_configure(2) should have failed." );
}
else {
print_r( sqlsrv_errors() );
}
$result = sqlsrv_get_config( 'blahblahblah' );
if( !$result && !sqlsrv_errors() ) {
FatalError( "sqlsrv_get_config should have failed." );
}
else {
print_r( sqlsrv_errors() );
$result = sqlsrv_configure("blahblahblah", 1);
if ($result) {
fatalError("sqlsrv_configure(2) should have failed.");
} else {
print_r(sqlsrv_errors());
}
$result = sqlsrv_configure( "WarningsReturnAsErrors", True );
if( !$result || sqlsrv_get_config( "WarningsReturnAsErrors" ) == false ) {
FatalError( "sqlsrv_configure(3) should have passed" );
}
$result = sqlsrv_configure( "WarningsReturnAsErrors", False );
if( !$result || sqlsrv_get_config( "WarningsReturnAsErrors" ) == true ) {
FatalError( "sqlsrv_configure(4) should have passed" );
}
$result = sqlsrv_configure( "WarningsReturnAsErrors", 1 );
if( !$result || sqlsrv_get_config( "WarningsReturnAsErrors" ) == false ) {
FatalError( "sqlsrv_configure(5) should have passed" );
}
$result = sqlsrv_configure( "WarningsReturnAsErrors", 0 );
if( !$result || sqlsrv_get_config( "WarningsReturnAsErrors" ) == true ) {
FatalError( "sqlsrv_configure(6) should have passed" );
}
$result = sqlsrv_configure( "WarningsReturnAsErrors", null );
if( !$result || sqlsrv_get_config( "WarningsReturnAsErrors" ) == true ) {
FatalError( "sqlsrv_configure(7) should have passed" );
$result = sqlsrv_get_config('blahblahblah');
if (!$result && !sqlsrv_errors()) {
fatalError("sqlsrv_get_config should have failed.");
} else {
print_r(sqlsrv_errors());
}
$result = sqlsrv_configure( "WarningsReturnAsErrors", "1" );
if( !$result || sqlsrv_get_config( "WarningsReturnAsErrors" ) == false ) {
FatalError( "sqlsrv_configure(8) should have passed" );
$result = sqlsrv_configure("WarningsReturnAsErrors", true);
if (!$result || sqlsrv_get_config("WarningsReturnAsErrors") == false) {
fatalError("sqlsrv_configure(3) should have passed");
}
$result = sqlsrv_configure( "WarningsReturnAsErrors", "0" );
if( !$result || sqlsrv_get_config( "WarningsReturnAsErrors" ) == true ) {
FatalError( "sqlsrv_configure(9) should have passed" );
$result = sqlsrv_configure("WarningsReturnAsErrors", false);
if (!$result || sqlsrv_get_config("WarningsReturnAsErrors") == true) {
fatalError("sqlsrv_configure(4) should have passed");
}
$result = sqlsrv_configure("WarningsReturnAsErrors", 1);
if (!$result || sqlsrv_get_config("WarningsReturnAsErrors") == false) {
fatalError("sqlsrv_configure(5) should have passed");
}
$result = sqlsrv_configure("WarningsReturnAsErrors", 0);
if (!$result || sqlsrv_get_config("WarningsReturnAsErrors") == true) {
fatalError("sqlsrv_configure(6) should have passed");
}
$result = sqlsrv_configure("WarningsReturnAsErrors", null);
if (!$result || sqlsrv_get_config("WarningsReturnAsErrors") == true) {
fatalError("sqlsrv_configure(7) should have passed");
}
$result = sqlsrv_configure("WarningsReturnAsErrors", "1");
if (!$result || sqlsrv_get_config("WarningsReturnAsErrors") == false) {
fatalError("sqlsrv_configure(8) should have passed");
}
$result = sqlsrv_configure("WarningsReturnAsErrors", "0");
if (!$result || sqlsrv_get_config("WarningsReturnAsErrors") == true) {
fatalError("sqlsrv_configure(9) should have passed");
}
// test values for LogSystem and LogSeverity
$result = sqlsrv_configure( "LogSeverity", SQLSRV_LOG_SEVERITY_ALL );
if( !$result ) {
FatalError( "sqlsrv_configure(10) should have passed." );
$result = sqlsrv_configure("LogSeverity", SQLSRV_LOG_SEVERITY_ALL);
if (!$result) {
fatalError("sqlsrv_configure(10) should have passed.");
}
$result = sqlsrv_configure( "LogSeverity", 0 );
if( $result ) {
FatalError( "sqlsrv_configure(11) should not have passed." );
$result = sqlsrv_configure("LogSeverity", 0);
if ($result) {
fatalError("sqlsrv_configure(11) should not have passed.");
}
$result = sqlsrv_configure( "LogSeverity", SQLSRV_LOG_SEVERITY_ERROR );
if( !$result ) {
FatalError( "sqlsrv_configure(12) should have passed." );
$result = sqlsrv_configure("LogSeverity", SQLSRV_LOG_SEVERITY_ERROR);
if (!$result) {
fatalError("sqlsrv_configure(12) should have passed.");
}
$result = sqlsrv_configure( "LogSeverity", SQLSRV_LOG_SEVERITY_WARNING );
if( !$result ) {
FatalError( "sqlsrv_configure(13) should have passed." );
$result = sqlsrv_configure("LogSeverity", SQLSRV_LOG_SEVERITY_WARNING);
if (!$result) {
fatalError("sqlsrv_configure(13) should have passed.");
}
$result = sqlsrv_configure( "LogSeverity", SQLSRV_LOG_SEVERITY_NOTICE );
if( !$result ) {
FatalError( "sqlsrv_configure(14) should have passed." );
$result = sqlsrv_configure("LogSeverity", SQLSRV_LOG_SEVERITY_NOTICE);
if (!$result) {
fatalError("sqlsrv_configure(14) should have passed.");
}
$result = sqlsrv_configure( "LogSeverity", 1000 );
if( $result ) {
FatalError( "sqlsrv_configure(15) should not have passed." );
$result = sqlsrv_configure("LogSeverity", 1000);
if ($result) {
fatalError("sqlsrv_configure(15) should not have passed.");
}
sqlsrv_configure( "LogSeverity", SQLSRV_LOG_SEVERITY_ALL );
sqlsrv_configure("LogSeverity", SQLSRV_LOG_SEVERITY_ALL);
$result = sqlsrv_configure( "LogSubsystems", SQLSRV_LOG_SYSTEM_ALL );
if( !$result ) {
FatalError( "sqlsrv_configure(16) should have passed." );
$result = sqlsrv_configure("LogSubsystems", SQLSRV_LOG_SYSTEM_ALL);
if (!$result) {
fatalError("sqlsrv_configure(16) should have passed.");
}
$result = sqlsrv_configure( "LogSubsystems", SQLSRV_LOG_SYSTEM_OFF );
if( !$result ) {
FatalError( "sqlsrv_configure(17) should not have passed." );
$result = sqlsrv_configure("LogSubsystems", SQLSRV_LOG_SYSTEM_OFF);
if (!$result) {
fatalError("sqlsrv_configure(17) should not have passed.");
}
$result = sqlsrv_configure( "LogSubsystems", SQLSRV_LOG_SYSTEM_INIT );
if( !$result ) {
FatalError( "sqlsrv_configure(18) should have passed." );
$result = sqlsrv_configure("LogSubsystems", SQLSRV_LOG_SYSTEM_INIT);
if (!$result) {
fatalError("sqlsrv_configure(18) should have passed.");
}
$result = sqlsrv_configure( "LogSubsystems", SQLSRV_LOG_SYSTEM_CONN );
if( !$result ) {
FatalError( "sqlsrv_configure(19) should have passed." );
$result = sqlsrv_configure("LogSubsystems", SQLSRV_LOG_SYSTEM_CONN);
if (!$result) {
fatalError("sqlsrv_configure(19) should have passed.");
}
$result = sqlsrv_configure( "LogSubsystems", SQLSRV_LOG_SYSTEM_STMT );
if( !$result ) {
FatalError( "sqlsrv_configure(20) should have passed." );
$result = sqlsrv_configure("LogSubsystems", SQLSRV_LOG_SYSTEM_STMT);
if (!$result) {
fatalError("sqlsrv_configure(20) should have passed.");
}
$result = sqlsrv_configure( "LogSubsystems", SQLSRV_LOG_SYSTEM_UTIL );
if( !$result ) {
FatalError( "sqlsrv_configure(21) should have passed." );
$result = sqlsrv_configure("LogSubsystems", SQLSRV_LOG_SYSTEM_UTIL);
if (!$result) {
fatalError("sqlsrv_configure(21) should have passed.");
}
$result = sqlsrv_configure( "LogSubsystems", 1000 );
if( $result ) {
FatalError( "sqlsrv_configure(22) should not have passed." );
$result = sqlsrv_configure("LogSubsystems", 1000);
if ($result) {
fatalError("sqlsrv_configure(22) should not have passed.");
}
?>
@ -167,4 +165,4 @@ Array
sqlsrv.LogSubsystems = -1
sqlsrv_configure: entering
sqlsrv.LogSubsystems = 8
sqlsrv_configure: entering
sqlsrv_configure: entering

View file

@ -1,115 +1,115 @@
--TEST--
sqlsrv_configure to test logs.
sqlsrv_configure to test logs.
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
<?php
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
sqlsrv_configure( 'LogSubsystems', SQLSRV_LOG_SYSTEM_ALL );
sqlsrv_configure('WarningsReturnAsErrors', 0);
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
sqlsrv_configure('LogSubsystems', SQLSRV_LOG_SYSTEM_ALL);
$result = sqlsrv_configure( "WarningsReturnAsErrors", True );
if( !$result || sqlsrv_get_config( "WarningsReturnAsErrors" ) == false ) {
FatalError( "sqlsrv_configure(3) should have passed" );
}
$result = sqlsrv_configure( "WarningsReturnAsErrors", False );
if( !$result || sqlsrv_get_config( "WarningsReturnAsErrors" ) == true ) {
FatalError( "sqlsrv_configure(4) should have passed" );
}
$result = sqlsrv_configure( "WarningsReturnAsErrors", 1 );
if( !$result || sqlsrv_get_config( "WarningsReturnAsErrors" ) == false ) {
FatalError( "sqlsrv_configure(5) should have passed" );
}
$result = sqlsrv_configure( "WarningsReturnAsErrors", 0 );
if( !$result || sqlsrv_get_config( "WarningsReturnAsErrors" ) == true ) {
FatalError( "sqlsrv_configure(6) should have passed" );
}
$result = sqlsrv_configure( "WarningsReturnAsErrors", null );
if( !$result || sqlsrv_get_config( "WarningsReturnAsErrors" ) == true ) {
FatalError( "sqlsrv_configure(7) should have passed" );
$result = sqlsrv_configure("WarningsReturnAsErrors", true);
if (!$result || sqlsrv_get_config("WarningsReturnAsErrors") == false) {
fatalError("sqlsrv_configure(3) should have passed");
}
$result = sqlsrv_configure( "WarningsReturnAsErrors", "1" );
if( !$result || sqlsrv_get_config( "WarningsReturnAsErrors" ) == false ) {
FatalError( "sqlsrv_configure(8) should have passed" );
$result = sqlsrv_configure("WarningsReturnAsErrors", false);
if (!$result || sqlsrv_get_config("WarningsReturnAsErrors") == true) {
fatalError("sqlsrv_configure(4) should have passed");
}
$result = sqlsrv_configure( "WarningsReturnAsErrors", "0" );
if( !$result || sqlsrv_get_config( "WarningsReturnAsErrors" ) == true ) {
FatalError( "sqlsrv_configure(9) should have passed" );
$result = sqlsrv_configure("WarningsReturnAsErrors", 1);
if (!$result || sqlsrv_get_config("WarningsReturnAsErrors") == false) {
fatalError("sqlsrv_configure(5) should have passed");
}
$result = sqlsrv_configure("WarningsReturnAsErrors", 0);
if (!$result || sqlsrv_get_config("WarningsReturnAsErrors") == true) {
fatalError("sqlsrv_configure(6) should have passed");
}
$result = sqlsrv_configure("WarningsReturnAsErrors", null);
if (!$result || sqlsrv_get_config("WarningsReturnAsErrors") == true) {
fatalError("sqlsrv_configure(7) should have passed");
}
$result = sqlsrv_configure("WarningsReturnAsErrors", "1");
if (!$result || sqlsrv_get_config("WarningsReturnAsErrors") == false) {
fatalError("sqlsrv_configure(8) should have passed");
}
$result = sqlsrv_configure("WarningsReturnAsErrors", "0");
if (!$result || sqlsrv_get_config("WarningsReturnAsErrors") == true) {
fatalError("sqlsrv_configure(9) should have passed");
}
// test values for LogSystem and LogSeverity
$result = sqlsrv_configure( "LogSeverity", SQLSRV_LOG_SEVERITY_ALL );
if( !$result ) {
FatalError( "sqlsrv_configure(10) should have passed." );
$result = sqlsrv_configure("LogSeverity", SQLSRV_LOG_SEVERITY_ALL);
if (!$result) {
fatalError("sqlsrv_configure(10) should have passed.");
}
$result = sqlsrv_configure( "LogSeverity", 0 );
if( $result ) {
FatalError( "sqlsrv_configure(11) should not have passed." );
$result = sqlsrv_configure("LogSeverity", 0);
if ($result) {
fatalError("sqlsrv_configure(11) should not have passed.");
}
$result = sqlsrv_configure( "LogSeverity", SQLSRV_LOG_SEVERITY_ERROR );
if( !$result ) {
FatalError( "sqlsrv_configure(12) should have passed." );
$result = sqlsrv_configure("LogSeverity", SQLSRV_LOG_SEVERITY_ERROR);
if (!$result) {
fatalError("sqlsrv_configure(12) should have passed.");
}
$result = sqlsrv_configure( "LogSeverity", SQLSRV_LOG_SEVERITY_WARNING );
if( !$result ) {
FatalError( "sqlsrv_configure(13) should have passed." );
$result = sqlsrv_configure("LogSeverity", SQLSRV_LOG_SEVERITY_WARNING);
if (!$result) {
fatalError("sqlsrv_configure(13) should have passed.");
}
$result = sqlsrv_configure( "LogSeverity", SQLSRV_LOG_SEVERITY_NOTICE );
if( !$result ) {
FatalError( "sqlsrv_configure(14) should have passed." );
$result = sqlsrv_configure("LogSeverity", SQLSRV_LOG_SEVERITY_NOTICE);
if (!$result) {
fatalError("sqlsrv_configure(14) should have passed.");
}
$result = sqlsrv_configure( "LogSeverity", 1000 );
if( $result ) {
FatalError( "sqlsrv_configure(15) should not have passed." );
$result = sqlsrv_configure("LogSeverity", 1000);
if ($result) {
fatalError("sqlsrv_configure(15) should not have passed.");
}
sqlsrv_configure( "LogSeverity", SQLSRV_LOG_SEVERITY_ALL );
sqlsrv_configure("LogSeverity", SQLSRV_LOG_SEVERITY_ALL);
$result = sqlsrv_configure( "LogSubsystems", SQLSRV_LOG_SYSTEM_ALL );
if( !$result ) {
FatalError( "sqlsrv_configure(16) should have passed." );
$result = sqlsrv_configure("LogSubsystems", SQLSRV_LOG_SYSTEM_ALL);
if (!$result) {
fatalError("sqlsrv_configure(16) should have passed.");
}
$result = sqlsrv_configure( "LogSubsystems", SQLSRV_LOG_SYSTEM_OFF );
if( !$result ) {
FatalError( "sqlsrv_configure(17) should not have passed." );
$result = sqlsrv_configure("LogSubsystems", SQLSRV_LOG_SYSTEM_OFF);
if (!$result) {
fatalError("sqlsrv_configure(17) should not have passed.");
}
$result = sqlsrv_configure( "LogSubsystems", SQLSRV_LOG_SYSTEM_INIT );
if( !$result ) {
FatalError( "sqlsrv_configure(18) should have passed." );
$result = sqlsrv_configure("LogSubsystems", SQLSRV_LOG_SYSTEM_INIT);
if (!$result) {
fatalError("sqlsrv_configure(18) should have passed.");
}
$result = sqlsrv_configure( "LogSubsystems", SQLSRV_LOG_SYSTEM_CONN );
if( !$result ) {
FatalError( "sqlsrv_configure(19) should have passed." );
$result = sqlsrv_configure("LogSubsystems", SQLSRV_LOG_SYSTEM_CONN);
if (!$result) {
fatalError("sqlsrv_configure(19) should have passed.");
}
$result = sqlsrv_configure( "LogSubsystems", SQLSRV_LOG_SYSTEM_STMT );
if( !$result ) {
FatalError( "sqlsrv_configure(20) should have passed." );
$result = sqlsrv_configure("LogSubsystems", SQLSRV_LOG_SYSTEM_STMT);
if (!$result) {
fatalError("sqlsrv_configure(20) should have passed.");
}
$result = sqlsrv_configure( "LogSubsystems", SQLSRV_LOG_SYSTEM_UTIL );
if( !$result ) {
FatalError( "sqlsrv_configure(21) should have passed." );
$result = sqlsrv_configure("LogSubsystems", SQLSRV_LOG_SYSTEM_UTIL);
if (!$result) {
fatalError("sqlsrv_configure(21) should have passed.");
}
$result = sqlsrv_configure( "LogSubsystems", 1000 );
if( $result ) {
FatalError( "sqlsrv_configure(22) should not have passed." );
$result = sqlsrv_configure("LogSubsystems", 1000);
if ($result) {
fatalError("sqlsrv_configure(22) should not have passed.");
}
?>
@ -148,4 +148,4 @@ sqlsrv_configure: entering
sqlsrv.LogSubsystems = -1
sqlsrv_configure: entering
sqlsrv.LogSubsystems = 8
sqlsrv_configure: entering
sqlsrv_configure: entering

View file

@ -5,8 +5,11 @@ UTF-8 connection strings
--FILE--
<?php
function connect($options=array()) {
require 'MsSetup.inc';
require_once('MsSetup.inc');
function connect($options=array())
{
global $server, $uid, $pwd, $databaseName;
if (!isset($options['UID']) && !isset($options['uid'])) {
$options['uid'] = $uid;
}
@ -14,67 +17,67 @@ function connect($options=array()) {
$options['pwd'] = $pwd;
}
if (!isset($options['Database'])) {
$options['database'] = $databaseName;
$options['database'] = $databaseName;
}
return sqlsrv_connect($server, $options);
}
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
sqlsrv_configure('WarningsReturnAsErrors', 0);
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
// test an invalid encoding
$c = connect(array( 'CharacterSet' => 'gibberish' ));
if( $c !== false ) {
FatalError( "Should have errored on an invalid encoding." );
if ($c !== false) {
fatalError("Should have errored on an invalid encoding.");
}
print_r( sqlsrv_errors() );
print_r(sqlsrv_errors());
$c = Connect(array( 'CharacterSet' => SQLSRV_ENC_BINARY ));
if( $c !== false ) {
FatalError( "Should have errored on an invalid encoding." );
$c = connect(array( 'CharacterSet' => SQLSRV_ENC_BINARY ));
if ($c !== false) {
fatalError("Should have errored on an invalid encoding.");
}
print_r( sqlsrv_errors() );
print_r(sqlsrv_errors());
$c = Connect(array( 'CharacterSet' => SQLSRV_ENC_CHAR ));
if( $c === false ) {
die( print_r( sqlsrv_errors(), true ));
$c = connect(array( 'CharacterSet' => SQLSRV_ENC_CHAR ));
if ($c === false) {
die(print_r(sqlsrv_errors(), true));
}
sqlsrv_close( $c );
sqlsrv_close($c);
// test an invalid server name in UTF-8
$server_invalid = pack( "H*", "ffc0" );
$c = sqlsrv_connect( $server_invalid, array( 'Database' => 'test', 'CharacterSet' => 'utf-8' ));
if( $c !== false ) {
FatalError( "sqlsrv_connect(1) should have failed" );
$server_invalid = pack("H*", "ffc0");
$c = sqlsrv_connect($server_invalid, array( 'Database' => 'test', 'CharacterSet' => 'utf-8' ));
if ($c !== false) {
fatalError("sqlsrv_connect(1) should have failed");
}
print_r( sqlsrv_errors() );
print_r(sqlsrv_errors());
// APP has a UTF-8 name
$c = Connect(array(
'App' => pack( 'H*', 'c59ec6a1d0bcc49720c59bc3a4e1839dd180c580e1bb8120ce86c59ac488c4a8c4b02dc5a5e284aec397c5a7' ),
$c = connect(array(
'App' => pack('H*', 'c59ec6a1d0bcc49720c59bc3a4e1839dd180c580e1bb8120ce86c59ac488c4a8c4b02dc5a5e284aec397c5a7'),
'CharacterSet' => 'utf-8' ));
if( $c === false ) {
die( print_r( sqlsrv_errors(), true ));
if ($c === false) {
die(print_r(sqlsrv_errors(), true));
}
$c = Connect(array(
'UID' => pack( 'H*', 'c59ec6a1d0bcc49720c59bc3a4e1839dd180c580e1bb8120ce86c59ac488c4a8c4b02dc5a5e284aec397c5a7' ),
'PWD' => pack( 'H*', 'c59ec6a1d0bcc49720c59bc3a4e1839dd180c580e1bb8120ce86c59ac488c4a8c4b02dc5a5e284aec397c5a7' ),
$c = connect(array(
'UID' => pack('H*', 'c59ec6a1d0bcc49720c59bc3a4e1839dd180c580e1bb8120ce86c59ac488c4a8c4b02dc5a5e284aec397c5a7'),
'PWD' => pack('H*', 'c59ec6a1d0bcc49720c59bc3a4e1839dd180c580e1bb8120ce86c59ac488c4a8c4b02dc5a5e284aec397c5a7'),
'CharacterSet' => 'utf-8' ));
if( $c !== false ) {
FatalError( "sqlsrv_connect(3) should have failed" );
if ($c !== false) {
fatalError("sqlsrv_connect(3) should have failed");
}
print_r( sqlsrv_errors() );
print_r(sqlsrv_errors());
// invalid UTF-8 in the pwd
$c = Connect(array(
'UID' => pack( 'H*', 'c59ec6a1d0bcc49720c59bc3a4e1839dd180c580e1bb8120ce86c59ac488c4a8c4b02dc5a5e284aec397c5a7' ),
'PWD' => pack( 'H*', 'c59ec6c0d0bcc49720c59bc3a4e1839dd180c580e1bb8120ce86c59ac488c4a8c4b02dc5a5e284aec397c5a7' ),
$c = connect(array(
'UID' => pack('H*', 'c59ec6a1d0bcc49720c59bc3a4e1839dd180c580e1bb8120ce86c59ac488c4a8c4b02dc5a5e284aec397c5a7'),
'PWD' => pack('H*', 'c59ec6c0d0bcc49720c59bc3a4e1839dd180c580e1bb8120ce86c59ac488c4a8c4b02dc5a5e284aec397c5a7'),
'CharacterSet' => 'utf-8' ));
if( $c !== false ) {
FatalError( "sqlsrv_connect(4) should have failed" );
if ($c !== false) {
fatalError("sqlsrv_connect(4) should have failed");
}
print_r( sqlsrv_errors() );
print_r(sqlsrv_errors());
echo "Test succeeded.\n";

View file

@ -4,32 +4,32 @@ functions return FALSE for errors.
<?php require('skipif.inc'); ?>
--FILE--
<?php
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
sqlsrv_configure('WarningsReturnAsErrors', 0);
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
require( 'MsSetup.inc' );
require_once('MsSetup.inc');
$conn = sqlsrv_connect( "_!@)(#" );
if( $conn !== false ) {
FatalError( "sqlsrv_connect should have returned false." );
$conn = sqlsrv_connect("_!@)(#");
if ($conn !== false) {
fatalError("sqlsrv_connect should have returned false.");
}
$conn = sqlsrv_connect( "_!@#$", array( "Driver" => "Danica Patrick" ));
if( $conn !== false ) {
FatalError( "sqlsrv_connect should have returned false." );
$conn = sqlsrv_connect("_!@#$", array( "Driver" => "Danica Patrick" ));
if ($conn !== false) {
fatalError("sqlsrv_connect should have returned false.");
}
$conn = sqlsrv_connect( $server, array( "uid" => $uid , "pwd" => $pwd ) );
if( $conn === false ) {
FatalError( "sqlsrv_connect should have connected." );
$conn = sqlsrv_connect($server, array( "uid" => $uid , "pwd" => $pwd ));
if ($conn === false) {
fatalError("sqlsrv_connect should have connected.");
}
$stmt = sqlsrv_query( $conn, "SELECT * FROM some_bogus_table" );
if( $stmt !== false ) {
FatalError( "sqlsrv_query should have returned false." );
$stmt = sqlsrv_query($conn, "SELECT * FROM some_bogus_table");
if ($stmt !== false) {
fatalError("sqlsrv_query should have returned false.");
}
echo "Test successful.\n";
?>
--EXPECT--

Some files were not shown because too many files have changed in this diff Show more