[pgsqlclient-checkins] SF.net SVN: pgsqlclient: [61] trunk/pgsqlclient/source/PostgreSql/Data/Postgr
Status: Inactive
Brought to you by:
carlosga_fb
From: <car...@us...> - 2006-03-28 12:14:01
|
Revision: 61 Author: carlosga_fb Date: 2006-03-28 04:13:51 -0800 (Tue, 28 Mar 2006) ViewCVS: http://svn.sourceforge.net/pgsqlclient/?rev=61&view=rev Log Message: ----------- ?\194?\183 More bug fixes Modified Paths: -------------- trunk/pgsqlclient/source/PostgreSql/Data/PostgreSqlClient/PgCommand.cs trunk/pgsqlclient/source/PostgreSql/Data/PostgreSqlClient/PgDataReader.cs Modified: trunk/pgsqlclient/source/PostgreSql/Data/PostgreSqlClient/PgCommand.cs =================================================================== --- trunk/pgsqlclient/source/PostgreSql/Data/PostgreSqlClient/PgCommand.cs 2006-03-28 11:24:30 UTC (rev 60) +++ trunk/pgsqlclient/source/PostgreSql/Data/PostgreSqlClient/PgCommand.cs 2006-03-28 12:13:51 UTC (rev 61) @@ -45,8 +45,6 @@ private int commandTimeout; private bool designTimeVisible; private StringCollection namedParameters; - private int matchIndex; - private Hashtable matchReplaces; private PgStatement statement; private PgDataReader activeDataReader; @@ -219,9 +217,26 @@ #endregion - #region \xB7 Constructors \xB7 + #region \xB7 Private Properties \xB7 - public PgCommand() + public StringCollection NamedParameters + { + get + { + if (this.namedParameters == null) + { + this.namedParameters = new StringCollection(); + } + + return this.namedParameters; + } + } + + #endregion + + #region \xB7 Constructors \xB7 + + public PgCommand() : base() { this.commandText = String.Empty; @@ -230,8 +245,6 @@ this.updatedRowSource = UpdateRowSource.Both; this.commandBehavior = CommandBehavior.Default; this.designTimeVisible = true; - this.namedParameters = new StringCollection(); - this.matchReplaces = new Hashtable(); } public PgCommand(string cmdText) @@ -276,11 +289,11 @@ this.commandText = null; - this.matchReplaces.Clear(); - this.matchReplaces = null; - - this.namedParameters.Clear(); - this.namedParameters = null; + if (this.namedParameters != null) + { + this.namedParameters.Clear(); + this.namedParameters = null; + } } // release any unmanaged resources @@ -432,7 +445,7 @@ string prepareName = "PS" + this.GetStmtName(); string portalName = "PR" + this.GetStmtName(); - this.statement = conn.Database.CreateStatement(prepareName, portalName, this.ParseParameterNames(sql)); + this.statement = conn.Database.CreateStatement(prepareName, portalName, this.ParseNamedParameters(sql)); // Parse statement this.statement.Parse(); @@ -598,61 +611,66 @@ return GetHashCode().ToString() + this.connection.GetHashCode().ToString() + DateTime.Now.Ticks; } - private string ParseParameterNames(string commandText) - { - string sql = commandText; + private string ParseNamedParameters(string sql) + { + StringBuilder builder = new StringBuilder(); + StringBuilder paramBuilder = new StringBuilder(); + bool inCommas = false; + bool inParam = false; + int paramIndex = 0; - this.namedParameters.Clear(); + this.NamedParameters.Clear(); - if (commandText.IndexOf("@") != -1) - { - this.matchReplaces.Clear(); - this.matchIndex = 0; + if (sql.IndexOf('@') == -1) + { + return sql; + } - string pattern = @"(('[^']*?\@[^']*')*[^'@]*?)*(?<param>@\w+)*([^'@]*?('[^']*?\@*[^']*'))*"; + for (int i = 0; i < sql.Length; i++) + { + char sym = sql[i]; - Regex r = new Regex(pattern, RegexOptions.ExplicitCapture); + if (inParam) + { + if (Char.IsLetterOrDigit(sym) || sym == '_' || sym == '$') + { + paramBuilder.Append(sym); + } + else + { + this.NamedParameters.Add(paramBuilder.ToString()); + paramBuilder.Length = 0; + builder.AppendFormat("${0}", ++paramIndex); + builder.Append(sym); + inParam = false; + } + } + else + { + if (sym == '\'') + { + inCommas = !inCommas; + } + else if (!inCommas && sym == '@') + { + inParam = true; + paramBuilder.Append(sym); + continue; + } - MatchEvaluator me = new MatchEvaluator(NamedParamsMatchEvaluator); + builder.Append(sym); + } + } - sql = r.Replace(sql, me); + if (inParam) + { + this.NamedParameters.Add(paramBuilder.ToString()); + builder.AppendFormat("${0}", ++paramIndex); + } - this.matchReplaces.Clear(); - } + return builder.ToString(); + } - return sql; - } - - private string NamedParamsMatchEvaluator(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); - - 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; - } - } - private void SetParameterValues() { if (this.Parameters.Count != 0) @@ -661,9 +679,9 @@ { int index = i; - if (this.namedParameters.Count > 0) + if (this.NamedParameters.Count > 0) { - index = this.Parameters.IndexOf(this.namedParameters[i]); + index = this.Parameters.IndexOf(this.NamedParameters[i]); } if (this.Parameters[index].Direction == ParameterDirection.Input || Modified: trunk/pgsqlclient/source/PostgreSql/Data/PostgreSqlClient/PgDataReader.cs =================================================================== --- trunk/pgsqlclient/source/PostgreSql/Data/PostgreSqlClient/PgDataReader.cs 2006-03-28 11:24:30 UTC (rev 60) +++ trunk/pgsqlclient/source/PostgreSql/Data/PostgreSqlClient/PgDataReader.cs 2006-03-28 12:13:51 UTC (rev 61) @@ -258,8 +258,8 @@ // Add row information DataRow schemaRow = schemaTable.NewRow(); - schemaRow["ColumnName"] = Convert.ToString(columnInfo[2]); - schemaRow["ColumnOrdinal"] = Convert.ToInt32(columnInfo[5]); + schemaRow["ColumnName"] = this.GetName(i); + schemaRow["ColumnOrdinal"] = (i + 1); schemaRow["ColumnSize"] = this.GetSize(i); if (this.IsNumeric(i)) { @@ -287,7 +287,7 @@ schemaRow["BaseColumnName"] = columnInfo[2].ToString(); schemaRow["IsReadOnly"] = (bool)columnInfo[7]; schemaRow["IsAutoIncrement"] = (bool)columnInfo[7]; - schemaRow["IsKey"] = this.IsPrimaryKey(pKeyInfo, (int)schemaRow["ColumnOrdinal"]); + schemaRow["IsKey"] = this.IsPrimaryKey(pKeyInfo, Convert.ToInt32(columnInfo[5])); schemaRow["AllowDBNull"] = ((bool)columnInfo[6]) ? false : true; } else This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |