Question

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!

Was it helpful?

Solution

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:

internal string i()
        {
            this.Parse();
            string str = "<?xml version=\"1.0\" ?>";
            string str1 = lzbasetype.PPAddLinebreak(str);
            object[] dbVendorStr = new object[] { lzbasetype.DbVendorStr[(int)this.i] };
            str = string.Concat(str1, SysUtils.Format("<sqlscript dbvendor=\"%s\">", dbVendorStr));
            if (this.ErrorCount <= 0)
            {
                int num = this.SqlStatements.Count() - 1;
                int num1 = 0;
                if (num >= num1)
                {
                    num++;
                    do
                    {
                        str = string.Concat(lzbasetype.PPAddLinebreak(str), this.SqlStatements[num1].AsXmlText);
                        num1++;
                    }
                    while (num1 != num);
                }
                str = string.Concat(lzbasetype.PPAddLinebreak(str), "</sqlscript>");
            }
            else
            {
                str = string.Concat(lzbasetype.PPAddLinebreak(str), "<SyntaxError>");
                str = string.Concat(lzbasetype.PPAddLinebreak(str), this.ErrorMessages);
                str = string.Concat(lzbasetype.PPAddLinebreak(str), "</SyntaxError>");
                str = string.Concat(lzbasetype.PPAddLinebreak(str), "</sqlscript>");
            }
            return str;
        }

variable i is essentially xmlText.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top