sqlparser icon indicating copy to clipboard operation
sqlparser copied to clipboard

Empty statements treated as parse errors

Open dt opened this issue 8 years ago • 0 comments

Discovered while looking at mysqldump's default output, which contains a couple things that currently cause syntax errors.

A mysqldump file consists of SQL statements that create tables and insert rows into them. However at the beginning of the file several comments are added -- some human readable, others with optional settings in them -- but what is important is that some of them are separated by semicolons, resulting in, after the comments are removed, effectively empty statements. For example:

/* some comment*/;
/* another comment */;
CREATE TABLE ...

Note: Lex usually discards comments until it finds a token to return but in the above case that is nil since it is an empty statement.

Currently the parser does not handle empty statements -- obviously when parsing individual statements this could be relatively easily handled by the caller, but when tokenizing and parsing a stream with ParseNext, this case is harder to handle in the caller.

dt avatar May 21 '18 13:05 dt