Refactoring sqlsrv tests with parameterized queries

This commit is contained in:
Jenny Tam 2017-11-28 16:40:49 -08:00
parent 0a30d49941
commit 0a2e6ad242
35 changed files with 1562 additions and 1468 deletions

View file

@ -1,28 +1,27 @@
--TEST--
reading streams of various types with a base64 decoding filter on top of them.
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
sqlsrv_configure( 'WarningsReturnAsErrors', false );
require( 'MsCommon.inc' );
sqlsrv_configure('WarningsReturnAsErrors', false);
require_once('MsCommon.inc');
function RunTest( $field_type ) {
PrepareParams($params);
$tableName = "dbo.B64TestTable";
$params['fieldType'] = $field_type;
function runTest($fieldType)
{
prepareParams($params);
($conn = Connect())
// change the input field type for each run
$params['fieldType'] = $fieldType;
$conn = AE\connect();
$originalStream = populateTestTable($conn, $params);
($stmt = sqlsrv_query($conn, $params['selectQuery']))
|| 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)
sqlsrv_fetch($stmt)
|| die(print_r(sqlsrv_errors(), true));
($stream = sqlsrv_get_field($stmt, 0, SQLSRV_PHPTYPE_STREAM("char")))
@ -33,74 +32,83 @@ function RunTest( $field_type ) {
while (($originalLine = fread($originalStream, 80)) &&
($dbLine = fread($stream, 80))) {
if( $originalLine != $dbLine )
die( "Not identical" );
if ($originalLine != $dbLine) {
die("Not identical");
}
}
dropTable($conn, $params['tableName']);
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)" );
runTest("varchar(max)");
runTest("varbinary(max)");
runTest("nvarchar(max)");
echo "Test successful.\n";
function PopulateTestTable($conn, $params) {
function populateTestTable($conn, $params)
{
$tblName = $params['tableName'];
$colName = $params['columnName'];
$fieldType = $params['fieldType'];
DropTestTable($conn, $params);
CreateTestTable($conn, $params);
// Create a test table of a column of type 'nvarchar(MAX)'
$columns = array(new AE\ColumnMeta('nvarchar(MAX)', $colName));
$stmt = AE\createTable($conn, $tblName, $columns);
if (!$stmt) {
fatalError("Failed to create table $tblName\n");
}
($data = fopen($params['testImageURL'], "rb")) || die("Couldn't open image for reading.");
stream_filter_append($data, "convert.base64-encode")
stream_filter_append($data, "convert.base64-encode")
|| die(print_r(error_get_last(), true));
if ($stmt = sqlsrv_query($conn, $params['insertQuery'], array($data))) {
do {
if (AE\isColEncrypted()) {
$stmt = AE\insertRow($conn, $tblName, array($colName => $data));
} else {
$insertQuery = $params['insertQuery'];
$stmt = sqlsrv_query($conn, $insertQuery, array($data));
}
if ($stmt) {
do {
$read = sqlsrv_send_stream_data($stmt);
if ($read === false) die(print_r(sqlsrv_errors(), true));
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
} else {
die(print_r(sqlsrv_errors(), true));
}
return fopen($params['testImageURL'], "rb");
return fopen($params['testImageURL'], "rb");
}
function PrepareParams(&$arr) {
$uname = php_uname();
$phpgif = "\\php.gif";
if (preg_match('/Win/',$uname))
{
function prepareParams(&$arr)
{
if (IsWindows()) {
$phpgif = '\\php.gif';
}
else // other than Windows
{
} else {
$phpgif = '/php.gif';
}
$arr['tableName'] = $tblName = "dbo.B64TestTable";
// the test table always has a column of type 'nvarchar(MAX)'
$arr['tableName'] = $tblName = "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));
$arr['testImageURL'] = dirname($_SERVER['PHP_SELF']) . $phpgif; // use this when no http access
}
?>

View file

@ -1,7 +1,7 @@
--TEST--
binding parameters, including output parameters, using the simplified syntax.
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
sqlsrv_configure('WarningsReturnAsErrors', 0);
@ -9,10 +9,7 @@ binding parameters, including output parameters, using the simplified syntax.
require_once('MsCommon.inc');
$conn = connect();
if (!$conn) {
fatalError("sqlsrv_create failed.");
}
$conn = AE\connect();
$v1 = 1;
$v2 = 2;

View file

@ -1,7 +1,7 @@
--TEST--
maximum size for both nonunicode and unicode data types.
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
@ -9,59 +9,48 @@ maximum size for both nonunicode and unicode data types.
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
require_once('MsCommon.inc');
$conn = connect();
if (!$conn) {
die(print_r(sqlsrv_errors(), true));
}
$conn = AE\connect();
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))");
$tableName = 'test_max_size';
$columns = array(new AE\ColumnMeta('int', 'id'),
new AE\ColumnMeta('nvarchar(4000)', 'test_nvarchar'),
new AE\ColumnMeta('nchar(4000)', 'test_nchar'),
new AE\ColumnMeta('varchar(8000)', 'test_varchar'),
new AE\ColumnMeta('varbinary(8000)', 'test_binary'));
$stmt = AE\createTable($conn, $tableName, $columns);
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
$stmt = sqlsrv_query(
$stmt = AE\executeQueryParams(
$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)))
"INSERT INTO $tableName (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))),
true,
"Should have failed (1)."
);
if ($stmt === false) {
print_r(sqlsrv_errors());
} else {
fatalError("Should have failed (1).");
}
$stmt = sqlsrv_query(
$stmt = AE\executeQueryParams(
$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)))
"INSERT INTO $tableName (id, test_nchar) VALUES (?, ?)",
array( 2, array( "this is a test", SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_NCHAR(8000))),
true,
"Should have failed (2)."
);
if ($stmt === false) {
print_r(sqlsrv_errors());
} else {
fatalError("Should have failed (2).");
}
$stmt = sqlsrv_query(
$stmt = AE\executeQueryParams(
$conn,
"INSERT INTO test_max_size (id, test_varchar) VALUES (?, ?)",
"INSERT INTO $tableName (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(
$stmt = AE\executeQueryParams(
$conn,
"INSERT INTO test_max_size (id, test_binary) VALUES (?, ?)",
"INSERT INTO $tableName (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()));
}
dropTable($conn, 'test_max_size');
dropTable($conn, '$tableName');
echo "Test succeeded.\n";
?>

View file

@ -1,46 +1,41 @@
--TEST--
inserting and retrieving UTF-8 text.
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_versions_old.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);
// For testing in Azure, can not switch databases
require( 'MsCommon.inc' );
$c = Connect();
require_once('MsCommon.inc');
$c = AE\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 ));
$columns = array(new AE\ColumnMeta('varchar(100)', 'c1'),
new AE\ColumnMeta('nvarchar(100)', 'c2'),
new AE\ColumnMeta('nvarchar(max)', 'c3'));
$stmt = AE\createTable($c, "utf8test", $columns);
if (!$stmt) {
fatalError("Failed to create table 'utf8test'\n");
}
$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 ));
}
$params = 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')));
$insertSql = "INSERT INTO utf8test (c1, c2, c3) VALUES (?,?,?)";
$s = AE\executeQueryParams($c, $insertSql, $params);
$s = sqlsrv_query( $c,
$s = sqlsrv_query(
$c,
"DROP PROCEDURE IntDoubleProc;
DROP PROCEDURE Utf8OutProc;
DROP PROCEDURE Utf8OutWithResultsetProc;
DROP PROCEDURE Utf8InOutProc;
DROP TABLE Utf8TestTable;" );
DROP TABLE Utf8TestTable;"
);
$create_proc = <<<PROC
CREATE PROCEDURE Utf8OutProc
@ -50,9 +45,9 @@ BEGIN
set @param = convert(nvarchar(25), 0x5E01A1013C04170120005B01E400DD1040044001C11E200086035A010801280130012D0065012E21D7006701);
END;
PROC;
$s = sqlsrv_query( $c, $create_proc );
if( $s === false ) {
die( print_r( sqlsrv_errors(), true ));
$s = sqlsrv_query($c, $create_proc);
if ($s === false) {
die(print_r(sqlsrv_errors(), true));
}
$create_proc = <<<PROC
@ -64,9 +59,9 @@ BEGIN
set @param = convert(nvarchar(25), 0x5E01A1013C04170120005B01E400DD1040044001C11E200086035A010801280130012D0065012E21D7006701);
END;
PROC;
$s = sqlsrv_query( $c, $create_proc );
if( $s === false ) {
die( print_r( sqlsrv_errors(), true ));
$s = sqlsrv_query($c, $create_proc);
if ($s === false) {
die(print_r(sqlsrv_errors(), true));
}
$create_proc = <<<PROC
@ -78,9 +73,9 @@ BEGIN
set @param = convert(nvarchar(25), 0x6001E11EDD10130120006101E200DD1040043A01BB1E2000C5005A01C700CF0007042D006501BF1E45046301);
END;
PROC;
$s = sqlsrv_query( $c, $create_proc );
if( $s === false ) {
die( print_r( sqlsrv_errors(), true ));
$s = sqlsrv_query($c, $create_proc);
if ($s === false) {
die(print_r(sqlsrv_errors(), true));
}
$create_proc = <<<PROC
@ -91,90 +86,97 @@ 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, $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 ));
$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 ));
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 ));
$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" );
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 ));
$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." );
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 ));
$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." );
if ($t != $utf8) {
die("nvarchar(max) doesn't match the inserted UTF-8 text.");
}
sqlsrv_free_stmt( $s );
sqlsrv_free_stmt($s);
// test proc to baseline with
$t = 1;
$sqlType = AE\isColEncrypted() ? SQLSRV_SQLTYPE_INT : null;
$s = sqlsrv_query( $c, "{call IntDoubleProc(?)}", array( array( &$t, SQLSRV_PARAM_INOUT, SQLSRV_PHPTYPE_INT )));
$s = sqlsrv_query($c, "{call IntDoubleProc(?)}", array(array(&$t, SQLSRV_PARAM_INOUT, SQLSRV_PHPTYPE_INT, $sqlType)));
if( $s === false ) {
die( print_r( sqlsrv_errors(), true ));
if ($s === false) {
die(print_r(sqlsrv_errors(), true));
}
if( $t != 2 ) {
die( "Incorrect results for IntDoubleProc" );
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)) ));
$s = sqlsrv_query(
$c,
"{call Utf8OutProc(?)}",
array(array(&$t, SQLSRV_PARAM_OUT, SQLSRV_PHPTYPE_STRING('utf-8'), SQLSRV_SQLTYPE_NVARCHAR(50)))
);
if( $s === false ) {
if ($s === false) {
echo "{call Utf8OutProc(?)} failed\n";
die( print_r( sqlsrv_errors(), true ));
die(print_r(sqlsrv_errors(), true));
}
if( $t != $utf8 ) {
die( "Incorrect results from Utf8OutProc\n" );
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)) ));
$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 ));
if ($s === false) {
die(print_r(sqlsrv_errors(), true));
}
// retrieve all the results
while( sqlsrv_next_result( $s ));
while (sqlsrv_next_result($s));
if( $t != $utf8 ) {
die( "Incorrect results from Utf8OutWithResultsetProc\n" );
if ($t != $utf8) {
die("Incorrect results from Utf8OutWithResultsetProc\n");
}
// another set of UTF-8 text to try
@ -184,73 +186,76 @@ $utf8 = "Šỡოē šâოрĺẻ ÅŚÇÏЇ-ťếхţ";
$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)) ));
$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 ($s === false) {
die(print_r(sqlsrv_errors(), true));
}
if( $t != $utf8 ) {
die( "Incorrect results from Utf8InOutProc 1\n" );
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" );
$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() );
print_r(sqlsrv_errors());
$t = pack( 'H*', '7a61cc86c7bdceb2f18fb3bf' );
$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() );
$params = 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')));
$insertSql = "INSERT INTO utf8test (c1, c2, c3) VALUES (?,?,?)";
$s = AE\executeQueryParams($c, $insertSql, $params);
$s = sqlsrv_query( $c, 'SELECT c1, c2, c3 FROM utf8test' );
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 ));
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 ));
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 ));
$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." );
if ($t !== $u) {
die("Round trip failed.");
}
$t = pack( 'H*', 'ffffffff' );
$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() );
$sqlType =
$params = array(array(&$t, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING('utf-8')));
$query = "{call IntDoubleProc(?)}";
$s = AE\executeQueryParams($c, $query, $params, true, "no error from an invalid utf-8 string");
sqlsrv_close( $c );
dropTable($c, 'utf8test');
sqlsrv_close($c);
echo "Test succeeded.\n";

View file

@ -1,41 +1,33 @@
--TEST--
inserting and retrieving UTF-8 text.
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
sqlsrv_configure('WarningsReturnAsErrors', 0);
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
require_once('MsCommon.inc');
$c = connect();
if ($c === false) {
die(print_r(sqlsrv_errors(), true));
}
dropTable($c, 'utf8test');
$c = AE\connect();
// 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));
$columns = array(new AE\ColumnMeta('varchar(100)', 'c1'),
new AE\ColumnMeta('nvarchar(100)', 'c2'),
new AE\ColumnMeta('nvarchar(max)', 'c3'));
$stmt = AE\createTable($c, "utf8test", $columns);
if (!$stmt) {
fatalError("Failed to create table 'utf8test'\n");
}
$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));
}
$params = 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')));
$insertSql = "INSERT INTO utf8test (c1, c2, c3) VALUES (?,?,?)";
$s = AE\executeQueryParams($c, $insertSql, $params);
$s = sqlsrv_query($c, 'SELECT * FROM utf8test');
$s = AE\executeQuery($c, 'SELECT * FROM utf8test');
if ($s === false) {
die(print_r(sqlsrv_errors(), true));
}

View file

@ -1,33 +1,30 @@
--TEST--
inserting UTF-8 text via a PHP and error conditions.
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
sqlsrv_configure('WarningsReturnAsErrors', 0);
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
require_once('MsCommon.inc');
$conn = connect();
$conn = AE\connect();
if (!$conn) {
fatalError("Failed to connect.");
$tableName = 'test_params';
$columns = array(new AE\ColumnMeta('tinyint', 'id'),
new AE\ColumnMeta('char(10)', 'name'),
new AE\ColumnMeta('float', 'double'),
new AE\ColumnMeta('varchar(max)', 'stuff'));
$stmt = AE\createTable($conn, $tableName, $columns);
if (!$stmt) {
fatalError("Failed to create table $tableName\n");
}
$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') ))); //,
$stmt = sqlsrv_prepare($conn, "INSERT INTO $tableName (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.");
@ -93,7 +90,7 @@ inserting UTF-8 text via a PHP and error conditions.
}
print_r(sqlsrv_errors());
$stmt = sqlsrv_query($conn, "DROP TABLE test_params");
dropTable($conn, $tableName);
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);

View file

@ -1,69 +1,53 @@
--TEST--
warnings for non reference variables.
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
sqlsrv_configure('WarningsReturnAsErrors', false);
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
require_once('MsCommon.inc');
$conn = connect();
if (!$conn) {
fatalError("sqlsrv_connect failed.");
}
$conn = AE\connect();
$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));
$tableName = 'test_empty_stream';
$columns = array(new AE\ColumnMeta('int', 'id'),
new AE\ColumnMeta('varchar(max)', 'varchar_stream'),
new AE\ColumnMeta('varbinary(max)', 'varbinary_stream'));
$stmt = AE\createTable($conn, $tableName, $columns);
if (!$stmt) {
fatalError("Failed to create table $tableName\n");
}
$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') ),
$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) {
fatalError("Expected sqlsrv_execute to fail!\n");
} else {
echo "sqlsrv_execute failed\n";
// verify the error contents
$error = sqlsrv_errors()[0];
if (AE\isColEncrypted()) {
// When AE is enabled, implicit conversion will not take place
verifyError($error, '22018', 'Invalid character value for cast specification');
} else {
verifyError($error, '42000', 'Implicit conversion from data type varchar(max) to varbinary(max) is not allowed. Use the CONVERT function to run this query.');
}
}
$stmt = sqlsrv_query($conn, "DROP TABLE test_empty_stream");
echo "Done\n";
dropTable($conn, $tableName);
sqlsrv_close($conn);
?>
--EXPECTREGEX--
sqlsrv_execute\(3\) failed
Array
\(
\[0\] => Array
\(
\[0\] => 42000
\[SQLSTATE\] => 42000
\[1\] => 257
\[code\] => 257
\[2\] => \[Microsoft\]\[ODBC Driver 1[1-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[1-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[1-9] for SQL Server\]\[SQL Server\]Statement\(s\) could not be prepared\.
\[message\] => \[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]\[SQL Server\]Statement\(s\) could not be prepared\.
\)
\)
--EXPECT--
sqlsrv_execute failed
Done

View file

@ -1,54 +1,77 @@
--TEST--
Variety of connection parameters.
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
set_time_limit(0);
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
function insertTime($conn, $tableName, $datetime2, $datetimeoffset, $time, $useSQLType = false)
{
if ($useSQLType) {
$inputs = 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));
} else {
$inputs = array($datetime2, $datetimeoffset, $time);
}
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 ));
$insertSql = "INSERT INTO $tableName (c1_datetime2, c2_datetimeoffset, c3_time) VALUES (?,?,?)";
if (AE\isColEncrypted()) {
$stmt = sqlsrv_prepare($conn, $insertSql, $inputs);
if ($stmt) {
$r = sqlsrv_execute($stmt);
if (!$r) {
fatalError("insertTime: failed to insert a row into $tableName!");
}
}
} else {
$stmt = sqlsrv_query($conn, $insertSql, $inputs);
}
if (!$stmt) {
fatalError("insertTime: failed to insert a row into $tableName!");
}
print_r(sqlsrv_errors(SQLSRV_ERR_WARNINGS));
}
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 0);
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
date_default_timezone_set('America/Vancouver');
require_once('MsCommon.inc');
$conn = AE\connect();
$tableName = 'php_table_SERIL1_1';
dropTable($conn, $tableName);
if (AE\isColEncrypted()) {
// With AE enabled, the sql types and SQLSRV SQLTYPES have to match exactly when binding
// Since SQLSRV SQLTYPES with datetime columns have no options for precision/scale,
// Use the default precision
$columns = array(new AE\ColumnMeta('datetime2', 'c1_datetime2'),
new AE\ColumnMeta('datetimeoffset', 'c2_datetimeoffset'),
new AE\ColumnMeta('time', 'c3_time'));
$stmt = AE\createTable($conn, $tableName, $columns);
} else {
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_datetime2] datetime2(0), [c2_datetimeoffset] datetimeoffset(0), [c3_time] time(0))");
}
if (!$stmt) {
fatalError("Failed to create table $tableName\n");
}
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' );
$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 ));
// Insert two rows with the same values, one with SQL Types one without
$stmt = insertTime($conn, $tableName, $datetime2, $datetimeoffset, $time);
$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 = insertTime($conn, $tableName, $datetime2, $datetimeoffset, $time, true);
$stmt = sqlsrv_query( $conn, "DROP TABLE [php_table_SERIL1_1]" );
dropTable($conn, $tableName);
sqlsrv_close($conn);
sqlsrv_close($conn);
echo "test succeeded.";

View file

@ -1,7 +1,7 @@
--TEST--
output string parameter fix to make sure the correct length is set.
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
$sql = 'CREATE PROCEDURE #GetAGuid
@ -14,16 +14,12 @@ output string parameter fix to make sure the correct length is set.
select 3
END';
require( 'MsCommon.inc' );
$conn = Connect();
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true ));
}
require_once('MsCommon.inc');
$conn = AE\connect();
$stmt = sqlsrv_query($conn, $sql);
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
$sql = '{CALL #GetAGuid (?)}';
@ -37,13 +33,13 @@ output string parameter fix to make sure the correct length is set.
);
$stmt = sqlsrv_query($conn, $sql, $params);
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
echo 'New Guid: >'.$guid."<\n";
while( sqlsrv_next_result( $stmt ) != NULL ) {
while (sqlsrv_next_result($stmt) != null) {
}
echo 'New Guid: >'.$guid."<\n";

View file

@ -1,7 +1,7 @@
--TEST--
For output string parameter crash when output variable is set initially to null
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
$sql = 'CREATE PROCEDURE #GetAGuid73
@ -14,16 +14,12 @@ For output string parameter crash when output variable is set initially to null
select 3
END';
require( 'MsCommon.inc' );
$conn = Connect();
require_once('MsCommon.inc');
$conn = AE\connect();
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$stmt = sqlsrv_query($conn, $sql);
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
$sql = '{CALL #GetAGuid73 (?)}';
@ -37,13 +33,13 @@ For output string parameter crash when output variable is set initially to null
);
$stmt = sqlsrv_query($conn, $sql, $params);
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
echo 'New Guid: >'.$guid."<\n";
while( sqlsrv_next_result( $stmt ) != NULL ) {
while (sqlsrv_next_result($stmt) != null) {
}
echo 'New Guid: >'.$guid."<\n";

View file

@ -1,44 +1,48 @@
--TEST--
output string parameters with rows affected return results before output parameter.
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
require( 'MsCommon.inc' );
$conn = Connect();
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true ));
function insertIntoStudies($conn, $id)
{
$intro = 'Test class ' . $id;
$stmt = AE\insertRow($conn, 'Studies', array('studyID' => $id, 'Intro' => $intro));
if ($stmt === 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" );
require_once('MsCommon.inc');
$conn = AE\connect();
$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 ));
// drop the procedure if exists
$stmt = sqlsrv_query($conn, "IF OBJECT_ID('sp_MakeSubject', 'P') IS NOT NULL DROP PROCEDURE sp_MakeSubject");
// Create Table 'Subjects' but do not encrypt the first column because in the stored procedure
// we rely on the server to get the current date time. With Column Encryption, all input values
// have to be provided by the client
$columns = array(new AE\ColumnMeta('datetime', 'StartTime', null, true, true),
new AE\ColumnMeta('nchar(32)', 'sn'),
new AE\ColumnMeta('nvarchar(50)', 'extref'));
$stmt = AE\createTable($conn, 'Subjects', $columns);
unset($columns);
// Create table 'sn_x_study'
$columns = array(new AE\ColumnMeta('int', 'studyID'),
new AE\ColumnMeta('nchar(32)', 'sn'));
$stmt = AE\createTable($conn, 'sn_x_study', $columns);
unset($columns);
// Create table 'Studies'
$columns = array(new AE\ColumnMeta('int', 'studyID'),
new AE\ColumnMeta('nvarchar(max)', 'Intro'));
$stmt = AE\createTable($conn, 'Studies', $columns);
unset($columns);
// Insert 3 rows into table 'Studies'
for ($i = 1; $i <= 3; $i++) {
insertIntoStudies($conn, $i);
}
$proc = <<<PROC
@ -67,41 +71,42 @@ 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 ));
$stmt = sqlsrv_query($conn, $proc);
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
$tsql_callSP = "{call sp_MakeSubject(?,?,?,?)}";
$introText="X";
$params = array(
// With AE, the sql type has to match the column definition
$outSQLType = AE\isColEncrypted() ? SQLSRV_SQLTYPE_NVARCHAR('max') : SQLSRV_SQLTYPE_NVARCHAR(256);
$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))
array( &$introText, SQLSRV_PARAM_OUT, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), $outSQLType)
);
$stmt = sqlsrv_query( $conn, $tsql_callSP, $params);
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
$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));
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");
dropTable($conn, 'Subjects');
dropTable($conn, 'sn_x_study');
dropTable($conn, 'Studies');
dropProc($conn, 'sp_MakeSubject');
sqlsrv_close( $conn );
sqlsrv_close($conn);
echo "$introText\n";

View file

@ -1,14 +1,13 @@
--TEST--
Fix for output string parameter truncation error
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
require( 'MsCommon.inc' );
$conn = Connect();
require_once('MsCommon.inc');
$conn = AE\connect();
$s = sqlsrv_query( $conn, "DROP PROCEDURE [test_output]" );
if( $s !== false ) sqlsrv_free_stmt( $s );
dropProc($conn, 'test_output');
$create_proc = <<<PROC
CREATE PROC [test_output] ( @p1 CHAR(512), @p2 VARCHAR(512) OUTPUT)
@ -17,29 +16,32 @@ BEGIN
SELECT @p2 = CONVERT( VARCHAR(512), @p1 )
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));
}
$inValue1 = "Some data";
$outValue1 = "";
$s = sqlsrv_query($conn, "{CALL [test_output] (?, ?)}",
$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))));
array(&$outValue1, SQLSRV_PARAM_OUT, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_VARCHAR(512)))
);
if( $s === false ) {
die( print_r( sqlsrv_errors(), true ));
if ($s === false) {
die(print_r(sqlsrv_errors(), true));
}
print_r( strlen( $outValue1 ));
print_r(strlen($outValue1));
echo "\n$outValue1";
$s = sqlsrv_query( $conn, "DROP PROCEDURE [test_output]" );
dropProc($conn, 'test_output');
sqlsrv_free_stmt( $s );
sqlsrv_close( $conn );
sqlsrv_free_stmt($s);
sqlsrv_close($conn);
?>
--EXPECT--

View file

@ -1,45 +1,47 @@
--TEST--
datetime server neutral to make sure it passes.
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
set_time_limit(0);
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSubsystems', SQLSRV_LOG_SYSTEM_ALL );
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 ));
require_once('MsCommon.inc');
$conn = AE\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 ));
$tableName ='test_datetime';
$columns = array(new AE\ColumnMeta('int', 'id'),
new AE\ColumnMeta('datetime', 'c2_datetime'),
new AE\ColumnMeta('smalldatetime', 'c3_smalldatetime'));
$stmt = AE\createTable($conn, $tableName, $columns);
if (!$stmt) {
fatalError("Failed to create table $tableName\n");
}
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));
}
$server_info = sqlsrv_server_info( $conn );
print_r( $server_info[ 'SQLServerVersion' ] );
sqlsrv_free_stmt($stmt);
sqlsrv_query( $conn, "DROP TABLE test_datetime" );
$server_info = sqlsrv_server_info($conn);
print_r($server_info[ 'SQLServerVersion' ]);
sqlsrv_close( $conn );
dropTable($conn, $tableName);
sqlsrv_close($conn);
?>
--EXPECTREGEX--

View file

@ -1,257 +1,268 @@
--TEST--
Fix for output string parameters length prior to output being delivered
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_versions_old.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 ));
<?php
function insertIntoStudies($conn, $id, $intro)
{
if (AE\isColEncrypted()) {
$stmt = AE\insertRow($conn, 'Studies', array('studyID' => $id, 'Intro' => $intro));
} else {
$stmt = sqlsrv_query($conn, "INSERT INTO Studies (studyID, Intro) VALUES (" . $id . ", N'". $intro ."')");
}
if ($stmt === false) {
fatalError("Failed to insert $id and $intro!\n");
}
}
if( sqlsrv_errors() != NULL ) {
print_r( sqlsrv_errors() );
}
echo "$introText\n";
sqlsrv_configure('WarningsReturnAsErrors', 0);
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
require_once('MsCommon.inc');
$conn = AE\connect();
if ($conn === false) {
die(print_r(sqlsrv_errors(), true));
}
dropProc($conn, 'sp_MakeSubject78');
$tsql_callSP = "{call sp_MakeSubject78(?,?,?,?)}";
$introText="X";
// Create Table 'Subjects' but do not encrypt the first column because in the stored procedure
// we rely on the server to get the current date time. With Column Encryption, all input values
// have to be provided by the client
$columns = array(new AE\ColumnMeta('datetime', 'StartTime', null, true, true),
new AE\ColumnMeta('nchar(32)', 'sn'),
new AE\ColumnMeta('nvarchar(50)', 'extref'));
$stmt = AE\createTable($conn, 'Subjects', $columns);
unset($columns);
// Create table 'sn_x_study'
$columns = array(new AE\ColumnMeta('int', 'studyID'),
new AE\ColumnMeta('nchar(32)', 'sn'));
$stmt = AE\createTable($conn, 'sn_x_study', $columns);
unset($columns);
// Create table 'Studies'. When AE is enabled, the sql type must match
// the column definition, but because this test wants to convert the
// output of column 'Intro' to nvarchar(256), we do not encrypt this second column
$columns = array(new AE\ColumnMeta('int', 'studyID'),
new AE\ColumnMeta('nchar(32)', 'Intro', null, true, true));
$stmt = AE\createTable($conn, 'Studies', $columns);
unset($columns);
// Insert 3 rows into table 'Studies'
insertIntoStudies($conn, 1, "Test class 1");
insertIntoStudies($conn, 2, "12345678901234567890123456789012");
insertIntoStudies($conn, 3, "Test class 3");
$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) {
fatalError("Error occurred when creating stored procedure 'sp_MakeSubject78'\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 );
$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) {
fatalError("Error occurred when calling stored procedure 'sp_MakeSubject78' (1)\n");
}
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) {
fatalError("Error occurred when calling stored procedure 'sp_MakeSubject78' (2)\n");
}
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) {
fatalError("Error occurred when calling stored procedure 'sp_MakeSubject78' (3)\n");
}
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) {
fatalError("Error occurred when calling stored procedure 'sp_MakeSubject78' (4)\n");
}
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) {
fatalError("Error occurred when calling stored procedure 'sp_MakeSubject78' (5)\n");
}
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) {
fatalError("Error occurred when calling stored procedure 'sp_MakeSubject78' (6)\n");
}
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";
dropTable($conn, 'Subjects');
dropTable($conn, 'sn_x_study');
dropTable($conn, 'Studies');
dropProc($conn, 'sp_MakeSubject78');
sqlsrv_close($conn);
?>
--EXPECT--
64

View file

@ -1,7 +1,7 @@
--TEST--
Invalid UTF-16 coming from the server
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
@ -10,32 +10,31 @@ sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
// For testing in Azure, can not switch databases
require_once('MsCommon.inc');
$conn = connect();
$conn = AE\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));
$tableName = 'utf16invalid';
$columns = array(new AE\ColumnMeta('int', 'id', 'identity'),
new AE\ColumnMeta('nvarchar(100)', 'c1'));
$stmt = AE\createTable($conn, $tableName, $columns);
if (!$stmt) {
fatalError("Failed to create table $tableName\n");
}
// 0xdc00,0xdbff is an invalid surrogate pair
$invalid_utf16 = pack("H*", '410042004300440000DCFFDB45004600');
$sqlType = AE\isColEncrypted()? SQLSRV_SQLTYPE_NVARCHAR(100) : null;
$s = sqlsrv_query(
$conn,
"INSERT INTO utf16invalid (c1) VALUES (?)",
"INSERT INTO $tableName (c1) VALUES (?)",
array(
array( &$invalid_utf16, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY)) )
array(&$invalid_utf16, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY), $sqlType))
);
if ($s === false) {
die(print_r(sqlsrv_errors(), true));
}
$s = sqlsrv_query($conn, 'SELECT * FROM utf16invalid');
$s = sqlsrv_query($conn, "SELECT * FROM $tableName");
if ($s === false) {
die(print_r(sqlsrv_errors(), true));
}
@ -48,8 +47,7 @@ if ($utf8 !== false) {
}
print_r(sqlsrv_errors());
$drop_proc = "DROP PROCEDURE Utf16InvalidOut";
$s = sqlsrv_query($conn, $drop_proc);
dropProc($conn, 'Utf16InvalidOut');
$create_proc = <<<PROC
CREATE PROCEDURE Utf16InvalidOut
@ -78,8 +76,8 @@ if ($s !== false) {
}
print_r(sqlsrv_errors());
sqlsrv_query($conn, "DROP TABLE utf16invalid");
sqlsrv_query($conn, $drop_proc);
dropTable($conn, $tableName);
dropProc($conn, 'Utf16InvalidOut');
sqlsrv_close($conn);
echo "Test succeeded.\n";

View file

@ -269,9 +269,13 @@ function createUniqueIndexEx($conn, $tableName, $tableIndex, $colIndex)
trace(" completed successfully.\n");
}
function dropTable($conn, $tableName)
function dropTable($conn, $tableName, $check = false)
{
$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 ($check) {
$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]");
} else {
$stmt = sqlsrv_query($conn, "DROP TABLE [$tableName]");
}
if ($stmt === false) {
} else {
sqlsrv_free_stmt($stmt);
@ -359,7 +363,7 @@ function createProc($conn, $procName, $procArgs, $procCode)
function dropProc($conn, $procName)
{
$stmt = sqlsrv_query($conn, "DROP PROC [$procName]");
$stmt = sqlsrv_query($conn, "IF OBJECT_ID('". $procName ."', 'P') IS NOT NULL DROP PROCEDURE [$procName]");
if ($stmt === false) {
} else {
sqlsrv_free_stmt($stmt);
@ -465,4 +469,17 @@ function isLocaleSupported()
}
}
function verifyError($error, $state, $message)
{
if ($error['SQLSTATE'] !== $state) {
echo $error['SQLSTATE'] . PHP_EOL;
fatalError("Unexpected SQL state\n");
}
if (strpos($error['message'], $message) === false) {
echo $error['message'] . PHP_EOL;
fatalError("Unexpected error message\n");
}
}
?>

View file

@ -253,7 +253,7 @@ function getDefaultColname($dataType)
*/
function getInsertSqlComplete($tbname, $inputs)
{
$colStr = "INSERT INTO $tbname (";
$colStr = "INSERT INTO [$tbname] (";
$valStr = "VALUES (";
if (empty($inputs)) {
echo "getInsertSqlComplete: inputs for inserting a row cannot be empty.\n";
@ -282,7 +282,7 @@ function getInsertSqlComplete($tbname, $inputs)
*/
function getInsertSqlPlaceholders($tbname, $inputs)
{
$colStr = "INSERT INTO $tbname (";
$colStr = "INSERT INTO [$tbname] (";
$valStr = "VALUES (";
if (empty($inputs)) {
echo "getInsertSqlPlaceholders: inputs for inserting a row cannot be empty.\n";
@ -304,7 +304,7 @@ function getInsertSqlPlaceholders($tbname, $inputs)
*/
function getCallProcSqlPlaceholders($spname, $num)
{
$callStr = "{CALL $spname (";
$callStr = "{CALL [$spname] (";
$callStr .= getSeqPlaceholders($num) . ")} ";
return $callStr;
}
@ -396,13 +396,13 @@ function connect($options = array(), $disableCE = false)
function createTable($conn, $tbname, $columnMetaArr)
{
require_once("MsCommon.inc");
dropTable($conn, $tbname);
dropTable($conn, $tbname, true);
$colDef = "";
foreach ($columnMetaArr as $meta) {
$colDef = $colDef . $meta->getColDef() . ", ";
}
$colDef = rtrim($colDef, ", ");
$createSql = "CREATE TABLE $tbname ( $colDef )";
$createSql = "CREATE TABLE [$tbname] ( $colDef )";
return sqlsrv_query($conn, $createSql);
}
@ -554,6 +554,38 @@ function executeQueryEx($conn, $sql, $options)
return $stmt;
}
/**
* Similar to executeQuery() but with params for binding and
* whether this query is expected to fail
* @return resource sqlsrv statement upon success or false otherwise
*/
function executeQueryParams($conn, $sql, $params, $expectedToFail = false, $message = '')
{
$res = true;
if (isColEncrypted()) {
$stmt = sqlsrv_prepare($conn, $sql, $params);
if ($stmt) {
$res = sqlsrv_execute($stmt);
}
} else {
$stmt = sqlsrv_query($conn, $sql, $params);
}
if ($stmt === false || !$res ) {
if (! $expectedToFail) {
fatalError($message);
} else {
print_r(sqlsrv_errors());
}
} else {
if ($expectedToFail) {
fatalError($message);
}
}
return $stmt;
}
/**
* Fetch all rows and all columns given a table name, and print them
* @param resource $conn : connection resource

View file

@ -1,7 +1,7 @@
--TEST--
fix for 182741.
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
sqlsrv_configure('WarningsReturnAsErrors', 0);
@ -9,36 +9,25 @@ fix for 182741.
require_once('MsCommon.inc');
$conn = connect();
if (!$conn) {
fatalError("Could not connect");
$conn = AE\connect();
$tableName = 'test_182741';
$columns = array(new AE\ColumnMeta('int', 'int_type'),
new AE\ColumnMeta('text', 'text_type'),
new AE\ColumnMeta('ntext', 'ntext_type'),
new AE\ColumnMeta('image', 'image_type'));
$stmt = AE\createTable($conn, $tableName, $columns);
if (!$stmt) {
fatalError("Failed to create table $tableName\n");
}
$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));
}
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)))
);
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
sqlsrv_query($conn, "DROP TABLE [182741]");
$sql = "INSERT INTO $tableName ([int_type], [text_type], [ntext_type], [image_type]) VALUES(?, ?, ?, ?)";
$params = 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)));
$stmt = AE\executeQueryParams($conn, $sql, $params);
dropTable($conn, $tableName);
sqlsrv_free_stmt($stmt);

View file

@ -1,7 +1,7 @@
--TEST--
new SQL Server 2008 date types.
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
date_default_timezone_set('America/Los_Angeles');
@ -12,70 +12,65 @@ sqlsrv_configure('LogSubsystems', SQLSRV_LOG_SYSTEM_OFF);
require_once('MsCommon.inc');
// For testing in Azure, can not switch databases
$conn = connect(array( 'ReturnDatesAsStrings' => true ));
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, "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");
$conn = AE\connect(array('ReturnDatesAsStrings' => true));
$tableName = '2008_date_types';
$columns = array(new AE\ColumnMeta('int', 'id'),
new AE\ColumnMeta('date', 'c1_date'),
new AE\ColumnMeta('time', 'c2_time'),
new AE\ColumnMeta('datetimeoffset', 'c3_datetimeoffset'),
new AE\ColumnMeta('datetime2', 'c4_datetime2'));
$stmt = AE\createTable($conn, $tableName, $columns);
if (!$stmt) {
fatalError("Failed to create table $tableName\n");
}
// 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])" .
" VALUES (?, ?, ?, ?, ?)",
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 ))
$insertSql = "INSERT INTO [$tableName] (id, [c1_date], [c2_time], [c3_datetimeoffset], [c4_datetime2]) VALUES (?, ?, ?, ?, ?)";
$stmt = AE\executeQueryParams(
$conn,
$insertSql,
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)),
false,
"Insert 1 failed"
);
if ($stmt === false) {
fatalError("Insert 1 failed");
}
// insert new date time types as DateTime objects (this works now)
$stmt = sqlsrv_query(
$stmt = AE\executeQueryParams(
$conn,
"INSERT INTO [2008_date_types] (id, [c1_date], [c2_time], [c3_datetimeoffset], [c4_datetime2])" .
" VALUES (?, ?, ?, ?, ?)",
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 ))
$insertSql,
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)),
false,
"Insert 2 failed"
);
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(
$stmt = AE\executeQueryParams(
$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())
$insertSql,
array(rand(0, 99999), date_create(), date_create(), date_create(), date_create()),
false,
"Insert 3 failed"
);
if ($stmt === false) {
fatalError("Insert 3 failed");
}
// insert new date time types as strings with no type information (this works)
$stmt = sqlsrv_query(
$stmt = AE\executeQueryParams(
$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'))
$insertSql,
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')),
false,
"Insert 4 failed"
);
if ($stmt === false) {
fatalError("Insert 4 failed");
}
// retrieve date time fields as strings (this works)
$stmt = sqlsrv_query($conn, "SELECT * FROM [2008_date_types]");
$stmt = sqlsrv_query($conn, "SELECT * FROM [$tableName]");
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));
@ -84,7 +79,7 @@ while (sqlsrv_fetch($stmt)) {
}
// retrieve date time fields as default (should come back as DateTime objects) (this works now)
$stmt = sqlsrv_query($conn, "SELECT * FROM [2008_date_types]");
$stmt = sqlsrv_query($conn, "SELECT * FROM [$tableName]");
if ($stmt === false) {
fatalError("Select from table failed");
}
@ -93,7 +88,7 @@ while ($row = sqlsrv_fetch_array($stmt)) {
}
// retrieve date itme fields as DateTime objects
$stmt = sqlsrv_query($conn, "SELECT * FROM [2008_date_types]");
$stmt = sqlsrv_query($conn, "SELECT * FROM [$tableName]");
while (sqlsrv_fetch($stmt)) {
for ($i = 1; $i < sqlsrv_num_fields($stmt); ++$i) {
$fld = sqlsrv_get_field($stmt, $i, SQLSRV_PHPTYPE_DATETIME);

View file

@ -6,17 +6,17 @@ steps to reproduce the issue:
1- create a store procedure with print and output parameter
2- initialize output parameters to a different data type other than the type declared in sp.
3- set the WarningsReturnAsErrors to true
4 - call sp.
4- call sp.
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
require_once('MsCommon.inc');
$conn = connect();
if ($conn === false) {
die(print_r(sqlsrv_errors(), true));
}
$conn = AE\connect();
//----------------Main---------------------------
$procName = GetTempProcName();
$procName = 'test_378';
createSP($conn, $procName);
sqlsrv_configure('WarningsReturnAsErrors', true);
@ -24,10 +24,15 @@ executeSP($conn, $procName);
sqlsrv_configure('WarningsReturnAsErrors', false);
executeSP($conn, $procName);
echo "Done";
dropProc($conn, $procName);
echo "Done\n";
//-------------------functions-------------------
function createSP($conn, $procName)
{
dropProc($conn, $procName);
$sp_sql="create proc $procName @p1 integer, @p2 integer, @p3 integer output
as
begin
@ -47,8 +52,17 @@ function executeSP($conn, $procName)
$v1 = 1;
$v2 = 2;
$v3 = 'str';
$stmt = sqlsrv_query($conn, "{call $procName( ?, ?, ? )}", array( $v1, $v2, array( &$v3, SQLSRV_PARAM_OUT )));
if ($stmt === false) {
$res = true;
if (AE\isColEncrypted()) {
$stmt = sqlsrv_prepare($conn, "{call $procName( ?, ?, ?)}", array($v1, $v2, array(&$v3, SQLSRV_PARAM_OUT)));
if ($stmt) {
$res = sqlsrv_execute($stmt);
}
} else {
$stmt = sqlsrv_query($conn, "{call $procName( ?, ?, ?)}", array($v1, $v2, array(&$v3, SQLSRV_PARAM_OUT)));
}
if ($stmt === false || !$res) {
print_r(sqlsrv_errors(), true);
}
if ($v3 != $expected) {

View file

@ -1,22 +1,18 @@
--TEST--
Verify the Binary and Char encoding output when binding output string with SQLSTYPE option with different size
Verify the Binary and Char encoding output
--DESCRIPTION--
Verify the Binary and Char encoding output when binding output string with SQLSRV SQL TYPE option with different size
Will not convert this test for AE testing because the goal of this test is to deliberately use a different size for SQLSRV SQL TYPE from the designated output param in the stored procedure
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
require_once('MsCommon.inc');
$conn = Connect();
if ($conn === false) {
fatalError("Could not connect");
}
$conn = AE\connect(null, true); // disable Always Encrypted feature
$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));
}
$tableName = 'BindStringTest';
dropTable($conn, $tableName);
dropProc($conn, 'uspPerson');
$stmt = sqlsrv_query($conn, "CREATE TABLE BindStringTest (PersonID int, Name nvarchar(50))");
if ($stmt === false) {
@ -60,7 +56,7 @@ $params = array(
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
SQLSRV_SQLTYPE_NVARCHAR(32)
SQLSRV_SQLTYPE_NVARCHAR(32)
));
if ($stmt = sqlsrv_query($conn, $tsql_callSP, $params) === false) {
@ -80,7 +76,7 @@ $params = array(
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY),
SQLSRV_SQLTYPE_NVARCHAR(32)
SQLSRV_SQLTYPE_NVARCHAR(32)
));
if ($stmt = sqlsrv_query($conn, $tsql_callSP, $params) == false) {
print_r(sqlsrv_errors(), true);
@ -102,7 +98,7 @@ $params = array(
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
SQLSRV_SQLTYPE_NVARCHAR(50)
SQLSRV_SQLTYPE_NVARCHAR(50)
));
if ($stmt = sqlsrv_query($conn, $tsql_callSP, $params) === false) {
@ -123,7 +119,7 @@ $params = array(
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY),
SQLSRV_SQLTYPE_NVARCHAR(50)
SQLSRV_SQLTYPE_NVARCHAR(50)
));
if ($stmt = sqlsrv_query($conn, $tsql_callSP, $params) == false) {
print_r(sqlsrv_errors(), true);
@ -147,7 +143,7 @@ $params = array(
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
SQLSRV_SQLTYPE_NVARCHAR(1)
SQLSRV_SQLTYPE_NVARCHAR(1)
));
if ($stmt = sqlsrv_query($conn, $tsql_callSP, $params) === false) {
@ -167,7 +163,7 @@ $params = array(
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY),
SQLSRV_SQLTYPE_NVARCHAR(1)
SQLSRV_SQLTYPE_NVARCHAR(1)
));
if ($stmt = sqlsrv_query($conn, $tsql_callSP, $params) == false) {
echo "Statement should fail\n";
@ -189,7 +185,7 @@ $params = array(
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
SQLSRV_SQLTYPE_NCHAR(32)
SQLSRV_SQLTYPE_NCHAR(32)
));
if ($stmt = sqlsrv_query($conn, $tsql_callSP, $params) === false) {
@ -209,7 +205,7 @@ $params = array(
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY),
SQLSRV_SQLTYPE_NCHAR(32)
SQLSRV_SQLTYPE_NCHAR(32)
));
if ($stmt = sqlsrv_query($conn, $tsql_callSP, $params) == false) {
print_r(sqlsrv_errors(), true);
@ -231,7 +227,7 @@ $params = array(
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
SQLSRV_SQLTYPE_NCHAR(0)
SQLSRV_SQLTYPE_NCHAR(0)
));
if ($stmt = sqlsrv_query($conn, $tsql_callSP, $params) === false) {
@ -251,7 +247,7 @@ $params = array(
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY),
SQLSRV_SQLTYPE_NCHAR(0)
SQLSRV_SQLTYPE_NCHAR(0)
));
if ($stmt = sqlsrv_query($conn, $tsql_callSP, $params) == false) {
echo "Statement should fail\n";
@ -273,7 +269,7 @@ $params = array(
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
SQLSRV_SQLTYPE_NCHAR(50)
SQLSRV_SQLTYPE_NCHAR(50)
));
if ($stmt = sqlsrv_query($conn, $tsql_callSP, $params) === false) {
@ -293,7 +289,7 @@ $params = array(
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY),
SQLSRV_SQLTYPE_NCHAR(50)
SQLSRV_SQLTYPE_NCHAR(50)
));
if ($stmt = sqlsrv_query($conn, $tsql_callSP, $params) == false) {
print_r(sqlsrv_errors(), true);
@ -316,7 +312,7 @@ $params = array(
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),
SQLSRV_SQLTYPE_NCHAR(1)
SQLSRV_SQLTYPE_NCHAR(1)
));
if ($stmt = sqlsrv_query($conn, $tsql_callSP, $params) === false) {
@ -336,7 +332,7 @@ $params = array(
array($id, SQLSRV_PARAM_IN),
array(&$return, SQLSRV_PARAM_OUT,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY),
SQLSRV_SQLTYPE_NCHAR(1)
SQLSRV_SQLTYPE_NCHAR(1)
));
if ($stmt = sqlsrv_query($conn, $tsql_callSP, $params) == false) {
print_r(sqlsrv_errors(), true);
@ -348,8 +344,10 @@ $actualValue = $return;
$actualLength = strlen($return);
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");
dropTable($conn, $tableName);
dropProc($conn, 'uspPerson');
sqlsrv_close($conn);
@ -372,6 +370,7 @@ function compareResults($expectedLength, $expectedValue, $actualLength, $actualV
}
if (!$match) {
echo "The actual result is different from the expected one \n";
echo "Expected $expectedValue($expectedLength) but get $actualValue($actualLength) \n";
} else {
echo "The actual result is the same as the expected one \n";
}

View file

@ -4,7 +4,7 @@ Test for binding boolean output and inout parameters
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
require_once("MsHelper.inc");
require_once('MsCommon.inc');
$conn = AE\connect();
@ -12,12 +12,13 @@ $conn = AE\connect();
$tbname = "bool_table";
AE\createTable($conn, $tbname, array(new AE\ColumnMeta("int", "c1_bool")));
// Create a Stored Procedure with output
$spname = "selectBool";
dropProc($conn, $spname);
$spSql = "CREATE PROCEDURE $spname (@c1_bool int OUTPUT) AS
SELECT @c1_bool = c1_bool FROM $tbname";
sqlsrv_query( $conn, $spSql );
sqlsrv_query($conn, $spSql);
// Insert 1
AE\insertRow($conn, $tbname, array("c1_bool" => 1));

View file

@ -1,50 +1,50 @@
--TEST--
test input param with unknown encoding
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
set_time_limit(0);
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
sqlsrv_configure( 'LogSubsystems', SQLSRV_LOG_SYSTEM_OFF );
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');
$conn = Connect();
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true ));
$conn = AE\connect();
$tableName = 'php_table_SERIL1_1';
$columns = array(new AE\ColumnMeta('int', 'c1_int'),
new AE\ColumnMeta('varchar(max)', 'c2_varchar_max'));
$stmt = AE\createTable($conn, $tableName, $columns);
if (!$stmt) {
fatalError("Failed to create table $tableName\n");
}
$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 );
$errState = 'IMSSP';
$errMessage = 'An invalid PHP type for parameter 2 was specified.';
$intType = AE\isColEncrypted() ? SQLSRV_SQLTYPE_INT : null;
$stmt = sqlsrv_query($conn, "INSERT INTO [php_table_SERIL1_1] (c1_int, c2_varchar_max) VALUES (?, ?)", array(array(1, null, null, $intType),
array("Test Data", SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_UNKNOWN), null)));
if ($stmt !== false) {
sqlsrv_free_stmt($stmt);
die("sqlsrv_query shouldn't have succeeded.");
}
$stmt = sqlsrv_query($conn, "CREATE TABLE [php_table_SERIL1_1] ([c1_int] int, [c2_varchar_max] varchar(max))");
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
}
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query($conn, "INSERT INTO [php_table_SERIL1_1] (c1_int, c2_varchar_max) VALUES (?, ?)", array(1, array("Test Data", SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_UNKNOWN), null)));
if( $stmt !== false ) {
sqlsrv_free_stmt( $stmt );
die( "sqlsrv_query shouldn't have succeeded." );
}
print_r( sqlsrv_errors() );
verifyError(sqlsrv_errors()[0], $errState, $errMessage);
$stmt = sqlsrv_prepare($conn, "INSERT INTO [php_table_SERIL1_1] (c1_int, c2_varchar_max) VALUES (?, ?)", array(1, array("Test Data", SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_UNKNOWN), null)));
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
$result = sqlsrv_execute( $stmt );
if( $result !== false ) {
sqlsrv_free_stmt( $stmt );
die( "sqlsrv_execute shouldn't have succeeded." );
$result = sqlsrv_execute($stmt);
if ($result !== false) {
sqlsrv_free_stmt($stmt);
die("sqlsrv_execute shouldn't have succeeded.");
}
print_r( sqlsrv_errors() );
verifyError(sqlsrv_errors()[0], $errState, $errMessage);
sqlsrv_query($conn, "DROP TABLE [php_table_SERIL1_1]");
@ -52,32 +52,6 @@ sqlsrv_close($conn);
?>
--EXPECTREGEX--
(Warning|Notice)\: Use of undefined constant SQLSRV_ENC_UNKNOWN - assumed \'SQLSRV_ENC_UNKNOWN\' (\(this will throw an Error in a future version of PHP\) )?in .+(\/|\\)sqlsrv_input_param_unknown_encoding\.php on line 26
Array
\(
\[0\] => Array
\(
\[0\] => IMSSP
\[SQLSTATE\] => IMSSP
\[1\] => -16
\[code\] => -16
\[2\] => An invalid PHP type for parameter 2 was specified\.
\[message\] => An invalid PHP type for parameter 2 was specified\.
\)
(Warning|Notice)\: Use of undefined constant SQLSRV_ENC_UNKNOWN - assumed \'SQLSRV_ENC_UNKNOWN\' (\(this will throw an Error in a future version of PHP\) )?in .+(\/|\\)sqlsrv_input_param_unknown_encoding\.php on line 24
\)
(Warning|Notice)\: Use of undefined constant SQLSRV_ENC_UNKNOWN - assumed \'SQLSRV_ENC_UNKNOWN\' (\(this will throw an Error in a future version of PHP\) )?in .+(\/|\\)sqlsrv_input_param_unknown_encoding\.php on line 33
Array
\(
\[0\] => Array
\(
\[0\] => IMSSP
\[SQLSTATE\] => IMSSP
\[1\] => -16
\[code\] => -16
\[2\] => An invalid PHP type for parameter 2 was specified\.
\[message\] => An invalid PHP type for parameter 2 was specified\.
\)
\)
(Warning|Notice)\: Use of undefined constant SQLSRV_ENC_UNKNOWN - assumed \'SQLSRV_ENC_UNKNOWN\' (\(this will throw an Error in a future version of PHP\) )?in .+(\/|\\)sqlsrv_input_param_unknown_encoding\.php on line 32

View file

@ -13,27 +13,56 @@ hierarchyid
geometry
datetimeoffset
User-defined types
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
require_once('MsCommon.inc');
require_once('tools.inc');
function CreateVariantTable($conn, $tableName)
function createVariantTable($conn, $tableName)
{
$dataType = "[c1_int] sql_variant, [c2_tinyint] sql_variant, [c3_smallint] sql_variant, [c4_bigint] sql_variant, [c5_bit] sql_variant, [c6_float] sql_variant, [c7_real] sql_variant, [c8_decimal] sql_variant, [c9_numeric] sql_variant, [c10_money] sql_variant, [c11_smallmoney] sql_variant, [c12_char] sql_variant, [c13_varchar] sql_variant, [c14_uniqueidentifier] sql_variant, [c15_datetime] sql_variant, [c16_smalldatetime] sql_variant";
createTableEx($conn, $tableName, $dataType);
// Do not encrypt the first column because we need to perform 'order by'
$columns = array(new AE\ColumnMeta('sql_variant', 'c1_int', null, null, true),
new AE\ColumnMeta('sql_variant', 'c2_tinyint'),
new AE\ColumnMeta('sql_variant', 'c3_smallint'),
new AE\ColumnMeta('sql_variant', 'c4_bigint'),
new AE\ColumnMeta('sql_variant', 'c5_bit'),
new AE\ColumnMeta('sql_variant', 'c6_float'),
new AE\ColumnMeta('sql_variant', 'c7_real'),
new AE\ColumnMeta('sql_variant', 'c8_decimal'),
new AE\ColumnMeta('sql_variant', 'c9_numeric'),
new AE\ColumnMeta('sql_variant', 'c10_money'),
new AE\ColumnMeta('sql_variant', 'c11_smallmoney'),
new AE\ColumnMeta('sql_variant', 'c12_char'),
new AE\ColumnMeta('sql_variant', 'c13_varchar'),
new AE\ColumnMeta('sql_variant', 'c14_uniqueidentifier'),
new AE\ColumnMeta('sql_variant', 'c15_datetime'),
new AE\ColumnMeta('sql_variant', 'c16_smalldatetime'));
$stmt = AE\createTable($conn, $tableName, $columns);
if (!$stmt) {
fatalError("Failed to create table $tableName\n");
}
}
function InsertData($conn, $tableName, $index)
function insertData($conn, $tableName, $index)
{
$data = GetInputData($index, $tableName);
$stmt = sqlsrv_query($conn, "INSERT INTO [$tableName] (c1_int, c2_tinyint, c3_smallint, c4_bigint, c5_bit, c6_float, c7_real, c8_decimal, c9_numeric, c10_money, c11_smallmoney, c12_char, c13_varchar, c14_uniqueidentifier, c15_datetime, c16_smalldatetime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", $data);
$data = getInputData($index, $tableName);
$insertSql = "INSERT INTO [$tableName] (c1_int, c2_tinyint, c3_smallint, c4_bigint, c5_bit, c6_float, c7_real, c8_decimal, c9_numeric, c10_money, c11_smallmoney, c12_char, c13_varchar, c14_uniqueidentifier, c15_datetime, c16_smalldatetime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
if (AE\isColEncrypted()) {
$stmt = sqlsrv_prepare($conn, $insertSql, $data);
if ($stmt) {
sqlsrv_execute($stmt);
}
} else {
$stmt = sqlsrv_query($conn, $insertSql, $data);
}
if (! $stmt) {
fatalError("Failed to insert row $index.\n");
}
}
function FetchData($conn, $tableName, $numRows)
function fetchData($conn, $tableName, $numRows)
{
$select = "SELECT * FROM $tableName ORDER BY c1_int";
$stmt = sqlsrv_query($conn, $select);
@ -41,7 +70,7 @@ function FetchData($conn, $tableName, $numRows)
$metadata = sqlsrv_field_metadata($stmt);
$numFields = count($metadata);
$noActualRows = ReadData($stmt, $stmt2, $numFields);
$noActualRows = readData($stmt, $stmt2, $numFields);
echo "Number of rows fetched: $noActualRows\n";
if ($noActualRows != $numRows) {
@ -49,7 +78,7 @@ function FetchData($conn, $tableName, $numRows)
}
}
function ReadData($stmt, $stmt2, $numFields)
function readData($stmt, $stmt2, $numFields)
{
$fetched = 0;
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_NUMERIC)) {
@ -66,28 +95,28 @@ function ReadData($stmt, $stmt2, $numFields)
}
$fld = 0;
DoValuesMatched($obj->c1_int, $row[$fld], $fetched, $fld++);
DoValuesMatched($obj->c2_tinyint, $row[$fld], $fetched, $fld++);
DoValuesMatched($obj->c3_smallint, $row[$fld], $fetched, $fld++);
DoValuesMatched($obj->c4_bigint, $row[$fld], $fetched, $fld++);
DoValuesMatched($obj->c5_bit, $row[$fld], $fetched, $fld++);
DoValuesMatched($obj->c6_float, $row[$fld], $fetched, $fld++);
DoValuesMatched($obj->c7_real, $row[$fld], $fetched, $fld++);
DoValuesMatched($obj->c8_decimal, $row[$fld], $fetched, $fld++);
DoValuesMatched($obj->c9_numeric, $row[$fld], $fetched, $fld++);
DoValuesMatched($obj->c10_money, $row[$fld], $fetched, $fld++);
DoValuesMatched($obj->c11_smallmoney, $row[$fld], $fetched, $fld++);
DoValuesMatched($obj->c12_char, $row[$fld], $fetched, $fld++);
DoValuesMatched($obj->c13_varchar, $row[$fld], $fetched, $fld++);
DoValuesMatched($obj->c14_uniqueidentifier, $row[$fld], $fetched, $fld++);
DoValuesMatched($obj->c15_datetime, $row[$fld], $fetched, $fld++);
DoValuesMatched($obj->c16_smalldatetime, $row[$fld], $fetched, $fld++);
doValuesMatched($obj->c1_int, $row[$fld], $fetched, $fld++);
doValuesMatched($obj->c2_tinyint, $row[$fld], $fetched, $fld++);
doValuesMatched($obj->c3_smallint, $row[$fld], $fetched, $fld++);
doValuesMatched($obj->c4_bigint, $row[$fld], $fetched, $fld++);
doValuesMatched($obj->c5_bit, $row[$fld], $fetched, $fld++);
doValuesMatched($obj->c6_float, $row[$fld], $fetched, $fld++);
doValuesMatched($obj->c7_real, $row[$fld], $fetched, $fld++);
doValuesMatched($obj->c8_decimal, $row[$fld], $fetched, $fld++);
doValuesMatched($obj->c9_numeric, $row[$fld], $fetched, $fld++);
doValuesMatched($obj->c10_money, $row[$fld], $fetched, $fld++);
doValuesMatched($obj->c11_smallmoney, $row[$fld], $fetched, $fld++);
doValuesMatched($obj->c12_char, $row[$fld], $fetched, $fld++);
doValuesMatched($obj->c13_varchar, $row[$fld], $fetched, $fld++);
doValuesMatched($obj->c14_uniqueidentifier, $row[$fld], $fetched, $fld++);
doValuesMatched($obj->c15_datetime, $row[$fld], $fetched, $fld++);
doValuesMatched($obj->c16_smalldatetime, $row[$fld], $fetched, $fld++);
}
// returns the number of rows fetched
return $fetched;
}
function DoValuesMatched($value1, $value2, $row, $col)
function doValuesMatched($value1, $value2, $row, $col)
{
$matched = false;
if (is_null($value1) && is_null($value2)) {
@ -106,7 +135,7 @@ function DoValuesMatched($value1, $value2, $row, $col)
}
}
function GetInputData($index)
function getInputData($index)
{
switch ($index) {
case 1:
@ -122,34 +151,29 @@ function GetInputData($index)
}
}
function RunTest()
{
startTest("sqlsrv_param_input_variants");
try {
setup();
$conn = connect();
try {
setup();
$conn = connect();
// Create a temp table that will be automatically dropped once the connection is closed
$tableName = GetTempTableName();
CreateVariantTable($conn, $tableName);
// Create a temp table that will be automatically dropped once the connection is closed
$tableName = 'param_input_variants';
createVariantTable($conn, $tableName);
// Insert data
$numRows = 4;
for ($i = 1; $i <= $numRows; $i++) {
InsertData($conn, $tableName, $i);
}
FetchData($conn, $tableName, $numRows);
sqlsrv_close($conn);
} catch (Exception $e) {
echo $e->getMessage();
// Insert data
$numRows = 4;
for ($i = 1; $i <= $numRows; $i++) {
insertData($conn, $tableName, $i);
}
echo "\nDone\n";
endTest("sqlsrv_param_input_variants");
}
RunTest();
fetchData($conn, $tableName, $numRows);
dropTable($conn, $tableName);
sqlsrv_close($conn);
} catch (Exception $e) {
echo $e->getMessage();
}
echo "\nDone\n";
?>
--EXPECT--
@ -160,4 +184,3 @@ Comparing data in row 4
Number of rows fetched: 4
Done
Test "sqlsrv_param_input_variants" completed successfully.

View file

@ -1,25 +1,28 @@
--TEST--
Test insertion with floats
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
require_once('MsCommon.inc');
function ExecData($withParams)
function execData($withParams)
{
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
// connect
$conn = connect();
if (!$conn) {
fatalError("Could not connect.\n");
$conn = AE\connect();
$tableName = 'test_ints_with_deletes';
$columns = array(new AE\ColumnMeta('int', 'c1_int'),
new AE\ColumnMeta('smallint', 'c2_smallint'));
$stmt = AE\createTable($conn, $tableName, $columns);
if (!$stmt) {
fatalError("Failed to create table $tableName\n");
}
$tableName = GetTempTableName();
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_smallint] smallint)");
sqlsrv_free_stmt($stmt);
if ($withParams) {
$stmt = sqlsrv_prepare($conn, "INSERT INTO $tableName (c1_int, c2_smallint) VALUES (?, ?)", array(array(&$v1, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_INT), array(&$v2, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_INT)));
} else {
@ -79,11 +82,13 @@ function ExecData($withParams)
}
sqlsrv_free_stmt($stmt);
DeleteRows($conn, $numRows, $tableName);
deleteRows($conn, $numRows, $tableName);
dropTable($conn, $tableName);
sqlsrv_close($conn);
}
function DeleteRows($conn, $numRows, $tableName)
function deleteRows($conn, $numRows, $tableName)
{
$stmt1 = sqlsrv_prepare($conn, "SELECT * FROM $tableName");
$stmt2 = sqlsrv_prepare($conn, "DELETE TOP(3) FROM $tableName");
@ -115,21 +120,15 @@ function DeleteRows($conn, $numRows, $tableName)
sqlsrv_free_stmt($stmt2);
}
function Repro()
{
startTest("sqlsrv_statement_exec_param_ints");
echo "\nTest begins...\n";
try {
ExecData(true);
ExecData(false);
} catch (Exception $e) {
echo $e->getMessage();
}
echo "\nDone\n";
endTest("sqlsrv_statement_exec_param_ints");
echo "\nTest begins...\n";
try {
execData(true);
execData(false);
} catch (Exception $e) {
echo $e->getMessage();
}
Repro();
echo "\nDone\n";
endTest("sqlsrv_statement_exec_param_ints");
?>
--EXPECT--

View file

@ -1,15 +1,20 @@
--TEST--
Test parametrized insert and sql_variant as an output parameter.
--DESCRIPTION--
sql_variant is not supported for output parameters, this test checks the error handling in this case
Normally, sql_variant is not supported for output parameters, this test checks the error handling in this case. However, when Always Encrypted is enabled, we are able to bind output parameters with prepared
statements.
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
require_once('MsCommon.inc');
function CreateVariantTable($conn, $tableName)
function createVariantTable($conn, $tableName)
{
$stmt = sqlsrv_query($conn, "CREATE TABLE [$tableName] ([c1_int] int, [c2_variant] sql_variant)");
if (! $stmt) {
$columns = array(new AE\ColumnMeta('int', 'c1_int'),
new AE\ColumnMeta('sql_variant', 'c2_variant'));
$stmt = AE\createTable($conn, $tableName, $columns);
if (!$stmt) {
fatalError("Failed to create table.\n");
}
@ -25,14 +30,28 @@ function CreateVariantTable($conn, $tableName)
sqlsrv_free_stmt($stmt);
}
function TestOutputParam($conn, $tableName)
function execProcedure($conn, $tsql, $params)
{
// First, create a temporary stored procedure
$procName = GetTempProcName('sqlVariant');
if (AE\isColEncrypted()) {
$stmt = sqlsrv_prepare($conn, $tsql, $params);
if ($stmt) {
sqlsrv_execute($stmt);
}
} else {
$stmt = sqlsrv_query($conn, $tsql, $params);
}
return $stmt;
}
function testOutputParam($conn, $tableName)
{
// First, create a stored procedure
$procName = getTempProcName('sqlVariant', false);
$spArgs = "@p2 sql_variant OUTPUT";
$spCode = "SET @p2 = ( SELECT [c2_variant] FROM $tableName WHERE [c1_int] = 1 )";
// There is only one row in the table
$spCode = "SET @p2 = ( SELECT [c2_variant] FROM $tableName )";
$stmt = sqlsrv_query($conn, "CREATE PROC [$procName] ($spArgs) AS BEGIN $spCode END");
sqlsrv_free_stmt($stmt);
@ -46,23 +65,21 @@ function TestOutputParam($conn, $tableName)
$phpType = SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR);
$params = array( array( &$callResult, SQLSRV_PARAM_OUT, $phpType ));
$params = array(array(&$callResult, SQLSRV_PARAM_OUT, $phpType));
$stmt = sqlsrv_query($conn, "{ CALL [$procName] ($callArgs)}", $params);
if (! $stmt) {
print_errors();
if (strcmp($initData, $callResult)) {
echo "initialized data and results should be the same";
}
echo "\n";
$stmt = execProcedure($conn, "{ CALL [$procName] ($callArgs)}", $params);
if (!$stmt) {
verifyErrorMessage(sqlsrv_errors()[0]);
}
dropProc($conn, $procName);
}
function TestInputAndOutputParam($conn, $tableName)
function testInputAndOutputParam($conn, $tableName)
{
$procName = GetTempProcName('sqlVariant');
$procName = getTempProcName('sqlVariant', false);
$spArgs = "@p1 int, @p2 sql_variant OUTPUT";
$spCode = "SET @p2 = ( SELECT [c2_variant] FROM $tableName WHERE [c1_int] = @p1 )";
$spCode = "SET @p2 = ( SELECT [c2_variant] FROM $tableName WHERE [c1_int] = @p1)";
$stmt = sqlsrv_query($conn, "CREATE PROC [$procName] ($spArgs) AS BEGIN $spCode END");
sqlsrv_free_stmt($stmt);
@ -70,62 +87,46 @@ function TestInputAndOutputParam($conn, $tableName)
$callResult = $initData;
$phpType = SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR);
$params = array( array( 1, SQLSRV_PARAM_IN ), array( &$callResult, SQLSRV_PARAM_OUT, $phpType ));
$params = array(array(1, SQLSRV_PARAM_IN), array(&$callResult, SQLSRV_PARAM_OUT, $phpType));
$callArgs = "?, ?";
$stmt = sqlsrv_query($conn, "{ CALL [$procName] ($callArgs)}", $params);
if (! $stmt) {
print_errors();
if (strcmp($initData, $callResult)) {
echo "initialized data and results should be the same\n";
}
$stmt = execProcedure($conn, "{ CALL [$procName] ($callArgs)}", $params);
if (!$stmt) {
verifyErrorMessage(sqlsrv_errors()[0]);
}
dropProc($conn, $procName);
}
function print_errors()
function verifyErrorMessage($error)
{
$errors = sqlsrv_errors();
$count = count($errors);
if ($count > 0) {
for ($i = 0; $i < $count; $i++) {
print($errors[$i]['message']."\n");
}
if (AE\isColEncrypted()) {
fatalError("With AE this should not have failed!");
}
// Expect to fail only when AE is disabled
$expected = "Operand type clash: varchar(max) is incompatible with sql_variant";
if (strpos($error['message'], $expected) === false) {
echo $error['message'] . PHP_EOL;
fatalError("Expected error: $expected\n");
}
}
function RunTest()
{
startTest("sqlsrv_param_output_variants");
try {
setup();
setup();
// connect
$conn = connect();
// connect
$conn = AE\connect();
// Create a temp table that will be automatically dropped once the connection is closed
$tableName = GetTempTableName();
CreateVariantTable($conn, $tableName);
echo "\n";
// Create a test table that will be automatically dropped once the connection is closed
$tableName = GetTempTableName('test_output_variants', false);
createVariantTable($conn, $tableName);
TestOutputParam($conn, $tableName);
TestInputAndOutputParam($conn, $tableName);
testOutputParam($conn, $tableName);
testInputAndOutputParam($conn, $tableName);
sqlsrv_close($conn);
} catch (Exception $e) {
echo $e->getMessage();
}
echo "\nDone\n";
endTest("sqlsrv_param_output_variants");
}
RunTest();
dropTable($conn, $tableName);
sqlsrv_close($conn);
print "Test completed successfully\n";
?>
--EXPECTREGEX--

\[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]\[SQL Server\]Operand type clash: varchar\(max\) is incompatible with sql_variant
\[Microsoft\]\[ODBC Driver 1[1-9] for SQL Server\]\[SQL Server\]Operand type clash: varchar\(max\) is incompatible with sql_variant
Done
Test \"sqlsrv_param_output_variants\" completed successfully\.
--EXPECT--
Test completed successfully

View file

@ -1,58 +1,64 @@
--TEST--
Test insert various numeric data types and fetch them back as strings
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
require_once('MsCommon.inc');
require_once('tools.inc');
function ParamQuery($conn, $type, $sqlsrvType, $inValue)
function paramQuery($conn, $type, $sqlsrvType, $inValue)
{
$tableName = GetTempTableName();
$tableName = 'param_test';
$stmt = sqlsrv_query($conn, "CREATE TABLE [$tableName] ([col1] int, [col2] $type)");
$columns = array(new AE\ColumnMeta('int', 'col1'),
new AE\ColumnMeta($type, 'col2'));
$stmt = AE\createTable($conn, $tableName, $columns);
if (!$stmt) {
fatalError("Failed to create table $tableName\n");
}
$insertSql = "INSERT INTO [$tableName] VALUES (?, ?)";
$params = array(1, array($inValue, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_FLOAT, $sqlsrvType));
if (AE\isColEncrypted()) {
$stmt = sqlsrv_prepare($conn, $insertSql, $params);
if ($stmt) {
sqlsrv_execute($stmt);
}
} else {
$stmt = sqlsrv_query($conn, $insertSql, $params);
}
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query($conn, "INSERT INTO [$tableName] VALUES (?, ?)", array(1, array($inValue, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_FLOAT, $sqlsrvType)));
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query($conn, "SELECT * FROM $tableName");
sqlsrv_fetch($stmt);
$value = sqlsrv_get_field($stmt, 1, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
CompareNumericData($value, $inValue);
compareNumericData($value, $inValue);
dropTable($conn, $tableName);
sqlsrv_free_stmt($stmt);
}
function Repro()
{
startTest("sqlsrv_param_query_data_types");
echo "\nTest begins...\n";
try {
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
echo "\nTest begins...\n";
try {
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
// connect
$conn = connect();
if (!$conn) {
fatalError("Could not connect.\n");
}
// connect
$conn = AE\connect();
ParamQuery($conn, "float", SQLSRV_SQLTYPE_FLOAT, 12.345);
ParamQuery($conn, "money", SQLSRV_SQLTYPE_MONEY, 56.78);
ParamQuery($conn, "numeric(32,4)", SQLSRV_SQLTYPE_NUMERIC(32, 4), 12.34);
ParamQuery($conn, "real", SQLSRV_SQLTYPE_REAL, 98.760);
ParamQuery($conn, "smallmoney", SQLSRV_SQLTYPE_SMALLMONEY, 56.78);
paramQuery($conn, "float", SQLSRV_SQLTYPE_FLOAT, 12.345);
paramQuery($conn, "money", SQLSRV_SQLTYPE_MONEY, 56.78);
paramQuery($conn, "numeric(32,4)", SQLSRV_SQLTYPE_NUMERIC(32, 4), 12.34);
paramQuery($conn, "real", SQLSRV_SQLTYPE_REAL, 98.760);
paramQuery($conn, "smallmoney", SQLSRV_SQLTYPE_SMALLMONEY, 56.78);
sqlsrv_close($conn);
} catch (Exception $e) {
echo $e->getMessage();
}
echo "\nDone\n";
endTest("sqlsrv_param_query_data_types");
sqlsrv_close($conn);
} catch (Exception $e) {
echo $e->getMessage();
}
Repro();
echo "\nDone\n";
?>
--EXPECT--
@ -60,4 +66,3 @@ Repro();
Test begins...
Done
Test "sqlsrv_param_query_data_types" completed successfully.

View file

@ -1,17 +1,35 @@
--TEST--
Insert with query params but with wrong parameters or types
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
require_once('MsCommon.inc');
function ParamQueryError_PhpType_Mismatch($conn)
function createTableForTesting($conn, $tableName)
{
$tableName = GetTempTableName('PhpType_Mismatch');
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_varchar_max] varchar(max))");
$columns = array(new AE\ColumnMeta('int', 'c1_int'),
new AE\ColumnMeta('varchar(max)', 'c2_varchar_max'));
$stmt = AE\createTable($conn, $tableName, $columns);
if (!$stmt) {
fatalError("Failed to create table $tableName\n");
}
sqlsrv_free_stmt($stmt);
}
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(1, array(1.5, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_FLOAT, SQLSRV_SQLTYPE_VARCHAR('max'))));
function getFirstInputParam()
{
$intType = AE\isColEncrypted() ? SQLSRV_SQLTYPE_INT : null;
return array(1, null, null, $intType);
}
function phpTypeMismatch($conn)
{
$tableName = 'phpTypeMismatch';
createTableForTesting($conn, $tableName);
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(getFirstInputParam(), array(1.5, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_FLOAT, SQLSRV_SQLTYPE_VARCHAR('max'))));
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query($conn, "SELECT * FROM $tableName");
@ -24,83 +42,69 @@ function ParamQueryError_PhpType_Mismatch($conn)
if ($value0 != "1" || $value1 != "1.5") {
echo "Data $value0 or $value1 unexpected\n";
}
dropTable($conn, $tableName);
}
function ParamQueryError_Dir_Invalid($conn)
function dirInvalid($conn)
{
$tableName = GetTempTableName('Dir_Invalid');
$tableName = 'dirInvalid';
createTableForTesting($conn, $tableName);
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_varchar_max] varchar(max))");
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(1, array("Test Data", 32, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_VARCHAR('max'))));
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(getFirstInputParam(), array("Test Data", 32, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_VARCHAR('max'))));
printErrors();
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(1, array("Test Data", 'SQLSRV_PARAM_INTERNAL', SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_VARCHAR('max'))));
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(getFirstInputParam(), array("Test Data", 'SQLSRV_PARAM_INTERNAL', SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_VARCHAR('max'))));
printErrors();
dropTable($conn, $tableName);
}
function ParamQueryError_PhpType_Encoding($conn)
function phpTypeEncoding($conn)
{
$tableName = GetTempTableName('PhpType_Encoding');
$tableName = 'phpTypeEncoding';
createTableForTesting($conn, $tableName);
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_varchar_max] varchar(max))");
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(1, array("Test Data", SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING('SQLSRV_ENC_UNKNOWN'), null)));
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(getFirstInputParam(), array("Test Data", SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING('SQLSRV_ENC_UNKNOWN'), null)));
printErrors();
dropTable($conn, $tableName);
}
function ParamQueryError_PhpType_Invalid($conn)
function phpTypeInvalid($conn)
{
$tableName = GetTempTableName('PhpType_Invalid');
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_varchar_max] varchar(max))");
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(1, array("Test Data", SQLSRV_PARAM_IN, 'SQLSRV_PHPTYPE_UNKNOWN', SQLSRV_SQLTYPE_VARCHAR('max'))));
$tableName = 'phpTypeInvalid';
createTableForTesting($conn, $tableName);
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(getFirstInputParam(), array("Test Data", SQLSRV_PARAM_IN, 'SQLSRV_PHPTYPE_UNKNOWN', SQLSRV_SQLTYPE_VARCHAR('max'))));
printErrors();
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(1, array("Test Data", SQLSRV_PARAM_IN, 6, SQLSRV_SQLTYPE_VARCHAR('max'))));
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(getFirstInputParam(), array("Test Data", SQLSRV_PARAM_IN, 6, SQLSRV_SQLTYPE_VARCHAR('max'))));
printErrors();
dropTable($conn, $tableName);
}
//--------------------------------------------------------------------
// RunTest
//
//--------------------------------------------------------------------
function RunTest()
{
startTest("sqlsrv_param_query_errors");
echo "\nTest begins...\n";
echo "\nTest begins...\n";
try {
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
try {
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
// connect
$conn = connect();
if (!$conn) {
fatalError("Could not connect.\n");
}
// connect
$conn = AE\connect();
ParamQueryError_PhpType_Mismatch($conn);
ParamQueryError_Dir_Invalid($conn);
ParamQueryError_PhpType_Encoding($conn);
ParamQueryError_PhpType_Invalid($conn);
phpTypeMismatch($conn);
dirInvalid($conn);
phpTypeEncoding($conn);
phpTypeInvalid($conn);
sqlsrv_close($conn);
} catch (Exception $e) {
echo $e->getMessage();
}
echo "\nDone\n";
endTest("sqlsrv_param_query_errors");
sqlsrv_close($conn);
} catch (Exception $e) {
echo $e->getMessage();
}
RunTest();
echo "\nDone\n";
?>
--EXPECT--

@ -112,4 +116,3 @@ An invalid PHP type for parameter 2 was specified.
An invalid PHP type for parameter 2 was specified.
Done
Test "sqlsrv_param_query_errors" completed successfully.

View file

@ -1,82 +1,90 @@
--TEST--
Insert with query params but with various invalid inputs or boundaries
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
require_once('MsCommon.inc');
function ParamQueryError_MinMaxScale($conn)
function getFirstInputParam()
{
$tableName = GetTempTableName('MinMaxScale');
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_decimal] decimal(28,4), [c3_numeric] numeric(32,4))");
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_decimal) VALUES (?, ?)", array(1, array(0.0, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_DECIMAL(28, 34))));
printErrors();
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c3_numeric) VALUES (?, ?)", array(1, array(0.0, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_NUMERIC(32, -1))));
printErrors();
$intType = AE\isColEncrypted() ? SQLSRV_SQLTYPE_INT : null;
return array(1, null, null, $intType);
}
function ParamQueryError_MinMaxSize($conn)
function MinMaxScale($conn)
{
$tableName = GetTempTableName('MinMaxSize');
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_varchar_max] varchar(max))");
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(1, array("Test Data", SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_VARCHAR(0))));
printErrors();
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(1, array("Test Data", SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_VARCHAR(9000))));
printErrors();
}
function ParamQueryError_MinMaxPrecision($conn)
{
$tableName = GetTempTableName('MinMaxPrecision');
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_decimal] decimal(28,4), [c3_numeric] numeric(32,4))");
sqlsrv_free_stmt($stmt);
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c3_numeric) VALUES (?, ?)", array(1, array(0.0, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_NUMERIC(40, 0))));
printErrors();
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_decimal) VALUES (?, ?)", array(1, array(0.0, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_DECIMAL(-1, 0))));
printErrors();
}
//--------------------------------------------------------------------
// RunTest
//
//--------------------------------------------------------------------
function RunTest()
{
startTest("sqlsrv_param_query_invalid_inputs");
echo "\nTest begins...\n";
try {
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
// connect
$conn = connect();
if (!$conn) {
fatalError("Could not connect.\n");
}
ParamQueryError_MinMaxScale($conn);
ParamQueryError_MinMaxSize($conn);
ParamQueryError_MinMaxPrecision($conn);
sqlsrv_close($conn);
} catch (Exception $e) {
echo $e->getMessage();
$tableName = 'MinMaxScale';
$columns = array(new AE\ColumnMeta('int', 'c1_int'),
new AE\ColumnMeta('decimal(28,4)', 'c2_decimal'),
new AE\ColumnMeta('numeric(32,4)', 'c3_numeric'));
$stmt = AE\createTable($conn, $tableName, $columns);
if (!$stmt) {
fatalError("Failed to create table $tableName\n");
}
echo "\nDone\n";
endTest("sqlsrv_param_query_invalid_inputs");
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_decimal) VALUES (?, ?)", array(getFirstInputParam(), array(0.0, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_DECIMAL(28, 34))));
printErrors();
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c3_numeric) VALUES (?, ?)", array(getFirstInputParam(), array(0.0, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_NUMERIC(32, -1))));
printErrors();
dropTable($conn, $tableName);
}
RunTest();
function MinMaxSize($conn)
{
$tableName = 'MinMaxSize';
$columns = array(new AE\ColumnMeta('int', 'c1_int'),
new AE\ColumnMeta('varchar(max)', 'c2_varchar_max'));
$stmt = AE\createTable($conn, $tableName, $columns);
if (!$stmt) {
fatalError("Failed to create table $tableName\n");
}
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(getFirstInputParam(), array("Test Data", SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_VARCHAR(0))));
printErrors();
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(getFirstInputParam(), array("Test Data", SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_VARCHAR(9000))));
printErrors();
dropTable($conn, $tableName);
}
function MinMaxPrecision($conn)
{
$tableName = 'MinMaxPrecision';
$columns = array(new AE\ColumnMeta('int', 'c1_int'),
new AE\ColumnMeta('decimal(28,4)', 'c2_decimal'),
new AE\ColumnMeta('numeric(32,4)', 'c3_numeric'));
$stmt = AE\createTable($conn, $tableName, $columns);
if (!$stmt) {
fatalError("Failed to create table $tableName\n");
}
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c3_numeric) VALUES (?, ?)", array(getFirstInputParam(), array(0.0, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_NUMERIC(40, 0))));
printErrors();
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_decimal) VALUES (?, ?)", array(getFirstInputParam(), array(0.0, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_DECIMAL(-1, 0))));
printErrors();
dropTable($conn, $tableName);
}
echo "\nTest begins...\n";
try {
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
// connect
$conn = AE\connect();
MinMaxScale($conn);
MinMaxSize($conn);
MinMaxPrecision($conn);
sqlsrv_close($conn);
} catch (Exception $e) {
echo $e->getMessage();
}
echo "\nDone\n";
?>
--EXPECT--
@ -90,4 +98,3 @@ An invalid size or precision for parameter 2 was specified.
An invalid size or precision for parameter 2 was specified.
Done
Test "sqlsrv_param_query_invalid_inputs" completed successfully.

View file

@ -1,7 +1,7 @@
--TEST--
sqlsrv_query test. Performs same tasks as 0006.phpt, using sqlsrv_query.
sqlsrv_query test. Performs same tasks as 0006.phpt, using sqlsrv_query.
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
sqlsrv_configure('WarningsReturnAsErrors', 0);
@ -9,37 +9,24 @@ sqlsrv_query test. Performs same tasks as 0006.phpt, using sqlsrv_query.
require_once('MsCommon.inc');
$conn = connect();
if (!$conn) {
fatalError("Failed to connect.");
}
$stmt = sqlsrv_query($conn, "IF OBJECT_ID('test_params', 'U') IS NOT NULL DROP TABLE test_params");
$conn = AE\connect();
$tableName = 'test_params';
$columns = array(new AE\ColumnMeta('tinyint', 'id'),
new AE\ColumnMeta('char(10)', 'name'),
new AE\ColumnMeta('float', 'double'),
new AE\ColumnMeta('varchar(max)', 'stuff'));
$stmt = AE\createTable($conn, $tableName, $columns);
if (!$stmt) {
$errors = sqlsrv_errors();
if ($errors[0]["SQLSTATE"] != "42S02") {
var_dump($errors);
die("sqlsrv_query(3) failed.");
}
}
$stmt = sqlsrv_query($conn, "CREATE TABLE test_params (id tinyint, name char(10), [double] float, stuff varchar(max))");
if (!$stmt) {
fatalError("sqlsrv_query(4) failed.");
fatalError("Failed to create table $tableName\n");
}
$insertSql = "INSERT INTO $tableName (id, name, [double], stuff) VALUES (?, ?, ?, ?)";
$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_query(
$conn,
"INSERT INTO test_params (id, name, [double], stuff) VALUES (?, ?, ?, ?)",
array( $f1, $f2, $f3, $f4 )
);
if (!$stmt) {
fatalError("sqlsrv_query(5) failed.");
}
$stmt = AE\executeQueryParams($conn, $insertSql, array( $f1, $f2, $f3, $f4 ), false, "sqlsrv_query(1) failed.");
while ($success = sqlsrv_send_stream_data($stmt)) {
}
if (!is_null($success)) {
@ -50,7 +37,7 @@ sqlsrv_query test. Performs same tasks as 0006.phpt, using sqlsrv_query.
$stmt = sqlsrv_query($conn, "SELECT id, [double], name, stuff FROM test_params");
if (!$stmt) {
fatalError("sqlsrv_query(6) failed.");
fatalError("sqlsrv_query(2) failed.");
}
while (sqlsrv_fetch($stmt)) {
@ -69,6 +56,7 @@ sqlsrv_query test. Performs same tasks as 0006.phpt, using sqlsrv_query.
}
sqlsrv_query($conn, "DROP TABLE test_params");
dropTable($conn, $tableName);
sqlsrv_close($conn);

View file

@ -1,7 +1,7 @@
--TEST--
binding streams using full syntax.
--SKIPIF--
<?php require('skipif.inc'); ?>
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
sqlsrv_configure('WarningsReturnAsErrors', 0);
@ -9,33 +9,32 @@ binding streams using full syntax.
require_once('MsCommon.inc');
$conn = connect();
if ($conn === false) {
fatalError("Failed to connect.");
$conn = AE\connect();
$tableName = 'test_params';
$columns = array(new AE\ColumnMeta('tinyint', 'id'),
new AE\ColumnMeta('char(10)', 'name'),
new AE\ColumnMeta('float', 'double'),
new AE\ColumnMeta('varbinary(max)', 'stuff'));
$stmt = AE\createTable($conn, $tableName, $columns);
if (!$stmt) {
fatalError("Failed to create table $tableName\n");
}
$stmt = sqlsrv_query($conn, "IF OBJECT_ID('test_params', 'U') IS NOT NULL DROP TABLE test_params");
if ($stmt !== false) {
sqlsrv_free_stmt($stmt);
}
$stmt = sqlsrv_query($conn, "CREATE TABLE test_params (id tinyint, name char(10), [double] float, stuff varbinary(max))");
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");
$insertSql = "INSERT INTO $tableName (id, name, [double], stuff) VALUES (?, ?, ?, ?)";
// use full details
$stmt = sqlsrv_query(
$conn,
"INSERT INTO test_params (id, name, [double], stuff) VALUES (?, ?, ?, ?)",
array(
array( &$f1, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_INT, SQLSRV_SQLTYPE_TINYINT ),
array( &$f2, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_CHAR(10)),
array( &$f3, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_FLOAT, SQLSRV_SQLTYPE_FLOAT),
array( &$f4, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_VARBINARY('max')))
$conn,
$insertSql,
array(
array(&$f1, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_INT, SQLSRV_SQLTYPE_TINYINT),
array(&$f2, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_CHAR(10)),
array(&$f3, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_FLOAT, SQLSRV_SQLTYPE_FLOAT),
array(&$f4, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_VARBINARY('max')))
);
if ($stmt === false) {
var_dump(sqlsrv_errors());
@ -55,17 +54,19 @@ binding streams using full syntax.
// use nulls for php types
$stmt = sqlsrv_query(
$conn,
"INSERT INTO test_params (id, name, [double], stuff) VALUES (?, ?, ?, ?)",
array(
array( &$f1, SQLSRV_PARAM_IN, null, SQLSRV_SQLTYPE_TINYINT ),
array( &$f2, SQLSRV_PARAM_IN, null, SQLSRV_SQLTYPE_CHAR(10)),
array( &$f3, SQLSRV_PARAM_IN, null, SQLSRV_SQLTYPE_FLOAT),
array( &$f4, SQLSRV_PARAM_IN, null, SQLSRV_SQLTYPE_VARBINARY('max')))
$insertSql,
array(
array(&$f1, SQLSRV_PARAM_IN, null, SQLSRV_SQLTYPE_TINYINT),
array(&$f2, SQLSRV_PARAM_IN, null, SQLSRV_SQLTYPE_CHAR(10)),
array(&$f3, SQLSRV_PARAM_IN, null, SQLSRV_SQLTYPE_FLOAT),
array(&$f4, SQLSRV_PARAM_IN, null, SQLSRV_SQLTYPE_VARBINARY('max')))
);
if ($stmt !== false) {
die("sqlsrv_query(2) should have failed.");
} else {
$error = sqlsrv_errors()[0];
verifyError($error, '22018', 'Invalid character value for cast specification');
}
print_r(sqlsrv_errors());
print_r("sqlsrv_query(2) failed.\n");
fclose($f4);
@ -74,15 +75,24 @@ binding streams using full syntax.
// use nulls for php types
$stmt = sqlsrv_query(
$conn,
"INSERT INTO test_params (id, name, [double], stuff) VALUES (?, ?, ?, ?)",
array(
array( &$f1, null, null, null ),
array( &$f2, null, null, null ),
array( &$f3, null, null, null ),
array( &$f4, null, null, null ))
$insertSql,
array(
array(&$f1, null, null, null),
array(&$f2, null, null, null),
array(&$f3, null, null, null),
array(&$f4, null, null, null))
);
$AEQueryError = 'Must specify the SQL type for each parameter in a parameterized query when using sqlsrv_query in a column encryption enabled connection.';
if ($stmt === false) {
print_r(sqlsrv_errors());
$error = sqlsrv_errors()[0];
if (AE\isColEncrypted()) {
// When AE is enabled, the error message will be about sqlsrv_query and
// parameterized query
verifyError($error, 'IMSSP', $AEQueryError);
} else {
verifyError($error, '42000', 'Implicit conversion from data type varchar(max) to varbinary(max) is not allowed. Use the CONVERT function to run this query.');
}
print_r("sqlsrv_query(3) failed.\n");
} else {
sqlsrv_free_stmt($stmt);
@ -117,70 +127,37 @@ binding streams using full syntax.
// use nulls for php types
$stmt = sqlsrv_query(
$conn,
"INSERT INTO test_params (id, name, [double], stuff) VALUES (?, ?, ?, ?)",
array(
array( &$f1, null, null, null ),
array(),
array( &$f3, null, null, null ),
array( &$f4, null, null, null ))
$insertSql,
array(
array(&$f1, null, null, null),
array(),
array(&$f3, null, null, null),
array(&$f4, null, null, null))
);
if ($stmt !== false) {
die("sqlsrv_query should have failed.");
}
var_dump(sqlsrv_errors());
$error = sqlsrv_errors()[0];
if (AE\isColEncrypted()) {
// When AE is enabled, the error message will be about sqlsrv_query and
// parameterized query
verifyError($error, 'IMSSP', $AEQueryError);
} else {
verifyError($error, 'IMSSP', 'Parameter array 2 must have at least one value or variable.');
}
fclose($f4);
echo "Done\n";
sqlsrv_query($conn, "DROP TABLE test_params");
dropTable($conn, $tableName);
sqlsrv_close($conn);
?>
--EXPECTF--
Array
(
[0] => Array
(
[0] => 22018
[SQLSTATE] => 22018
[1] => 0
[code] => 0
[2] => %SInvalid character value for cast specification
[message] => %SInvalid character value for cast specification
)
)
--EXPECT--
sqlsrv_query(2) failed.
Array
(
[0] => Array
(
[0] => 42000
[SQLSTATE] => 42000
[1] => 257
[code] => 257
[2] => %SImplicit conversion from data type varchar(max) to varbinary(max) is not allowed. Use the CONVERT function to run this query.
[message] => %SImplicit conversion from data type varchar(max) to varbinary(max) is not allowed. Use the CONVERT function to run this query.
)
)
sqlsrv_query(3) failed.
1
12.0
testtestte
This is some text meant to test binding parameters to streams
array(1) {
[0]=>
array(6) {
[0]=>
string(5) "IMSSP"
["SQLSTATE"]=>
string(5) "IMSSP"
[1]=>
int(-9)
["code"]=>
int(-9)
[2]=>
string(59) "Parameter array 2 must have at least one value or variable."
["message"]=>
string(59) "Parameter array 2 must have at least one value or variable."
}
}
Done

View file

@ -1,54 +1,73 @@
--TEST--
Populate different test tables with character fields using empty stream data as inputs
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
require_once('MsCommon.inc');
function EmptyStream_Char2Stream($conn, $fileName)
function sendQueryStream($conn, $query, $value, $fileName)
{
$tableName = GetTempTableName();
$fname = fopen($fileName, "r");
$res = true;
if (AE\isColEncrypted()) {
$stmt = sqlsrv_prepare($conn, $query, array($value, &$fname), array('SendStreamParamsAtExec' => 0));
if ($stmt) {
$res = sqlsrv_execute($stmt);
}
} else {
$stmt = sqlsrv_query($conn, $query, array($value, &$fname), array('SendStreamParamsAtExec' => 0));
}
if ($stmt === false || !$res) {
fclose($fname);
fatalError("Failed in sendQueryStream for $value\n");
}
sqlsrv_send_stream_data($stmt);
sqlsrv_free_stmt($stmt);
fclose($fname);
}
function char2Stream($conn, $fileName)
{
$tableName = 'streams_empty_char';
// create a test table
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_char] char(512), [c3_varchar] varchar(512), [c4_varchar_max] varchar(max), [c5_text] text)");
$columns = array(new AE\ColumnMeta('int', 'c1_int'),
new AE\ColumnMeta('char(512)', 'c2_char'),
new AE\ColumnMeta('varchar(512)', 'c3_varchar'),
new AE\ColumnMeta('varchar(max)', 'c4_varchar_max'),
new AE\ColumnMeta('text', 'c5_text'));
$stmt = AE\createTable($conn, $tableName, $columns);
if (!$stmt) {
fatalError("Failed to create table $tableName\n");
}
sqlsrv_free_stmt($stmt);
// insert data
$fname = fopen($fileName, "r");
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_char) VALUES (?, ?)", array(1, &$fname), array('SendStreamParamsAtExec' => 0));
sqlsrv_send_stream_data($stmt);
sqlsrv_free_stmt($stmt);
fclose($fname);
sendQueryStream($conn, "INSERT INTO $tableName (c1_int, c2_char) VALUES (?, ?)", 1, $fileName);
fetchData($conn, $tableName, 1);
FetchData($conn, $tableName, 1);
sendQueryStream($conn, "INSERT INTO $tableName (c1_int, c3_varchar) VALUES (?, ?)", 2, $fileName);
fetchData($conn, $tableName, 2);
$fname = fopen($fileName, "r");
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c3_varchar) VALUES (?, ?)", array(2, &$fname), array('SendStreamParamsAtExec' => 0));
sqlsrv_send_stream_data($stmt);
sqlsrv_free_stmt($stmt);
fclose($fname);
sendQueryStream($conn, "INSERT INTO $tableName (c1_int, c4_varchar_max) VALUES (?, ?)", 3, $fileName);
fetchData($conn, $tableName, 3);
FetchData($conn, $tableName, 2);
$fname = fopen($fileName, "r");
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c4_varchar_max) VALUES (?, ?)", array(3, &$fname), array('SendStreamParamsAtExec' => 0));
sqlsrv_send_stream_data($stmt);
sqlsrv_free_stmt($stmt);
fclose($fname);
FetchData($conn, $tableName, 3);
$fname = fopen($fileName, "r");
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c5_text) VALUES (?, ?)", array(4, &$fname), array('SendStreamParamsAtExec' => 0));
sqlsrv_send_stream_data($stmt);
sqlsrv_free_stmt($stmt);
fclose($fname);
FetchData($conn, $tableName, 4);
sendQueryStream($conn, "INSERT INTO $tableName (c1_int, c5_text) VALUES (?, ?)", 4, $fileName);
fetchData($conn, $tableName, 4);
dropTable($conn, $tableName);
}
function FetchData($conn, $tableName, $fld)
function fetchData($conn, $tableName, $fld)
{
$stmt = sqlsrv_prepare($conn, "SELECT * FROM $tableName WHERE c1_int = $fld");
if (AE\isColEncrypted()) {
// bind param when AE is enabled
$stmt = sqlsrv_prepare($conn, "SELECT * FROM $tableName WHERE c1_int = ?", array($fld));
} else {
$stmt = sqlsrv_prepare($conn, "SELECT * FROM $tableName WHERE c1_int = $fld");
}
sqlsrv_execute($stmt);
$result = sqlsrv_fetch($stmt);
$stream = sqlsrv_get_field($stmt, $fld, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY));
@ -58,44 +77,32 @@ function FetchData($conn, $tableName, $fld)
$result = sqlsrv_fetch($stmt);
$value = sqlsrv_get_field($stmt, $fld, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY));
var_dump($value);
sqlsrv_free_stmt($stmt);
}
//--------------------------------------------------------------------
// RunTest
//
//--------------------------------------------------------------------
function RunTest()
{
startTest("sqlsrv_streams_empty_char");
echo "\nTest begins...\n";
try {
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
echo "\nTest begins...\n";
try {
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
// connect
$conn = connect();
if (!$conn) {
fatalError("Could not connect.\n");
}
// connect
$conn = AE\connect();
// create an empty file
$fileName = "sqlsrv_streams_empty_char.dat";
$fp = fopen($fileName, "wb");
fclose($fp);
// create an empty file
$fileName = "sqlsrv_streams_empty_char.dat";
$fp = fopen($fileName, "wb");
fclose($fp);
EmptyStream_Char2Stream($conn, $fileName);
char2Stream($conn, $fileName);
// delete the file
unlink($fileName);
sqlsrv_close($conn);
} catch (Exception $e) {
echo $e->getMessage();
}
echo "\nDone\n";
endTest("sqlsrv_streams_empty_char");
// delete the file
unlink($fileName);
sqlsrv_close($conn);
} catch (Exception $e) {
echo $e->getMessage();
}
RunTest();
echo "\nDone\n";
?>
--EXPECT--
@ -111,4 +118,3 @@ bool(false)
bool(false)
Done
Test "sqlsrv_streams_empty_char" completed successfully.

View file

@ -1,33 +1,57 @@
--TEST--
Populate different binary fields using null stream data as inputs.
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
require_once('MsCommon.inc');
function NullStream_Bin2String($conn, $tableName)
function nullBin2String($conn, $tableName)
{
$fname = null;
$value = -2106133115;
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varbinary, c3_varbinary_max, c4_image) VALUES (?, ?, ?, ?)", array($value, array(&$fname, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_VARBINARY(512)), array(&$fname, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_VARBINARY('max')), array(&$fname, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_IMAGE)));
$intType = AE\isColEncrypted() ? SQLSRV_SQLTYPE_INT : null;
$stmt = sqlsrv_query($conn,
"INSERT INTO $tableName (c1_int, c2_varbinary, c3_varbinary_max, c4_image) VALUES (?, ?, ?, ?)",
array(array($value, null, null, $intType),
array(&$fname, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_VARBINARY(512)),
array(&$fname, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_VARBINARY('max')),
array(&$fname, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_IMAGE)));
sqlsrv_free_stmt($stmt);
FetchData($conn, $tableName, $value);
fetchData($conn, $tableName, $value);
}
function NullStreamPrep_Bin2String($conn, $tableName)
function nullPrepBin2String($conn, $tableName)
{
$fname = null;
$value = -413736480;
$stmt = sqlsrv_prepare($conn, "INSERT INTO $tableName (c1_int, c2_varbinary, c3_varbinary_max, c4_image) VALUES (?, ?, ?, ?)", array($value, array(&$fname, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_VARBINARY(512)), array(&$fname, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_VARBINARY('max')), array(&$fname, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_IMAGE)));
$stmt = sqlsrv_prepare($conn,
"INSERT INTO $tableName (c1_int, c2_varbinary, c3_varbinary_max, c4_image) VALUES (?, ?, ?, ?)",
array($value,
array(&$fname, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_VARBINARY(512)),
array(&$fname, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_VARBINARY('max')),
array(&$fname, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_IMAGE)));
sqlsrv_execute($stmt);
sqlsrv_free_stmt($stmt);
FetchData($conn, $tableName, $value);
fetchData($conn, $tableName, $value);
}
function FetchData($conn, $tableName, $value)
function fetchData($conn, $tableName, $value)
{
$stmt = sqlsrv_query($conn, "SELECT * FROM $tableName WHERE c1_int = $value");
if (AE\isColEncrypted()) {
// bind param when AE is enabled
$stmt = sqlsrv_prepare($conn, "SELECT * FROM $tableName WHERE c1_int = ?", array($value));
if ($stmt) {
sqlsrv_execute($stmt);
}
} else {
$stmt = sqlsrv_query($conn, "SELECT * FROM $tableName WHERE c1_int = $value");
}
if (!$stmt) {
fatalError("Failed in fetch data with value $value\n");
}
$result = sqlsrv_fetch($stmt);
$numfields = sqlsrv_num_fields($stmt);
for ($i = 1; $i < $numfields; $i++) {
@ -36,41 +60,32 @@ function FetchData($conn, $tableName, $value)
}
}
//--------------------------------------------------------------------
// RunTest
//
//--------------------------------------------------------------------
function RunTest()
{
startTest("sqlsrv_streams_null_binary");
echo "\nTest begins...\n";
try {
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
echo "\nTest begins...\n";
try {
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
// connect
$conn = connect();
if (!$conn) {
fatalError("Could not connect.\n");
}
// create a test table
$tableName = GetTempTableName();
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_varbinary] varbinary(512), [c3_varbinary_max] varbinary(max), [c4_image] image)");
sqlsrv_free_stmt($stmt);
NullStream_Bin2String($conn, $tableName);
NullStreamPrep_Bin2String($conn, $tableName);
sqlsrv_close($conn);
} catch (Exception $e) {
echo $e->getMessage();
// connect
$conn = connect();
if (!$conn) {
fatalError("Could not connect.\n");
}
echo "\nDone\n";
endTest("sqlsrv_streams_null_binary");
}
RunTest();
// create a test table
$tableName = 'null_binary_stream';
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_varbinary] varbinary(512), [c3_varbinary_max] varbinary(max), [c4_image] image)");
sqlsrv_free_stmt($stmt);
nullBin2String($conn, $tableName);
nullPrepBin2String($conn, $tableName);
dropTable($conn, $tableName);
sqlsrv_close($conn);
} catch (Exception $e) {
echo $e->getMessage();
}
echo "\nDone\n";
?>
--EXPECT--
@ -84,4 +99,3 @@ NULL
NULL
Done
Test "sqlsrv_streams_null_binary" completed successfully.

View file

@ -1,25 +1,50 @@
--TEST--
Populate different unicode character fields using null stream data as inputs
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
require_once('MsCommon.inc');
function NullStream_Char2Stream($conn)
function char2Stream($conn)
{
$tableName = GetTempTableName();
$tableName = 'streams_null_nchar';
// create a test table
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_nchar] nchar(512), [c3_nvarchar] nvarchar(512), [c4_nvarchar_max] nvarchar(max), [c5_ntext] ntext)");
$columns = array(new AE\ColumnMeta('int', 'c1_int'),
new AE\ColumnMeta('nchar(512)', 'c2_nchar'),
new AE\ColumnMeta('nvarchar(512)', 'c3_nvarchar'),
new AE\ColumnMeta('nvarchar(max)', 'c4_nvarchar_max'),
new AE\ColumnMeta('ntext', 'c5_ntext'));
$stmt = AE\createTable($conn, $tableName, $columns);
if (!$stmt) {
fatalError("Failed to create table $tableName\n");
}
sqlsrv_free_stmt($stmt);
$fname = null;
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_nchar, c3_nvarchar, c4_nvarchar_max, c5_ntext) VALUES (?, ?, ?, ?, ?)", array(-187518515, &$fname, &$fname, &$fname, &$fname));
$query = "INSERT INTO $tableName (c1_int, c2_nchar, c3_nvarchar, c4_nvarchar_max, c5_ntext) VALUES (?, ?, ?, ?, ?)";
$res = true;
if (AE\isColEncrypted()) {
$stmt = sqlsrv_prepare($conn, $query, array(-187518515, &$fname, &$fname, &$fname, &$fname));
if ($stmt) {
$res = sqlsrv_execute($stmt);
}
} else {
$stmt = sqlsrv_query($conn, $query, array(-187518515, &$fname, &$fname, &$fname, &$fname));
}
if ($stmt === false || !$res) {
fatalError("Failed in sendQueryStream for $value\n");
}
sqlsrv_send_stream_data($stmt);
sqlsrv_free_stmt($stmt);
FetchData($conn, $tableName);
fetchData($conn, $tableName);
dropTable($conn, $tableName);
}
function FetchData($conn, $tableName)
function fetchData($conn, $tableName)
{
$stmt = sqlsrv_prepare($conn, "SELECT * FROM $tableName");
sqlsrv_execute($stmt);
@ -31,35 +56,21 @@ function FetchData($conn, $tableName)
}
}
//--------------------------------------------------------------------
// RunTest
//
//--------------------------------------------------------------------
function RunTest()
{
startTest("sqlsrv_streams_null_nchar");
echo "\nTest begins...\n";
try {
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
echo "\nTest begins...\n";
try {
set_time_limit(0);
sqlsrv_configure('WarningsReturnAsErrors', 1);
// connect
$conn = connect();
if (!$conn) {
fatalError("Could not connect.\n");
}
// connect
$conn = AE\connect();
NullStream_Char2Stream($conn);
char2Stream($conn);
sqlsrv_close($conn);
} catch (Exception $e) {
echo $e->getMessage();
}
echo "\nDone\n";
endTest("sqlsrv_streams_null_nchar");
sqlsrv_close($conn);
} catch (Exception $e) {
echo $e->getMessage();
}
RunTest();
echo "\nDone\n";
?>
--EXPECT--
@ -71,4 +82,3 @@ NULL
NULL
Done
Test "sqlsrv_streams_null_nchar" completed successfully.

View file

@ -1,39 +1,72 @@
--TEST--
Transaction operations: commit successful transactions
--SKIPIF--
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
require_once("MsCommon.inc");
function PrintContent($conn)
function printContent($conn)
{
global $tableName;
$query = "SELECT * FROM $tableName";
$stmt = sqlsrv_query($conn, $query);
// To ensure we always get the first row, use a where clause
$stmt = AE\executeQuery($conn, $query, "GroupId = ?", array("ID1"));
// Fetch first row
$row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC);
print_r($row);
}
// connect
$conn = connect();
if (!$conn) {
printErrors("Connection could not be established.\n");
function runQuery($conn, $sql, $params)
{
if (AE\isColEncrypted()) {
$stmt = sqlsrv_prepare($conn, $sql, $params);
if ($stmt) {
sqlsrv_execute($stmt);
}
} else {
$stmt = sqlsrv_query($conn, $sql, $params);
}
if (!$stmt) {
fatalError("Failed to run query $sql");
}
return $stmt;
}
$tableName = GetTempTableName();
// connect
$conn = AE\connect();
$tableName = 'srv_036_test';
// Create table
$sql = "CREATE TABLE $tableName (
GroupId VARCHAR(10) primary key, Accepted INT,
Tentative INT NOT NULL CHECK (Tentative >= 0))";
$stmt = sqlsrv_query($conn, $sql);
// Do not encrypt the integer columns because of the operations required later
$columns = array(new AE\ColumnMeta('VARCHAR(10)', 'GroupId', 'primary key'),
new AE\ColumnMeta('INT', 'Accepted', null, null, true),
new AE\ColumnMeta('INT', 'Tentative', 'NOT NULL CHECK (Tentative >= 0)', null, true));
$stmt = AE\createTable($conn, $tableName, $columns);
if (!$stmt) {
fatalError("Failed to create table $tableName\n");
}
sqlsrv_free_stmt($stmt);
// Set initial data
$sql = "INSERT INTO $tableName VALUES ('ID1','12','5'),('ID102','20','1')";
$stmt = sqlsrv_query($conn, $sql) ?: die(print_r(sqlsrv_errors(), true));
if (AE\isColEncrypted()) {
$stmt = sqlsrv_query($conn,
"INSERT INTO $tableName VALUES (?,?,?),(?,?,?)",
array(array('ID1', null, null, SQLSRV_SQLTYPE_VARCHAR(10)),
array(12, null, null, SQLSRV_SQLTYPE_INT),
array(5, null, null, SQLSRV_SQLTYPE_INT),
array('ID102', null, null, SQLSRV_SQLTYPE_VARCHAR(10)),
array(20, null, null, SQLSRV_SQLTYPE_INT),
array(1, null, null, SQLSRV_SQLTYPE_INT)));
} else {
$sql = "INSERT INTO $tableName VALUES ('ID1','12','5'),('ID102','20','1')";
$stmt = sqlsrv_query($conn, $sql);
}
if (!$stmt) {
fatalError("Failed to insert data\n");
}
//Initiate transaction
sqlsrv_begin_transaction($conn) ?: die(print_r(sqlsrv_errors(), true));
@ -45,11 +78,11 @@ $params = array($count, $groupId);
// Update Accepted column
$sql = "UPDATE $tableName SET Accepted = (Accepted + ?) WHERE GroupId = ?";
$stmt1 = sqlsrv_query($conn, $sql, $params) ?: die(print_r(sqlsrv_errors(), true));
$stmt1 = runQuery($conn, $sql, $params);
// Update Tentative column
$sql = "UPDATE $tableName SET Tentative = (Tentative - ?) WHERE GroupId = ?";
$stmt2 = sqlsrv_query($conn, $sql, $params);
$stmt2 = runQuery($conn, $sql, $params);
// Commit the transactions
if ($stmt1 && $stmt2) {
@ -60,7 +93,9 @@ if ($stmt1 && $stmt2) {
echo "\nTransactions were rolled back.\n";
}
PrintContent($conn);
printContent($conn);
dropTable($conn, $tableName);
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);