Skip to content

Unresolvable query not reported in debug mode #504

Closed
@hemberger

Description

@hemberger

I was hoping to use debug mode to find all queries that phpstan-dba fails to resolve, since these will not report any errors in non-debug mode. However, there appears to be a class of queries that silently fail to resolve, which makes it challenging to find and fix the queries.

Here are some examples that I used to explore this behavior:

  • If the query is joined with a mixed type, we are alerted to the failure to resolve the query:

    $query = 'SELECT * FROM table_does_not_exist WHERE col1 = ' . return_mixed();

    Unresolvable Query: Cannot simulate parameter value for type: mixed.

  • If the query is joined with an int type, the query is properly analyzed:

    $query = 'SELECT * FROM table_does_not_exist WHERE col1 = ' . return_int();

    Query error: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'dbname.table_does_not_exist' doesn't exist (42S02).

  • If the query is joined with a string type, the error is silently ignored:

    $query = 'SELECT * FROM table_does_not_exist WHERE col1 = ' . return_string();

    No errors

Obviously, in this particular example, a prepared query would solve the problem, but there are legitimate use cases where we might join a non-literal string to a query string, and in such a case we'd want to get an error when the query cannot be resolved (in debug mode, at least). Is this possible?

Please let me know if further information is needed. I'm also happy to look into this myself if you can point me in the right direction.

Thanks again for this awesome library! I'm really looking forward to using it to help refactor an old codebase that used manual escaping instead of prepared queries.

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