first set of sqlsrv functional tests
This commit is contained in:
parent
9b930973f2
commit
60f7fe024d
|
@ -31,13 +31,11 @@ def executeSQLscriptUnix(sqlfile, conn_options, dbname):
|
|||
redirect_string = '(echo :setvar dbname {0}) > {2}; cat {1} >> {2}; '
|
||||
sqlcmd = 'sqlcmd ' + conn_options + ' -i ' + tmpFileName
|
||||
|
||||
# this step seems necessary in travis CI
|
||||
show_cmd = 'sqlcmd ' + conn_options + ' -Q \"select @@Version\" '
|
||||
executeCommmand(show_cmd)
|
||||
# Execute a simple query via sqlcmd: without this step, the next step fails in travis CI
|
||||
simple_cmd = 'sqlcmd ' + conn_options + ' -Q \"select @@Version\" '
|
||||
executeCommmand(simple_cmd)
|
||||
|
||||
inst_command = redirect_string.format(dbname, sqlfile, tmpFileName) + sqlcmd
|
||||
#inst_command = redirect_string.format(dbname, sqlfile, tmpFileName)
|
||||
executeCommmand(inst_command)
|
||||
#executeCommmand(sqlcmd)
|
||||
|
||||
os.remove(tmpFileName)
|
||||
|
|
29
test/sqlsrv/0013.phpt
Normal file
29
test/sqlsrv/0013.phpt
Normal file
|
@ -0,0 +1,29 @@
|
|||
--TEST--
|
||||
A test for a simple query
|
||||
--SKIPIF--
|
||||
<?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");
|
||||
}
|
||||
$stmt = sqlsrv_query($conn, "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/>
|
108
test/sqlsrv/0020.phpt
Normal file
108
test/sqlsrv/0020.phpt
Normal file
|
@ -0,0 +1,108 @@
|
|||
--TEST--
|
||||
reading streams of various types with a base64 decoding filter on top of them.
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
sqlsrv_configure( 'WarningsReturnAsErrors', false );
|
||||
require( 'MsCommon.inc' );
|
||||
|
||||
function RunTest( $field_type ) {
|
||||
|
||||
PrepareParams($params);
|
||||
$tableName = "dbo.B64TestTable";
|
||||
$params['fieldType'] = $field_type;
|
||||
|
||||
($conn = Connect())
|
||||
|| die(print_r(sqlsrv_errors(), true));
|
||||
|
||||
$originalStream = PopulateTestTable($conn, $params);
|
||||
|
||||
($stmt = sqlsrv_query($conn, $params['selectQuery']))
|
||||
|| die(print_r(sqlsrv_errors(), true));
|
||||
|
||||
sqlsrv_fetch($stmt)
|
||||
|| die(print_r(sqlsrv_errors(), true));
|
||||
|
||||
($stream = sqlsrv_get_field($stmt, 0, SQLSRV_PHPTYPE_STREAM("char")))
|
||||
|| die(print_r(sqlsrv_errors(), true));
|
||||
|
||||
stream_filter_append($originalStream, "convert.base64-encode")
|
||||
|| die(print_r(error_get_last()));
|
||||
|
||||
while (($originalLine = fread($originalStream, 80)) &&
|
||||
($dbLine = fread($stream, 80))) {
|
||||
if( $originalLine != $dbLine )
|
||||
die( "Not identical" );
|
||||
}
|
||||
|
||||
sqlsrv_free_stmt($stmt) || die(print_r(sqlsrv_errors(), true));
|
||||
|
||||
sqlsrv_close($conn) || die(print_r(sqlsrv_errors(), true));
|
||||
}
|
||||
|
||||
RunTest( "varchar(max)" );
|
||||
RunTest( "varbinary(max)" );
|
||||
RunTest( "nvarchar(max)" );
|
||||
|
||||
echo "Test successful.\n";
|
||||
|
||||
function PopulateTestTable($conn, $params) {
|
||||
|
||||
DropTestTable($conn, $params);
|
||||
CreateTestTable($conn, $params);
|
||||
|
||||
($data = fopen($params['testImageURL'], "rb")) || die("Couldn't open image for reading.");
|
||||
|
||||
stream_filter_append($data, "convert.base64-encode")
|
||||
|| die(print_r(error_get_last(), true));
|
||||
|
||||
if ($stmt = sqlsrv_query($conn, $params['insertQuery'], array($data))) {
|
||||
do {
|
||||
$read = sqlsrv_send_stream_data($stmt);
|
||||
if ($read === false) die(print_r(sqlsrv_errors(), true));
|
||||
} while ($read);
|
||||
|
||||
fclose($data) || die(print_r(error_get_last(), true));
|
||||
|
||||
sqlsrv_free_stmt($stmt) || die(print_r(sqlsrv_errors(), true));
|
||||
} else
|
||||
die(print_r(sqlsrv_errors(), true));
|
||||
|
||||
return fopen($params['testImageURL'], "rb");
|
||||
}
|
||||
|
||||
function PrepareParams(&$arr) {
|
||||
$uname = php_uname();
|
||||
$phpgif = "\\php.gif";
|
||||
if (preg_match('/Win/',$uname))
|
||||
{
|
||||
$phpgif = '\\php.gif';
|
||||
}
|
||||
else // other than Windows
|
||||
{
|
||||
$phpgif = '/php.gif';
|
||||
}
|
||||
$arr['tableName'] = $tblName = "dbo.B64TestTable";
|
||||
$arr['columnName'] = $colName = "Base64Image";
|
||||
$arr['fieldType'] = $fieldType = "nvarchar(MAX)";
|
||||
$arr['dropQuery'] = "IF OBJECT_ID(N'$tblName', N'U') IS NOT NULL DROP TABLE $tblName";
|
||||
$arr['createQuery'] = "CREATE TABLE $tblName ($colName $fieldType)";
|
||||
$arr['insertQuery'] = "INSERT INTO $tblName ($colName) VALUES (?)";
|
||||
$arr['selectQuery'] = "SELECT TOP 1 $colName FROM $tblName";
|
||||
// $arr['testImageURL'] = "http://static.php.net/www.php.net/images/php.gif";
|
||||
$arr['testImageURL'] = dirname( $_SERVER['PHP_SELF'] ).$phpgif; // use this when no http access
|
||||
$arr['MIMEType'] = "image/gif";
|
||||
}
|
||||
|
||||
function DropTestTable($conn, $params) { RunQuery($conn, $params['dropQuery']); }
|
||||
function CreateTestTable($conn, $params) { RunQuery($conn, $params['createQuery']); }
|
||||
function RunQuery($conn, $query) {
|
||||
($qStmt = sqlsrv_query($conn, $query)) && $qStmt && sqlsrv_free_stmt($qStmt)
|
||||
|| die(print_r(sqlsrv_errors(), true));
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
Test successful.
|
70
test/sqlsrv/0022.phpt
Normal file
70
test/sqlsrv/0022.phpt
Normal file
|
@ -0,0 +1,70 @@
|
|||
--TEST--
|
||||
zombied streams after sqlsrv_stmt_cancel.
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
|
||||
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
|
||||
|
||||
require( 'MsCommon.inc' );
|
||||
|
||||
$conn = Connect();
|
||||
if( !$conn ) {
|
||||
var_dump( sqlsrv_errors() );
|
||||
die( "sqlsrv_connect failed." );
|
||||
}
|
||||
|
||||
$stmt = sqlsrv_query( $conn, "SELECT review1 FROM cd_info" );
|
||||
if( $stmt == false ) {
|
||||
var_dump( sqlsrv_errors() );
|
||||
die( "sqlsrv_query failed." );
|
||||
}
|
||||
|
||||
sqlsrv_fetch( $stmt );
|
||||
$stream = sqlsrv_get_field( $stmt, 0, SQLSRV_PHPTYPE_STREAM("binary"));
|
||||
while( !feof( $stream )) {
|
||||
$str = fread( $stream, 80 );
|
||||
echo "$str\n";
|
||||
}
|
||||
|
||||
sqlsrv_fetch( $stmt );
|
||||
$stream = sqlsrv_get_field( $stmt, 0, SQLSRV_PHPTYPE_STREAM("binary"));
|
||||
$str = fread( $stream, 80 );
|
||||
echo "$str\n";
|
||||
sqlsrv_cancel( $stmt );
|
||||
while( !feof( $stream ) && is_resource($stream)) {
|
||||
$str = fread( $stream, 80 );
|
||||
echo "$str\n";
|
||||
}
|
||||
sqlsrv_free_stmt( $stmt );
|
||||
|
||||
$stmt = sqlsrv_query( $conn, "SELECT review1 FROM cd_info" );
|
||||
// the fread causes a Function Sequence error in ODBC and doesn't work at all.
|
||||
sqlsrv_fetch( $stmt );
|
||||
$stream = sqlsrv_get_field( $stmt, 0, SQLSRV_PHPTYPE_STREAM("binary"));
|
||||
sqlsrv_cancel( $stmt );
|
||||
while( !feof( $stream ) && is_resource($stream) ) {
|
||||
$str = fread( $stream, 80 );
|
||||
echo "$str\n";
|
||||
}
|
||||
|
||||
sqlsrv_free_stmt( $stmt );
|
||||
sqlsrv_close( $conn );
|
||||
|
||||
?>
|
||||
--EXPECTREGEX--
|
||||
Source: Amazon.com \- As it turned out, Led Zeppelins infamous 1969 debut album w
|
||||
as indicative of the decade to come--one that, fittingly, this band helped defin
|
||||
e with its decadently exaggerated, bowdlerized blues-rock. In shrieker Robert Pl
|
||||
ant, ex-Yardbird Jimmy Page found a vocalist who could match his guitar pyrotech
|
||||
nics, and the band pounded out its music with swaggering ferocity and Richter-sc
|
||||
ale-worthy volume. Pumping up blues classics such as Otis Rushs I Cant Quit You
|
||||
Baby and Howlin Wolfs How Many More Times into near-cartoon parodies, the band a
|
||||
lso hinted at things to come with the manic Communication Breakdown and the lumb
|
||||
ering set stopper Dazed and Confused. \<I\>--Billy Altman\<\/I\>
|
||||
Source: Amazon.com essential recording - Most critics complain \<I\>Back in Black\<
|
||||
|
||||
Warning: feof\(\): supplied resource is not a valid stream resource in .+(\/|\\)0022\.php on line [0-9]+
|
||||
|
||||
Warning: feof\(\): supplied resource is not a valid stream resource in .+(\/|\\)0022\.php on line [0-9]+
|
64
test/sqlsrv/0052.phpt
Normal file
64
test/sqlsrv/0052.phpt
Normal file
|
@ -0,0 +1,64 @@
|
|||
--TEST--
|
||||
scrollable results with no rows.
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
|
||||
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
|
||||
|
||||
require( 'MsCommon.inc' );
|
||||
|
||||
$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 ));
|
||||
}
|
||||
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 ));
|
||||
}
|
||||
$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" );
|
||||
};
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
$stmt = sqlsrv_query( $conn, "DROP TABLE ScrollTest" );
|
||||
|
||||
echo "Test succeeded.\n";
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
Test succeeded.
|
66
test/sqlsrv/0053.phpt
Normal file
66
test/sqlsrv/0053.phpt
Normal file
|
@ -0,0 +1,66 @@
|
|||
--TEST--
|
||||
binding parameters, including output parameters, using the simplified syntax.
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
set_time_limit(0);
|
||||
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
|
||||
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
|
||||
|
||||
require( 'MsCommon.inc' );
|
||||
|
||||
$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 ));
|
||||
}
|
||||
|
||||
$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"
|
||||
?>
|
||||
--EXPECT--
|
||||
Test succeeded.
|
66
test/sqlsrv/0060.phpt
Normal file
66
test/sqlsrv/0060.phpt
Normal file
|
@ -0,0 +1,66 @@
|
|||
--TEST--
|
||||
binding parameters, including output parameters, using the simplified syntax.
|
||||
--SKIPIF--
|
||||
<?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( "sqlsrv_create failed." );
|
||||
}
|
||||
|
||||
$v1 = 1;
|
||||
$v2 = 2;
|
||||
$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 )));
|
||||
|
||||
$result = sqlsrv_execute( $stmt );
|
||||
if( $result === false ) {
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
while( sqlsrv_next_result( $stmt ) != null );
|
||||
echo "$v3\n";
|
||||
|
||||
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 )));
|
||||
|
||||
$result = sqlsrv_execute( $stmt );
|
||||
if( $result === false ) {
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
while( sqlsrv_next_result( $stmt ) != null );
|
||||
echo "$v3\n";
|
||||
|
||||
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)));
|
||||
|
||||
$result = sqlsrv_execute( $stmt );
|
||||
if( $result === false ) {
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
|
||||
while( sqlsrv_next_result( $stmt ) != null );
|
||||
echo "$v3\n";
|
||||
|
||||
sqlsrv_free_stmt( $stmt );
|
||||
|
||||
sqlsrv_close( $conn );
|
||||
?>
|
||||
--EXPECT--
|
||||
3
|
||||
3
|
||||
3
|
85
test/sqlsrv/0061.phpt
Normal file
85
test/sqlsrv/0061.phpt
Normal file
|
@ -0,0 +1,85 @@
|
|||
--TEST--
|
||||
maximum size for both nonunicode and unicode data types.
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--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 ));
|
||||
}
|
||||
|
||||
$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 ));
|
||||
}
|
||||
|
||||
$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_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, "DROP TABLE test_max_size" );
|
||||
|
||||
echo "Test succeeded.\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
Array
|
||||
(
|
||||
[0] => Array
|
||||
(
|
||||
[0] => IMSSP
|
||||
[SQLSTATE] => IMSSP
|
||||
[1] => -31
|
||||
[code] => -31
|
||||
[2] => An invalid size or precision for parameter 2 was specified.
|
||||
[message] => An invalid size or precision for parameter 2 was specified.
|
||||
)
|
||||
|
||||
)
|
||||
Array
|
||||
(
|
||||
[0] => Array
|
||||
(
|
||||
[0] => IMSSP
|
||||
[SQLSTATE] => IMSSP
|
||||
[1] => -31
|
||||
[code] => -31
|
||||
[2] => An invalid size or precision for parameter 2 was specified.
|
||||
[message] => An invalid size or precision for parameter 2 was specified.
|
||||
)
|
||||
|
||||
)
|
||||
Test succeeded.
|
285
test/sqlsrv/0065.phpt
Normal file
285
test/sqlsrv/0065.phpt
Normal file
|
@ -0,0 +1,285 @@
|
|||
--TEST--
|
||||
inserting and retrieving UTF-8 text.
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
|
||||
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
|
||||
|
||||
// For testing in Azure, can not switch databases
|
||||
require( 'MsCommon.inc' );
|
||||
$c = Connect();
|
||||
|
||||
if( $c === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
|
||||
$s = sqlsrv_query( $c, "IF OBJECT_ID('utf8test', 'U') IS NOT NULL DROP TABLE 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 ));
|
||||
}
|
||||
|
||||
$utf8 = "Şơмė śäოрŀề ΆŚĈĨİ-ť℮×ŧ";
|
||||
|
||||
$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 ));
|
||||
}
|
||||
|
||||
$s = sqlsrv_query( $c,
|
||||
"DROP PROCEDURE IntDoubleProc;
|
||||
DROP PROCEDURE Utf8OutProc;
|
||||
DROP PROCEDURE Utf8OutWithResultsetProc;
|
||||
DROP PROCEDURE Utf8InOutProc;
|
||||
DROP TABLE Utf8TestTable;" );
|
||||
|
||||
$create_proc = <<<PROC
|
||||
CREATE PROCEDURE Utf8OutProc
|
||||
@param nvarchar(25) OUTPUT
|
||||
AS
|
||||
BEGIN
|
||||
set @param = convert(nvarchar(25), 0x5E01A1013C04170120005B01E400DD1040044001C11E200086035A010801280130012D0065012E21D7006701);
|
||||
END;
|
||||
PROC;
|
||||
$s = sqlsrv_query( $c, $create_proc );
|
||||
if( $s === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
|
||||
$create_proc = <<<PROC
|
||||
CREATE PROCEDURE Utf8OutWithResultsetProc
|
||||
@param nvarchar(25) output
|
||||
AS
|
||||
BEGIN
|
||||
select c1, c2, c3 from utf8test
|
||||
set @param = convert(nvarchar(25), 0x5E01A1013C04170120005B01E400DD1040044001C11E200086035A010801280130012D0065012E21D7006701);
|
||||
END;
|
||||
PROC;
|
||||
$s = sqlsrv_query( $c, $create_proc );
|
||||
if( $s === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
|
||||
$create_proc = <<<PROC
|
||||
CREATE PROCEDURE Utf8InOutProc
|
||||
@param nvarchar(25) output
|
||||
AS
|
||||
BEGIN
|
||||
-- INSERT INTO utf8test (c1, c2, c3) VALUES (@param, @param, @param);
|
||||
set @param = convert(nvarchar(25), 0x6001E11EDD10130120006101E200DD1040043A01BB1E2000C5005A01C700CF0007042D006501BF1E45046301);
|
||||
END;
|
||||
PROC;
|
||||
$s = sqlsrv_query( $c, $create_proc );
|
||||
if( $s === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
|
||||
$create_proc = <<<PROC
|
||||
CREATE PROCEDURE IntDoubleProc
|
||||
@param int output
|
||||
AS
|
||||
BEGIN
|
||||
set @param = @param + @param;
|
||||
END;
|
||||
PROC;
|
||||
$s = sqlsrv_query( $c, $create_proc );
|
||||
if( $s === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
|
||||
$s = sqlsrv_query( $c, 'SELECT c1, c2, c3 FROM utf8test' );
|
||||
if( $s === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
|
||||
if( sqlsrv_fetch( $s ) === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
|
||||
$t = sqlsrv_get_field( $s, 0, SQLSRV_PHPTYPE_STRING( 'utf-8' ));
|
||||
if( $t === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
|
||||
if( $t != "So?e sä???? ?SCII-te×t" ) {
|
||||
die( "varchar(100) doesn't match So?e sä???? ?SCII-te×t" );
|
||||
}
|
||||
|
||||
$t = sqlsrv_get_field( $s, 1, SQLSRV_PHPTYPE_STRING( 'utf-8' ));
|
||||
if( $t === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
|
||||
if( $t != $utf8 ) {
|
||||
die( "nvarchar(100) doesn't match the inserted UTF-8 text." );
|
||||
}
|
||||
|
||||
$t = sqlsrv_get_field( $s, 2, SQLSRV_PHPTYPE_STRING( 'utf-8' ));
|
||||
if( $t === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
|
||||
if( $t != $utf8 ) {
|
||||
die( "nvarchar(max) doesn't match the inserted UTF-8 text." );
|
||||
}
|
||||
|
||||
sqlsrv_free_stmt( $s );
|
||||
|
||||
// test proc to baseline with
|
||||
$t = 1;
|
||||
|
||||
$s = sqlsrv_query( $c, "{call IntDoubleProc(?)}", array( array( &$t, SQLSRV_PARAM_INOUT, SQLSRV_PHPTYPE_INT )));
|
||||
|
||||
if( $s === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
if( $t != 2 ) {
|
||||
die( "Incorrect results for IntDoubleProc" );
|
||||
}
|
||||
|
||||
$t = "";
|
||||
|
||||
// output param with immediate conversion
|
||||
$s = sqlsrv_query( $c, "{call Utf8OutProc(?)}",
|
||||
array( array( &$t, SQLSRV_PARAM_OUT, SQLSRV_PHPTYPE_STRING('utf-8'), SQLSRV_SQLTYPE_NVARCHAR(50)) ));
|
||||
|
||||
if( $s === false ) {
|
||||
echo "{call Utf8OutProc(?)} failed\n";
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
|
||||
if( $t != $utf8 ) {
|
||||
die( "Incorrect results from Utf8OutProc\n" );
|
||||
}
|
||||
|
||||
$t = "";
|
||||
|
||||
$s = sqlsrv_query( $c, "{call Utf8OutWithResultsetProc(?)}",
|
||||
array( array( &$t, SQLSRV_PARAM_OUT, SQLSRV_PHPTYPE_STRING('utf-8'), SQLSRV_SQLTYPE_NVARCHAR(50)) ));
|
||||
|
||||
if( $s === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
|
||||
// retrieve all the results
|
||||
while( sqlsrv_next_result( $s ));
|
||||
|
||||
if( $t != $utf8 ) {
|
||||
die( "Incorrect results from Utf8OutWithResultsetProc\n" );
|
||||
}
|
||||
|
||||
// another set of UTF-8 text to try
|
||||
$utf8 = "Šỡოē šâოрĺẻ ÅŚÇÏЇ-ťếхţ";
|
||||
|
||||
// this input string is smaller than the output size for testing
|
||||
$t = "This is a test.";
|
||||
|
||||
// this works
|
||||
$s = sqlsrv_query( $c, "{call Utf8InOutProc(?)}",
|
||||
array( array( &$t, SQLSRV_PARAM_INOUT, SQLSRV_PHPTYPE_STRING('utf-8'), SQLSRV_SQLTYPE_NVARCHAR(25)) ));
|
||||
|
||||
if( $s === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
|
||||
if( $t != $utf8 ) {
|
||||
die( "Incorrect results from Utf8InOutProc 1\n" );
|
||||
}
|
||||
|
||||
|
||||
$t = "This is a longer test that exceeds the returned values buffer size so that we can test an input buffer size larger than the output buffer size.";
|
||||
|
||||
// this returns an error 22001, meaning that the string is too large
|
||||
$s = sqlsrv_query( $c, "{call Utf8InOutProc(?)}",
|
||||
array( array( &$t, SQLSRV_PARAM_INOUT, SQLSRV_PHPTYPE_STRING('utf-8'), SQLSRV_SQLTYPE_NVARCHAR(25)) ));
|
||||
|
||||
if( $s !== false ) {
|
||||
die( "Should have failed since the string is too long" );
|
||||
}
|
||||
|
||||
print_r( sqlsrv_errors() );
|
||||
|
||||
$t = pack( 'H*', '7a61cc86c7bdceb2f18fb3bf' );
|
||||
|
||||
$s = sqlsrv_query( $c, "INSERT INTO utf8test (c1, c2, c3) VALUES (?,?,?)",
|
||||
array(
|
||||
array( &$t, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING('utf-8')),
|
||||
array( &$t, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING('utf-8')),
|
||||
array( &$t, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING('utf-8')) ));
|
||||
if( $s === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
print_r( sqlsrv_errors() );
|
||||
|
||||
$s = sqlsrv_query( $c, 'SELECT c1, c2, c3 FROM utf8test' );
|
||||
if( $s === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
|
||||
if( sqlsrv_fetch( $s ) === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
// move to the second row
|
||||
if( sqlsrv_fetch( $s ) === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
|
||||
$u = sqlsrv_get_field( $s, 1, SQLSRV_PHPTYPE_STRING( 'utf-8' ));
|
||||
if( $u === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
|
||||
if( $t !== $u ) {
|
||||
die( "Round trip failed." );
|
||||
}
|
||||
|
||||
$t = pack( 'H*', 'ffffffff' );
|
||||
|
||||
$s = sqlsrv_query( $c, "{call IntProc(?)}", array( array( &$t, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING('utf-8'))));
|
||||
if( $s !== false ) {
|
||||
die( "no error from an invalid utf-8 string" );
|
||||
}
|
||||
print_r( sqlsrv_errors() );
|
||||
|
||||
sqlsrv_close( $c );
|
||||
|
||||
echo "Test succeeded.\n";
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Array
|
||||
(
|
||||
[0] => Array
|
||||
(
|
||||
[0] => 22001
|
||||
[SQLSTATE] => 22001
|
||||
[1] => 0
|
||||
[code] => 0
|
||||
[2] => %SString data, right truncation
|
||||
[message] => %SString data, right truncation
|
||||
)
|
||||
|
||||
)
|
||||
Array
|
||||
(
|
||||
[0] => Array
|
||||
(
|
||||
[0] => IMSSP
|
||||
[SQLSTATE] => IMSSP
|
||||
[1] => -40
|
||||
[code] => -40
|
||||
[2] => An error occurred translating string for input param 1 to UCS-2: %a
|
||||
[message] => An error occurred translating string for input param 1 to UCS-2: %a
|
||||
)
|
||||
|
||||
)
|
||||
Test succeeded.
|
60
test/sqlsrv/0066.phpt
Normal file
60
test/sqlsrv/0066.phpt
Normal file
|
@ -0,0 +1,60 @@
|
|||
--TEST--
|
||||
inserting and retrieving UTF-8 text.
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
|
||||
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
|
||||
|
||||
require( 'MsCommon.inc' );
|
||||
$c = Connect();
|
||||
|
||||
if( $c === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
|
||||
$s = sqlsrv_query( $c, "IF OBJECT_ID('utf8test', 'U') IS NOT NULL DROP TABLE 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 ));
|
||||
}
|
||||
$utf8 = pack( 'H*', 'efbbbfc5a6c4a5c4afc59d20c790c59f20e1baa120c5a5c499c5a1c5a720e1bb97c69220c399c5a4e282a32d3820c2a2d19be1baa7c599e1bab1c2a2c5a3e1bb81c59520c48fc78ec5a5e1baad' );
|
||||
|
||||
$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 ));
|
||||
}
|
||||
|
||||
$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 ));
|
||||
}
|
||||
|
||||
$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" );
|
||||
}
|
||||
|
||||
$stmt = sqlsrv_query( $c, "DROP TABLE utf8test" );
|
||||
|
||||
echo "Test succeeded\n";
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
Test succeeded
|
131
test/sqlsrv/0067.phpt
Normal file
131
test/sqlsrv/0067.phpt
Normal file
|
@ -0,0 +1,131 @@
|
|||
--TEST--
|
||||
inserting UTF-8 text via a PHP and error conditions.
|
||||
--SKIPIF--
|
||||
<?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." );
|
||||
}
|
||||
|
||||
$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,
|
||||
array( &$f4, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM('utf-8') ))); //,
|
||||
if( !$stmt ) {
|
||||
var_dump( sqlsrv_errors() );
|
||||
FatalError( "sqlsrv_prepare failed." );
|
||||
}
|
||||
|
||||
$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 = $utf8 . "e38395";
|
||||
$utf8 = pack( "H*", $utf8 );
|
||||
$f4 = fopen( "data://text/plain," . $utf8, "r" );
|
||||
|
||||
$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 = $utf8 . "dfa0";
|
||||
$utf8 = pack( "H*", $utf8 );
|
||||
$f4 = fopen( "data://text/plain," . $utf8, "r" );
|
||||
|
||||
$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 = $utf8 . "f1a680bf";
|
||||
$utf8 = pack( "H*", $utf8 );
|
||||
$f4 = fopen( "data://text/plain," . $utf8, "r" );
|
||||
|
||||
$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 = $utf8 . "e383";
|
||||
$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' );
|
||||
}
|
||||
print_r( sqlsrv_errors() );
|
||||
|
||||
// test UTF-8 invalid/corrupt stream
|
||||
$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" );
|
||||
|
||||
$success = sqlsrv_execute( $stmt );
|
||||
if( $success !== false ) {
|
||||
FatalError( 'Should have failed with an invalid UTF-8 string' );
|
||||
}
|
||||
print_r( sqlsrv_errors() );
|
||||
|
||||
$stmt = sqlsrv_query( $conn, "DROP TABLE test_params" );
|
||||
|
||||
sqlsrv_free_stmt( $stmt );
|
||||
sqlsrv_close( $conn );
|
||||
|
||||
echo "Test succeeded\n";
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Array
|
||||
(
|
||||
[0] => Array
|
||||
(
|
||||
[0] => IMSSP
|
||||
[SQLSTATE] => IMSSP
|
||||
[1] => -43
|
||||
[code] => -43
|
||||
[2] => An error occurred translating a PHP stream from UTF-8 to UTF-16: %a
|
||||
[message] => An error occurred translating a PHP stream from UTF-8 to UTF-16: %a
|
||||
)
|
||||
|
||||
)
|
||||
Array
|
||||
(
|
||||
[0] => Array
|
||||
(
|
||||
[0] => IMSSP
|
||||
[SQLSTATE] => IMSSP
|
||||
[1] => -43
|
||||
[code] => -43
|
||||
[2] => An error occurred translating a PHP stream from UTF-8 to UTF-16: %a
|
||||
[message] => An error occurred translating a PHP stream from UTF-8 to UTF-16: %a
|
||||
)
|
||||
|
||||
)
|
||||
Test succeeded
|
67
test/sqlsrv/0068.phpt
Normal file
67
test/sqlsrv/0068.phpt
Normal file
|
@ -0,0 +1,67 @@
|
|||
--TEST--
|
||||
warnings for non reference variables.
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
sqlsrv_configure( 'WarningsReturnAsErrors', false );
|
||||
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
|
||||
|
||||
require( '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, "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() );
|
||||
}
|
||||
$result = sqlsrv_execute($stmt);
|
||||
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 );
|
||||
?>
|
||||
--EXPECTREGEX--
|
||||
sqlsrv_execute\(3\) failed
|
||||
Array
|
||||
\(
|
||||
\[0\] => Array
|
||||
\(
|
||||
\[0\] => 42000
|
||||
\[SQLSTATE\] => 42000
|
||||
\[1\] => 257
|
||||
\[code\] => 257
|
||||
\[2\] => \[Microsoft\]\[ODBC Driver 1[0-9] for SQL Server\]\[SQL Server\]Implicit conversion from data type varchar\(max\) to varbinary\(max\) is not allowed\. Use the CONVERT function to run this query\.
|
||||
\[message\] => \[Microsoft\]\[ODBC Driver 1[0-9] for SQL Server\]\[SQL Server\]Implicit conversion from data type varchar\(max\) to varbinary\(max\) is not allowed\. Use the CONVERT function to run this query\.
|
||||
\)
|
||||
|
||||
\[1\] => Array
|
||||
\(
|
||||
\[0\] => 42000
|
||||
\[SQLSTATE\] => 42000
|
||||
\[1\] => 8180
|
||||
\[code\] => 8180
|
||||
\[2\] => \[Microsoft\]\[ODBC Driver 1[0-9] for SQL Server\]\[SQL Server\]Statement\(s\) could not be prepared\.
|
||||
\[message\] => \[Microsoft\]\[ODBC Driver 1[0-9] for SQL Server\]\[SQL Server\]Statement\(s\) could not be prepared\.
|
||||
\)
|
||||
|
||||
\)
|
57
test/sqlsrv/0069.phpt
Normal file
57
test/sqlsrv/0069.phpt
Normal file
|
@ -0,0 +1,57 @@
|
|||
--TEST--
|
||||
Variety of connection parameters.
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
set_time_limit(0);
|
||||
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
|
||||
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
|
||||
|
||||
date_default_timezone_set( 'America/Vancouver' );
|
||||
|
||||
require( 'MsCommon.inc' );
|
||||
$conn = Connect();
|
||||
|
||||
if( $conn === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
$stmt = sqlsrv_query($conn, "IF OBJECT_ID('php_table_SERIL1_1', 'U') IS NOT NULL DROP TABLE [php_table_SERIL1_1]");
|
||||
if( $stmt !== false ) sqlsrv_free_stmt( $stmt );
|
||||
|
||||
$stmt = sqlsrv_query($conn, "CREATE TABLE [php_table_SERIL1_1] ([c1_datetime2] datetime2(0), [c2_datetimeoffset] datetimeoffset(0), [c3_time] time(0))");
|
||||
if( $stmt === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
// test inserting into date time as a default
|
||||
$datetime2 = date_create( '1963-02-01 20:56:04.0123456' );
|
||||
$datetimeoffset = date_create( '1963-02-01 20:56:04.0123456 -07:00' );
|
||||
$time = date_create( '20:56:04.98765' );
|
||||
|
||||
$stmt = sqlsrv_query($conn, "INSERT INTO [php_table_SERIL1_1] (c1_datetime2, c2_datetimeoffset, c3_time) VALUES (?,?,?)", array( $datetime2, $datetimeoffset, $time ));
|
||||
if( $stmt === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
print_r( sqlsrv_errors( SQLSRV_ERR_WARNINGS ));
|
||||
|
||||
$stmt = sqlsrv_query($conn, "INSERT INTO [php_table_SERIL1_1] (c1_datetime2, c2_datetimeoffset, c3_time) VALUES (?,?,?)",
|
||||
array(
|
||||
array( $datetime2, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_DATETIME, SQLSRV_SQLTYPE_DATETIME2 ),
|
||||
array( $datetimeoffset, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_DATETIME, SQLSRV_SQLTYPE_DATETIMEOFFSET ),
|
||||
array( $time, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_DATETIME, SQLSRV_SQLTYPE_TIME )));
|
||||
if( $stmt === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
print_r( sqlsrv_errors( SQLSRV_ERR_WARNINGS ));
|
||||
|
||||
$stmt = sqlsrv_query( $conn, "DROP TABLE [php_table_SERIL1_1]" );
|
||||
|
||||
sqlsrv_close($conn);
|
||||
|
||||
echo "test succeeded.";
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
test succeeded.
|
54
test/sqlsrv/0072.phpt
Normal file
54
test/sqlsrv/0072.phpt
Normal file
|
@ -0,0 +1,54 @@
|
|||
--TEST--
|
||||
output string parameter fix to make sure the correct length is set.
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
$sql = 'CREATE PROCEDURE #GetAGuid
|
||||
(@NewValue varchar(50) OUTPUT)
|
||||
AS
|
||||
BEGIN
|
||||
set @NewValue = NEWID()
|
||||
select 1
|
||||
select 2
|
||||
select 3
|
||||
END';
|
||||
|
||||
require( 'MsCommon.inc' );
|
||||
$conn = Connect();
|
||||
|
||||
if( $conn === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
|
||||
$stmt = sqlsrv_query($conn, $sql);
|
||||
if( $stmt === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
|
||||
$sql = '{CALL #GetAGuid (?)}';
|
||||
$guid = 'test.';
|
||||
$params = array(
|
||||
array(&$guid,
|
||||
SQLSRV_PARAM_OUT,
|
||||
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
|
||||
SQLSRV_SQLTYPE_VARCHAR(50)
|
||||
)
|
||||
);
|
||||
|
||||
$stmt = sqlsrv_query($conn, $sql, $params);
|
||||
if( $stmt === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
|
||||
echo 'New Guid: >'.$guid."<\n";
|
||||
|
||||
while( sqlsrv_next_result( $stmt ) != NULL ) {
|
||||
}
|
||||
|
||||
echo 'New Guid: >'.$guid."<\n";
|
||||
|
||||
?>
|
||||
--EXPECTREGEX--
|
||||
New Guid: \>test\..*\<
|
||||
New Guid: \>[0-9A-F]{8}\-[0-9A-F]{4}\-[0-9A-F]{4}\-[0-9A-F]{4}\-[0-9A-F]{12}\<
|
54
test/sqlsrv/0073.phpt
Normal file
54
test/sqlsrv/0073.phpt
Normal file
|
@ -0,0 +1,54 @@
|
|||
--TEST--
|
||||
For output string parameter crash when output variable is set initially to null
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
$sql = 'CREATE PROCEDURE #GetAGuid73
|
||||
(@NewValue varchar(50) OUTPUT)
|
||||
AS
|
||||
BEGIN
|
||||
set @NewValue = NEWID()
|
||||
select 1
|
||||
select 2
|
||||
select 3
|
||||
END';
|
||||
|
||||
require( 'MsCommon.inc' );
|
||||
$conn = Connect();
|
||||
|
||||
if( $conn === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
|
||||
$stmt = sqlsrv_query($conn, $sql);
|
||||
if( $stmt === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
|
||||
$sql = '{CALL #GetAGuid73 (?)}';
|
||||
$guid = null;
|
||||
$params = array(
|
||||
array( &$guid,
|
||||
SQLSRV_PARAM_OUT,
|
||||
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
|
||||
SQLSRV_SQLTYPE_VARCHAR(50)
|
||||
)
|
||||
);
|
||||
|
||||
$stmt = sqlsrv_query($conn, $sql, $params);
|
||||
if( $stmt === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
|
||||
echo 'New Guid: >'.$guid."<\n";
|
||||
|
||||
while( sqlsrv_next_result( $stmt ) != NULL ) {
|
||||
}
|
||||
|
||||
echo 'New Guid: >'.$guid."<\n";
|
||||
|
||||
?>
|
||||
--EXPECTREGEX--
|
||||
New Guid: \>.+\<
|
||||
New Guid: \>[0-9A-F]{8}\-[0-9A-F]{4}\-[0-9A-F]{4}\-[0-9A-F]{4}\-[0-9A-F]{12}\<
|
110
test/sqlsrv/0074.phpt
Normal file
110
test/sqlsrv/0074.phpt
Normal file
|
@ -0,0 +1,110 @@
|
|||
--TEST--
|
||||
output string parameters with rows affected return results before output parameter.
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
require( 'MsCommon.inc' );
|
||||
$conn = Connect();
|
||||
if( $conn === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
|
||||
$stmt = sqlsrv_query( $conn, "IF OBJECT_ID('Subjects', 'U') IS NOT NULL DROP TABLE Subjects" );
|
||||
$stmt = sqlsrv_query( $conn, "IF OBJECT_ID('sn_x_study', 'U') IS NOT NULL DROP TABLE sn_x_study" );
|
||||
$stmt = sqlsrv_query( $conn, "IF OBJECT_ID('Studies', 'U') IS NOT NULL DROP TABLE Studies" );
|
||||
$stmt = sqlsrv_query( $conn, "IF OBJECT_ID('sp_MakeSubject', 'P') IS NOT NULL DROP PROCEDURE sp_MakeSubject" );
|
||||
|
||||
$stmt = sqlsrv_query( $conn, "CREATE TABLE Subjects (StartTime datetime, sn nchar(32), extref nvarchar(50))" );
|
||||
if( $stmt === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
$stmt = sqlsrv_query( $conn, "CREATE TABLE sn_x_study (studyID int, sn nchar(32))" );
|
||||
if( $stmt === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
$stmt = sqlsrv_query( $conn, "CREATE TABLE Studies (studyID int, Intro nvarchar(max))" );
|
||||
if( $stmt === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
$stmt = sqlsrv_query( $conn, "INSERT INTO Studies (studyID, Intro) VALUES (1, 'Test class 1')" );
|
||||
if( $stmt === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
$stmt = sqlsrv_query( $conn, "INSERT INTO Studies (studyID, Intro) VALUES (2, 'Test class 2')" );
|
||||
if( $stmt === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
$stmt = sqlsrv_query( $conn, "INSERT INTO Studies (studyID, Intro) VALUES (3, 'Test class 3')" );
|
||||
if( $stmt === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
|
||||
$proc = <<<PROC
|
||||
CREATE PROCEDURE [dbo].[sp_MakeSubject]
|
||||
-- Add the parameters for the stored procedure here
|
||||
@studyID int,
|
||||
@sn nchar(32),
|
||||
@extref nvarchar(50),
|
||||
@introText nvarchar(max) OUTPUT
|
||||
AS
|
||||
BEGIN
|
||||
|
||||
if @extref IS NULL
|
||||
begin
|
||||
insert into Subjects (StartTime,sn) values (GETDATE(),@sn)
|
||||
end
|
||||
else
|
||||
begin
|
||||
insert into Subjects (StartTime,sn,extref) values (GETDATE(),@sn,@extref)
|
||||
end
|
||||
|
||||
insert into sn_x_study (studyID,sn) values (@studyID,@sn)
|
||||
|
||||
select @introText=(select Intro from Studies where studyID=@studyID)
|
||||
|
||||
END
|
||||
PROC;
|
||||
|
||||
$stmt = sqlsrv_query( $conn, $proc );
|
||||
if( $stmt === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
|
||||
$tsql_callSP = "{call sp_MakeSubject(?,?,?,?)}";
|
||||
$introText="X";
|
||||
|
||||
$params = array(
|
||||
array( 1, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_INT, SQLSRV_SQLTYPE_INT ),
|
||||
array( 'BLAH', SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_NCHAR(32)),
|
||||
array( 'blahblahblah', SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_NVARCHAR(50)),
|
||||
array( &$introText, SQLSRV_PARAM_OUT, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_NVARCHAR(256))
|
||||
);
|
||||
|
||||
$stmt = sqlsrv_query( $conn, $tsql_callSP, $params);
|
||||
|
||||
if( $stmt === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
// when 337726 is fixed, this will print out the string length of 512
|
||||
// print_r( strlen( $introText ));
|
||||
|
||||
while(( $result = sqlsrv_next_result( $stmt )) != null ) {
|
||||
if( $result === false ) {
|
||||
die( print_r( sqlsrv_errors(),true));
|
||||
}
|
||||
}
|
||||
|
||||
sqlsrv_query( $conn, "DROP TABLE Subjects" );
|
||||
sqlsrv_query( $conn, "DROP TABLE sn_x_study" );
|
||||
sqlsrv_query( $conn, "DROP TABLE Studies" );
|
||||
sqlsrv_query( $conn, "DROP PROCEDURE sp_MakeSubject");
|
||||
|
||||
sqlsrv_close( $conn );
|
||||
|
||||
echo "$introText\n";
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
Test class 1
|
47
test/sqlsrv/0075.phpt
Normal file
47
test/sqlsrv/0075.phpt
Normal file
|
@ -0,0 +1,47 @@
|
|||
--TEST--
|
||||
Fix for output string parameter truncation error
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require( 'MsCommon.inc' );
|
||||
$conn = Connect();
|
||||
|
||||
$s = sqlsrv_query( $conn, "DROP PROCEDURE [test_output]" );
|
||||
if( $s !== false ) sqlsrv_free_stmt( $s );
|
||||
|
||||
$create_proc = <<<PROC
|
||||
CREATE PROC [test_output] ( @p1 CHAR(512), @p2 VARCHAR(512) OUTPUT)
|
||||
AS
|
||||
BEGIN
|
||||
SELECT @p2 = CONVERT( VARCHAR(512), @p1 )
|
||||
END
|
||||
PROC;
|
||||
$s = sqlsrv_query( $conn, $create_proc );
|
||||
if( $s === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
|
||||
$inValue1 = "Some data";
|
||||
$outValue1 = "";
|
||||
$s = sqlsrv_query($conn, "{CALL [test_output] (?, ?)}",
|
||||
array(array($inValue1, SQLSRV_PARAM_IN, null, SQLSRV_SQLTYPE_VARCHAR(512)),
|
||||
array(&$outValue1, SQLSRV_PARAM_OUT, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_VARCHAR(512))));
|
||||
|
||||
if( $s === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
|
||||
print_r( strlen( $outValue1 ));
|
||||
|
||||
echo "\n$outValue1";
|
||||
|
||||
$s = sqlsrv_query( $conn, "DROP PROCEDURE [test_output]" );
|
||||
|
||||
sqlsrv_free_stmt( $s );
|
||||
sqlsrv_close( $conn );
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
512
|
||||
Some data
|
46
test/sqlsrv/0076.phpt
Normal file
46
test/sqlsrv/0076.phpt
Normal file
|
@ -0,0 +1,46 @@
|
|||
--TEST--
|
||||
datetime server neutral to make sure it passes.
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
set_time_limit(0);
|
||||
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
|
||||
sqlsrv_configure( 'LogSubsystems', SQLSRV_LOG_SYSTEM_ALL );
|
||||
|
||||
require( 'MsCommon.inc' );
|
||||
$conn = Connect();
|
||||
if( $conn === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
|
||||
$stmt = sqlsrv_query( $conn, "IF OBJECT_ID('test_datetime', 'U') IS NOT NULL DROP TABLE test_datetime" );
|
||||
if( $stmt !== false ) sqlsrv_free_stmt( $stmt );
|
||||
|
||||
$stmt = sqlsrv_query( $conn, "CREATE TABLE test_datetime (id int, c2_datetime datetime, c3_smalldatetime smalldatetime)" );
|
||||
if( $stmt === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
sqlsrv_free_stmt( $stmt );
|
||||
|
||||
$stmt = sqlsrv_query( $conn, "INSERT INTO test_datetime (id, c2_datetime, c3_smalldatetime) VALUES (?, ?, ?)",
|
||||
array(array(1912963494, null, null, SQLSRV_SQLTYPE_INT),
|
||||
array('5413-07-02 02:24:18.791', null, null, SQLSRV_SQLTYPE_DATETIME),
|
||||
array('1927-07-29 08:37:00', null, null, SQLSRV_SQLTYPE_SMALLDATETIME)));
|
||||
if( $stmt === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
|
||||
sqlsrv_free_stmt( $stmt );
|
||||
|
||||
$server_info = sqlsrv_server_info( $conn );
|
||||
print_r( $server_info[ 'SQLServerVersion' ] );
|
||||
|
||||
sqlsrv_query( $conn, "DROP TABLE test_datetime" );
|
||||
|
||||
sqlsrv_close( $conn );
|
||||
|
||||
?>
|
||||
--EXPECTREGEX--
|
||||
1[0-9]\.[0-9]{2}\.[0-9]{4}
|
268
test/sqlsrv/0078.phpt
Normal file
268
test/sqlsrv/0078.phpt
Normal file
|
@ -0,0 +1,268 @@
|
|||
--TEST--
|
||||
Fix for output string parameters length prior to output being delivered
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
|
||||
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
|
||||
|
||||
require( 'MsCommon.inc' );
|
||||
$conn = Connect();
|
||||
if( $conn === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
|
||||
$stmt = sqlsrv_query( $conn, "IF OBJECT_ID('Subjects', 'U') IS NOT NULL DROP TABLE Subjects" );
|
||||
$stmt = sqlsrv_query( $conn, "IF OBJECT_ID('sn_x_study', 'U') IS NOT NULL DROP TABLE sn_x_study" );
|
||||
$stmt = sqlsrv_query( $conn, "IF OBJECT_ID('Studies', 'U') IS NOT NULL DROP TABLE Studies" );
|
||||
$stmt = sqlsrv_query( $conn, "IF OBJECT_ID('sp_MakeSubject78', 'P') IS NOT NULL DROP PROCEDURE sp_MakeSubject78" );
|
||||
|
||||
$stmt = sqlsrv_query( $conn, "CREATE TABLE Subjects (StartTime datetime, sn nchar(32), extref nvarchar(50))" );
|
||||
if( $stmt === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
$stmt = sqlsrv_query( $conn, "CREATE TABLE sn_x_study (studyID int, sn nchar(32))" );
|
||||
if( $stmt === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
$stmt = sqlsrv_query( $conn, "CREATE TABLE Studies (studyID int, Intro nchar(32))" );
|
||||
if( $stmt === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
$stmt = sqlsrv_query( $conn, "INSERT INTO Studies (studyID, Intro) VALUES (1, N'Test class 1')" );
|
||||
if( $stmt === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
$stmt = sqlsrv_query( $conn, "INSERT INTO Studies (studyID, Intro) VALUES (2, N'12345678901234567890123456789012')" );
|
||||
if( $stmt === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
$stmt = sqlsrv_query( $conn, "INSERT INTO Studies (studyID, Intro) VALUES (3, N'Test class 3')" );
|
||||
if( $stmt === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
|
||||
$proc = <<<PROC
|
||||
CREATE PROCEDURE [sp_MakeSubject78]
|
||||
-- Add the parameters for the stored procedure here
|
||||
@studyID int,
|
||||
@sn nchar(32),
|
||||
@extref nvarchar(50),
|
||||
@introText nvarchar(256) OUTPUT
|
||||
AS
|
||||
BEGIN
|
||||
|
||||
if @extref IS NULL
|
||||
begin
|
||||
insert into Subjects (StartTime,sn) values (GETDATE(),@sn)
|
||||
end
|
||||
else
|
||||
begin
|
||||
insert into Subjects (StartTime,sn,extref) values (GETDATE(),@sn,@extref)
|
||||
end
|
||||
|
||||
insert into sn_x_study (studyID,sn) values (@studyID,@sn)
|
||||
|
||||
select @introText=(select Intro from Studies where studyID=@studyID)
|
||||
|
||||
END
|
||||
PROC;
|
||||
|
||||
$stmt = sqlsrv_query( $conn, $proc );
|
||||
if( $stmt === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
|
||||
$tsql_callSP = "{call sp_MakeSubject78(?,?,?,?)}";
|
||||
$introText="X";
|
||||
|
||||
$params = array(
|
||||
array( 2, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_INT, SQLSRV_SQLTYPE_INT ),
|
||||
array( 'HLAB', SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_NCHAR(32)),
|
||||
array( 'hlabhlabhlabhlab', SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_NVARCHAR(50)),
|
||||
array( &$introText, SQLSRV_PARAM_INOUT, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_NCHAR(32))
|
||||
);
|
||||
|
||||
$stmt = sqlsrv_query( $conn, $tsql_callSP, $params);
|
||||
|
||||
if( $stmt === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
|
||||
print_r( strlen( $introText ));
|
||||
echo "\n";
|
||||
|
||||
while(( $result = sqlsrv_next_result( $stmt )) != null ) {
|
||||
if( $result === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
}
|
||||
if( sqlsrv_errors() != NULL ) {
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
echo "$introText\n";
|
||||
|
||||
$tsql_callSP = "{call sp_MakeSubject78(?,?,?,?)}";
|
||||
$introText="X";
|
||||
|
||||
$params = array(
|
||||
array( 2, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_INT, SQLSRV_SQLTYPE_INT ),
|
||||
array( 'HLAB', SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_NCHAR(32)),
|
||||
array( 'hlabhlabhlabhlab', SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_NVARCHAR(50)),
|
||||
array( &$introText, SQLSRV_PARAM_INOUT, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_NCHAR(32))
|
||||
);
|
||||
|
||||
$stmt = sqlsrv_query( $conn, $tsql_callSP, $params);
|
||||
|
||||
if( $stmt === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
|
||||
print_r( strlen( $introText ));
|
||||
echo "\n";
|
||||
|
||||
while(( $result = sqlsrv_next_result( $stmt )) != null ) {
|
||||
if( $result === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
}
|
||||
if( sqlsrv_errors() != NULL ) {
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
|
||||
echo "$introText\n";
|
||||
|
||||
$tsql_callSP = "{call sp_MakeSubject78(?,?,?,?)}";
|
||||
$introText="X";
|
||||
|
||||
$params = array(
|
||||
array( 2, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_INT, SQLSRV_SQLTYPE_INT ),
|
||||
array( 'HLAB', SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_NCHAR(32)),
|
||||
array( 'hlabhlabhlabhlab', SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_NVARCHAR(50)),
|
||||
array( &$introText, SQLSRV_PARAM_INOUT, SQLSRV_PHPTYPE_STRING('utf-8'), SQLSRV_SQLTYPE_NCHAR(32))
|
||||
);
|
||||
|
||||
$stmt = sqlsrv_query( $conn, $tsql_callSP, $params);
|
||||
|
||||
if( $stmt === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
|
||||
print_r( strlen( $introText ));
|
||||
echo "\n";
|
||||
|
||||
while(( $result = sqlsrv_next_result( $stmt )) != null ) {
|
||||
if( $result === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
}
|
||||
if( sqlsrv_errors() != NULL ) {
|
||||
print_r( sqlsrv_errors() );
|
||||
}
|
||||
|
||||
echo "$introText\n";
|
||||
|
||||
$tsql_callSP = "{call sp_MakeSubject78(?,?,?,?)}";
|
||||
$introText="X";
|
||||
|
||||
$params = array(
|
||||
array( 2, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_INT, SQLSRV_SQLTYPE_INT ),
|
||||
array( 'HLAB', SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_NCHAR(32)),
|
||||
array( 'hlabhlabhlabhlab', SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_NVARCHAR(50)),
|
||||
array( &$introText, SQLSRV_PARAM_OUT, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_NCHAR(32))
|
||||
);
|
||||
|
||||
$stmt = sqlsrv_query( $conn, $tsql_callSP, $params);
|
||||
|
||||
if( $stmt === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
|
||||
print_r( strlen( $introText ));
|
||||
echo "\n";
|
||||
|
||||
while(( $result = sqlsrv_next_result( $stmt )) != null ) {
|
||||
if( $result === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
}
|
||||
|
||||
echo "$introText\n";
|
||||
|
||||
$tsql_callSP = "{call sp_MakeSubject78(?,?,?,?)}";
|
||||
$introText="X";
|
||||
|
||||
$params = array(
|
||||
array( 2, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_INT, SQLSRV_SQLTYPE_INT ),
|
||||
array( 'HLAB', SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_NCHAR(32)),
|
||||
array( 'hlabhlabhlabhlab', SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_NVARCHAR(50)),
|
||||
array( &$introText, SQLSRV_PARAM_OUT, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_NCHAR(32))
|
||||
);
|
||||
|
||||
$stmt = sqlsrv_query( $conn, $tsql_callSP, $params);
|
||||
|
||||
if( $stmt === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
|
||||
print_r( strlen( $introText ));
|
||||
echo "\n";
|
||||
|
||||
while(( $result = sqlsrv_next_result( $stmt )) != null ) {
|
||||
if( $result === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
}
|
||||
|
||||
echo "$introText\n";
|
||||
|
||||
$tsql_callSP = "{call sp_MakeSubject78(?,?,?,?)}";
|
||||
$introText="X";
|
||||
|
||||
$params = array(
|
||||
array( 2, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_INT, SQLSRV_SQLTYPE_INT ),
|
||||
array( 'HLAB', SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_NCHAR(32)),
|
||||
array( 'hlabhlabhlabhlab', SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_NVARCHAR(50)),
|
||||
array( &$introText, SQLSRV_PARAM_OUT, SQLSRV_PHPTYPE_STRING('utf-8'), SQLSRV_SQLTYPE_NCHAR(32))
|
||||
);
|
||||
|
||||
$stmt = sqlsrv_query( $conn, $tsql_callSP, $params);
|
||||
|
||||
if( $stmt === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
|
||||
print_r( strlen( $introText ));
|
||||
echo "\n";
|
||||
|
||||
while(( $result = sqlsrv_next_result( $stmt )) != null ) {
|
||||
if( $result === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
}
|
||||
}
|
||||
|
||||
echo "$introText\n";
|
||||
|
||||
sqlsrv_query( $conn, "DROP TABLE Subjects" );
|
||||
sqlsrv_query( $conn, "DROP TABLE sn_x_study" );
|
||||
sqlsrv_query( $conn, "DROP TABLE Studies" );
|
||||
sqlsrv_query( $conn, "DROP PROCEDURE sp_MakeSubject78" );
|
||||
|
||||
sqlsrv_close( $conn );
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
64
|
||||
1 |