sql-formatter-org / sql-formatter-org/sql-formatter
ODBC Date and Time Literals Crash Parser
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 2.9k
- Forks
- 456
- Avg merge
- 3d 4h
- Merged PRs (30d)
- 3
Description
Describe the bug
Try to format a query that uses ODBC date and time literal syntax.
Microsoft - Date, Time, and Timestamp Escape Sequences
MariaDB - Date and Time Literals
Reproduce:
echo "SELECT {ts '2022-10-11 00:00:00'}" | ./node_modules/.bin/sql-formatter
Expected behavior
Correctly format or gracefully handle unexpected syntax instead of crashing
Actual behavior
Exception thrown in JS console:
Error: Parse error: Unexpected "{ts '2022-" at line 1 column 3318
at TokenizerEngine.createParseError (TokenizerEngine.js:53:12)
at TokenizerEngine.tokenize (TokenizerEngine.js:35:22)
at Tokenizer.tokenize (Tokenizer.js:16:47)
at LexerAdapter.tokenize (createParser.js:16:76)
at LexerAdapter.reset (LexerAdapter.js:17:24)
at Parser.feed (nearley.js:281:15)
at Object.parse (createParser.js:26:18)
at TransactSqlFormatter.parse (Formatter.js:60:49)
at TransactSqlFormatter.format (Formatter.js:53:22)
at format (sqlFormatter.js:69:36)
Usage
- How are you calling / using the library? Client side through angular pipe
- What SQL language(s) does this apply to? Any that use ODBC Date and Time literal syntax
- Which SQL Formatter version are you using? 11.0.2
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the ./node_modules/.bin/sql-formatter command, then trace the input through TokenizerEngine.js, Tokenizer.js, createParser.js, and Formatter.js as shown in the stack trace. Determine how ODBC date and time literals should be handled, and consider the issue done when the example is formatted correctly or handled without a parser crash.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- sql, typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100