Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collect all diagnostics available from SQLGetDiagRec as nested exceptions #315

Open
mloskot opened this issue Apr 22, 2022 · 1 comment
Open
Labels
category/enhancement good-first-issue Opportunity for new contributors to help us status/help-wanted Looking for help or expertise on a subject

Comments

@mloskot
Copy link
Member

mloskot commented Apr 22, 2022

The recent_error calls SQLGetDiagRec in a loop already:

nanodbc/nanodbc/nanodbc.cpp

Lines 391 to 394 in 9b9e819

do
{
NANODBC_CALL_RC(
NANODBC_FUNC(SQLGetDiagRec),

} while (rc != SQL_NO_DATA);

because there sometimes is a list of available diagnostics, but it currently captures the last one only.

A desired enhancement is to collect all available diagnostics as perhaps nested or linked exceptions.
For example, faciliated database_error with std::nested_exception.

References

@mloskot mloskot added category/enhancement status/help-wanted Looking for help or expertise on a subject good-first-issue Opportunity for new contributors to help us labels Apr 22, 2022
@thebyohazard
Copy link

As mentioned in #361, I also wish to see all diagnostics. I am using MSSQL Server 2008 + Ubuntu Focal + unixodbc + MSSQL ODBC driver 17 for Linux + nanodbc. There is a section of code at the end of recent_error as follows:

// NOTE: unixODBC using PostgreSQL and SQLite drivers crash if you call SQLGetDiagRec()
// more than once. So as a (terrible but the best possible) workaround just exit
// this loop early on non-Windows systems.
#ifndef _MSC_VER
        break;
#endif

When I commented that out, I see all of the print statements from my stored procedure as desired because it appends them all together. For my purposes, this is sufficient and I don't need it in a nested exception.

So maybe there needs to be a more elaborate check as to what type of driver is being used if that is possible rather than just removing other diagnostics for all non-windows systems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category/enhancement good-first-issue Opportunity for new contributors to help us status/help-wanted Looking for help or expertise on a subject
Projects
None yet
Development

No branches or pull requests

2 participants