[pgsqlclient-checkins] pgsqlclient_10/PostgreSql.Data.PgSqlClient/source PgCommand.cs,1.16,1.17
Status: Inactive
Brought to you by:
carlosga_fb
From: <car...@us...> - 2003-11-21 21:55:57
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source In directory sc8-pr-cvs1:/tmp/cvs-serv24163 Modified Files: PgCommand.cs Log Message: * source/PgCommand.cs: - Added change for try to make a correct replace of named parameters. Index: PgCommand.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/PgCommand.cs,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** PgCommand.cs 21 Nov 2003 18:04:19 -0000 1.16 --- PgCommand.cs 21 Nov 2003 21:55:54 -0000 1.17 *************** *** 49,52 **** --- 49,54 ---- private Regex search; private MatchCollection namedParameters; + private int matchIndex; + private Hashtable matchReplaces; private PgStatement statement; *************** *** 219,223 **** this.designTimeVisible = true; this.parameters = new PgParameterCollection(); ! this.search = new Regex("(@([a-zA-Z-$][a-zA-Z0-9_$]*))"); GC.SuppressFinalize(this); --- 221,225 ---- this.designTimeVisible = true; this.parameters = new PgParameterCollection(); ! this.search = new Regex("(@[a-zA-Z-$][a-zA-Z0-9_$]*)"); GC.SuppressFinalize(this); *************** *** 623,633 **** if (namedParameters.Count != 0) { ! for (int i = 0; i < namedParameters.Count; i++) ! { ! sql = search.Replace(sql, @"$$" + (i + 1).ToString(), 1); ! } } return sql; } --- 625,649 ---- if (namedParameters.Count != 0) { ! matchIndex = 0; ! matchReplaces = new Hashtable(); ! ! sql = search.Replace( ! sql, ! new MatchEvaluator(matchEvaluator)); ! ! matchReplaces.Clear(); } return sql; + } + + private string matchEvaluator(Match match) + { + if (!matchReplaces.ContainsKey(match.Value)) + { + matchReplaces.Add(match.Value, "$" + ((matchIndex++) + 1).ToString()); + } + + return matchReplaces[match.Value].ToString(); } |