TZTokenizer fails to detect -- comments

Code patches written by our users to solve certain "problems" that were not solved, yet.

Moderators: gto, cipto_kh, EgonHugeist, mdaems

Post Reply
User avatar
aehimself
Zeos Dev Team
Zeos Dev Team
Posts: 797
Joined: 18.11.2018, 17:37
Location: Hungary

TZTokenizer fails to detect -- comments

Post by aehimself »

Hello,

In my application I needed to distinguish if a query returns a resultset or not so I wrote a string parser to look for the first valid keyword of a text. For a while I migrated this logic to use TZTokenizer instead and now I found out that the following query:

Code: Select all

-- This is a comment
SELECT * FROM MyTabe
is actually considered one WITHOUT a resultset, as TZTokenizer finds "This" as the first word token.

Code: Select all

/* This is a comment */
SELECT * FROM MyTable
works fine. Which is actually a bug as "-" is declared as a possible comment token, see ZGenericSQLToken.pas : 531 (TZGenericSQLTokenizer.CreateTokenStates):

Code: Select all

  SetCharacterState('-', '-', CommentState);
I sent a pull request on GitHub with the possible fix, however I'm unsure if this is the correct way to do this. Take it with a grain of salt, please :)
Delphi 12.2, Zeos 8 from latest GIT snapshot
Using:
- MySQL server 8.0.18; libmysql.dll 8.0.40 x64 5.7.19 x68, libmariadb.dll 3.3.11
- Oracle server 11.2.0, 12.1.0, 19.0.0; oci.dll 21.15
- MSSQL 2012, 2019; sybdb.dll FreeTDS_3102
- SQLite 3.47
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1956
Joined: 17.01.2011, 14:17

Re: TZTokenizer fails to detect -- comments

Post by marsupilami »

Hello aehimself,

I finally got around to applying your patch. Currently I am waiting for the results of the test suite.

Best regards,

Jan
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1956
Joined: 17.01.2011, 14:17

Re: TZTokenizer fails to detect -- comments

Post by marsupilami »

Your patch triggers two test that fail now:
Jenkins wrote: basic.core.TZTestTokenizer.TZTestTokenizer.TestNumber
basic.parsesql.TZTestGenericStatementAnalyser.TZTestGenericStatementAnalyser.TestSelectParser
Do you have a chance to look into this?
User avatar
aehimself
Zeos Dev Team
Zeos Dev Team
Posts: 797
Joined: 18.11.2018, 17:37
Location: Hungary

Re: TZTokenizer fails to detect -- comments

Post by aehimself »

Jan,

Done, second commit is in the same pull request.
Unfortunately I was unable to execute any tests in the suite (option was greyed out) but I replicated the failing tests in an application and they executed correctly.

Thanks!
Delphi 12.2, Zeos 8 from latest GIT snapshot
Using:
- MySQL server 8.0.18; libmysql.dll 8.0.40 x64 5.7.19 x68, libmariadb.dll 3.3.11
- Oracle server 11.2.0, 12.1.0, 19.0.0; oci.dll 21.15
- MSSQL 2012, 2019; sybdb.dll FreeTDS_3102
- SQLite 3.47
Post Reply