in source/sqlsrv/util.cpp [851:928]
bool handle_errors_and_warnings( _Inout_ sqlsrv_context& ctx, _Inout_ zval* reported_chain, _Inout_ zval* ignored_chain, _In_ logging_severity log_severity,
_In_ unsigned int sqlsrv_error_code, _In_ int warning, _In_opt_ va_list* print_args )
{
bool result = true;
bool errors_ignored = false;
size_t prev_reported_cnt = 0;
bool reported_chain_was_null = false;
bool ignored_chain_was_null = false;
zval error_z;
ZVAL_UNDEF(&error_z);
sqlsrv_error_auto_ptr error;
// array of reported errors
if( Z_TYPE_P( reported_chain ) == IS_NULL ) {
reported_chain_was_null = true;
array_init(reported_chain);
}
else {
prev_reported_cnt = zend_hash_num_elements( Z_ARRVAL_P( reported_chain ));
}
// array of ignored errors
if( ignored_chain != NULL ) {
if( Z_TYPE_P( ignored_chain ) == IS_NULL ) {
ignored_chain_was_null = true;
array_init( ignored_chain );
}
}
if( sqlsrv_error_code != SQLSRV_ERROR_ODBC ) {
core_sqlsrv_format_driver_error( ctx, get_error_message( sqlsrv_error_code ), error, log_severity, print_args );
copy_error_to_zval( &error_z, error, reported_chain, ignored_chain, warning );
}
SQLSMALLINT record_number = 0;
do {
result = core_sqlsrv_get_odbc_error( ctx, ++record_number, error, log_severity );
if( result ) {
copy_error_to_zval( &error_z, error, reported_chain, ignored_chain, warning );
}
} while( result );
// If it were a warning, we report that warnings where ignored except if warnings_return_as_errors
// was true and we added some warnings to the reported_chain.
if( warning ) {
errors_ignored = true;
if( SQLSRV_G( warnings_return_as_errors ) ) {
if( zend_hash_num_elements( Z_ARRVAL_P( reported_chain )) > prev_reported_cnt ) {
// We actually added some errors
errors_ignored = false;
}
}
}
// if the error array came in as NULL and didn't have anything added to it, return it as NULL
if( reported_chain_was_null && zend_hash_num_elements( Z_ARRVAL_P( reported_chain )) == 0 ) {
zend_hash_destroy( Z_ARRVAL_P( reported_chain ));
FREE_HASHTABLE( Z_ARRVAL_P( reported_chain ));
ZVAL_NULL( reported_chain );
}
if( ignored_chain != NULL && ignored_chain_was_null && zend_hash_num_elements( Z_ARRVAL_P( ignored_chain )) == 0 ) {
zend_hash_destroy( Z_ARRVAL_P( ignored_chain ));
FREE_HASHTABLE( Z_ARRVAL_P( ignored_chain ));
ZVAL_NULL( ignored_chain );
}
// If it was an error instead of a warning than we always return errors_ignored = false.
return errors_ignored;
}