Fixed tests and added code comments

This commit is contained in:
David Puglielli 2017-09-28 14:16:50 -07:00
parent d56446c41c
commit 3acab1ae0c
4 changed files with 202 additions and 175 deletions

View file

@ -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){

View file

@ -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();
} }

View file

@ -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
) )
) )

View file

@ -145,6 +145,15 @@ Array
[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
(
[0] => HY010
[SQLSTATE] => HY010
[1] => 0
[code] => 0
[2] => [unixODBC][Driver Manager]Function sequence error
[message] => [unixODBC][Driver Manager]Function sequence error
)
) )
Array Array