I'm using a sqlparser(c#) provided by gudusoft (sqlparser.com), not sure anyone have used it before.
The sqlparser provides a parser object to which you can input a sql string. Then by calling the parse() method, you can get all the tokens, labels and etc. The parser was nicely built.
Here is how I used it, very straight forward:
line 1: TGSqlParser parser = new TGSqlParser(TDbVendor.DbVMssql); // init the parser object
line 2: parser.SqlText.Text = code; // set input sql code, for e.g. "SELECT * FROM table_sales"
line 3: int parser_ret = parser.Parse(); // call parse method
line 4: string output = parser.XmlText; // retrieve the xml generated by line 3. The xmlText could be 500,000-character long.
Line 1-3 works very efficiently (Done in less a second). However, line 4 is very slow (could take a minute or more). The confusing thing is that, by using debugger, I figured that parser.XmlText is already generated and ready for access at line 3. Line 4 is merely for accessing that value.
How come that accessing a value is much slower than actually generating it?
I'm a newbie to c#, not sure whether it's more likely to be the problem of this specific parser or it's a general problem of c#.
Thanks!
Nevermind, I found out the reason. It's the problem of this specific parser.
xmlText is not ready at Line 3. It has to be generated when being accessed. I used a decompiler and found:
variable i is essentially xmlText.