TylerBrinks / SqlParser-cs

A Friendly SQL Parser for .NET
MIT License
109 stars 20 forks source link

SQLite parsing fails with "ON CONFLICT REPLACE" clause for UNIQUE constraint #35

Open OddQuesadilla opened 2 months ago

OddQuesadilla commented 2 months ago

When trying to parse a SQLite CREATE TABLE statement an exception is thrown when running the following code

new Parser().ParseSql("CREATE TABLE test(column1, UNIQUE(column1) ON CONFLICT REPLACE)", new SQLiteDialect());

And here is the exception thrown:

SqlParser.ParserException: Expected ',' or ')' after column definition, found ON, Line: 1, Col: 44
   at SqlParser.Parser.ThrowExpected(String expected, Token actual)
   at SqlParser.Parser.ParseColumns()
   at SqlParser.Parser.ParseCreateTable(Boolean orReplace, Boolean temporary, Nullable`1 global, Boolean transient)
   at SqlParser.Parser.ParseCreate()
   at SqlParser.Parser.ParseKeywordStatement(Word word)
   at SqlParser.Parser.ParseStatement()
   at SqlParser.Parser.ParseStatements()
   at SqlParser.Parser.ParseSql(ReadOnlySpan`1 sql, Dialect dialect, ParserOptions options)

It seems to me that the issue would be in the ParseConstraintCharacteristics method, but I am not familiar enough with the parser code to be sure.