Merge pull request #610 from yitam/sqlsrv_params
Refactoring sqlsrv tests with parameterized queries
This commit is contained in:
commit
639e9f8bd4
|
@ -1,28 +1,26 @@
|
|||
--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)
|
||||
{
|
||||
// change the input field type for each run
|
||||
prepareParams($params, $fieldType);
|
||||
|
||||
($conn = Connect())
|
||||
$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 +31,82 @@ 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 single column of a certain field type
|
||||
$columns = array(new AE\ColumnMeta($fieldType, $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, $fieldType)
|
||||
{
|
||||
if (isWindows()) {
|
||||
$phpgif = '\\php.gif';
|
||||
}
|
||||
else // other than Windows
|
||||
{
|
||||
} else {
|
||||
$phpgif = '/php.gif';
|
||||
}
|
||||
$arr['tableName'] = $tblName = "dbo.B64TestTable";
|
||||
|
||||
$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['fieldType'] = $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
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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";
|
||||
?>
|
||||
|
|
|
@ -1,46 +1,37 @@
|
|||
--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 ));
|
||||
$tableName = 'utf8test';
|
||||
$columns = array(new AE\ColumnMeta('varchar(100)', 'c1'),
|
||||
new AE\ColumnMeta('nvarchar(100)', 'c2'),
|
||||
new AE\ColumnMeta('nvarchar(max)', 'c3'));
|
||||
$stmt = AE\createTable($c, $tableName, $columns);
|
||||
if (!$stmt) {
|
||||
fatalError("Failed to create table $tableName\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 $tableName (c1, c2, c3) VALUES (?,?,?)";
|
||||
$s = AE\executeQueryParams($c, $insertSql, $params);
|
||||
|
||||
$s = sqlsrv_query( $c,
|
||||
"DROP PROCEDURE IntDoubleProc;
|
||||
DROP PROCEDURE Utf8OutProc;
|
||||
DROP PROCEDURE Utf8OutWithResultsetProc;
|
||||
DROP PROCEDURE Utf8InOutProc;
|
||||
DROP TABLE Utf8TestTable;" );
|
||||
$query = "DROP PROCEDURE IntDoubleProc; DROP PROCEDURE Utf8OutProc; DROP PROCEDURE Utf8OutWithResultsetProc; DROP PROCEDURE Utf8InOutProc; DROP TABLE Utf8TestTable;";
|
||||
|
||||
$s = sqlsrv_query($c, $query);
|
||||
|
||||
$create_proc = <<<PROC
|
||||
CREATE PROCEDURE Utf8OutProc
|
||||
|
@ -50,131 +41,115 @@ 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
|
||||
CREATE PROCEDURE Utf8OutWithResultsetProc
|
||||
@param nvarchar(25) output
|
||||
AS
|
||||
BEGIN
|
||||
select c1, c2, c3 from utf8test
|
||||
set @param = convert(nvarchar(25), 0x5E01A1013C04170120005B01E400DD1040044001C11E200086035A010801280130012D0065012E21D7006701);
|
||||
END;
|
||||
PROC;
|
||||
$s = sqlsrv_query( $c, $create_proc );
|
||||
if( $s === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
$createProc = "CREATE PROCEDURE Utf8OutWithResultsetProc @param NVARCHAR(25) OUTPUT AS BEGIN SELECT c1, c2, c3 FROM $tableName SET @param = CONVERT(NVARCHAR(25), 0x5E01A1013C04170120005B01E400DD1040044001C11E200086035A010801280130012D0065012E21D7006701); END";
|
||||
$s = sqlsrv_query($c, $createProc);
|
||||
if ($s === false) {
|
||||
die(print_r(sqlsrv_errors(), true));
|
||||
}
|
||||
|
||||
$create_proc = <<<PROC
|
||||
CREATE PROCEDURE Utf8InOutProc
|
||||
@param nvarchar(25) output
|
||||
AS
|
||||
BEGIN
|
||||
-- INSERT INTO utf8test (c1, c2, c3) VALUES (@param, @param, @param);
|
||||
set @param = convert(nvarchar(25), 0x6001E11EDD10130120006101E200DD1040043A01BB1E2000C5005A01C700CF0007042D006501BF1E45046301);
|
||||
END;
|
||||
PROC;
|
||||
$s = sqlsrv_query( $c, $create_proc );
|
||||
if( $s === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
$createProc = "CREATE PROCEDURE Utf8InOutProc @param NVARCHAR(25) OUTPUT AS BEGIN SET @param = CONVERT(NVARCHAR(25), 0x6001E11EDD10130120006101E200DD1040043A01BB1E2000C5005A01C700CF0007042D006501BF1E45046301); END";
|
||||
$s = sqlsrv_query($c, $createProc);
|
||||
if ($s === false) {
|
||||
die(print_r(sqlsrv_errors(), true));
|
||||
}
|
||||
|
||||
$create_proc = <<<PROC
|
||||
CREATE PROCEDURE IntDoubleProc
|
||||
@param int output
|
||||
AS
|
||||
BEGIN
|
||||
set @param = @param + @param;
|
||||
END;
|
||||
PROC;
|
||||
$s = sqlsrv_query( $c, $create_proc );
|
||||
if( $s === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
$createProc = "CREATE PROCEDURE IntDoubleProc @param INT OUTPUT AS BEGIN SET @param = @param + @param; END;";
|
||||
$s = sqlsrv_query($c, $createProc);
|
||||
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 $tableName");
|
||||
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 +159,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 $tableName (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 $tableName");
|
||||
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, $tableName);
|
||||
|
||||
sqlsrv_close($c);
|
||||
|
||||
echo "Test succeeded.\n";
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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';
|
||||
|
||||
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 {
|
||||
dropTable($conn, $tableName);
|
||||
$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.";
|
||||
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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
|
||||
dropProc($conn, '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 stored procedure parameter 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";
|
||||
|
||||
|
|
|
@ -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--
|
||||
|
|
|
@ -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--
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -271,7 +271,7 @@ function createUniqueIndexEx($conn, $tableName, $tableIndex, $colIndex)
|
|||
|
||||
function dropTable($conn, $tableName)
|
||||
{
|
||||
$stmt = sqlsrv_query($conn, "IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'" . $tableName . "') AND type in (N'U')) DROP TABLE $tableName");
|
||||
$stmt = sqlsrv_query($conn, "IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'" . $tableName . "') AND type in (N'U')) DROP TABLE [$tableName]");
|
||||
if ($stmt === false) {
|
||||
} else {
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
@ -359,7 +359,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);
|
||||
|
@ -467,4 +467,17 @@ function isLocaleSupported()
|
|||
return true;
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
@ -402,7 +402,7 @@ function createTable($conn, $tbname, $columnMetaArr)
|
|||
$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
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -5,8 +5,9 @@ if (!extension_loaded("sqlsrv"))
|
|||
|
||||
require_once('MsCommon.inc');
|
||||
|
||||
if ($keystore != AE\KEYSTORE_KSP)
|
||||
if ($keystore != AE\KEYSTORE_KSP) {
|
||||
die('skip - this test requires a custom keystore provider.');
|
||||
}
|
||||
|
||||
$conn = AE\connect();
|
||||
if (! $conn) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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,8 @@ $actualValue = $return;
|
|||
$actualLength = strlen($return);
|
||||
compareResults($expectedLength, $expectedValue, $actualLength, $actualValue);
|
||||
|
||||
sqlsrv_query($conn, "DROP TABLE BindStringTest");
|
||||
sqlsrv_query($conn, "DROP PROCEDURE uspPerson");
|
||||
dropTable($conn, $tableName);
|
||||
dropProc($conn, 'uspPerson');
|
||||
|
||||
sqlsrv_close($conn);
|
||||
|
||||
|
@ -372,6 +368,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";
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -7,17 +7,14 @@ false as a bit, a true value cast to a bit, a true value as an int.
|
|||
--ENV--
|
||||
PHPT_EXEC=true
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
<?php require('skipif_versions_old.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once('MsCommon.inc');
|
||||
|
||||
$conn = connect();
|
||||
if (!$conn) {
|
||||
fatalError("Could not connect");
|
||||
}
|
||||
$conn = AE\connect();
|
||||
|
||||
$stmt = sqlsrv_query($conn, "IF OBJECT_ID('testBoolean', 'P') IS NOT NULL DROP PROCEDURE testBoolean");
|
||||
dropProc($conn, 'testBoolean');
|
||||
|
||||
$createSP = <<<SQL
|
||||
CREATE PROCEDURE testBoolean
|
||||
|
@ -41,15 +38,21 @@ $bit_true = 0;
|
|||
$bit_false = 1;
|
||||
$bit_cast_true = 0;
|
||||
$int_true = 0;
|
||||
$params = array(array(&$bit_true, SQLSRV_PARAM_INOUT, SQLSRV_PHPTYPE_INT), array(&$bit_false, SQLSRV_PARAM_INOUT, SQLSRV_PHPTYPE_INT), array(&$bit_cast_true, SQLSRV_PARAM_INOUT, SQLSRV_PHPTYPE_INT), array(&$int_true, SQLSRV_PARAM_INOUT, SQLSRV_PHPTYPE_INT));
|
||||
$sqlType = AE\isColEncrypted() ? SQLSRV_SQLTYPE_BIT : null;
|
||||
$params = array(array(&$bit_true, SQLSRV_PARAM_INOUT, SQLSRV_PHPTYPE_INT, $sqlType), array(&$bit_false, SQLSRV_PARAM_INOUT, SQLSRV_PHPTYPE_INT, $sqlType), array(&$bit_cast_true, SQLSRV_PARAM_INOUT, SQLSRV_PHPTYPE_INT, $sqlType), array(&$int_true, SQLSRV_PARAM_INOUT, SQLSRV_PHPTYPE_INT, $sqlType));
|
||||
|
||||
$stmt = sqlsrv_query($conn, $callSP, $params);
|
||||
if (! $stmt){
|
||||
fatalError("Failed when calling testBoolean.");
|
||||
}
|
||||
|
||||
var_dump($bit_true);
|
||||
var_dump($bit_false);
|
||||
var_dump($bit_cast_true);
|
||||
var_dump($int_true);
|
||||
|
||||
dropProc($conn, 'testBoolean');
|
||||
|
||||
sqlsrv_free_stmt($stmt);
|
||||
sqlsrv_close($conn);
|
||||
?>
|
||||
|
|
|
@ -7,17 +7,14 @@ false as a bool, a true value cast to a bool, a true value as an bool.
|
|||
--ENV--
|
||||
PHPT_EXEC=true
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
<?php require('skipif_versions_old.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once('MsCommon.inc');
|
||||
|
||||
$conn = Connect();
|
||||
if( !$conn ) {
|
||||
fatalError("Could not connect");
|
||||
}
|
||||
$conn = AE\connect();
|
||||
|
||||
$stmt = sqlsrv_query($conn, "IF OBJECT_ID('testBoolean', 'P') IS NOT NULL DROP PROCEDURE testBoolean");
|
||||
dropProc($conn, 'testBoolean');
|
||||
|
||||
$createSP = <<<SQL
|
||||
CREATE PROCEDURE testBoolean
|
||||
|
@ -41,15 +38,22 @@ $bit_true = false;
|
|||
$bit_false = true;
|
||||
$bit_cast_true = false;
|
||||
$int_true = false;
|
||||
$params = array(array(&$bit_true, SQLSRV_PARAM_INOUT, SQLSRV_PHPTYPE_INT), array(&$bit_false, SQLSRV_PARAM_INOUT, SQLSRV_PHPTYPE_INT), array(&$bit_cast_true, SQLSRV_PARAM_INOUT, SQLSRV_PHPTYPE_INT), array(&$int_true, SQLSRV_PARAM_INOUT, SQLSRV_PHPTYPE_INT));
|
||||
|
||||
$sqlType = AE\isColEncrypted() ? SQLSRV_SQLTYPE_BIT : null;
|
||||
$params = array(array(&$bit_true, SQLSRV_PARAM_INOUT, SQLSRV_PHPTYPE_INT, $sqlType), array(&$bit_false, SQLSRV_PARAM_INOUT, SQLSRV_PHPTYPE_INT, $sqlType), array(&$bit_cast_true, SQLSRV_PARAM_INOUT, SQLSRV_PHPTYPE_INT, $sqlType), array(&$int_true, SQLSRV_PARAM_INOUT, SQLSRV_PHPTYPE_INT, $sqlType));
|
||||
|
||||
$stmt = sqlsrv_query($conn, $callSP, $params);
|
||||
if (! $stmt){
|
||||
fatalError("Failed when calling testBoolean.");
|
||||
}
|
||||
|
||||
var_dump($bit_true);
|
||||
var_dump($bit_false);
|
||||
var_dump($bit_cast_true);
|
||||
var_dump($int_true);
|
||||
|
||||
dropProc($conn, 'testBoolean');
|
||||
|
||||
sqlsrv_free_stmt($stmt);
|
||||
sqlsrv_close($conn);
|
||||
?>
|
||||
|
|
|
@ -7,19 +7,14 @@ false as a bit, a true value cast to a bit, a true value as an int.
|
|||
--ENV--
|
||||
PHPT_EXEC=true
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
<?php require('skipif_versions_old.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
/* Fails on PHP 7, producing 1's and 2's instead of 0's and 1's. */
|
||||
|
||||
require_once('MsCommon.inc');
|
||||
|
||||
$conn = Connect();
|
||||
if (!$conn) {
|
||||
fatalError("Could not connect");
|
||||
}
|
||||
$conn = AE\connect();
|
||||
|
||||
$stmt = sqlsrv_query($conn, "IF OBJECT_ID('testBoolean', 'P') IS NOT NULL DROP PROCEDURE testBoolean");
|
||||
dropProc($conn, 'testBoolean');
|
||||
|
||||
$createSP = <<<SQL
|
||||
CREATE PROCEDURE testBoolean
|
||||
|
@ -43,15 +38,22 @@ $bit_true = 0;
|
|||
$bit_false = 0;
|
||||
$bit_cast_true = 0;
|
||||
$int_true = 0;
|
||||
$params = array(array(&$bit_true, SQLSRV_PARAM_OUT, SQLSRV_PHPTYPE_INT), array(&$bit_false, SQLSRV_PARAM_OUT, SQLSRV_PHPTYPE_INT), array(&$bit_cast_true, SQLSRV_PARAM_OUT, SQLSRV_PHPTYPE_INT), array(&$int_true, SQLSRV_PARAM_OUT, SQLSRV_PHPTYPE_INT));
|
||||
|
||||
$sqlType = AE\isColEncrypted() ? SQLSRV_SQLTYPE_BIT : null;
|
||||
$params = array(array(&$bit_true, SQLSRV_PARAM_OUT, SQLSRV_PHPTYPE_INT, $sqlType), array(&$bit_false, SQLSRV_PARAM_OUT, SQLSRV_PHPTYPE_INT, $sqlType), array(&$bit_cast_true, SQLSRV_PARAM_OUT, SQLSRV_PHPTYPE_INT, $sqlType), array(&$int_true, SQLSRV_PARAM_OUT, SQLSRV_PHPTYPE_INT, $sqlType));
|
||||
|
||||
$stmt = sqlsrv_query($conn, $callSP, $params);
|
||||
if (! $stmt){
|
||||
fatalError("Failed when calling testBoolean.");
|
||||
}
|
||||
|
||||
var_dump($bit_true);
|
||||
var_dump($bit_false);
|
||||
var_dump($bit_cast_true);
|
||||
var_dump($int_true);
|
||||
|
||||
dropProc($conn, 'testBoolean');
|
||||
|
||||
sqlsrv_free_stmt($stmt);
|
||||
sqlsrv_close($conn);
|
||||
?>
|
||||
|
|
|
@ -7,19 +7,14 @@ false as a bool, a true value cast to a bool, a true value as an bool.
|
|||
--ENV--
|
||||
PHPT_EXEC=true
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
<?php require('skipif_versions_old.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
/* Fails on PHP 7, producing 1's and 2's instead of 0's and 1's. */
|
||||
|
||||
require_once('MsCommon.inc');
|
||||
|
||||
$conn = Connect();
|
||||
if (!$conn) {
|
||||
fatalError("Could not connect");
|
||||
}
|
||||
$conn = AE\connect();
|
||||
|
||||
$stmt = sqlsrv_query($conn, "IF OBJECT_ID('testBoolean', 'P') IS NOT NULL DROP PROCEDURE testBoolean");
|
||||
dropProc($conn, 'testBoolean');
|
||||
|
||||
$createSP = <<<SQL
|
||||
CREATE PROCEDURE testBoolean
|
||||
|
@ -43,15 +38,22 @@ $bit_true = false;
|
|||
$bit_false = false;
|
||||
$bit_cast_true = false;
|
||||
$int_true = false;
|
||||
$params = array(array(&$bit_true, SQLSRV_PARAM_OUT, SQLSRV_PHPTYPE_INT), array(&$bit_false, SQLSRV_PARAM_OUT, SQLSRV_PHPTYPE_INT), array(&$bit_cast_true, SQLSRV_PARAM_OUT, SQLSRV_PHPTYPE_INT), array(&$int_true, SQLSRV_PARAM_OUT, SQLSRV_PHPTYPE_INT));
|
||||
|
||||
$sqlType = AE\isColEncrypted() ? SQLSRV_SQLTYPE_BIT : null;
|
||||
$params = array(array(&$bit_true, SQLSRV_PARAM_OUT, SQLSRV_PHPTYPE_INT, $sqlType), array(&$bit_false, SQLSRV_PARAM_OUT, SQLSRV_PHPTYPE_INT, $sqlType), array(&$bit_cast_true, SQLSRV_PARAM_OUT, SQLSRV_PHPTYPE_INT, $sqlType), array(&$int_true, SQLSRV_PARAM_OUT, SQLSRV_PHPTYPE_INT, $sqlType));
|
||||
|
||||
$stmt = sqlsrv_query($conn, $callSP, $params);
|
||||
if (! $stmt){
|
||||
fatalError("Failed when calling testBoolean.");
|
||||
}
|
||||
|
||||
var_dump($bit_true);
|
||||
var_dump($bit_false);
|
||||
var_dump($bit_cast_true);
|
||||
var_dump($int_true);
|
||||
|
||||
dropProc($conn, 'testBoolean');
|
||||
|
||||
sqlsrv_free_stmt($stmt);
|
||||
sqlsrv_close($conn);
|
||||
?>
|
||||
|
|
|
@ -1,23 +1,56 @@
|
|||
--TEST--
|
||||
Test a complex query with IDENTITY_INSERT
|
||||
--DESCRIPTION--
|
||||
Verifies the behavior of INSERT queries with and without the IDENTITY flag set.
|
||||
This test is similar to the other test TC33_ComplexQuery but using UTF-8 data
|
||||
--SKIPIF--
|
||||
<?php require('skipif_versions_old.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once('MsCommon.inc');
|
||||
|
||||
function ComplexQuery()
|
||||
function insertTest($conn, $tableName, $inputs, $query)
|
||||
{
|
||||
$stmt = null;
|
||||
if (!AE\isColEncrypted()) {
|
||||
$insertSql = AE\getInsertSqlComplete($tableName, $inputs);
|
||||
$sql = str_replace("SQL", $insertSql, $query);
|
||||
$stmt = sqlsrv_query($conn, $sql);
|
||||
} else {
|
||||
// must bind parameters
|
||||
$insertSql = AE\getInsertSqlPlaceholders($tableName, $inputs);
|
||||
$params = array();
|
||||
foreach ($inputs as $key => $input) {
|
||||
array_push($params, $inputs[$key]);
|
||||
}
|
||||
// this contains a batch of sql statements,
|
||||
// with set identity_insert on or off
|
||||
// thus, sqlsrv_query should be called
|
||||
$sql = str_replace("SQL", $insertSql, $query);
|
||||
$stmt = sqlsrv_query($conn, $sql, $params);
|
||||
}
|
||||
|
||||
return $stmt;
|
||||
}
|
||||
|
||||
function complexQuery()
|
||||
{
|
||||
set_time_limit(0);
|
||||
sqlsrv_configure('WarningsReturnAsErrors', 1);
|
||||
|
||||
// Connect
|
||||
$conn = connect(array("CharacterSet"=>"UTF-8"));
|
||||
if (!$conn) {
|
||||
fatalError("Could not connect.\n");
|
||||
$conn = AE\connect(array("CharacterSet"=>"UTF-8"));
|
||||
|
||||
$tableName = 'complex_query_test';
|
||||
$columns = array(new AE\ColumnMeta('int', 'c1_int', "IDENTITY"),
|
||||
new AE\ColumnMeta('tinyint', 'c2_tinyint'),
|
||||
new AE\ColumnMeta('smallint', 'c3_smallint'),
|
||||
new AE\ColumnMeta('bigint', 'c4_bigint'),
|
||||
new AE\ColumnMeta('varchar(512)', 'c5_varchar'));
|
||||
$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 IDENTITY, [c2_tinyint] tinyint, [c3_smallint] smallint, [c4_bigint] bigint, [c5_varchar] varchar(512))");
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
$noExpectedRows = 0;
|
||||
|
@ -26,12 +59,16 @@ function ComplexQuery()
|
|||
sqlsrv_free_stmt($stmt);
|
||||
$noExpectedRows++;
|
||||
|
||||
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_tinyint, c3_smallint, c4_bigint, c5_varchar) VALUES (1324944463, 105, 18521, 2022363960, 'üv£ª©*@*rãCaC|/ä*,,@ý©bvªäîCUBão_+ßZhUªî¢~ÖÜ/ª@ä+ßßar~Özr,aß/,bCaü<ÖÐhÐbß<î/ðzãý+bÜ:Zßöüª@BÖUß<U@¢Ö<hÖhubÄrÐÃ*.å|a/,ª¢ßOa@oubýãýý£îZ~,ä¢î|+ª¢rZUCrOu,B£åß|:£ªîoBärÐA/BzOoß<bvu~ßuîCãߢ¢îýA@aðuAa,UÐ.>Ußaåab|¢ª¢|ü£/ÃßzzuªãA.ªZUöß<©a>OzübBüÜ|bZ./öbvß*rbö>ß©r//~ÖCÜhð¢bßz:¢Ä+_Ã__£ý£Uýh:v¢bý,©Ü£©,A:Zh>ßåvö+Ä>Ã.ßvC|:Ü*Üü*åz|b.©©üAý@uU.oOÜýAÜÐÜð©OB|rrîbU<övoUßäZÃÖ<ÄåªAÄ.Ua*ÖOªB,åîzB:ÜhövÖZhýðüC')");
|
||||
$inputs = array("c1_int" => 1324944463, "c2_tinyint" => 105, "c3_smallint" => 18521, "c4_bigint" => 2022363960, "c5_varchar" => "üv£ª©*@*rãCaC|/ä*,,@ý©bvªäîCUBão_+ßZhUªî¢~ÖÜ/ª@ä+ßßar~Özr,aß/,bCaü<ÖÐhÐbß<î/ðzãý+bÜ:Zßöüª@BÖUß<U@¢Ö<hÖhubÄrÐÃ*.å|a/,ª¢ßOa@oubýãýý£îZ~,ä¢î|+ª¢rZUCrOu,B£åß|:£ªîoBärÐA/BzOoß<bvu~ßuîCãߢ¢îýA@aðuAa,UÐ.>Ußaåab|¢ª¢|ü£/ÃßzzuªãA.ªZUöß<©a>OzübBüÜ|bZ./öbvß*rbö>ß©r//~ÖCÜhð¢bßz:¢Ä+_Ã__£ý£Uýh:v¢bý,©Ü£©,A:Zh>ßåvö+Ä>Ã.ßvC|:Ü*Üü*åz|b.©©üAý@uU.oOÜýAÜÐÜð©OB|rrîbU<övoUßäZÃÖ<ÄåªAÄ.Ua*ÖOªB,åîzB:ÜhövÖZhýðüC");
|
||||
$stmt = AE\insertRow($conn, $tableName, $inputs);
|
||||
unset($inputs);
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
$stmt = sqlsrv_query($conn, "SET IDENTITY_INSERT $tableName OFF;");
|
||||
sqlsrv_free_stmt($stmt);
|
||||
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_tinyint, c3_smallint, c4_bigint, c5_varchar) VALUES (-1554807493, 253, -12809, -1698802997, 'ßöîÄ@v+oß+î|ruý*Ü¢ãÖ~.*ArABªßOBzUU£ßUuÜ<ðýr|b~_äaü/OÖzv.¢ä>>OÜ+¢vªzöªoB_ä+ߪrÜö£>U~ãÖð~ðýur,ÖvZh¢ªZ>vªUäåîz,>ÃräðäýðO_ä*a,ö+üÐß~bÃü¢<<+îýÐöäªO/zA+:îZ,öBÐü<î£îåhBÖzßÄ~,:>bð<~aÐãö¢*¢våvÃÐåî@a<vBãßÖä媢<üa.u:>_Äu£öa~våu>¢Bã©å:Aßã£Üvåö+aä£U<bUu*rv+@U_|ð@+v@Üßb|,.ªäÖ/*êýÄ¢¢Ö/+ä><¢b@|zbãÖ@ÃãUb|ÄB£©,~ßð©ðUßöZÜöî£Zz<>åäZßð©ßaÖÖ¢bð£ßÄ>îÃÃ.~z>h_ý~ÜrüÖBruß+ª©CB©O>rå,Chro,£ßbZ_ß©,ÃUu|ßåüÄ/ý*åu|~Ö.ßZUoä:~A~CZhðU|öZ:ä/£Ä*î©ÄhävhbrzîÐ@.rãß©@uÜ©~>ÖÜööCÄzÜCü+>oZÄÜ/ABßA_b|b¢bÜh<|uBr.B*rü>aCª|AÄ©@öÖßÖ~Ö<rÐ,ä@©|££.C.üå¢/rbªßî')");
|
||||
$inputs = array("c1_int" => -1554807493, "c2_tinyint" => 253, "c3_smallint" => -12809, "c4_bigint" => -1698802997, "c5_varchar" => "ßöîÄ@v+oß+î|ruý*Ü¢ãÖ~.*ArABªßOBzUU£ßUuÜ<ðýr|b~_äaü/OÖzv.¢ä>>OÜ+¢vªzöªoB_ä+ߪrÜö£>U~ãÖð~ðýur,ÖvZh¢ªZ>vªUäåîz,>ÃräðäýðO_ä*a,ö+üÐß~bÃü¢<<+îýÐöäªO/zA+:îZ,öBÐü<î£îåhBÖzßÄ~,:>bð<~aÐãö¢*¢våvÃÐåî@a<vBãßÖä媢<üa.u:>_Äu£öa~våu>¢Bã©å:Aßã£Üvåö+aä£U<bUu*rv+@U_|ð@+v@Üßb|,.ªäÖ/*êýÄ¢¢Ö/+ä><¢b@|zbãÖ@ÃãUb|ÄB£©,~ßð©ðUßöZÜöî£Zz<>åäZßð©ßaÖÖ¢bð£ßÄ>îÃÃ.~z>h_ý~ÜrüÖBruß+ª©CB©O>rå,Chro,£ßbZ_ß©,ÃUu|ßåüÄ/ý*åu|~Ö.ßZUoä:~A~CZhðU|öZ:ä/£Ä*î©ÄhävhbrzîÐ@.rãß©@uÜ©~>ÖÜööCÄzÜCü+>oZÄÜ/ABßA_b|b¢bÜh<|uBr.B*rü>aCª|AÄ©@öÖßÖ~Ö<rÐ,ä@©|££.C.üå¢/rbªßî");
|
||||
$stmt = AE\insertRow($conn, $tableName, $inputs);
|
||||
unset($inputs);
|
||||
|
||||
$errors = sqlsrv_errors(SQLSRV_ERR_ALL);
|
||||
$count1 = count($errors);
|
||||
|
@ -44,7 +81,20 @@ function ComplexQuery()
|
|||
print "$value3\n";
|
||||
$noExpectedRows++;
|
||||
|
||||
$stmt = sqlsrv_query($conn, "SET IDENTITY_INSERT $tableName ON;INSERT INTO $tableName (c1_int, c2_tinyint, c3_smallint, c4_bigint, c5_varchar) VALUES (1994559593, 129, -8455, -236232445, 'ߣ*ÐO+ö+<ã:>üoîzÄ¢zz~Ãýö|vUå>|CÄUü~>buÃv<ä~Ö+.ü*ªbuî_bBC©.oîCbåîÐÖUa~/U>öAäÐBu~ozîZ/zrOOä:ß©bßo.ü©A¢höÖoßÖü>r+A/ßaªrß:ª@|bhhªª/oå<Ö:rüa+oC¢~uÄü>/.ãbOöª_b@bbߢ|uzߪ֢~uäýub©ãaZäC£ÄrÖ,üöäu+Ãîö|||,U.BråãoýbüåöÃburöoî+>öä©î,u_öb©@C:ÜåÜîÜåAÖzýbð|Z<Ãý.£rîZ|/z@¢£AýZ,ßuZ*:b.AzТä¢üßöbvbväð|<**~Uv.Ð*Ä©B*ýCUöa¢åO©Ãß*ÃÃ|ÜðA@îÃßaB<hÜîaZoöå>öüahUUA+ߣ_u|~äö.©hr£oBo<äãüO+_å<OЪÖßßväzA,~u~Obbî@ßÃãÜää©,.bO:C£Ü,äUO¢åå**hÐ~UZ©ðh<abß*üÖîC.äßh~Uð<r*ßäv£î*@¢Cv/BÖhAüB~ýAå@Z@<a_O|<©ßb*CZO,o:ã+¢£ÃZC©B¢o+>O:Z~Üoîßzb£ª£A.AÖÜÄ._O_å£ß');SET IDENTITY_INSERT $tableName OFF;");
|
||||
if (AE\isColEncrypted()) {
|
||||
// When AE is enabled, SQL types must be specified for sqlsrv_query
|
||||
$inputs = array("c1_int" => array(1994559593, null, null, SQLSRV_SQLTYPE_INT),
|
||||
"c2_tinyint" => array(129, null, null, SQLSRV_SQLTYPE_TINYINT),
|
||||
"c3_smallint" => array(-8455, null, null, SQLSRV_SQLTYPE_SMALLINT),
|
||||
"c4_bigint" => array(-236232445, null, null, SQLSRV_SQLTYPE_BIGINT),
|
||||
"c5_varchar" => array("ߣ*ÐO+ö+<ã:>üoîzÄ¢zz~Ãýö|vUå>|CÄUü~>buÃv<ä~Ö+.ü*ªbuî_bBC©.oîCbåîÐÖUa~/U>öAäÐBu~ozîZ/zrOOä:ß©bßo.ü©A¢höÖoßÖü>r+A/ßaªrß:ª@|bhhªª/oå<Ö:rüa+oC¢~uÄü>/.ãbOöª_b@bbߢ|uzߪ֢~uäýub©ãaZäC£ÄrÖ,üöäu+Ãîö|||,U.BråãoýbüåöÃburöoî+>öä©î,u_öb©@C:ÜåÜîÜåAÖzýbð|Z<Ãý.£rîZ|/z@¢£AýZ,ßuZ*:b.AzТä¢üßöbvbväð|<**~Uv.Ð*Ä©B*ýCUöa¢åO©Ãß*ÃÃ|ÜðA@îÃßaB<hÜîaZoöå>öüahUUA+ߣ_u|~äö.©hr£oBo<äãüO+_å<OЪÖßßväzA,~u~Obbî@ßÃãÜää©,.bO:C£Ü,äUO¢åå**hÐ~UZ©ðh<abß*üÖîC.äßh~Uð<r*ßäv£î*@¢Cv/BÖhAüB~ýAå@Z@<a_O|<©ßb*CZO,o:ã+¢£ÃZC©B¢o+>O:Z~Üoîßzb£ª£A.AÖÜÄ._O_å£ß", null, null, SQLSRV_SQLTYPE_VARCHAR(512)));
|
||||
} else {
|
||||
$inputs = array("c1_int" => 1994559593, "c2_tinyint" => 129, "c3_smallint" => -8455, "c4_bigint" => -236232445, "c5_varchar" => "ߣ*ÐO+ö+<ã:>üoîzÄ¢zz~Ãýö|vUå>|CÄUü~>buÃv<ä~Ö+.ü*ªbuî_bBC©.oîCbåîÐÖUa~/U>öAäÐBu~ozîZ/zrOOä:ß©bßo.ü©A¢höÖoßÖü>r+A/ßaªrß:ª@|bhhªª/oå<Ö:rüa+oC¢~uÄü>/.ãbOöª_b@bbߢ|uzߪ֢~uäýub©ãaZäC£ÄrÖ,üöäu+Ãîö|||,U.BråãoýbüåöÃburöoî+>öä©î,u_öb©@C:ÜåÜîÜåAÖzýbð|Z<Ãý.£rîZ|/z@¢£AýZ,ßuZ*:b.AzТä¢üßöbvbväð|<**~Uv.Ð*Ä©B*ýCUöa¢åO©Ãß*ÃÃ|ÜðA@îÃßaB<hÜîaZoöå>öüahUUA+ߣ_u|~äö.©hr£oBo<äãüO+_å<OЪÖßßväzA,~u~Obbî@ßÃãÜää©,.bO:C£Ü,äUO¢åå**hÐ~UZ©ðh<abß*üÖîC.äßh~Uð<r*ßäv£î*@¢Cv/BÖhAüB~ýAå@Z@<a_O|<©ßb*CZO,o:ã+¢£ÃZC©B¢o+>O:Z~Üoîßzb£ª£A.AÖÜÄ._O_å£ß");
|
||||
}
|
||||
$query = "SET IDENTITY_INSERT [$tableName] ON; SQL; SET IDENTITY_INSERT [$tableName] OFF;";
|
||||
$stmt = insertTest($conn, $tableName, $inputs, $query);
|
||||
print_r(sqlsrv_errors());
|
||||
unset($inputs);
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
echo "Number of rows inserted: $noExpectedRows\n";
|
||||
|
@ -60,28 +110,19 @@ function ComplexQuery()
|
|||
if ($noActualRows != $noExpectedRows) {
|
||||
echo("Number of rows does not match expected value\n");
|
||||
}
|
||||
|
||||
dropTable($conn, $tableName);
|
||||
sqlsrv_close($conn);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// Repro
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
function Repro()
|
||||
{
|
||||
startTest("sqlsrv_statement_complex_query");
|
||||
echo "\nTest begins...\n";
|
||||
echo "\nTest begins...\n";
|
||||
|
||||
try {
|
||||
ComplexQuery();
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
echo "\nDone\n";
|
||||
endTest("sqlsrv_statement_complex_query");
|
||||
try {
|
||||
complexQuery();
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
|
||||
Repro();
|
||||
echo "\nDone\n";
|
||||
|
||||
?>
|
||||
--EXPECTREGEX--
|
||||
|
@ -94,4 +135,3 @@ Number of rows inserted: 2
|
|||
Number of rows fetched: 2
|
||||
|
||||
Done
|
||||
Test \"sqlsrv_statement_complex_query\" completed successfully\.
|
||||
|
|
|
@ -4,15 +4,49 @@ Fetch data from a prepopulated test table given a custom keystore provider
|
|||
<?php require('skipif_not_ksp.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
function verifyData($row, $num)
|
||||
{
|
||||
$c1 = $num * 10 + $num + 1;
|
||||
if (AE\isColEncrypted()) {
|
||||
$c2 = "Sample data $num for column 2";
|
||||
|
||||
$c3 = '';
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
// add to letter 'a'
|
||||
$c3 .= chr(97 + $num + $i);
|
||||
}
|
||||
$c4 = "2017-08-" . ($num + 10);
|
||||
|
||||
// need to trim the third value because it is a char(5)
|
||||
if ($row[0] !== $c1 || $row[1] !== $c2 || trim($row[2]) !== $c3 || $row[3] !== $c4) {
|
||||
echo "Expected the following\n";
|
||||
echo "c1=$c1\nc2=$c2\nc3=$c3\nc4=$c4\n";
|
||||
echo "But got these instead\n";
|
||||
echo "c1=" . $row[0] . "\nc2=" . $row[1] . "\nc3=" . $row[2] . "\nc4=" . $row[3] . "\n" ;
|
||||
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if ($row[0] !== $c1) {
|
||||
echo "Expected $c1 but got $row[0]\n";
|
||||
}
|
||||
// should expect binary values for the other columns
|
||||
for ($i = 1; $i <= 3; $i++) {
|
||||
if (ctype_print($row[1])) {
|
||||
print "Error: expected a binary array for column $i!\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
sqlsrv_configure('WarningsReturnAsErrors', 1);
|
||||
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
|
||||
|
||||
require_once('MsHelper.inc');
|
||||
require_once('MsCommon.inc');
|
||||
$conn = AE\connect(array('ReturnDatesAsStrings'=>true));
|
||||
if ($conn === false) {
|
||||
echo "Failed to connect.\n";
|
||||
print_r(sqlsrv_errors());
|
||||
} else {
|
||||
if ($conn !== false) {
|
||||
echo "Connected successfully with ColumnEncryption enabled.\n";
|
||||
}
|
||||
|
||||
|
@ -20,13 +54,15 @@ Fetch data from a prepopulated test table given a custom keystore provider
|
|||
$tsql = "SELECT * FROM $ksp_test_table";
|
||||
$stmt = sqlsrv_prepare($conn, $tsql);
|
||||
if (!sqlsrv_execute($stmt)) {
|
||||
echo "Failed to fetch data.\n";
|
||||
print_r(sqlsrv_errors());
|
||||
fatalError("Failed to fetch data.\n");
|
||||
}
|
||||
|
||||
// fetch data
|
||||
$id = 0;
|
||||
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_NUMERIC)) {
|
||||
echo "c1=" . $row[0] . "\tc2=" . $row[1] . "\tc3=" . $row[2] . "\tc4=" . $row[3] . "\n" ;
|
||||
if (!verifyData($row, $id++)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
@ -36,14 +72,4 @@ Fetch data from a prepopulated test table given a custom keystore provider
|
|||
?>
|
||||
--EXPECT--
|
||||
Connected successfully with ColumnEncryption enabled.
|
||||
c1=1 c2=Sample data 0 for column 2 c3=abc c4=2017-08-10
|
||||
c1=12 c2=Sample data 1 for column 2 c3=bcd c4=2017-08-11
|
||||
c1=23 c2=Sample data 2 for column 2 c3=cde c4=2017-08-12
|
||||
c1=34 c2=Sample data 3 for column 2 c3=def c4=2017-08-13
|
||||
c1=45 c2=Sample data 4 for column 2 c3=efg c4=2017-08-14
|
||||
c1=56 c2=Sample data 5 for column 2 c3=fgh c4=2017-08-15
|
||||
c1=67 c2=Sample data 6 for column 2 c3=ghi c4=2017-08-16
|
||||
c1=78 c2=Sample data 7 for column 2 c3=hij c4=2017-08-17
|
||||
c1=89 c2=Sample data 8 for column 2 c3=ijk c4=2017-08-18
|
||||
c1=100 c2=Sample data 9 for column 2 c3=jkl c4=2017-08-19
|
||||
Done
|
||||
|
|
|
@ -7,7 +7,7 @@ Fetch encrypted data from a prepopulated test table given a custom keystore prov
|
|||
sqlsrv_configure('WarningsReturnAsErrors', 1);
|
||||
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
|
||||
|
||||
require_once('MsHelper.inc');
|
||||
require_once('MsCommon.inc');
|
||||
$conn = AE\connect(array('ReturnDatesAsStrings'=>true));
|
||||
if ($conn === false) {
|
||||
fatalError("Failed to connect.\n");
|
||||
|
|
|
@ -1,45 +1,64 @@
|
|||
--TEST--
|
||||
Test insert various data types and fetch as strings
|
||||
--SKIPIF--
|
||||
<?php require('skipif_versions_old.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once('MsCommon.inc');
|
||||
require_once('tools.inc');
|
||||
|
||||
function ExplicitFetch()
|
||||
function explicitFetch()
|
||||
{
|
||||
set_time_limit(0);
|
||||
sqlsrv_configure('WarningsReturnAsErrors', 1);
|
||||
|
||||
// Connect
|
||||
$connectionInfo = array("CharacterSet"=>"UTF-8");
|
||||
$conn = connect($connectionInfo);
|
||||
if (!$conn) {
|
||||
fatalError("Could not connect.\n");
|
||||
$conn = AE\connect($connectionInfo);
|
||||
|
||||
$tableName = 'types_explict_fetch';
|
||||
$columns = array(new AE\ColumnMeta('int', 'c1_int'),
|
||||
new AE\ColumnMeta('tinyint', 'c2_tinyint'),
|
||||
new AE\ColumnMeta('smallint', 'c3_smallint'),
|
||||
new AE\ColumnMeta('bigint', 'c4_bigint'),
|
||||
new AE\ColumnMeta('bit', 'c5_bit'),
|
||||
new AE\ColumnMeta('float', 'c6_float'),
|
||||
new AE\ColumnMeta('real', 'c7_real'),
|
||||
new AE\ColumnMeta('decimal(28,4)', 'c8_decimal'),
|
||||
new AE\ColumnMeta('numeric(32,4)', 'c9_numeric'),
|
||||
new AE\ColumnMeta('money', 'c10_money', null, true, true),
|
||||
new AE\ColumnMeta('smallmoney', 'c11_smallmoney', null, true, true),
|
||||
new AE\ColumnMeta('char(512)', 'c12_char'),
|
||||
new AE\ColumnMeta('varchar(512)', 'c13_varchar'),
|
||||
new AE\ColumnMeta('varchar(max)', 'c14_varchar_max'),
|
||||
new AE\ColumnMeta('uniqueidentifier', 'c15_uniqueidentifier'),
|
||||
new AE\ColumnMeta('datetime', 'c16_datetime'),
|
||||
new AE\ColumnMeta('smalldatetime', 'c17_smalldatetime'),
|
||||
new AE\ColumnMeta('timestamp', 'c18_timestamp')
|
||||
);
|
||||
$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_tinyint] tinyint, [c3_smallint] smallint, [c4_bigint] bigint, [c5_bit] bit, [c6_float] float, [c7_real] real, [c8_decimal] decimal(28,4), [c9_numeric] numeric(32,4), [c10_money] money, [c11_smallmoney] smallmoney, [c12_char] char(512), [c13_varchar] varchar(512), [c14_varchar_max] varchar(max), [c15_uniqueidentifier] uniqueidentifier, [c16_datetime] datetime, [c17_smalldatetime] smalldatetime, [c18_timestamp] timestamp)");
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
$numRows = 0;
|
||||
$data = GetInputData(++$numRows);
|
||||
$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_varchar_max, c15_uniqueidentifier, c16_datetime, c17_smalldatetime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", $data);
|
||||
$data = getInputData(++$numRows);
|
||||
$stmt = AE\executeQueryParams($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_varchar_max, c15_uniqueidentifier, c16_datetime, c17_smalldatetime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", $data);
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
$data = GetInputData(++$numRows);
|
||||
$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_varchar_max, c15_uniqueidentifier, c16_datetime, c17_smalldatetime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", $data);
|
||||
$data = getInputData(++$numRows);
|
||||
$stmt = AE\executeQueryParams($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_varchar_max, c15_uniqueidentifier, c16_datetime, c17_smalldatetime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", $data);
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
$data = GetInputData(++$numRows);
|
||||
$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_varchar_max, c15_uniqueidentifier, c16_datetime, c17_smalldatetime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", $data);
|
||||
$data = getInputData(++$numRows);
|
||||
$stmt = AE\executeQueryParams($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_varchar_max, c15_uniqueidentifier, c16_datetime, c17_smalldatetime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", $data);
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
$data = GetInputData(++$numRows);
|
||||
$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_varchar_max, c15_uniqueidentifier, c16_datetime, c17_smalldatetime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", $data);
|
||||
$data = getInputData(++$numRows);
|
||||
$stmt = AE\executeQueryParams($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_varchar_max, c15_uniqueidentifier, c16_datetime, c17_smalldatetime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", $data);
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
$stmt = sqlsrv_query($conn, "SELECT * FROM $tableName ORDER BY c18_timestamp");
|
||||
$stmt = AE\executeQuery($conn, "SELECT * FROM $tableName ORDER BY c18_timestamp");
|
||||
|
||||
$metadata = sqlsrv_field_metadata($stmt);
|
||||
$numFields = count($metadata);
|
||||
|
@ -49,10 +68,11 @@ function ExplicitFetch()
|
|||
echo "Number of Actual Rows $noActualRows is unexpected!\n";
|
||||
}
|
||||
|
||||
dropTable($conn, $tableName);
|
||||
sqlsrv_close($conn);
|
||||
}
|
||||
|
||||
function GetInputData($index)
|
||||
function getInputData($index)
|
||||
{
|
||||
switch ($index) {
|
||||
case 1:
|
||||
|
@ -68,20 +88,13 @@ function GetInputData($index)
|
|||
}
|
||||
}
|
||||
|
||||
function Repro()
|
||||
{
|
||||
startTest("sqlsrv_data_types_explict_fetch");
|
||||
echo "\nTest begins...\n";
|
||||
try {
|
||||
ExplicitFetch();
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
echo "\nDone\n";
|
||||
endTest("sqlsrv_data_types_explict_fetch");
|
||||
echo "\nTest begins...\n";
|
||||
try {
|
||||
explicitFetch();
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
|
||||
Repro();
|
||||
echo "\nDone\n";
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
|
@ -93,4 +106,3 @@ Comparing data in row 3
|
|||
Comparing data in row 4
|
||||
|
||||
Done
|
||||
Test "sqlsrv_data_types_explict_fetch" completed successfully.
|
||||
|
|
|
@ -1,9 +1,25 @@
|
|||
--TEST--
|
||||
Test using sqlsrv_query for binding parameters with column encryption and a custom keystore provider
|
||||
--SKIPIF--
|
||||
<?php require('skipif_not_ksp.inc'); ?>
|
||||
<?php require('skipif_versions_old.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
class Patient
|
||||
{
|
||||
public $SSN;
|
||||
public $FirstName;
|
||||
public $LastName;
|
||||
public $BirthDate;
|
||||
|
||||
public function __construct($ssn, $fname, $lname, $bdate)
|
||||
{
|
||||
$this->SSN = $ssn;
|
||||
$this->FirstName = $fname;
|
||||
$this->LastName = $lname;
|
||||
$this->BirthDate = $bdate;
|
||||
}
|
||||
}
|
||||
|
||||
function createPatientsTable()
|
||||
{
|
||||
global $conn;
|
||||
|
@ -23,26 +39,49 @@ Test using sqlsrv_query for binding parameters with column encryption and a cust
|
|||
|
||||
function selectData()
|
||||
{
|
||||
global $conn, $tableName;
|
||||
global $conn, $tableName, $numRows, $patient;
|
||||
|
||||
$stmt = sqlsrv_query($conn, "SELECT * FROM $tableName");
|
||||
|
||||
$id = 1;
|
||||
while ($obj = sqlsrv_fetch_object($stmt)) {
|
||||
echo $obj->PatientId . "\n";
|
||||
echo $obj->SSN . "\n";
|
||||
echo $obj->FirstName . "\n";
|
||||
echo $obj->LastName . "\n";
|
||||
echo $obj->BirthDate . "\n\n";
|
||||
if ($obj->PatientId !== $id) {
|
||||
echo "Expected $id but got $obj->PatientId\n";
|
||||
}
|
||||
if ($obj->SSN !== $patient->SSN) {
|
||||
echo "Expected $patient->SSN but got $obj->SSN\n";
|
||||
}
|
||||
if ($obj->FirstName !== $patient->FirstName) {
|
||||
echo "Expected $patient->FirstName but got $obj->FirstName\n";
|
||||
}
|
||||
if ($obj->LastName !== $patient->LastName) {
|
||||
echo "Expected $patient->LastName but got $obj->LastName\n";
|
||||
}
|
||||
if ($obj->BirthDate !== $patient->BirthDate) {
|
||||
echo "Expected $patient->BirthDate but got $obj->BirthDate\n";
|
||||
}
|
||||
|
||||
$id++;
|
||||
}
|
||||
$rowFetched = $id - 1;
|
||||
if ($rowFetched != $numRows){
|
||||
echo "Expected $numRows rows but got $rowFetched\n";
|
||||
}
|
||||
}
|
||||
|
||||
function printError()
|
||||
{
|
||||
global $AEQueryError;
|
||||
|
||||
$errors = sqlsrv_errors();
|
||||
foreach ($errors as $error) {
|
||||
echo " SQLSTATE: " . $error['SQLSTATE'] . "\n";
|
||||
echo " code: " . $error['code'] . "\n";
|
||||
echo " message: " . $error['message'] . "\n\n";
|
||||
if (AE\isColEncrypted()) {
|
||||
verifyError($errors[0], 'IMSSP', $AEQueryError);
|
||||
} else {
|
||||
foreach ($errors as $error) {
|
||||
echo " SQLSTATE: " . $error['SQLSTATE'] . "\n";
|
||||
echo " code: " . $error['code'] . "\n";
|
||||
echo " message: " . $error['message'] . "\n\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,24 +90,28 @@ Test using sqlsrv_query for binding parameters with column encryption and a cust
|
|||
|
||||
require_once('MsHelper.inc');
|
||||
$conn = AE\connect(array('ReturnDatesAsStrings'=>true));
|
||||
|
||||
if ($conn === false) {
|
||||
echo "Failed to connect.\n";
|
||||
printError();
|
||||
} else {
|
||||
if ($conn !== false) {
|
||||
echo "Connected successfully with ColumnEncryption enabled.\n\n";
|
||||
}
|
||||
|
||||
$AEQueryError = 'Must specify the SQL type for each parameter in a parameterized query when using sqlsrv_query in a column encryption enabled connection.';
|
||||
|
||||
$tableName = createPatientsTable();
|
||||
|
||||
$numRows = 0;
|
||||
|
||||
$tsql = "INSERT INTO $tableName (SSN, FirstName, LastName, BirthDate) VALUES (?, ?, ?, ?)";
|
||||
$inputs = array('748-68-0245', 'Jeannette', 'McDonald', '2002-11-28');
|
||||
$patient = new Patient('748-68-0245', 'Jeannette', 'McDonald', '2002-11-28');
|
||||
$inputs = array($patient->SSN, $patient->FirstName, $patient->LastName, $patient->BirthDate);
|
||||
|
||||
// expects an error in Column Encryption enabled connection
|
||||
print_r("Using sqlsrv_query and binding parameters with literal values:\n");
|
||||
|
||||
$stmt = sqlsrv_query($conn, $tsql, $inputs);
|
||||
if (!$stmt) {
|
||||
printError();
|
||||
} else {
|
||||
$numRows++;
|
||||
}
|
||||
|
||||
// expects an error in Column Encryption enabled connection
|
||||
|
@ -79,7 +122,10 @@ Test using sqlsrv_query for binding parameters with column encryption and a cust
|
|||
array($inputs[3], SQLSRV_PARAM_IN)));
|
||||
if (!$stmt) {
|
||||
printError();
|
||||
} else {
|
||||
$numRows++;
|
||||
}
|
||||
|
||||
// no error is expected
|
||||
print_r("Using sqlsrv_query and binding parameters with parameter arrays and sqltypes provided:\n");
|
||||
$stmt = sqlsrv_query($conn, $tsql, array(array($inputs[0], null, null, SQLSRV_SQLTYPE_CHAR(11)),
|
||||
|
@ -88,7 +134,10 @@ Test using sqlsrv_query for binding parameters with column encryption and a cust
|
|||
array($inputs[3], null, null, SQLSRV_SQLTYPE_DATE)));
|
||||
if (!$stmt) {
|
||||
printError();
|
||||
} else {
|
||||
$numRows++;
|
||||
}
|
||||
|
||||
selectData();
|
||||
|
||||
echo "Done\n";
|
||||
|
@ -97,20 +146,6 @@ Test using sqlsrv_query for binding parameters with column encryption and a cust
|
|||
Connected successfully with ColumnEncryption enabled.
|
||||
|
||||
Using sqlsrv_query and binding parameters with literal values:
|
||||
SQLSTATE: IMSSP
|
||||
code: -63
|
||||
message: Must specify the SQL type for each parameter in a parameterized query when using sqlsrv_query in a column encryption enabled connection.
|
||||
|
||||
Using sqlsrv_query and binding parameters with parameter arrays and no sqltypes provided:
|
||||
SQLSTATE: IMSSP
|
||||
code: -63
|
||||
message: Must specify the SQL type for each parameter in a parameterized query when using sqlsrv_query in a column encryption enabled connection.
|
||||
|
||||
Using sqlsrv_query and binding parameters with parameter arrays and sqltypes provided:
|
||||
1
|
||||
748-68-0245
|
||||
Jeannette
|
||||
McDonald
|
||||
2002-11-28
|
||||
|
||||
Done
|
|
@ -5,119 +5,118 @@ make sure errors are cleared for each new API call
|
|||
invalid parameters are reported via sqlsrv_errors, and
|
||||
sqlsrv_close returns true even if an error happens.
|
||||
--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);
|
||||
|
||||
require( 'MsCommon.inc' );
|
||||
require('MsCommon.inc');
|
||||
|
||||
$conn = sqlsrv_connect( "InvalidServerName", array( "Database" => "test" ));
|
||||
$conn = sqlsrv_connect("InvalidServerName", array( "Database" => "test" ));
|
||||
$result = sqlsrv_close($conn);
|
||||
$errors = sqlsrv_errors();
|
||||
if( $result !== false ) {
|
||||
die( "sqlsrv_close succeeded despite an invalid server name." );
|
||||
if ($result !== false) {
|
||||
die("sqlsrv_close succeeded despite an invalid server name.");
|
||||
}
|
||||
print_r( $errors );
|
||||
print_r($errors);
|
||||
|
||||
$conn = Connect();
|
||||
if( !$conn ) {
|
||||
var_dump( sqlsrv_errors() );
|
||||
die( "sqlsrv_create failed." );
|
||||
$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) {
|
||||
fatalError("Failed to create table $tableName\n");
|
||||
}
|
||||
|
||||
$stmt = sqlsrv_query( $conn, "IF OBJECT_ID('test_params', 'U') IS NOT NULL DROP TABLE test_params" );
|
||||
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 );
|
||||
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" );
|
||||
$f4 = fopen("data://text/plain,This%20is%20some%20text%20meant%20to%20test%20binding%20parameters%20to%20streams", "r");
|
||||
|
||||
$stmt = sqlsrv_prepare( $conn, "INSERT INTO test_params (id, name, [double], stuff) VALUES (?, ?, ?, ?)", array( &$f1, "testtestte", &$f3, &$f4 ));
|
||||
if( !$stmt ) {
|
||||
var_dump( sqlsrv_errors() );
|
||||
die( "sqlsrv_prepare failed." );
|
||||
$stmt = sqlsrv_prepare($conn, "INSERT INTO $tableName (id, name, [double], stuff) VALUES (?, ?, ?, ?)", array( &$f1, "testtestte", &$f3, &$f4 ));
|
||||
if (!$stmt) {
|
||||
var_dump(sqlsrv_errors());
|
||||
die("sqlsrv_prepare failed.");
|
||||
}
|
||||
|
||||
$success = sqlsrv_execute( $stmt );
|
||||
if( !$success ) {
|
||||
var_dump( sqlsrv_errors() );
|
||||
die( "sqlsrv_execute failed." );
|
||||
$success = sqlsrv_execute($stmt);
|
||||
if (!$success) {
|
||||
var_dump(sqlsrv_errors());
|
||||
die("sqlsrv_execute failed.");
|
||||
}
|
||||
while( $success = sqlsrv_send_stream_data( $stmt )) {
|
||||
while ($success = sqlsrv_send_stream_data($stmt)) {
|
||||
}
|
||||
if( !is_null( $success )) {
|
||||
sqlsrv_cancel( $stmt );
|
||||
sqlsrv_free_stmt( $stmt );
|
||||
die( "sqlsrv_send_stream_data failed." );
|
||||
if (!is_null($success)) {
|
||||
sqlsrv_cancel($stmt);
|
||||
sqlsrv_free_stmt($stmt);
|
||||
die("sqlsrv_send_stream_data failed.");
|
||||
}
|
||||
|
||||
$f1 = 2;
|
||||
$f3 = 13.0;
|
||||
$f4 = fopen( "data://text/plain,This%20is%20some%20more%20text%20meant%20to%20test%20binding%20parameters%20to%20streams", "r" );
|
||||
$success = sqlsrv_execute( $stmt );
|
||||
if( !$success ) {
|
||||
var_dump( sqlsrv_errors() );
|
||||
die( "sqlsrv_execute failed." );
|
||||
$f4 = fopen("data://text/plain,This%20is%20some%20more%20text%20meant%20to%20test%20binding%20parameters%20to%20streams", "r");
|
||||
$success = sqlsrv_execute($stmt);
|
||||
if (!$success) {
|
||||
var_dump(sqlsrv_errors());
|
||||
die("sqlsrv_execute failed.");
|
||||
}
|
||||
while( $success = sqlsrv_send_stream_data( $stmt )) {
|
||||
while ($success = sqlsrv_send_stream_data($stmt)) {
|
||||
}
|
||||
if( !is_null( $success )) {
|
||||
sqlsrv_cancel( $stmt );
|
||||
sqlsrv_free_stmt( $stmt );
|
||||
die( "sqlsrv_send_stream_data failed." );
|
||||
if (!is_null($success)) {
|
||||
sqlsrv_cancel($stmt);
|
||||
sqlsrv_free_stmt($stmt);
|
||||
die("sqlsrv_send_stream_data failed.");
|
||||
}
|
||||
|
||||
$result = sqlsrv_free_stmt( $stmt );
|
||||
if( $result === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
$result = sqlsrv_free_stmt($stmt);
|
||||
if ($result === false) {
|
||||
die(print_r(sqlsrv_errors(), true));
|
||||
}
|
||||
$result = sqlsrv_free_stmt( $stmt );
|
||||
if( $result === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
$result = sqlsrv_free_stmt($stmt);
|
||||
if ($result === false) {
|
||||
die(print_r(sqlsrv_errors(), true));
|
||||
}
|
||||
$result = sqlsrv_free_stmt( null );
|
||||
if( $result === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
$result = sqlsrv_free_stmt(null);
|
||||
if ($result === false) {
|
||||
die(print_r(sqlsrv_errors(), true));
|
||||
}
|
||||
$result = sqlsrv_free_stmt( $conn );
|
||||
if( $result !== false ) {
|
||||
die( "sqlsrv_free_stmt shouldn't have freed the connection resource" );
|
||||
$result = sqlsrv_free_stmt($conn);
|
||||
if ($result !== false) {
|
||||
die("sqlsrv_free_stmt shouldn't have freed the connection resource");
|
||||
}
|
||||
print_r( sqlsrv_errors() );
|
||||
$result = sqlsrv_free_stmt( 1 );
|
||||
if( $result !== false ) {
|
||||
die( "sqlsrv_free_stmt shouldn't have freed a 1" );
|
||||
print_r(sqlsrv_errors());
|
||||
$result = sqlsrv_free_stmt(1);
|
||||
if ($result !== false) {
|
||||
die("sqlsrv_free_stmt shouldn't have freed a 1");
|
||||
}
|
||||
print_r( sqlsrv_errors() );
|
||||
print_r(sqlsrv_errors());
|
||||
|
||||
sqlsrv_query( $conn, "DROP TABLE test_params" );
|
||||
dropTable($conn, $tableName);
|
||||
|
||||
$result = sqlsrv_close( $conn );
|
||||
if( $result === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
$result = sqlsrv_close($conn);
|
||||
if ($result === false) {
|
||||
die(print_r(sqlsrv_errors(), true));
|
||||
}
|
||||
$result = sqlsrv_close( $conn );
|
||||
if( $result === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
$result = sqlsrv_close($conn);
|
||||
if ($result === false) {
|
||||
die(print_r(sqlsrv_errors(), true));
|
||||
}
|
||||
$result = sqlsrv_close( null );
|
||||
if( $result === false ) {
|
||||
die( print_r( sqlsrv_errors(), true ));
|
||||
$result = sqlsrv_close(null);
|
||||
if ($result === false) {
|
||||
die(print_r(sqlsrv_errors(), true));
|
||||
}
|
||||
$result = sqlsrv_close( 1 );
|
||||
if( $result !== false ) {
|
||||
die( "sqlsrv_close shouldn't have freed a 1" );
|
||||
$result = sqlsrv_close(1);
|
||||
if ($result !== false) {
|
||||
die("sqlsrv_close shouldn't have freed a 1");
|
||||
}
|
||||
print_r( sqlsrv_errors() );
|
||||
print_r(sqlsrv_errors());
|
||||
|
||||
echo "Test successful.\n";
|
||||
echo "Test successfully done.\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: sqlsrv_close() expects parameter 1 to be resource, boolean given in %Ssqlsrv_errors.php on line %x
|
||||
|
@ -187,4 +186,4 @@ Array
|
|||
)
|
||||
|
||||
)
|
||||
Test successful.
|
||||
Test successfully done.
|
||||
|
|
|
@ -1,14 +1,20 @@
|
|||
--TEST--
|
||||
Test transactions commit, rollback and aborting in between
|
||||
--SKIPIF--
|
||||
<?php require('skipif_versions_old.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once('MsCommon.inc');
|
||||
|
||||
function ComplexTransaction($conn, $conn2)
|
||||
function complexTransaction($conn, $conn2)
|
||||
{
|
||||
$tableName = GetTempTableName('testTransaction', false);
|
||||
|
||||
$stmt = sqlsrv_query($conn, "CREATE TABLE $tableName ([c1_int] int, [c2_real] real)");
|
||||
$tableName = 'testTransaction';
|
||||
$columns = array(new AE\ColumnMeta('int', 'c1_int'),
|
||||
new AE\ColumnMeta('real', 'c2_real'));
|
||||
$stmt = AE\createTable($conn, $tableName, $columns);
|
||||
if (!$stmt) {
|
||||
fatalError("Failed to create table $tableName\n");
|
||||
}
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
$stmtSelect = sqlsrv_prepare($conn, "SELECT * FROM $tableName");
|
||||
|
@ -16,8 +22,8 @@ function ComplexTransaction($conn, $conn2)
|
|||
|
||||
// insert ten rows
|
||||
$numRows = 10;
|
||||
InsertData($conn, $tableName, $numRows);
|
||||
FetchData($stmtSelect, $tableName, $numRows);
|
||||
insertData($conn, $tableName, $numRows);
|
||||
fetchData($stmtSelect, $tableName, $numRows);
|
||||
|
||||
sqlsrv_begin_transaction($conn);
|
||||
sqlsrv_execute($stmtDelete);
|
||||
|
@ -26,14 +32,14 @@ function ComplexTransaction($conn, $conn2)
|
|||
echo "Committed deleting 3 rows\n";
|
||||
|
||||
$numRows = $numRows - $rowsAffected;
|
||||
FetchData($stmtSelect, $tableName, $numRows);
|
||||
fetchData($stmtSelect, $tableName, $numRows);
|
||||
|
||||
sqlsrv_begin_transaction($conn);
|
||||
sqlsrv_execute($stmtDelete);
|
||||
sqlsrv_rollback($conn);
|
||||
echo "Rolled back\n";
|
||||
|
||||
FetchData($stmtSelect, $tableName, $numRows);
|
||||
fetchData($stmtSelect, $tableName, $numRows);
|
||||
|
||||
sqlsrv_begin_transaction($conn);
|
||||
sqlsrv_execute($stmtDelete);
|
||||
|
@ -42,14 +48,14 @@ function ComplexTransaction($conn, $conn2)
|
|||
echo "Committed deleting 3 rows\n";
|
||||
|
||||
$numRows = $numRows - $rowsAffected;
|
||||
FetchData($stmtSelect, $tableName, $numRows);
|
||||
fetchData($stmtSelect, $tableName, $numRows);
|
||||
|
||||
sqlsrv_begin_transaction($conn);
|
||||
sqlsrv_execute($stmtDelete);
|
||||
sqlsrv_rollback($conn);
|
||||
echo "Rolled back\n";
|
||||
|
||||
FetchData($stmtSelect, $tableName, $numRows);
|
||||
fetchData($stmtSelect, $tableName, $numRows);
|
||||
|
||||
sqlsrv_begin_transaction($conn);
|
||||
sqlsrv_execute($stmtDelete);
|
||||
|
@ -59,12 +65,12 @@ function ComplexTransaction($conn, $conn2)
|
|||
|
||||
// select table using the second connection
|
||||
$stmt = sqlsrv_prepare($conn2, "SELECT * FROM $tableName");
|
||||
FetchData($stmt, $tableName, $numRows);
|
||||
fetchData($stmt, $tableName, $numRows);
|
||||
|
||||
sqlsrv_query($conn2, "DROP TABLE $tableName");
|
||||
dropTable($conn2, $tableName);
|
||||
}
|
||||
|
||||
function InsertData($conn, $tableName, $count)
|
||||
function insertData($conn, $tableName, $count)
|
||||
{
|
||||
$stmt = sqlsrv_prepare($conn, "INSERT INTO $tableName (c1_int, c2_real) VALUES (?, ?)", array(&$v1, &$v2));
|
||||
|
||||
|
@ -76,7 +82,7 @@ function InsertData($conn, $tableName, $count)
|
|||
}
|
||||
}
|
||||
|
||||
function FetchData($stmt, $tableName, $numRows)
|
||||
function fetchData($stmt, $tableName, $numRows)
|
||||
{
|
||||
$numFetched = 0;
|
||||
sqlsrv_execute($stmt);
|
||||
|
@ -90,41 +96,23 @@ function FetchData($stmt, $tableName, $numRows)
|
|||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// RunTest
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
function RunTest()
|
||||
{
|
||||
startTest("sqlsrv_fetch_complex_transactions");
|
||||
try {
|
||||
set_time_limit(0);
|
||||
sqlsrv_configure('WarningsReturnAsErrors', 1);
|
||||
try {
|
||||
set_time_limit(0);
|
||||
sqlsrv_configure('WarningsReturnAsErrors', 1);
|
||||
|
||||
echo "\nTest begins...\n";
|
||||
echo "\nTest begins...\n";
|
||||
|
||||
// Connect
|
||||
$conn = connect();
|
||||
if (!$conn) {
|
||||
fatalError("Could not connect.\n");
|
||||
}
|
||||
// Connect
|
||||
$conn = AE\connect();
|
||||
$conn2 = AE\connect();
|
||||
|
||||
$conn2 = connect();
|
||||
if (!$conn2) {
|
||||
fatalError("Could not connect.\n");
|
||||
}
|
||||
complexTransaction($conn, $conn2);
|
||||
|
||||
ComplexTransaction($conn, $conn2);
|
||||
|
||||
sqlsrv_close($conn2); // $conn should have been closed
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
echo "\nDone\n";
|
||||
endTest("sqlsrv_fetch_complex_transactions");
|
||||
sqlsrv_close($conn2); // $conn should have been closed
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
|
||||
RunTest();
|
||||
echo "\nDone\n";
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
|
@ -143,4 +131,3 @@ Deletion aborted
|
|||
Number of rows fetched: 4
|
||||
|
||||
Done
|
||||
Test "sqlsrv_fetch_complex_transactions" completed successfully.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
--TEST--
|
||||
sqlsrv_num_fields and output params without sqlsrv_next_result.
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
<?php require('skipif_versions_old.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
sqlsrv_configure('WarningsReturnAsErrors', 0);
|
||||
|
@ -9,10 +9,7 @@ sqlsrv_num_fields and output params without sqlsrv_next_result.
|
|||
|
||||
require_once('MsCommon.inc');
|
||||
|
||||
$conn = connect();
|
||||
if (!$conn) {
|
||||
fatalError("Failed to connect.");
|
||||
}
|
||||
$conn = AE\connect();
|
||||
|
||||
// test num_fields on a statement that doesn't generate a result set.
|
||||
$stmt = sqlsrv_prepare($conn, "USE 'tempdb'");
|
||||
|
@ -24,12 +21,17 @@ sqlsrv_num_fields and output params without sqlsrv_next_result.
|
|||
echo "$field_count\n";
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
$stmt = sqlsrv_prepare( $conn, "IF OBJECT_ID('test_params', 'U') IS NOT NULL DROP TABLE test_params" );
|
||||
sqlsrv_execute($stmt);
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
// test sqlsrv_num_fields immediately after a prepare
|
||||
$stmt = sqlsrv_prepare($conn, "CREATE TABLE test_params (id tinyint, name char(10), [double] float, stuff varchar(max))");
|
||||
// test sqlsrv_num_fields immediately after creating a table
|
||||
$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");
|
||||
}
|
||||
|
||||
$field_count = sqlsrv_num_fields($stmt);
|
||||
if ($field_count === false) {
|
||||
die(print_r(sqlsrv_errors(), true));
|
||||
|
@ -43,7 +45,7 @@ sqlsrv_num_fields and output params without sqlsrv_next_result.
|
|||
$f3 = 12.0;
|
||||
$f4 = fopen("data://text/plain,This%20is%20some%20text%20meant%20to%20test%20binding%20parameters%20to%20streams", "r");
|
||||
|
||||
$stmt = sqlsrv_prepare($conn, "INSERT INTO test_params (id, name, [double], stuff) VALUES (?, ?, ?, ?)", array( &$f1, "testtestte", &$f3, &$f4 ));
|
||||
$stmt = sqlsrv_prepare($conn, "INSERT INTO $tableName (id, name, [double], stuff) VALUES (?, ?, ?, ?)", array( &$f1, "testtestte", &$f3, &$f4 ));
|
||||
if (!$stmt) {
|
||||
fatalError("sqlsrv_prepare failed.");
|
||||
}
|
||||
|
@ -63,7 +65,7 @@ sqlsrv_num_fields and output params without sqlsrv_next_result.
|
|||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
// test num_fields on a valid statement that produces a result set.
|
||||
$stmt = sqlsrv_prepare($conn, "SELECT id, [double], name, stuff FROM test_params");
|
||||
$stmt = sqlsrv_prepare($conn, "SELECT id, [double], name, stuff FROM $tableName");
|
||||
$success = sqlsrv_execute($stmt);
|
||||
if (!$success) {
|
||||
var_dump(sqlsrv_errors());
|
||||
|
@ -91,7 +93,7 @@ sqlsrv_num_fields and output params without sqlsrv_next_result.
|
|||
// this should return 3, but shorthand output parameters are disabled for now.
|
||||
echo "$v3\n";
|
||||
|
||||
dropTable($conn, 'test_params');
|
||||
dropTable($conn, $tableName);
|
||||
|
||||
sqlsrv_free_stmt($stmt);
|
||||
sqlsrv_close($conn);
|
||||
|
|
|
@ -1,25 +1,26 @@
|
|||
--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 = 'param_floats';
|
||||
$columns = array(new AE\ColumnMeta('float', 'c1_float'),
|
||||
new AE\ColumnMeta('real', 'c2_real'));
|
||||
$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_float] float, [c2_real] real)");
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
|
||||
if ($withParams) {
|
||||
$stmt = sqlsrv_prepare($conn, "INSERT INTO $tableName (c1_float, c2_real) VALUES (?, ?)", array(array(&$v1, SQLSRV_PARAM_IN), array(&$v2, SQLSRV_PARAM_IN)));
|
||||
} else {
|
||||
|
@ -77,25 +78,20 @@ function ExecData($withParams)
|
|||
}
|
||||
}
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
dropTable($conn, $tableName);
|
||||
sqlsrv_close($conn);
|
||||
}
|
||||
|
||||
function Repro()
|
||||
{
|
||||
startTest("sqlsrv_statement_exec_param_floats");
|
||||
echo "\nTest begins...\n";
|
||||
echo "\nTest begins...\n";
|
||||
|
||||
try {
|
||||
ExecData(true);
|
||||
ExecData(false);
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
echo "\nDone\n";
|
||||
endTest("sqlsrv_statement_exec_param_floats");
|
||||
try {
|
||||
execData(true);
|
||||
execData(false);
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
|
||||
Repro();
|
||||
echo "\nDone\n";
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
|
@ -103,4 +99,3 @@ Repro();
|
|||
Test begins...
|
||||
|
||||
Done
|
||||
Test "sqlsrv_statement_exec_param_floats" completed successfully.
|
||||
|
|
|
@ -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 = AE\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.
|
||||
|
|
|
@ -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--
|
||||
|
|
|
@ -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 = 'sqlVariant_out_proc';
|
||||
|
||||
$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 = 'sqlVariant_inout_proc';
|
||||
$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
|
||||
$tableName = 'test_output_variants';
|
||||
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
|
|
@ -4,13 +4,15 @@ Test insert various numeric data types and fetch them back as strings
|
|||
<?php
|
||||
require_once('MsCommon.inc');
|
||||
|
||||
function ExecData_Value($conn, $numRows, $phpType = SQLSRV_PHPTYPE_NULL)
|
||||
function execDataValue($conn, $numRows, $phpType = SQLSRV_PHPTYPE_NULL)
|
||||
{
|
||||
$tableName = GetTempTableName();
|
||||
|
||||
$stmt = sqlsrv_query($conn, "CREATE TABLE [$tableName] ([c1_int] int, [c2_smallint] smallint)");
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
$tableName = 'param_query_value';
|
||||
$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");
|
||||
}
|
||||
if ($phpType == SQLSRV_PHPTYPE_NULL) {
|
||||
echo "Insert integers without PHP type\n";
|
||||
$stmt = sqlsrv_prepare($conn, "INSERT INTO [$tableName] (c1_int, c2_smallint) VALUES (?, ?)", array(array(&$v1), array(&$v2)));
|
||||
|
@ -18,12 +20,18 @@ function ExecData_Value($conn, $numRows, $phpType = SQLSRV_PHPTYPE_NULL)
|
|||
echo "Insert integers as SQLSRV_PHPTYPE_INT\n";
|
||||
$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)));
|
||||
}
|
||||
if (!$stmt) {
|
||||
fatalError("execDataValue: failed to prepare statement!");
|
||||
}
|
||||
|
||||
$value = 1;
|
||||
for ($i = 0; $i < $numRows; $i++) {
|
||||
$v1 = $value;
|
||||
$v2 = $v1 + 1;
|
||||
sqlsrv_execute($stmt);
|
||||
$res = sqlsrv_execute($stmt);
|
||||
if (!$res) {
|
||||
fatalError("execDataValue: failed to insert $v1, $v2");
|
||||
}
|
||||
|
||||
$value += 10;
|
||||
}
|
||||
|
@ -31,17 +39,22 @@ function ExecData_Value($conn, $numRows, $phpType = SQLSRV_PHPTYPE_NULL)
|
|||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
$stmt = sqlsrv_query($conn, "SELECT * FROM $tableName");
|
||||
FetchData($stmt, $numRows);
|
||||
fetchData($stmt, $numRows);
|
||||
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
dropTable($conn, $tableName);
|
||||
}
|
||||
|
||||
function ExecData_Param($conn, $numRows, $withParam = false)
|
||||
function execDataParam($conn, $numRows, $withParam = false)
|
||||
{
|
||||
$tableName = GetTempTableName();
|
||||
|
||||
$stmt = sqlsrv_query($conn, "CREATE TABLE [$tableName] ([c1_float] float, [c2_real] real)");
|
||||
sqlsrv_free_stmt($stmt);
|
||||
$tableName = 'param_query_param';
|
||||
$columns = array(new AE\ColumnMeta('float', 'c1_float'),
|
||||
new AE\ColumnMeta('real', 'c2_real'));
|
||||
$stmt = AE\createTable($conn, $tableName, $columns);
|
||||
if (!$stmt) {
|
||||
fatalError("failed to create table $tableName\n");
|
||||
}
|
||||
|
||||
if ($withParam) {
|
||||
echo "Insert floats with direction specified\n";
|
||||
|
@ -50,12 +63,18 @@ function ExecData_Param($conn, $numRows, $withParam = false)
|
|||
echo "Insert floats without direction\n";
|
||||
$stmt = sqlsrv_prepare($conn, "INSERT INTO [$tableName] (c1_float, c2_real) VALUES (?, ?)", array(&$v1, &$v2));
|
||||
}
|
||||
if (!$stmt) {
|
||||
fatalError("execDataParam: failed to prepare statement!");
|
||||
}
|
||||
|
||||
$value = 1.0;
|
||||
for ($i = 0; $i < $numRows; $i++) {
|
||||
$v1 = $value;
|
||||
$v2 = $v1 + 1.0;
|
||||
sqlsrv_execute($stmt);
|
||||
$res = sqlsrv_execute($stmt);
|
||||
if (!$res) {
|
||||
fatalError("execDataParam: failed to insert $v1, $v2");
|
||||
}
|
||||
|
||||
$value += 10;
|
||||
}
|
||||
|
@ -63,12 +82,14 @@ function ExecData_Param($conn, $numRows, $withParam = false)
|
|||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
$stmt = sqlsrv_query($conn, "SELECT * FROM $tableName");
|
||||
FetchData($stmt, $numRows);
|
||||
fetchData($stmt, $numRows);
|
||||
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
dropTable($conn, $tableName);
|
||||
}
|
||||
|
||||
function FetchData($stmt, $numRows)
|
||||
function fetchData($stmt, $numRows)
|
||||
{
|
||||
for ($i = 0; $i < $numRows; $i++) {
|
||||
sqlsrv_fetch($stmt);
|
||||
|
@ -81,36 +102,26 @@ function FetchData($stmt, $numRows)
|
|||
}
|
||||
}
|
||||
|
||||
function Repro()
|
||||
{
|
||||
startTest("sqlsrv_param_query_array_inputs");
|
||||
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();
|
||||
|
||||
$numRows = 5;
|
||||
$numRows = 5;
|
||||
|
||||
ExecData_Value($conn, $numRows);
|
||||
ExecData_Value($conn, $numRows, SQLSRV_PHPTYPE_INT);
|
||||
ExecData_Param($conn, $numRows, true);
|
||||
ExecData_Param($conn, $numRows);
|
||||
execDataValue($conn, $numRows);
|
||||
execDataValue($conn, $numRows, SQLSRV_PHPTYPE_INT);
|
||||
execDataParam($conn, $numRows, true);
|
||||
execDataParam($conn, $numRows);
|
||||
|
||||
sqlsrv_close($conn);
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
echo "\nDone\n";
|
||||
endTest("sqlsrv_param_query_array_inputs");
|
||||
sqlsrv_close($conn);
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
|
||||
Repro();
|
||||
echo "\nDone\n";
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
|
@ -142,4 +153,3 @@ Insert floats without direction
|
|||
41.0, 42.0
|
||||
|
||||
Done
|
||||
Test "sqlsrv_param_query_array_inputs" completed successfully.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
--TEST--
|
||||
binding parameters, including output parameters, using the simplified syntax.
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
<?php require('skipif_versions_old.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once('MsCommon.inc');
|
||||
|
||||
$conn = connect();
|
||||
if (!$conn) {
|
||||
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('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;
|
||||
|
@ -24,7 +24,7 @@ binding parameters, including output parameters, using the simplified syntax.
|
|||
$f3 = 12.0;
|
||||
$f4 = fopen("data://text/plain,This%20is%20some%20text%20meant%20to%20test%20binding%20parameters%20to%20streams", "r");
|
||||
|
||||
$stmt = sqlsrv_prepare($conn, "INSERT INTO test_params (id, name, [double], stuff) VALUES (?, ?, ?, ?)", array( &$f1, "testtestte", &$f3, &$f4 ));
|
||||
$stmt = sqlsrv_prepare($conn, "INSERT INTO $tableName (id, name, [double], stuff) VALUES (?, ?, ?, ?)", array( &$f1, "testtestte", &$f3, &$f4 ));
|
||||
if (!$stmt) {
|
||||
var_dump(sqlsrv_errors());
|
||||
die("sqlsrv_prepare failed.");
|
||||
|
@ -61,7 +61,7 @@ binding parameters, including output parameters, using the simplified syntax.
|
|||
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
$stmt = sqlsrv_prepare($conn, "SELECT id, [double], name, stuff FROM test_params");
|
||||
$stmt = sqlsrv_prepare($conn, "SELECT id, [double], name, stuff FROM $tableName");
|
||||
$success = sqlsrv_execute($stmt);
|
||||
if (!$success) {
|
||||
var_dump(sqlsrv_errors());
|
||||
|
@ -116,7 +116,7 @@ binding parameters, including output parameters, using the simplified syntax.
|
|||
// this should return 4, but shorthand output parameters are disabled for now.
|
||||
echo "$v3\n";
|
||||
|
||||
sqlsrv_query($conn, "DROP TABLE test_params");
|
||||
sqlsrv_query($conn, "DROP TABLE $tableName");
|
||||
|
||||
sqlsrv_free_stmt($stmt);
|
||||
sqlsrv_close($conn);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
--TEST--
|
||||
sqlsrv_stmt_rows_affected.
|
||||
--SKIPIF--
|
||||
<?php require('skipif.inc'); ?>
|
||||
<?php require('skipif_versions_old.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
sqlsrv_configure('WarningsReturnAsErrors', 0);
|
||||
|
@ -10,34 +10,22 @@ sqlsrv_stmt_rows_affected.
|
|||
|
||||
require_once('MsCommon.inc');
|
||||
|
||||
$conn = connect();
|
||||
if (!$conn) {
|
||||
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('varchar(4000)', '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");
|
||||
$result = sqlsrv_execute($stmt);
|
||||
if (!$result) {
|
||||
$errors = sqlsrv_errors();
|
||||
if ($errors[0]["SQLSTATE"] != "42S02") {
|
||||
var_dump($errors);
|
||||
die("sqlsrv_execute(2) failed.");
|
||||
}
|
||||
}
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
$stmt = sqlsrv_prepare($conn, "CREATE TABLE test_params (id tinyint, name char(10), [double] float, stuff varchar(4000))");
|
||||
$result = sqlsrv_execute($stmt);
|
||||
if (!$result) {
|
||||
fatalError("sqlsrv_execute(3) failed.");
|
||||
}
|
||||
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, &$f2, &$f3, &$f4 ));
|
||||
$stmt = sqlsrv_prepare($conn, "INSERT INTO $tableName (id, name, [double], stuff) VALUES (?, ?, ?, ?)", array( &$f1, &$f2, &$f3, &$f4 ));
|
||||
if (!$stmt) {
|
||||
fatalError("sqlsrv_prepare(4) failed.");
|
||||
}
|
||||
|
@ -65,7 +53,11 @@ sqlsrv_stmt_rows_affected.
|
|||
}
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
$stmt = sqlsrv_prepare($conn, "UPDATE test_params SET [double] = 13.0 FROM test_params WHERE [double] = 12.0");
|
||||
if (AE\isColEncrypted()) {
|
||||
$stmt = sqlsrv_prepare($conn, "UPDATE $tableName SET [double] = ? FROM $tableName WHERE [double] = ?", array(13.0, 12.0));
|
||||
} else {
|
||||
$stmt = sqlsrv_prepare($conn, "UPDATE $tableName SET [double] = 13.0 FROM $tableName WHERE [double] = 12.0");
|
||||
}
|
||||
if (!$stmt) {
|
||||
fatalError("sqlsrv_prepare(2) failed.");
|
||||
}
|
||||
|
@ -82,7 +74,7 @@ sqlsrv_stmt_rows_affected.
|
|||
}
|
||||
echo "rows = $row_count<br/>\n";
|
||||
|
||||
sqlsrv_query($conn, "DROP TABLE test_params");
|
||||
dropTable($conn, $tableName);
|
||||
|
||||
sqlsrv_free_stmt($stmt);
|
||||
sqlsrv_close($conn);
|
||||
|
|
|
@ -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
|
|
@ -2,6 +2,8 @@
|
|||
Test simple insert and update sql_variants using parameters of some different data types
|
||||
--DESCRIPTION--
|
||||
ORDER BY should work with sql_variants
|
||||
--SKIPIF--
|
||||
<?php require('skipif_versions_old.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once('MsCommon.inc');
|
||||
|
@ -22,20 +24,25 @@ class Country
|
|||
}
|
||||
}
|
||||
|
||||
function CreateVariantTable($conn, $tableName)
|
||||
function createVariantTable($conn, $tableName)
|
||||
{
|
||||
// create a table for testing
|
||||
$dataType = "[id] sql_variant, [country] sql_variant, [continent] sql_variant";
|
||||
createTableEx($conn, $tableName, $dataType);
|
||||
$columns = array(new AE\ColumnMeta('sql_variant', 'id'),
|
||||
new AE\ColumnMeta('sql_variant', 'country'),
|
||||
new AE\ColumnMeta('sql_variant', 'continent'));
|
||||
$stmt = AE\createTable($conn, $tableName, $columns);
|
||||
if (!$stmt) {
|
||||
fatalError("Failed to create table $tableName\n");
|
||||
}
|
||||
}
|
||||
|
||||
function AddCountry($conn, $tableName, $id, $country, $continent)
|
||||
function addCountry($conn, $tableName, $id, $country, $continent)
|
||||
{
|
||||
$query = "INSERT $tableName ([id], [country], [continent]) VALUES (?, ?, ?)";
|
||||
|
||||
// set parameters
|
||||
$params = array($id, $country, $continent);
|
||||
$stmt = sqlsrv_query($conn, $query, $params);
|
||||
$stmt = AE\executeQueryParams($conn, $query, $params);
|
||||
|
||||
if ($stmt) {
|
||||
echo "\nAdded $country in $continent with ID $id.";
|
||||
|
@ -44,7 +51,7 @@ function AddCountry($conn, $tableName, $id, $country, $continent)
|
|||
}
|
||||
}
|
||||
|
||||
function UpdateID($conn, $tableName, $id, $country, $continent)
|
||||
function updateID($conn, $tableName, $id, $country, $continent)
|
||||
{
|
||||
$query = "UPDATE $tableName SET id = ? WHERE country = ? AND continent = ?";
|
||||
$param1 = $id;
|
||||
|
@ -63,7 +70,7 @@ function UpdateID($conn, $tableName, $id, $country, $continent)
|
|||
}
|
||||
}
|
||||
|
||||
function UpdateCountry($conn, $tableName, $id, $country, $continent)
|
||||
function updateCountry($conn, $tableName, $id, $country, $continent)
|
||||
{
|
||||
$query = "UPDATE $tableName SET country = ? WHERE id = ? AND continent = ?";
|
||||
$param1 = $country;
|
||||
|
@ -82,7 +89,7 @@ function UpdateCountry($conn, $tableName, $id, $country, $continent)
|
|||
}
|
||||
}
|
||||
|
||||
function Fetch($conn, $tableName)
|
||||
function fetch($conn, $tableName)
|
||||
{
|
||||
$select = "SELECT * FROM $tableName ORDER BY id";
|
||||
$stmt = sqlsrv_query($conn, $select);
|
||||
|
@ -96,59 +103,50 @@ function Fetch($conn, $tableName)
|
|||
sqlsrv_free_stmt($stmt);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// RunTest
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
function RunTest()
|
||||
{
|
||||
startTest("sqlsrv_simple_update_variants");
|
||||
try {
|
||||
setup();
|
||||
try {
|
||||
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);
|
||||
// Create a temp table that will be automatically dropped once the connection is closed
|
||||
$tableName = 'simple_update_variants';
|
||||
createVariantTable($conn, $tableName);
|
||||
|
||||
// Add three countries
|
||||
AddCountry($conn, $tableName, 1, 'Canada', 'North America');
|
||||
AddCountry($conn, $tableName, 3, 'France', 'Europe');
|
||||
AddCountry($conn, $tableName, 5, 'Australia', 'Australia');
|
||||
// Add three countries
|
||||
addCountry($conn, $tableName, 1, 'Canada', 'North America');
|
||||
addCountry($conn, $tableName, 3, 'France', 'Europe');
|
||||
addCountry($conn, $tableName, 5, 'Australia', 'Australia');
|
||||
|
||||
// Read data
|
||||
Fetch($conn, $tableName);
|
||||
// Read data
|
||||
fetch($conn, $tableName);
|
||||
|
||||
// Update id
|
||||
UpdateID($conn, $tableName, 4, 'Canada', 'North America');
|
||||
// Update id
|
||||
updateID($conn, $tableName, 4, 'Canada', 'North America');
|
||||
|
||||
// Read data
|
||||
Fetch($conn, $tableName);
|
||||
// Read data
|
||||
fetch($conn, $tableName);
|
||||
|
||||
// Update country
|
||||
UpdateCountry($conn, $tableName, 4, 'Mexico', 'North America');
|
||||
// Update country
|
||||
updateCountry($conn, $tableName, 4, 'Mexico', 'North America');
|
||||
|
||||
// Read data
|
||||
Fetch($conn, $tableName);
|
||||
// Read data
|
||||
fetch($conn, $tableName);
|
||||
|
||||
// Add two more countries
|
||||
AddCountry($conn, $tableName, 6, 'Brazil', 'South America');
|
||||
AddCountry($conn, $tableName, 2, 'Egypt', 'Africa');
|
||||
// Add two more countries
|
||||
addCountry($conn, $tableName, 6, 'Brazil', 'South America');
|
||||
addCountry($conn, $tableName, 2, 'Egypt', 'Africa');
|
||||
|
||||
// Read data
|
||||
Fetch($conn, $tableName);
|
||||
// Read data
|
||||
fetch($conn, $tableName);
|
||||
|
||||
dropTable($conn, $tableName);
|
||||
|
||||
sqlsrv_close($conn);
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
echo "\nDone\n";
|
||||
endTest("sqlsrv_simple_update_variants");
|
||||
sqlsrv_close($conn);
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
|
||||
RunTest();
|
||||
echo "\nDone\n";
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
|
@ -175,4 +173,3 @@ ID: 4 Mexico, North America
|
|||
ID: 5 Australia, Australia
|
||||
ID: 6 Brazil, South America
|
||||
Done
|
||||
Test "sqlsrv_simple_update_variants" completed successfully.
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
--TEST--
|
||||
Test stored procedure that returns a varchar
|
||||
--SKIPIF--
|
||||
<?php require('skipif_versions_old.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once('MsCommon.inc');
|
||||
|
||||
function StoredProc_varchar()
|
||||
function storedProcVarchar()
|
||||
{
|
||||
set_time_limit(0);
|
||||
sqlsrv_configure('WarningsReturnAsErrors', 1);
|
||||
|
||||
// connect
|
||||
$conn = connect();
|
||||
if (!$conn) {
|
||||
fatalError("Could not connect.\n");
|
||||
}
|
||||
$conn = AE\connect();
|
||||
|
||||
$procName = GetTempProcName();
|
||||
$procName = 'sp_varchar';
|
||||
dropProc($conn, $procName);
|
||||
|
||||
$tsql = "CREATE PROC $procName (@p1 VARCHAR(37) OUTPUT, @p2 VARCHAR(21), @p3 VARCHAR(14))
|
||||
AS
|
||||
|
@ -42,23 +42,18 @@ function StoredProc_varchar()
|
|||
sqlsrv_execute($stmt);
|
||||
echo("$retValue\n");
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
dropProc($conn, $procName);
|
||||
sqlsrv_close($conn);
|
||||
}
|
||||
|
||||
function Repro()
|
||||
{
|
||||
startTest("sqlsrv_stored_proc_varchar");
|
||||
echo "\nTest begins...\n";
|
||||
try {
|
||||
StoredProc_varchar();
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
echo "\nDone\n";
|
||||
endTest("sqlsrv_stored_proc_varchar");
|
||||
echo "\nTest begins...\n";
|
||||
try {
|
||||
storedProcVarchar();
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
|
||||
Repro();
|
||||
echo "\nDone\n";
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
|
@ -71,4 +66,3 @@ Microsoft SQL Server Driver for PHP
|
|||
Microsoft SQL Server Driver for PHP
|
||||
|
||||
Done
|
||||
Test "sqlsrv_stored_proc_varchar" completed successfully.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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,35 @@ 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");
|
||||
}
|
||||
// connect
|
||||
$conn = AE\connect();
|
||||
|
||||
// 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();
|
||||
// create a test table
|
||||
$tableName = 'null_binary_stream';
|
||||
$columns = array(new AE\ColumnMeta('int', 'c1_int'),
|
||||
new AE\ColumnMeta('varbinary(512)', 'c2_varbinary'),
|
||||
new AE\ColumnMeta('varbinary(max)', 'c3_varbinary_max'),
|
||||
new AE\ColumnMeta('image', 'c4_image'));
|
||||
$stmt = AE\createTable($conn, $tableName, $columns);
|
||||
if (!$stmt) {
|
||||
fatalError("Failed to create table.\n");
|
||||
}
|
||||
echo "\nDone\n";
|
||||
endTest("sqlsrv_streams_null_binary");
|
||||
}
|
||||
|
||||
RunTest();
|
||||
nullBin2String($conn, $tableName);
|
||||
nullPrepBin2String($conn, $tableName);
|
||||
|
||||
dropTable($conn, $tableName);
|
||||
|
||||
sqlsrv_close($conn);
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
echo "\nDone\n";
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
|
@ -84,4 +102,3 @@ NULL
|
|||
NULL
|
||||
|
||||
Done
|
||||
Test "sqlsrv_streams_null_binary" completed successfully.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -9,11 +9,11 @@ Intentionally provide an invalid server name and set LoginTimeout. Verify the ti
|
|||
|
||||
$serverName = "WRONG_SERVER_NAME";
|
||||
|
||||
$t0 = round(microtime(true));
|
||||
$t0 = microtime(true);
|
||||
|
||||
$conn = sqlsrv_connect( $serverName , array("LoginTimeout" => 8));
|
||||
$conn = sqlsrv_connect($serverName , array("LoginTimeout" => 8));
|
||||
|
||||
$t1 = round(microtime(true));
|
||||
$t1 = microtime(true);
|
||||
|
||||
echo "Connection attempt time: " . ($t1 - $t0) . " [sec]\n";
|
||||
|
||||
|
@ -21,5 +21,5 @@ print "Done";
|
|||
?>
|
||||
|
||||
--EXPECTREGEX--
|
||||
Connection attempt time: [7-9] \[sec\]
|
||||
Connection attempt time: [7-9]\.[0-9]+ \[sec\]
|
||||
Done
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -13,15 +13,11 @@ require_once("MsCommon.inc");
|
|||
|
||||
// connect
|
||||
$conn = AE\connect();
|
||||
if (!$conn) {
|
||||
fatalError("Connection could not be established.\n");
|
||||
}
|
||||
|
||||
$tableName = 'testLOBTypes_GH231';
|
||||
$tableName = 'testLOBTypes_GH231_lob';
|
||||
$columnNames = array("c1", "c2");
|
||||
|
||||
for ($k = 1; $k <= 3; $k++) {
|
||||
$sqlType = sqlType($k);
|
||||
$sqlType = SQLType($k);
|
||||
$columns = array(new AE\ColumnMeta('int', $columnNames[0]),
|
||||
new AE\ColumnMeta($sqlType, $columnNames[1]));
|
||||
AE\createTable($conn, $tableName, $columns);
|
||||
|
@ -95,7 +91,7 @@ function getData($k)
|
|||
return $data;
|
||||
}
|
||||
|
||||
function sqlType($k)
|
||||
function SQLType($k)
|
||||
{
|
||||
switch ($k) {
|
||||
case 1: return ("text");
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
--TEST--
|
||||
GitHub issue #231 - String truncation when binding varchar(max)
|
||||
--SKIPIF--
|
||||
<?php require('skipif_versions_old.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
|
@ -9,93 +10,100 @@ sqlsrv_configure('WarningsReturnAsErrors', 1);
|
|||
require_once("MsCommon.inc");
|
||||
|
||||
// connect
|
||||
$conn = connect();
|
||||
if (!$conn) {
|
||||
printErrors("Connection could not be established.\n");
|
||||
}
|
||||
|
||||
$tableName = GetTempTableName('testDataTypes_GH231');
|
||||
$columnNames = array( "c1","c2" );
|
||||
$conn = AE\connect();
|
||||
$tableName = 'testDataTypes_GH231_VC';
|
||||
$columnNames = array("c1", "c2");
|
||||
|
||||
for ($k = 1; $k <= 8; $k++) {
|
||||
$sqlType = SqlType($k);
|
||||
$dataType = "[$columnNames[0]] int, [$columnNames[1]] $sqlType";
|
||||
|
||||
$sql = "CREATE TABLE [$tableName] ($dataType)";
|
||||
$stmt1 = sqlsrv_query($conn, $sql);
|
||||
sqlsrv_free_stmt($stmt1);
|
||||
$sqlType = SQLType($k);
|
||||
$columns = array(new AE\ColumnMeta('int', $columnNames[0]),
|
||||
new AE\ColumnMeta($sqlType, $columnNames[1]));
|
||||
AE\createTable($conn, $tableName, $columns);
|
||||
|
||||
$sql = "INSERT INTO [$tableName] ($columnNames[0], $columnNames[1]) VALUES (?, ?)";
|
||||
$data = GetData($k);
|
||||
$phpType = PhpType($k);
|
||||
$driverType = DriverType($k, strlen($data));
|
||||
$data = getData($k);
|
||||
$phpType = getPhpType($k);
|
||||
|
||||
$len = AE\isColEncrypted() ? 512 : strlen($data);
|
||||
$sqlsrvType = getSQLSRVType($k, $len);
|
||||
|
||||
$params = array($k, array($data, SQLSRV_PARAM_IN, $phpType, $driverType));
|
||||
$stmt2 = sqlsrv_prepare($conn, $sql, $params);
|
||||
sqlsrv_execute($stmt2);
|
||||
sqlsrv_free_stmt($stmt2);
|
||||
$params = array($k, array($data, SQLSRV_PARAM_IN, $phpType, $sqlsrvType));
|
||||
$stmt = sqlsrv_prepare($conn, $sql, $params);
|
||||
sqlsrv_execute($stmt);
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
ExecProc($conn, $tableName, $columnNames, $k, $data, $sqlType);
|
||||
execProc($conn, $tableName, $columnNames, $k, $data, $sqlType);
|
||||
|
||||
$stmt3 = sqlsrv_query($conn, "DROP TABLE [$tableName]");
|
||||
sqlsrv_free_stmt($stmt3);
|
||||
dropTable($conn, $tableName);
|
||||
}
|
||||
|
||||
sqlsrv_close($conn);
|
||||
|
||||
|
||||
function ExecProc($conn, $tableName, $columnNames, $k, $data, $sqlType)
|
||||
function execProc($conn, $tableName, $columnNames, $k, $data, $sqlType)
|
||||
{
|
||||
$spArgs = "@p1 int, @p2 $sqlType OUTPUT";
|
||||
$spCode = "SET @p2 = ( SELECT c2 FROM $tableName WHERE c1 = @p1 )";
|
||||
$procName = "testBindOutSp";
|
||||
|
||||
dropProc($conn, $procName);
|
||||
$stmt1 = sqlsrv_query($conn, "CREATE PROC [$procName] ($spArgs) AS BEGIN $spCode END");
|
||||
sqlsrv_free_stmt($stmt1);
|
||||
if (!$stmt1) {
|
||||
fatalError("Failed to create stored procedure $procName");
|
||||
} else {
|
||||
sqlsrv_free_stmt($stmt1);
|
||||
}
|
||||
|
||||
echo "\nData Type: ".$sqlType." binding as \n";
|
||||
|
||||
$direction = SQLSRV_PARAM_OUT;
|
||||
echo "Output parameter: \t";
|
||||
InvokeProc($conn, $procName, $k, $direction, $data);
|
||||
invokeProc($conn, $procName, $k, $direction, $data);
|
||||
|
||||
$direction = SQLSRV_PARAM_INOUT;
|
||||
echo "InOut parameter: \t";
|
||||
InvokeProc($conn, $procName, $k, $direction, $data);
|
||||
invokeProc($conn, $procName, $k, $direction, $data);
|
||||
|
||||
$stmt2 = sqlsrv_query($conn, "DROP PROC [$procName]");
|
||||
sqlsrv_free_stmt($stmt2);
|
||||
dropProc($conn, $procName);
|
||||
}
|
||||
|
||||
function InvokeProc($conn, $procName, $k, $direction, $data)
|
||||
function invokeProc($conn, $procName, $k, $direction, $data)
|
||||
{
|
||||
$driverType = DriverType($k, strlen($data));
|
||||
$len = AE\isColEncrypted() ? 512 : strlen($data);
|
||||
$sqlsrvType = getSQLSRVType($k, $len);
|
||||
|
||||
$callArgs = "?, ?";
|
||||
|
||||
// Data to initialize $callResult variable. This variable should be shorter than inserted data in the table
|
||||
// Data to initialize $callResult variable. This variable
|
||||
// should be shorter than inserted data in the table
|
||||
$initData = "ShortString";
|
||||
$callResult = $initData;
|
||||
|
||||
// Make sure not to specify the PHP type
|
||||
$params = array( array( $k, SQLSRV_PARAM_IN ),
|
||||
array( &$callResult, $direction, null, $driverType ));
|
||||
$stmt = sqlsrv_query($conn, "{ CALL [$procName] ($callArgs)}", $params);
|
||||
array( &$callResult, $direction, null, $sqlsrvType ));
|
||||
$stmt = AE\executeQueryParams($conn, "{ CALL [$procName] ($callArgs)}", $params);
|
||||
if ($stmt === false) {
|
||||
die(print_r(sqlsrv_errors(), true));
|
||||
}
|
||||
|
||||
// $callResult should be updated to the value in the table
|
||||
$matched = ($callResult === $data);
|
||||
if (AE\isColEncrypted()) {
|
||||
// with AE enabled, char/nchar fields have size up to 512
|
||||
$matched = (trim($callResult) === $data);
|
||||
} else {
|
||||
$matched = ($callResult === $data);
|
||||
}
|
||||
if ($matched) {
|
||||
echo "data matched!\n";
|
||||
} else {
|
||||
echo "failed!\n";
|
||||
echo "failed! $callResult vs $data\n";
|
||||
}
|
||||
|
||||
sqlsrv_free_stmt($stmt);
|
||||
}
|
||||
|
||||
function GetData($k)
|
||||
function getData($k)
|
||||
{
|
||||
$data = "LongStringForTesting";
|
||||
if ($k == 8) {
|
||||
|
@ -105,7 +113,7 @@ function GetData($k)
|
|||
return $data;
|
||||
}
|
||||
|
||||
function PhpType($k)
|
||||
function getPhpType($k)
|
||||
{
|
||||
$phpType = SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR);
|
||||
if ($k == 7) {
|
||||
|
@ -115,7 +123,7 @@ function PhpType($k)
|
|||
return $phpType;
|
||||
}
|
||||
|
||||
function SqlType($k)
|
||||
function SQLType($k)
|
||||
{
|
||||
switch ($k) {
|
||||
case 1: return ("char(512)");
|
||||
|
@ -131,7 +139,7 @@ function SqlType($k)
|
|||
return ("udt");
|
||||
}
|
||||
|
||||
function DriverType($k, $dataSize)
|
||||
function getSQLSRVType($k, $dataSize)
|
||||
{
|
||||
switch ($k) {
|
||||
case 1: return (SQLSRV_SQLTYPE_CHAR($dataSize));
|
||||
|
|
|
@ -1,33 +1,28 @@
|
|||
--TEST--
|
||||
Send an empty stream and null stream test.
|
||||
--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) VALUES (?, ?)", array( &$f1, &$f2 ));
|
||||
$stmt = sqlsrv_prepare($conn, "INSERT INTO $tableName (id, varchar_stream) VALUES (?, ?)", array( &$f1, &$f2 ));
|
||||
if ($stmt === false) {
|
||||
print_r("sqlsrv_prepare failed.");
|
||||
die(print_r(sqlsrv_errors(), true));
|
||||
|
@ -50,7 +45,7 @@ Send an empty stream and null stream test.
|
|||
$f4 = fopen("data://text/plain,", "r");
|
||||
$stmt = sqlsrv_prepare(
|
||||
$conn,
|
||||
"INSERT INTO test_empty_stream (id, varbinary_stream) VALUES (?, ?)",
|
||||
"INSERT INTO $tableName (id, varbinary_stream) VALUES (?, ?)",
|
||||
array( &$f3,
|
||||
array( &$f4, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_VARBINARY('max')) )
|
||||
);
|
||||
|
@ -72,7 +67,7 @@ Send an empty stream and null stream test.
|
|||
die(print_r(sqlsrv_errors(), true));
|
||||
}
|
||||
|
||||
$stmt = sqlsrv_query($conn, "SELECT id, varchar_stream, varbinary_stream FROM test_empty_stream");
|
||||
$stmt = AE\executeQuery($conn, "SELECT id, varchar_stream, varbinary_stream FROM $tableName");
|
||||
if ($stmt === false) {
|
||||
die(print_r(sqlsrv_errors(), true));
|
||||
}
|
||||
|
@ -127,7 +122,7 @@ Send an empty stream and null stream test.
|
|||
}
|
||||
print_r(sqlsrv_errors());
|
||||
|
||||
sqlsrv_query($conn, "DROP TABLE test_empty_stream");
|
||||
dropTable($conn, $tableName);
|
||||
sqlsrv_close($conn);
|
||||
?>
|
||||
--EXPECT--
|
||||
|
|
|
@ -1,32 +1,30 @@
|
|||
--TEST--
|
||||
error messages when trying to retrieve past the end of a result set and when no result set exists.
|
||||
--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();
|
||||
if (!$conn) {
|
||||
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('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, &$f4 ));
|
||||
$stmt = sqlsrv_prepare($conn, "INSERT INTO $tableName (id, name, [double], stuff) VALUES (?, ?, ?, ?)", array( &$f1, "testtestte", &$f3, &$f4 ));
|
||||
if (!$stmt) {
|
||||
var_dump(sqlsrv_errors());
|
||||
die("sqlsrv_prepare failed.");
|
||||
|
@ -69,7 +67,7 @@ error messages when trying to retrieve past the end of a result set and when no
|
|||
|
||||
sqlsrv_free_stmt($stmt);
|
||||
|
||||
$stmt = sqlsrv_prepare($conn, "SELECT id, [double], name, stuff FROM test_params");
|
||||
$stmt = sqlsrv_prepare($conn, "SELECT id, [double], name, stuff FROM $tableName");
|
||||
$success = sqlsrv_execute($stmt);
|
||||
if (!$success) {
|
||||
var_dump(sqlsrv_errors());
|
||||
|
@ -107,7 +105,7 @@ error messages when trying to retrieve past the end of a result set and when no
|
|||
}
|
||||
print_r(sqlsrv_errors());
|
||||
|
||||
sqlsrv_query($conn, "DROP TABLE test_params");
|
||||
dropTable($conn, $tableName);
|
||||
|
||||
sqlsrv_free_stmt($stmt);
|
||||
sqlsrv_close($conn);
|
||||
|
|
Loading…
Reference in a new issue