Skip to content

Commit

Permalink
Refactor format_or_get_all_errors function (#1467)
Browse files Browse the repository at this point in the history
  • Loading branch information
absci authored Aug 9, 2023
1 parent 79d4b38 commit abe4471
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions source/pdo_sqlsrv/pdo_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,23 +679,18 @@ void format_or_get_all_errors(_Inout_ sqlsrv_context& ctx, _In_opt_ unsigned int
strcpy_s(error_code, sizeof(pdo_error_type), reinterpret_cast<const char*>(error->sqlstate));
}
else {
bool result = core_sqlsrv_get_odbc_error(ctx, 1, error, SEV_ERROR, true);
if (result) {
// Check if there exist more errors
int rec_number = 2;
if(core_sqlsrv_get_odbc_error(ctx, 1, error, SEV_ERROR, true)) {
unsigned int rec_number = 2;
sqlsrv_error_auto_ptr err;
sqlsrv_error *p = error;

do {
result = core_sqlsrv_get_odbc_error(ctx, rec_number++, err, SEV_ERROR, true);
if (result) {
p->next = err.get();
err.transferred();
p = p->next;
}
} while (result);
while(core_sqlsrv_get_odbc_error(ctx, rec_number++, err, SEV_ERROR, true)) {
p->next = err.get();
err.transferred();
p = p->next;
}
}

// core_sqlsrv_get_odbc_error() returns the error_code of size SQL_SQLSTATE_BUFSIZE,
// which is the same size as pdo_error_type
strcpy_s(error_code, sizeof(pdo_error_type), reinterpret_cast<const char*>(error->sqlstate));
Expand Down

0 comments on commit abe4471

Please sign in to comment.