? commandperformance.diff
? build/mono
? build/ms
? build/nunit2tests
? build/res
Index: NpgsqlCommand.cs
===================================================================
RCS file: /cvsroot/npgsql/Npgsql/src/Npgsql/NpgsqlCommand.cs,v
retrieving revision 1.85
diff -u -r1.85 NpgsqlCommand.cs
--- NpgsqlCommand.cs	29 Dec 2005 03:43:12 -0000	1.85
+++ NpgsqlCommand.cs	29 Dec 2005 20:04:05 -0000
@@ -52,7 +52,7 @@
         // Logging related values
         private static readonly String CLASSNAME = "NpgsqlCommand";
         private static ResourceManager resman = new ResourceManager(typeof(NpgsqlCommand));
-        private static readonly Regex parameterReplace = new Regex(@"(:[\w\.]*)|(@[\w\.]*)|(.)", RegexOptions.Singleline);
+        private static readonly Regex parameterReplace = new Regex(@"([:@][\w\.]*)", RegexOptions.Singleline);
 
         private NpgsqlConnection            connection;
         private NpgsqlConnector             connector;
@@ -881,76 +881,72 @@
             // parameter values in order they were put in parameter collection.
 
 
-            // If parenthesis don't need to be added, they were added by user with parameter names. Replace them.
-            if (!addProcedureParenthesis)
-            {
-
-                StringBuilder sb = new StringBuilder();
-
-                for ( Match m = parameterReplace.Match(result); m.Success; m = m.NextMatch() )
-                {
-                    String s = m.Groups[0].ToString();
-
-                    if ((s.StartsWith(":") ||
-                         s.StartsWith("@")) &&
-                         Parameters.Contains(s))
-                    {
-                        // It's a parameter. Lets handle it.
-
-                        NpgsqlParameter p = Parameters[s];
-                        if ((p.Direction == ParameterDirection.Input) ||
-                             (p.Direction == ParameterDirection.InputOutput))
-                        {
-
-                            // FIXME DEBUG ONLY
-                            // adding the '::<datatype>' on the end of a parameter is a highly
-                            // questionable practice, but it is great for debugging!
-                            sb.Append(p.TypeInfo.ConvertToBackend(p.Value, false));
-
-                            // Only add data type info if we are calling an stored procedure.
-
-                            if (type == CommandType.StoredProcedure)
-                            {
-                                sb.Append("::");
-                                sb.Append(p.TypeInfo.Name);
-
-                                if (p.TypeInfo.UseSize && (p.Size > 0))
-                                    sb.Append("(").Append(p.Size).Append(")");
-                            }
-                        }
-
-                    }
-                    else
-                        sb.Append(s);
-
-                }
-
-                result = sb.ToString();
-            }
-
-
-            else
-            {
-
-                for (Int32 i = 0; i < parameters.Count; i++)
-                {
-                    NpgsqlParameter Param = parameters[i];
-
-
-                    if ((Param.Direction == ParameterDirection.Input) ||
-                         (Param.Direction == ParameterDirection.InputOutput))
-
-
-                        result += Param.TypeInfo.ConvertToBackend(Param.Value, false) + "::" + Param.TypeInfo.Name + ",";
-                }
-
-
-                // Remove a trailing comma added from parameter handling above. If any.
-                // Maybe there are only output parameters. If so, there will be no comma.
-                if (result.EndsWith(","))
-                    result = result.Remove(result.Length - 1, 1);
-
-                result += ")";
+            // If parenthesis don't need to be added, they were added by user with parameter names. Replace them.
+            if (!addProcedureParenthesis)
+            {
+                StringBuilder sb = new StringBuilder();
+                NpgsqlParameter p;
+                string[] queryparts = parameterReplace.Split(result);
+
+                foreach (String s in queryparts)
+                {
+                    if (s == string.Empty)
+                        continue;
+
+                    if ((s[0] == ':' || s[0] == '@') &&
+                        Parameters.TryGetValue(s, out p))
+                    {
+                        // It's a parameter. Lets handle it.
+                        if ((p.Direction == ParameterDirection.Input) ||
+                             (p.Direction == ParameterDirection.InputOutput))
+                        {
+                            // FIXME DEBUG ONLY
+                            // adding the '::<datatype>' on the end of a parameter is a highly
+                            // questionable practice, but it is great for debugging!
+                            sb.Append(p.TypeInfo.ConvertToBackend(p.Value, false));
+
+                            // Only add data type info if we are calling an stored procedure.
+
+                            if (type == CommandType.StoredProcedure)
+                            {
+                                sb.Append("::");
+                                sb.Append(p.TypeInfo.Name);
+
+                                if (p.TypeInfo.UseSize && (p.Size > 0))
+                                    sb.Append("(").Append(p.Size).Append(")");
+                            }
+                        }
+
+                    }
+                    else
+                        sb.Append(s);
+                }
+
+                result = sb.ToString();
+            }
+
+            else
+            {
+
+                for (Int32 i = 0; i < parameters.Count; i++)
+                {
+                    NpgsqlParameter Param = parameters[i];
+
+
+                    if ((Param.Direction == ParameterDirection.Input) ||
+                         (Param.Direction == ParameterDirection.InputOutput))
+
+
+                        result += Param.TypeInfo.ConvertToBackend(Param.Value, false) + "::" + Param.TypeInfo.Name + ",";
+                }
+
+
+                // Remove a trailing comma added from parameter handling above. If any.
+                // Maybe there are only output parameters. If so, there will be no comma.
+                if (result.EndsWith(","))
+                    result = result.Remove(result.Length - 1, 1);
+
+                result += ")";
             }
 
             if (functionReturnsRecord)
Index: NpgsqlParameterCollection.cs
===================================================================
RCS file: /cvsroot/npgsql/Npgsql/src/Npgsql/NpgsqlParameterCollection.cs,v
retrieving revision 1.21
diff -u -r1.21 NpgsqlParameterCollection.cs
--- NpgsqlParameterCollection.cs	26 Aug 2005 04:05:45 -0000	1.21
+++ NpgsqlParameterCollection.cs	29 Dec 2005 20:04:05 -0000
@@ -249,14 +249,14 @@
             NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "IndexOf", parameterName);
 
             // Iterate values to see what is the index of parameter.
-            Int32 index = 0;
-            if ( (parameterName[0] != ':') && (parameterName[0] != '@') )
-                parameterName = ':' + parameterName;
-
-            foreach(NpgsqlParameter parameter in this)
-            {
-                if (parameter.ParameterName.Remove(0, 1) == parameterName.Remove(0, 1))
-                    return index;
+            Int32 index = 0;
+            if ((parameterName[0] == ':') || (parameterName[0] == '@'))
+                parameterName = parameterName.Remove(0, 1);
+
+            foreach (NpgsqlParameter parameter in this)
+            {
+                if (parameter.ParameterName.Remove(0, 1) == parameterName)
+                    return index;
                 index++;
             }
             return -1;
@@ -331,7 +331,29 @@
             NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "Contains", value);
             CheckType(value);
             return this.InternalList.Contains(value);
-        }
+        }
+
+        /// <summary>
+        /// Gets a value indicating whether a <see cref="Npgsql.NpgsqlParameter">NpgsqlParameter</see> with the specified parameter name exists in the collection.
+        /// </summary>
+        /// <param name="parameterName">The name of the <see cref="Npgsql.NpgsqlParameter">NpgsqlParameter</see> object to find.</param>
+        /// <param name="parameter">A reference to the requested parameter is returned in this out param if it is found in the list.  This value is null if the parameter is not found.</param>
+        /// <returns><b>true</b> if the collection contains the parameter and param will contain the parameter; otherwise, <b>false</b>.</returns>
+        public bool TryGetValue(string parameterName, out NpgsqlParameter parameter)
+        {
+            NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "TryGetValue", parameterName);
+            int index = IndexOf(parameterName);
+            if (index != -1)
+            {
+                parameter = this[index];
+                return true;
+            }
+            else
+            {
+                parameter = null;
+                return false;
+            }
+        }
 
         /// <summary>
         /// Removes all items from the collection.
