This parse method seems ok, I have run all of the client unit tests with it and some of my own. p.s. DNET-217 patch caused unit test errors in Version10\GdsStatement, I used the prior version to run the tests.
This method runs faster than the current one, it does not strip anything except "@PARAMETER" text to "?" and there are not alot of booleans. If you think this is ok, I will add a patch to DNET-176. public string ParseNamedParameters(string sql) { // Clear old parameters. this.namedParameters.Clear(); // We do not need to parse if there are no parameters. if (sql.IndexOf('@') == -1) { return sql; } int index; int end = sql.Length - 1; StringBuilder resultBuilder = new StringBuilder(sql.Length); for (int i = 0, j = sql.Length; i < j; i++) { switch (sql[i]) { // Read a named parameter. case '@': for (index = i + 1; index < j && (Char.IsLetterOrDigit(sql[index]) || sql[index] == '_' || sql[index] == '$'); index++); resultBuilder.Append('?'); this.namedParameters.Add(sql.Substring(i, index - i)); i = index - 1; continue; // Read quoted text. case '\'': case '"': for (index = i + 1; index < j && sql[index] != sql[i]; index++); resultBuilder.Append(sql.Substring(i, index + 1 - i)); i = index; continue; // Read a single line comment. case '-': if ((i < end) && (sql[i + 1] == '-')) { for (index = i + 1; index < j && (sql[index] != '\r' && sql[index] != '\n'); index++); resultBuilder.Append(sql.Substring(i, index - i)); i = index - 1; continue; } resultBuilder.Append('-'); continue; // Read a block comment. case '/': if ((i < end) && (sql[i + 1] == '*')) { while (i < j) { resultBuilder.Append(sql[i]); if (sql[i] == '*' && i < end && sql[i + 1] == '/') { break; } i++; } continue; } resultBuilder.Append('/'); continue; // Read content. default: resultBuilder.Append(sql[i]); continue; } } return resultBuilder.ToString(); } On Thu, Feb 26, 2009 at 10:48 AM, Jiri Cincura <disk...@cincura.net> wrote: > On Wed, Feb 25, 2009 at 23:10, Gareth <gareth.gosl...@gmail.com> wrote: >> It removes single line comments "-- " and block comments "/* */". > > You shouldn't remove anything from command text. Maybe somebody is > logging it etc. > >> It replaces tabs, newlines, carriage returns and multiple spaces with >> a single space. > > Same as above. You need to keep the query as developer created it. > >> It also extracts the parameter names. >> >> Has anyone got any comments ? > > -- > Jiri {x2} Cincura (CTO x2develop.com) > http://blog.vyvojar.cz/jirka/ | http://www.ID3renamer.com > > ------------------------------------------------------------------------------ > Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA > -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise > -Strategies to boost innovation and cut costs with open source participation > -Receive a $600 discount off the registration fee with the source code: SFAD > http://p.sf.net/sfu/XcvMzF8H > _______________________________________________ > Firebird-net-provider mailing list > Firebird-net-provider@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/firebird-net-provider > -- Gareth ------------------------------------------------------------------------------ Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise -Strategies to boost innovation and cut costs with open source participation -Receive a $600 discount off the registration fee with the source code: SFAD http://p.sf.net/sfu/XcvMzF8H _______________________________________________ Firebird-net-provider mailing list Firebird-net-provider@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/firebird-net-provider