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

cppdb: get original statement and full query for debugging or logging purposes #77

Open
dreaming-augustin opened this issue Nov 13, 2020 · 1 comment

Comments

@dreaming-augustin
Copy link
Collaborator

This is an old request, and I have at last found some time to have a go at it, although the patch I am sharing below is incomplete and hackish at best. But it can help get the conversation started.

Basically, when the MySQL backend throws cppdb_error, we only get the error string reported by MySQL itself. Sometimes, at least for debugging purposes, it would be very convenient to get the full query, with or without the bound values for prepared statements.

As pointed out by Artyom in an earlier discussion, SQL queries can leak sensitive information, so it is understood that a developer would not leak such information to end users. Instead, dedicated calls can be made for debugging and logging purposes, for the use of the developer.

Anyway, I am not very competent, but I still had a go at it. The patch below is only a stub: it introduces new methods to cppdb_error to get the original statement, and the bound parameters. It's at best a work in progress, and parts of it are hackish, but it's enough for debugging purposes, and at least we get something that can be discussed and that can be improved on.

error-show-full-query.patch.txt

Here is a sample usage:

    catch (cppdb::cppdb_error& e) {
            BOOSTER_DEBUG("DEBUG - CppcmsApplication::main") << "cppdb::cppdb_error = "  << e.what();
            BOOSTER_DEBUG("DEBUG - CppcmsApplication::main") << "cppdb::cppdb statement = " << e.get_statement();
            BOOSTER_DEBUG("DEBUG - CppcmsApplication::main") << "cppdb::cppdb query = "  << e.get_query();
   }
@dreaming-augustin
Copy link
Collaborator Author

Updated to include e.get_errno():

error-show-full-query.patch.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant