1 // created on 18/5/2002 at 00:59
3 // Npgsql.NpgsqlParameterCollection.cs
6 // Francisco Jr. (fxjrlists@yahoo.com.br)
8 // Copyright (C) 2002 The Npgsql Development Team
9 // npgsql-general@gborg.postgresql.org
10 // http://gborg.postgresql.org/project/npgsql/projdisplay.php
13 // This library is free software; you can redistribute it and/or
14 // modify it under the terms of the GNU Lesser General Public
15 // License as published by the Free Software Foundation; either
16 // version 2.1 of the License, or (at your option) any later version.
18 // This library is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 // Lesser General Public License for more details.
23 // You should have received a copy of the GNU Lesser General Public
24 // License along with this library; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 using System.Collections;
37 // Use ArrayList as base class so that we can get a lot of required methods implemented.
39 // [TODO] Implement more Add methods that construct the Parameter object.
40 // [TODO] Remove dependency on ArrayList. Implement the interfaces by hand.
42 public sealed class NpgsqlParameterCollection : ArrayList, IDataParameterCollection
45 // Logging related values
46 private static readonly String CLASSNAME = "NpgsqlParameterCollection";
48 public override Int32 Add(Object parameter)
50 NpgsqlEventLog.LogMsg("Entering " + CLASSNAME + ".Add()", LogLevel.Debug);
52 // Call the add version that receives a NpgsqlParameter as parameter
55 Add((NpgsqlParameter) parameter);
56 return IndexOf(((NpgsqlParameter) parameter).ParameterName);
58 catch(InvalidCastException e)
60 throw new NpgsqlException("Only NpgsqlParameter objects can be added to collection.", e);
64 public NpgsqlParameter Add(NpgsqlParameter parameter)
66 NpgsqlEventLog.LogMsg("Entering " + CLASSNAME + ".Add()", LogLevel.Debug);
68 // Check if the parameter has at least a name.
69 if (parameter.ParameterName != null)
73 // Return the parameter added.
77 throw new NpgsqlException("A parameter must have a name when added to collection");
81 public Boolean Contains(String parameterName)
83 NpgsqlEventLog.LogMsg("Entering " + CLASSNAME + ".Contains(" + parameterName + ")", LogLevel.Debug);
85 // Check if parameterName is in the collection.
86 return (IndexOf(parameterName) != -1);
89 public Int32 IndexOf(String parameterName)
91 NpgsqlEventLog.LogMsg("Entering " + CLASSNAME + ".IndexOf(" + parameterName + ")", LogLevel.Debug);
93 // Iterate values to see what is the index of parameter.
96 if (parameterName[0] != ':')
97 parameterName = ':' + parameterName;
98 foreach(NpgsqlParameter parameter in this)
100 if (parameter.ParameterName == parameterName)
108 public void RemoveAt(String parameterName)
110 NpgsqlEventLog.LogMsg("Entering " + CLASSNAME + ".RemoveAt(" + parameterName + ")", LogLevel.Debug);
112 base.RemoveAt(IndexOf(parameterName));
115 public NpgsqlParameter this[String parameterName]
119 // return base[IndexOf(parameterName)];
120 NpgsqlEventLog.LogMsg("Get " + CLASSNAME + ".this[]", LogLevel.Normal);
121 return (NpgsqlParameter) base[IndexOf(parameterName)];
125 // base[IndexOf(parameterName)] = value;
126 base[IndexOf(parameterName)] = value;
127 NpgsqlEventLog.LogMsg("Set " + CLASSNAME + ".Value", LogLevel.Normal);
131 public new NpgsqlParameter this[Int32 i]
135 // return base[IndexOf(parameterName)];
136 NpgsqlEventLog.LogMsg("Get " + CLASSNAME + ".this[]", LogLevel.Normal);
137 return (NpgsqlParameter) base[i];
141 // base[IndexOf(parameterName)] = value;
143 NpgsqlEventLog.LogMsg("Set " + CLASSNAME + ".Value", LogLevel.Normal);
147 Object IDataParameterCollection.this[String parameterName]
151 return this[parameterName];
156 this[parameterName] = (NpgsqlParameter)value;