Fixed tests and added code comments
This commit is contained in:
parent
d56446c41c
commit
3acab1ae0c
|
@ -1067,17 +1067,22 @@ int pdo_sqlsrv_stmt_next_rowset( _Inout_ pdo_stmt_t *stmt TSRMLS_DC )
|
||||||
|
|
||||||
SQLSRV_ASSERT( driver_stmt != NULL, "pdo_sqlsrv_stmt_next_rowset: driver_data object was null" );
|
SQLSRV_ASSERT( driver_stmt != NULL, "pdo_sqlsrv_stmt_next_rowset: driver_data object was null" );
|
||||||
|
|
||||||
// Make sure that we haven't gone past the end of the result set, then make sure that
|
// Return the correct error in case the user calls nextRowset() on a null result set.
|
||||||
// the result set is not null. Null means SQLNumResultCols returns 0 and SQLRowCount
|
// Null means that SQLNumResultCols() returns 0 and SQLRowCount is not return > 0. But first
|
||||||
// is not > 0. Normally the latter error is handled in core_sqlsrv_fetch(), but if the
|
// check that the statement has been executed and that we are not past the end of a non-null
|
||||||
// user calls nextRowset() before fetch() the error is never shown so we handle it here.
|
// result set to make sure the user gets the correct error message. These checks are also
|
||||||
// In that case, however, core_sqlsrv_has_any_result would return false if we are at
|
// done in core_sqlsrv_next_result(), but we cannot check for null results there because that
|
||||||
// the end of a non-null result set, so we check for that error first to make sure the
|
// function can be called without calling this one, and SQLSRV_ERROR_NO_FIELDS can then
|
||||||
// user gets the correct error message.
|
// be triggered incorrectly.
|
||||||
|
CHECK_CUSTOM_ERROR( !driver_stmt->executed, driver_stmt, SQLSRV_ERROR_STATEMENT_NOT_EXECUTED ) {
|
||||||
|
throw core::CoreException();
|
||||||
|
}
|
||||||
|
|
||||||
CHECK_CUSTOM_ERROR( driver_stmt->past_next_result_end, driver_stmt, SQLSRV_ERROR_NEXT_RESULT_PAST_END ) {
|
CHECK_CUSTOM_ERROR( driver_stmt->past_next_result_end, driver_stmt, SQLSRV_ERROR_NEXT_RESULT_PAST_END ) {
|
||||||
throw core::CoreException();
|
throw core::CoreException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Now make sure the result set is not null.
|
||||||
bool has_result = core_sqlsrv_has_any_result( driver_stmt );
|
bool has_result = core_sqlsrv_has_any_result( driver_stmt );
|
||||||
|
|
||||||
if(!driver_stmt->fetch_called){
|
if(!driver_stmt->fetch_called){
|
||||||
|
|
|
@ -561,13 +561,17 @@ PHP_FUNCTION( sqlsrv_next_result )
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// Make sure that we haven't gone past the end of the result set, then make sure that
|
// Return the correct error in case the user calls sqlsrv_next_result() on a null result set.
|
||||||
// the result set is not null. Null means SQLNumResultCols returns 0 and SQLRowCount
|
// Null means that SQLNumResultCols() returns 0 and SQLRowCount is not return > 0. But first
|
||||||
// is not > 0. Normally the latter error is handled in core_sqlsrv_fetch(), but if the
|
// check that the statement has been executed and that we are not past the end of a non-null
|
||||||
// user calls sqlsrv_next_result() before fetch() the error is never shown so we handle it here.
|
// result set to make sure the user gets the correct error message. These checks are also
|
||||||
// In that case, however, core_sqlsrv_has_any_result would return false if we are at
|
// done in core_sqlsrv_next_result(), but we cannot check for null results there because that
|
||||||
// the end of a non-null result set, so we check for that error first to make sure the
|
// function can be called without calling this one, and SQLSRV_ERROR_NO_FIELDS can then
|
||||||
// user gets the correct error message.
|
// be triggered incorrectly.
|
||||||
|
CHECK_CUSTOM_ERROR( !stmt->executed, stmt, SQLSRV_ERROR_STATEMENT_NOT_EXECUTED ) {
|
||||||
|
throw core::CoreException();
|
||||||
|
}
|
||||||
|
|
||||||
CHECK_CUSTOM_ERROR( stmt->past_next_result_end, stmt, SQLSRV_ERROR_NEXT_RESULT_PAST_END ) {
|
CHECK_CUSTOM_ERROR( stmt->past_next_result_end, stmt, SQLSRV_ERROR_NEXT_RESULT_PAST_END ) {
|
||||||
throw core::CoreException();
|
throw core::CoreException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,13 +68,22 @@ Array
|
||||||
Array
|
Array
|
||||||
(
|
(
|
||||||
[0] => Array
|
[0] => Array
|
||||||
|
(
|
||||||
|
[0] => IMSSP
|
||||||
|
[SQLSTATE] => IMSSP
|
||||||
|
[1] => -26
|
||||||
|
[code] => -26
|
||||||
|
[2] => There are no more results returned by the query.
|
||||||
|
[message] => There are no more results returned by the query.
|
||||||
|
)
|
||||||
|
[1] => Array
|
||||||
(
|
(
|
||||||
[0] => HY010
|
[0] => HY010
|
||||||
[SQLSTATE] => HY010
|
[SQLSTATE] => HY010
|
||||||
[1] => 0
|
[1] => 0
|
||||||
[code] => 0
|
[code] => 0
|
||||||
[2] => [unixODBC][Driver Manager]Function sequence error
|
[2] => [Microsoft][ODBC Driver Manager] Function sequence error
|
||||||
[message] => [unixODBC][Driver Manager]Function sequence error
|
[message] => [Microsoft][ODBC Driver Manager] Function sequence error
|
||||||
)
|
)
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,159 +1,168 @@
|
||||||
--TEST--
|
--TEST--
|
||||||
warnings as errors
|
warnings as errors
|
||||||
--SKIPIF--
|
--SKIPIF--
|
||||||
<?php require('skipif.inc'); ?>
|
<?php require('skipif.inc'); ?>
|
||||||
--FILE--
|
--FILE--
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
|
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
|
||||||
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
|
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
|
||||||
|
|
||||||
require( 'MsCommon.inc' );
|
require( 'MsCommon.inc' );
|
||||||
|
|
||||||
$conn = Connect();
|
$conn = Connect();
|
||||||
if( $conn === false ) {
|
if( $conn === false ) {
|
||||||
die( print_r( sqlsrv_errors(), true ));
|
die( print_r( sqlsrv_errors(), true ));
|
||||||
}
|
}
|
||||||
|
|
||||||
$stmt = sqlsrv_prepare( $conn, "SELECT * FROM [cd_info]");
|
$stmt = sqlsrv_prepare( $conn, "SELECT * FROM [cd_info]");
|
||||||
|
|
||||||
$result = sqlsrv_field_metadata( $stmt );
|
$result = sqlsrv_field_metadata( $stmt );
|
||||||
if( $result === false ) {
|
if( $result === false ) {
|
||||||
die( "sqlsrv_field_metadata should have succeeded." );
|
die( "sqlsrv_field_metadata should have succeeded." );
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = sqlsrv_fetch( $stmt );
|
$result = sqlsrv_fetch( $stmt );
|
||||||
if( $result !== false ) {
|
if( $result !== false ) {
|
||||||
die( "sqlsrv_fetch should have failed because it wasn't yet executed." );
|
die( "sqlsrv_fetch should have failed because it wasn't yet executed." );
|
||||||
}
|
}
|
||||||
print_r( sqlsrv_errors() );
|
print_r( sqlsrv_errors() );
|
||||||
|
|
||||||
$result = sqlsrv_fetch_array( $stmt );
|
$result = sqlsrv_fetch_array( $stmt );
|
||||||
if( $result !== false ) {
|
if( $result !== false ) {
|
||||||
die( "sqlsrv_fetch_array should have failed because it wasn't yet executed." );
|
die( "sqlsrv_fetch_array should have failed because it wasn't yet executed." );
|
||||||
}
|
}
|
||||||
print_r( sqlsrv_errors() );
|
print_r( sqlsrv_errors() );
|
||||||
|
|
||||||
$result = sqlsrv_get_field( $stmt, 0 );
|
$result = sqlsrv_get_field( $stmt, 0 );
|
||||||
if( $result !== false ) {
|
if( $result !== false ) {
|
||||||
die( "sqlsrv_get_field should have failed because it wasn't yet executed." );
|
die( "sqlsrv_get_field should have failed because it wasn't yet executed." );
|
||||||
}
|
}
|
||||||
print_r( sqlsrv_errors() );
|
print_r( sqlsrv_errors() );
|
||||||
|
|
||||||
$result = sqlsrv_next_result( $stmt );
|
$result = sqlsrv_next_result( $stmt );
|
||||||
if( $result !== false ) {
|
if( $result !== false ) {
|
||||||
die( "sqlsrv_next_result should have failed because it wasn't yet executed." );
|
die( "sqlsrv_next_result should have failed because it wasn't yet executed." );
|
||||||
}
|
}
|
||||||
print_r( sqlsrv_errors() );
|
print_r( sqlsrv_errors() );
|
||||||
|
|
||||||
$result = sqlsrv_rows_affected( $stmt );
|
$result = sqlsrv_rows_affected( $stmt );
|
||||||
if( $result !== false ) {
|
if( $result !== false ) {
|
||||||
die( "sqlsrv_rows_affected should have failed because it wasn't yet executed." );
|
die( "sqlsrv_rows_affected should have failed because it wasn't yet executed." );
|
||||||
}
|
}
|
||||||
// Outputting the zero element of the error array works around a bug in the
|
// Outputting the zero element of the error array works around a bug in the
|
||||||
// ODBC driver for Linux that produces an error message saying 'Cancel treated
|
// ODBC driver for Linux that produces an error message saying 'Cancel treated
|
||||||
// as FreeStmt/Close' on a statement that has not been executed.
|
// as FreeStmt/Close' on a statement that has not been executed.
|
||||||
print_r( sqlsrv_errors()[0] );
|
print_r( sqlsrv_errors()[0] );
|
||||||
|
|
||||||
sqlsrv_execute( $stmt );
|
sqlsrv_execute( $stmt );
|
||||||
|
|
||||||
$result = sqlsrv_field_metadata( $stmt );
|
$result = sqlsrv_field_metadata( $stmt );
|
||||||
if( $result === false ) {
|
if( $result === false ) {
|
||||||
die( print_r( sqlsrv_errors(), true ));
|
die( print_r( sqlsrv_errors(), true ));
|
||||||
}
|
}
|
||||||
print_r( sqlsrv_errors() );
|
print_r( sqlsrv_errors() );
|
||||||
|
|
||||||
$result = sqlsrv_rows_affected( $stmt );
|
$result = sqlsrv_rows_affected( $stmt );
|
||||||
if( $result === false ) {
|
if( $result === false ) {
|
||||||
die( print_r( sqlsrv_errors(), true ));
|
die( print_r( sqlsrv_errors(), true ));
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = sqlsrv_fetch_array( $stmt );
|
$result = sqlsrv_fetch_array( $stmt );
|
||||||
if( $result === false ) {
|
if( $result === false ) {
|
||||||
die( print_r( sqlsrv_errors(), true ));
|
die( print_r( sqlsrv_errors(), true ));
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = sqlsrv_fetch( $stmt );
|
$result = sqlsrv_fetch( $stmt );
|
||||||
if( $result === false ) {
|
if( $result === false ) {
|
||||||
die( print_r( sqlsrv_errors(), true ));
|
die( print_r( sqlsrv_errors(), true ));
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = sqlsrv_get_field( $stmt, 0 );
|
$result = sqlsrv_get_field( $stmt, 0 );
|
||||||
if( $result === false ) {
|
if( $result === false ) {
|
||||||
die( print_r( sqlsrv_errors(), true ));
|
die( print_r( sqlsrv_errors(), true ));
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = sqlsrv_next_result( $stmt );
|
$result = sqlsrv_next_result( $stmt );
|
||||||
if( $result === false ) {
|
if( $result === false ) {
|
||||||
die( print_r( sqlsrv_errors(), true ));
|
die( print_r( sqlsrv_errors(), true ));
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlsrv_free_stmt( $stmt );
|
sqlsrv_free_stmt( $stmt );
|
||||||
|
|
||||||
sqlsrv_close( $conn );
|
sqlsrv_close( $conn );
|
||||||
|
|
||||||
print "Test successful";
|
print "Test successful";
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
Array
|
Array
|
||||||
(
|
(
|
||||||
[0] => Array
|
[0] => Array
|
||||||
(
|
(
|
||||||
[0] => IMSSP
|
[0] => IMSSP
|
||||||
[SQLSTATE] => IMSSP
|
[SQLSTATE] => IMSSP
|
||||||
[1] => -11
|
[1] => -11
|
||||||
[code] => -11
|
[code] => -11
|
||||||
[2] => The statement must be executed before results can be retrieved.
|
[2] => The statement must be executed before results can be retrieved.
|
||||||
[message] => The statement must be executed before results can be retrieved.
|
[message] => The statement must be executed before results can be retrieved.
|
||||||
)
|
)
|
||||||
|
|
||||||
)
|
)
|
||||||
Array
|
Array
|
||||||
(
|
(
|
||||||
[0] => Array
|
[0] => Array
|
||||||
(
|
(
|
||||||
[0] => IMSSP
|
[0] => IMSSP
|
||||||
[SQLSTATE] => IMSSP
|
[SQLSTATE] => IMSSP
|
||||||
[1] => -11
|
[1] => -11
|
||||||
[code] => -11
|
[code] => -11
|
||||||
[2] => The statement must be executed before results can be retrieved.
|
[2] => The statement must be executed before results can be retrieved.
|
||||||
[message] => The statement must be executed before results can be retrieved.
|
[message] => The statement must be executed before results can be retrieved.
|
||||||
)
|
)
|
||||||
|
|
||||||
)
|
)
|
||||||
Array
|
Array
|
||||||
(
|
(
|
||||||
[0] => Array
|
[0] => Array
|
||||||
(
|
(
|
||||||
[0] => IMSSP
|
[0] => IMSSP
|
||||||
[SQLSTATE] => IMSSP
|
[SQLSTATE] => IMSSP
|
||||||
[1] => -11
|
[1] => -11
|
||||||
[code] => -11
|
[code] => -11
|
||||||
[2] => The statement must be executed before results can be retrieved.
|
[2] => The statement must be executed before results can be retrieved.
|
||||||
[message] => The statement must be executed before results can be retrieved.
|
[message] => The statement must be executed before results can be retrieved.
|
||||||
)
|
)
|
||||||
|
|
||||||
)
|
)
|
||||||
Array
|
Array
|
||||||
(
|
(
|
||||||
[0] => Array
|
[0] => Array
|
||||||
(
|
(
|
||||||
[0] => IMSSP
|
[0] => IMSSP
|
||||||
[SQLSTATE] => IMSSP
|
[SQLSTATE] => IMSSP
|
||||||
[1] => -11
|
[1] => -11
|
||||||
[code] => -11
|
[code] => -11
|
||||||
[2] => The statement must be executed before results can be retrieved.
|
[2] => The statement must be executed before results can be retrieved.
|
||||||
[message] => The statement must be executed before results can be retrieved.
|
[message] => The statement must be executed before results can be retrieved.
|
||||||
)
|
)
|
||||||
|
[1] => Array
|
||||||
)
|
(
|
||||||
Array
|
[0] => HY010
|
||||||
(
|
[SQLSTATE] => HY010
|
||||||
[0] => IMSSP
|
[1] => 0
|
||||||
[SQLSTATE] => IMSSP
|
[code] => 0
|
||||||
[1] => -11
|
[2] => [unixODBC][Driver Manager]Function sequence error
|
||||||
[code] => -11
|
[message] => [unixODBC][Driver Manager]Function sequence error
|
||||||
[2] => The statement must be executed before results can be retrieved.
|
)
|
||||||
[message] => The statement must be executed before results can be retrieved.
|
|
||||||
)
|
)
|
||||||
Test successful
|
Array
|
||||||
|
(
|
||||||
|
[0] => IMSSP
|
||||||
|
[SQLSTATE] => IMSSP
|
||||||
|
[1] => -11
|
||||||
|
[code] => -11
|
||||||
|
[2] => The statement must be executed before results can be retrieved.
|
||||||
|
[message] => The statement must be executed before results can be retrieved.
|
||||||
|
)
|
||||||
|
Test successful
|
||||||
|
|
Loading…
Reference in a new issue