Thread: [pgsqlclient-checkins] pgsqlclient_10/PostgreSql.Data.PgSqlClient/source PgCommand.cs,1.28,1.29
Status: Inactive
Brought to you by:
carlosga_fb
From: <car...@us...> - 2004-03-05 23:52:40
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28925 Modified Files: PgCommand.cs Log Message: 2004-03-06 Carlos Guzman Alvarez <car...@te...> * source/PgCommand.cs: - Improved named parameters support. Index: PgCommand.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/PgCommand.cs,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** PgCommand.cs 12 Feb 2004 19:50:41 -0000 1.28 --- PgCommand.cs 5 Mar 2004 23:38:14 -0000 1.29 *************** *** 21,24 **** --- 21,25 ---- using System.Drawing; using System.Collections; + using System.Collections.Specialized; using System.ComponentModel; using System.Text; *************** *** 47,52 **** private int commandTimeout; private bool designTimeVisible; ! private Regex search; ! private MatchCollection namedParameters; private int matchIndex; private Hashtable matchReplaces; --- 48,52 ---- private int commandTimeout; private bool designTimeVisible; ! private StringCollection namedParameters; private int matchIndex; private Hashtable matchReplaces; *************** *** 220,224 **** this.designTimeVisible = true; this.parameters = new PgParameterCollection(); ! this.search = new Regex("(@[a-zA-Z-$][a-zA-Z0-9_$]*)"); GC.SuppressFinalize(this); --- 220,225 ---- this.designTimeVisible = true; this.parameters = new PgParameterCollection(); ! this.namedParameters = new StringCollection(); ! this.matchReplaces = new Hashtable(); GC.SuppressFinalize(this); *************** *** 264,269 **** this.commandText = String.Empty; this.actualCommand = -1; - this.search = null; this.commands = null; } --- 265,275 ---- this.commandText = String.Empty; this.actualCommand = -1; this.commands = null; + + this.matchReplaces.Clear(); + this.matchReplaces = null; + + this.namedParameters.Clear(); + this.namedParameters = null; } *************** *** 455,461 **** commands[actualCommand] = parseSPCommandText(); } - - // Get named parameters in CommandText - namedParameters = search.Matches(commands[actualCommand]); string prepareName = "PS" + getStmtName(); --- 461,464 ---- *************** *** 465,469 **** prepareName, portalName, ! parseParameterNames()); // Parse statement --- 468,472 ---- prepareName, portalName, ! this.parseParameterNames()); // Parse statement *************** *** 534,541 **** } - // Get named parameters in CommandText - this.namedParameters = this.search.Matches( - this.commands[this.actualCommand]); - this.statement = this.connection.DbConnection.DB.CreateStatement( String.Empty, --- 537,540 ---- *************** *** 705,721 **** private string parseParameterNames() { ! string sql = commands[actualCommand]; ! if (namedParameters.Count != 0) { ! matchIndex = 0; ! matchReplaces = new Hashtable(); ! sql = search.Replace( ! sql, ! new MatchEvaluator(matchEvaluator)); ! matchReplaces.Clear(); ! } return sql; --- 704,725 ---- private string parseParameterNames() { ! string sql = this.commands[actualCommand]; ! ! this.namedParameters.Clear(); ! if (sql.IndexOf("@") != -1) { ! this.matchReplaces.Clear(); ! string pattern = @"(('[^']*?\@[^']*')*[^'@]*?)*(?<param>@\w+)*([^'@]*?('[^']*?\@*[^']*'))*"; ! Regex r = new Regex(pattern, RegexOptions.ExplicitCapture); ! ! MatchEvaluator me = new MatchEvaluator(matchEvaluator); ! ! sql = r.Replace(sql, me); ! ! this.matchReplaces.Clear(); ! } return sql; *************** *** 724,744 **** private string matchEvaluator(Match match) { ! if (!this.matchReplaces.ContainsKey(match.Value)) ! { ! if (this.connection.DbConnection.Settings.SimpleQueryMode) { ! this.matchReplaces.Add( ! match.Value, ! this.parameters[matchIndex++].ConvertToPgString()); } else { ! this.matchReplaces.Add( ! match.Value, ! "$" + ((matchIndex++) + 1).ToString()); } } - - return this.matchReplaces[match.Value].ToString(); } --- 728,764 ---- private string matchEvaluator(Match match) { ! string input = match.Value; ! string replace = String.Empty; ! ! if (match.Groups["param"].Success) ! { ! Group g = match.Groups["param"]; ! ! if (!this.matchReplaces.ContainsKey(g.Value)) { ! this.namedParameters.Add(g.Value); ! ! if (this.connection.DbConnection.Settings.SimpleQueryMode) ! { ! replace = this.parameters[matchIndex++].ConvertToPgString(); ! } ! else ! { ! replace = "$" + ((this.matchIndex++) + 1).ToString(); ! } ! ! this.matchReplaces.Add(g.Value, replace); } else { ! replace = this.matchReplaces[g.Value].ToString(); } + + return Regex.Replace(input, g.Value, replace); + } + else + { + return match.Value; } } *************** *** 754,758 **** try { ! parameterName = namedParameters[i].Value.Trim(); } catch --- 774,778 ---- try { ! parameterName = namedParameters[i].Trim(); } catch |