Added more checks for error conditions (#965)
This commit is contained in:
parent
7d389e0cff
commit
1ba1f21eb8
|
@ -1,5 +1,7 @@
|
|||
--TEST--
|
||||
Fix for output string parameter truncation error
|
||||
--DESCRIPTION--
|
||||
This test includes calling sqlsrv_query with an array of parameters with a named key, which should result in an error.
|
||||
--SKIPIF--
|
||||
<?php require('skipif_versions_old.inc'); ?>
|
||||
--FILE--
|
||||
|
@ -23,10 +25,25 @@ if ($s === false) {
|
|||
|
||||
$inValue1 = "Some data";
|
||||
$outValue1 = "";
|
||||
$tsql = '{CALL [test_output] (?, ?)}';
|
||||
|
||||
$s = sqlsrv_query(
|
||||
$conn,
|
||||
"{CALL [test_output] (?, ?)}",
|
||||
array(array($inValue1, SQLSRV_PARAM_IN, null, SQLSRV_SQLTYPE_VARCHAR(512)),
|
||||
$tsql,
|
||||
array("k1" => array($inValue1, SQLSRV_PARAM_IN, null, SQLSRV_SQLTYPE_VARCHAR(512)),
|
||||
array(&$outValue1, SQLSRV_PARAM_OUT, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_VARCHAR(512)))
|
||||
);
|
||||
|
||||
if ($s !== false) {
|
||||
echo "Expect this to fail!\n";
|
||||
} else {
|
||||
print_r(sqlsrv_errors());
|
||||
}
|
||||
|
||||
$s = sqlsrv_query(
|
||||
$conn,
|
||||
$tsql,
|
||||
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)))
|
||||
);
|
||||
|
||||
|
@ -45,5 +62,18 @@ sqlsrv_close($conn);
|
|||
|
||||
?>
|
||||
--EXPECT--
|
||||
Array
|
||||
(
|
||||
[0] => Array
|
||||
(
|
||||
[0] => IMSSP
|
||||
[SQLSTATE] => IMSSP
|
||||
[1] => -57
|
||||
[code] => -57
|
||||
[2] => String keys are not allowed in parameters arrays.
|
||||
[message] => String keys are not allowed in parameters arrays.
|
||||
)
|
||||
|
||||
)
|
||||
512
|
||||
Some data
|
||||
|
|
|
@ -2,11 +2,14 @@
|
|||
This test verifies that GitHub issue #378 is fixed.
|
||||
--DESCRIPTION--
|
||||
GitHub issue #378 - output parameters appends garbage info when variable is initialized with different data type
|
||||
steps to reproduce the issue:
|
||||
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.
|
||||
Also check error conditions by passing output parameters NOT by reference.
|
||||
--ENV--
|
||||
PHPT_EXEC=true
|
||||
--SKIPIF--
|
||||
<?php require('skipif_versions_old.inc'); ?>
|
||||
--FILE--
|
||||
|
@ -19,11 +22,8 @@ $conn = AE\connect();
|
|||
$procName = 'test_378';
|
||||
createSP($conn, $procName);
|
||||
|
||||
sqlsrv_configure('WarningsReturnAsErrors', true);
|
||||
executeSP($conn, $procName);
|
||||
|
||||
sqlsrv_configure('WarningsReturnAsErrors', false);
|
||||
executeSP($conn, $procName);
|
||||
runTests($conn, $procName, true);
|
||||
runTests($conn, $procName, false);
|
||||
|
||||
dropProc($conn, $procName);
|
||||
echo "Done\n";
|
||||
|
@ -46,7 +46,34 @@ function createSP($conn, $procName)
|
|||
}
|
||||
}
|
||||
|
||||
function executeSP($conn, $procName)
|
||||
//-------------------functions-------------------
|
||||
function runTests($conn, $procName, $warningAsErrors)
|
||||
{
|
||||
sqlsrv_configure('WarningsReturnAsErrors', $warningAsErrors);
|
||||
|
||||
trace("\nWarningsReturnAsErrors: $warningAsErrors\n");
|
||||
|
||||
executeSP($conn, $procName, true, false);
|
||||
executeSP($conn, $procName, true, true);
|
||||
executeSP($conn, $procName, false, false);
|
||||
executeSP($conn, $procName, false, true);
|
||||
}
|
||||
|
||||
function compareErrors()
|
||||
{
|
||||
$message = 'Variable parameter 3 not passed by reference (prefaced with an &). Output or bidirectional variable parameters (SQLSRV_PARAM_OUT and SQLSRV_PARAM_INOUT) passed to sqlsrv_prepare or sqlsrv_query should be passed by reference, not by value.';
|
||||
|
||||
$error = sqlsrv_errors()[0]['message'];
|
||||
|
||||
if ($error !== $message) {
|
||||
print_r(sqlsrv_errors(), true);
|
||||
return;
|
||||
}
|
||||
|
||||
trace("Comparing errors: matched!\n");
|
||||
}
|
||||
|
||||
function executeSP($conn, $procName, $noRef, $prepare)
|
||||
{
|
||||
$expected = 3;
|
||||
$v1 = 1;
|
||||
|
@ -54,14 +81,44 @@ function executeSP($conn, $procName)
|
|||
$v3 = 'str';
|
||||
|
||||
$res = true;
|
||||
if (AE\isColEncrypted()) {
|
||||
$stmt = sqlsrv_prepare($conn, "{call $procName( ?, ?, ?)}", array($v1, $v2, array(&$v3, SQLSRV_PARAM_OUT)));
|
||||
$tsql = "{call $procName( ?, ?, ?)}";
|
||||
|
||||
if ($noRef) {
|
||||
$params = array($v1, $v2, array($v3, SQLSRV_PARAM_OUT));
|
||||
} else {
|
||||
$params = array($v1, $v2, array(&$v3, SQLSRV_PARAM_OUT));
|
||||
}
|
||||
|
||||
trace("No reference: $noRef\n");
|
||||
trace("Use prepared stmt: $prepare\n");
|
||||
|
||||
if (AE\isColEncrypted() || $prepare) {
|
||||
$stmt = sqlsrv_prepare($conn, $tsql, $params);
|
||||
if ($stmt) {
|
||||
$res = sqlsrv_execute($stmt);
|
||||
} else {
|
||||
fatalError("executeSP: failed in preparing statement with reference($noRef)");
|
||||
}
|
||||
if ($noRef) {
|
||||
if ($res !== false) {
|
||||
echo "Expect this to fail!\n";
|
||||
}
|
||||
compareErrors();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
$stmt = sqlsrv_query($conn, "{call $procName( ?, ?, ?)}", array($v1, $v2, array(&$v3, SQLSRV_PARAM_OUT)));
|
||||
$stmt = sqlsrv_query($conn, $tsql, $params);
|
||||
if ($noRef) {
|
||||
if ($stmt !== false) {
|
||||
echo "Expect this to fail!\n";
|
||||
}
|
||||
compareErrors();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
trace("No errors: $v3 and $expected\n");
|
||||
// No errors expected
|
||||
if ($stmt === false || !$res) {
|
||||
print_r(sqlsrv_errors(), true);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
--TEST--
|
||||
large types to strings of 1MB size.
|
||||
--DESCRIPTION--
|
||||
This includes a test by providing an invalid php type.
|
||||
--SKIPIF--
|
||||
<?php require('skipif_azure_dw.inc'); ?>
|
||||
--FILE--
|
||||
|
@ -8,7 +10,7 @@ large types to strings of 1MB size.
|
|||
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
|
||||
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
|
||||
|
||||
require( 'MsCommon.inc' );
|
||||
require_once( 'MsCommon.inc' );
|
||||
|
||||
$conn = Connect();
|
||||
if( !$conn ) {
|
||||
|
@ -59,6 +61,16 @@ large types to strings of 1MB size.
|
|||
die( "sqlsrv_get_field(6) failed." );
|
||||
}
|
||||
|
||||
$str = sqlsrv_get_field( $stmt, 0, SQLSRV_PHPTYPE_STRING("UTF") );
|
||||
if ($str === false) {
|
||||
$error = sqlsrv_errors()[0]['message'];
|
||||
if ($error !== 'Invalid type') {
|
||||
fatalError('Unexpected error returned');
|
||||
}
|
||||
} else {
|
||||
echo "Expect sqlsrv_get_field(7) to fail!\n";
|
||||
}
|
||||
|
||||
sqlsrv_free_stmt( $stmt );
|
||||
sqlsrv_close( $conn );
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
--TEST--
|
||||
scrollable result sets.
|
||||
Scrollable result sets with a simple test for an expected error.
|
||||
--SKIPIF--
|
||||
<?php require('skipif_versions_old.inc'); ?>
|
||||
--FILE--
|
||||
|
@ -69,6 +69,13 @@ for ($i = 1; $i <= $numRows; $i++) {
|
|||
}
|
||||
|
||||
$query = "SELECT * FROM $tableName";
|
||||
$options = array('Scrollable' => 'dummy');
|
||||
$stmt = sqlsrv_query($conn, $query, array(), $options);
|
||||
if ($stmt !== false) {
|
||||
fatalError("Expect dummy scrollable to fail!\n");
|
||||
}
|
||||
print_r(sqlsrv_errors());
|
||||
|
||||
$options = array('Scrollable' => SQLSRV_CURSOR_FORWARD);
|
||||
$stmt = sqlsrv_query($conn, $query, array(), $options);
|
||||
|
||||
|
@ -205,4 +212,17 @@ echo "Test succeeded.\n";
|
|||
|
||||
?>
|
||||
--EXPECT--
|
||||
Array
|
||||
(
|
||||
[0] => Array
|
||||
(
|
||||
[0] => IMSSP
|
||||
[SQLSTATE] => IMSSP
|
||||
[1] => -54
|
||||
[code] => -54
|
||||
[2] => The value passed for the 'Scrollable' statement option is invalid. Please use 'static', 'dynamic', 'keyset', 'forward', or 'buffered'.
|
||||
[message] => The value passed for the 'Scrollable' statement option is invalid. Please use 'static', 'dynamic', 'keyset', 'forward', or 'buffered'.
|
||||
)
|
||||
|
||||
)
|
||||
Test succeeded.
|
||||
|
|
Loading…
Reference in a new issue