Skip to content

SQL-chunking algorithm may treat invalid SQL as a comment #14

@koyae

Description

@koyae

At least on my own system, the following passes with exit-code 0:

SELECT '
-- this is not really a comment' AS c;
SELECT '
-- neither is this' AS c spam;

Despite the fact the above statements should actually fail with something like:

psql:shouldfail3.sql:4: ERROR:  syntax error at or near "spam"
LINE 2: -- neither is this' AS c spam;

No error is emitted because the statement is incorrectly prepared as:

EXEC SQL SELECT '
-- this is not really a comment' AS c;
SELECT '
-- neither is this' AS c spam;

I presume that ECPG just ignores everything after the first semicolon above, and therefore the invalid SQL in this example is simply not encountered.

I discovered this when I was trying to understand how the chunking algorithm did its thing, having wanted to grok it before trying to implement the ability to step over psql-commands.

More realistic instances similar to the above scenario likely exist under use of $$.

Short of fully integrating a tokenizer to get around this, I could probably just up the rock-paper-scissors game that's already going on in prepare_sql() with the if not in_block_comment business. Doing so should allow psql-stuff to be handled more readily.

What's your take?

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