FirebirdSQL / NETProvider

Firebird ADO.NET Data Provider
https://www.firebirdsql.org/en/net-provider/
Other
152 stars 62 forks source link

Calling FbScript.Parse throws exception when script contains trailing comment #1136

Closed WarrenQuill closed 9 months ago

WarrenQuill commented 9 months ago

An exception is thrown in the Parse method of FbScript when the source script contains a trailing comment.

Exception:

System.ArgumentException: 'The type of the SQL statement could not be determined.
Statement: 

-- This is a trailing comment

Code:

var contents = System.IO.File.ReadAllText("test_table.ddl");

FbScript script;
script = new FbScript(contents);

script.Parse();

Source script:

SET SQL DIALECT 3;

CREATE TABLE TEST_TABLE (
    ID       INTEGER NOT NULL,
    NAME     VARCHAR(50)
);

ALTER TABLE TEST_TABLE ADD CONSTRAINT PK_TEST_TABLE PRIMARY KEY (ID);

-- This is a trailing comment

Removing the comment does not result in an exception. Behaviour changed between 4.8.1.1. & 4.9.0-beta, and remains the case in 9.2.0-beta.

cincuranet commented 9 months ago

That's expected. It is really an unknown statement, because it's a comment. You can handle it via this event and continue executing. Also you're welcome to add support for comments into the parser (but it's not a one afternoon project).