OracleCompiler incorrectly quotes * inside JSON path string literals

#785 · open · 0 comments

View on GitHub ↗

dsp85103

## OracleCompiler incorrectly quotes `*` inside JSON path literals ### Environment - SqlKata: 4.0.1 - Runtime: .NET 8 - Database: Oracle - Compiler: `SqlKata.Compilers.OracleCompiler` ### Description When using `FromRaw` with an Oracle `JSON_TABLE` expression, the Oracle compiler incorrectly rewrites the `*` character inside a SQL string literal. The JSON path: ```sql '$[*]' ``` is compiled as: ``` '$"*"' ``` This produces the following Oracle error: ```log ORA-40597: JSON path expression syntax error ('$"*"') JZN-00233: invalid character at the start of a step ``` ### Minimal reproduction ```csharp using SqlKata; using SqlKata.Compilers; var query = new Query() .FromRaw(""" ( SELECT PKEY_ORDER.item FROM SOME_TABLE S CROSS JOIN JSON_TABLE( S.SORTED, '$[*]' COLUMNS ( item VARCHAR2(200) PATH '$.PersonKey', casePersonType VARCHAR2(200) PATH '$.Type', ord FOR ORDINALITY ) ) PKEY_ORDER ) BASE_DATA """) .Select("BASE_DATA.item"); var sql = new OracleCompiler().Compile(query).Sql; Console.WriteLine(sql); ``` ### Actual output ```sql SELECT "BASE_DATA"."item" FROM ( SELECT PKEY_ORDER.item FROM SOME_TABLE S CROSS JOIN JSON_TABLE( S.SORTED, '$"*"' COLUMNS ( item VARCHAR2(200) PATH '$.PersonKey', casePersonType VARCHAR2(200) PATH '$.Type', ord FOR ORDINALITY ) ) PKEY_ORDER ) BASE_DATA ``` ### Expected output The string literal should remain unchanged: ```sql '$[*]' ``` Expected compiled SQL: ```sql SELECT "BASE_DATA"."item" FROM ( SELECT PKEY_ORDER.item FROM SOME_TABLE S CROSS JOIN JSON_TABLE( S.SORTED, '$[*]' COLUMNS ( item VARCHAR2(200) PATH '$.PersonKey', casePersonType VARCHAR2(200) PATH '$.Type', ord FOR ORDINALITY ) ) PKEY_ORDER ) BASE_DATA ``` ### Analysis `'$[*]'` is an Oracle JSON path expression. The `*` is inside a single-quoted SQL string literal and should not be treated as an SQL identifier or be passed through identifier quoting. It appears that the Oracle compiler applies identifier quoting to the contents of a raw SQL expression without excluding characters inside string literals. ### Suggested fix When compiling RawFromClause or other raw SQL expressions, string literals should be preserved verbatim. Identifier quoting should not be applied to tokens inside single-quoted literals. A regression test covering the following input would be useful: ```sql JSON_TABLE(S.SORTED, '$[*]' COLUMNS (...)) ``` ### Temporary workaround The application currently replaces the `*` inside SQL string literals with a placeholder before compilation and restores it after compilation.

Comments