Skip to content

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

@dreaming-augustin

Description

@dreaming-augustin

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions