1 // -*- c-basic-offset: 8; inent-tabs-mode: nil -*-
3 // SqliteParameterCollection.cs
5 // Author(s): Vladimir Vukicevic <vladimir@pobox.com>
7 // Copyright (C) 2002 Vladimir Vukicevic
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Collections;
35 namespace Mono.Data.SqliteClient
37 public class SqliteParameterCollection : IDataParameterCollection,
40 ArrayList numeric_param_list = new ArrayList ();
41 Hashtable named_param_hash = new Hashtable ();
43 public IEnumerator GetEnumerator ()
45 throw new NotImplementedException ();
48 public void RemoveAt (string parameterName)
50 if (!named_param_hash.Contains (parameterName))
51 throw new ApplicationException ("Parameter " + parameterName + " not found");
53 numeric_param_list.RemoveAt ((int) named_param_hash[parameterName]);
54 named_param_hash.Remove (parameterName);
59 public void RemoveAt (SqliteParameter param)
61 RemoveAt (param.ParameterName);
64 public void RemoveAt (int index)
66 RemoveAt (((SqliteParameter) numeric_param_list[index]).ParameterName);
69 int IList.IndexOf (object o)
71 return IndexOf ((SqliteParameter) o);
74 public int IndexOf (string parameterName)
76 return (int) named_param_hash[parameterName];
79 public int IndexOf (SqliteParameter param)
81 return IndexOf (param.ParameterName);
84 bool IList.Contains (object value)
86 return Contains ((SqliteParameter) value);
89 public bool Contains (string parameterName)
91 return named_param_hash.Contains (parameterName);
94 public bool Contains (SqliteParameter param)
96 return Contains (param.ParameterName);
99 object IList.this[int index] {
104 CheckSqliteParam (value);
105 this[index] = (SqliteParameter) value;
109 object IDataParameterCollection.this[string parameterName] {
111 return this[parameterName];
114 CheckSqliteParam (value);
115 this[parameterName] = (SqliteParameter) value;
119 public SqliteParameter this[string parameterName] {
121 return this[(int) named_param_hash[parameterName]];
124 if (this.Contains (parameterName))
125 numeric_param_list[(int) named_param_hash[parameterName]] = value;
126 else // uhm, do we add it if it doesn't exist? what does ms do?
131 public SqliteParameter this[int parameterIndex] {
133 return (SqliteParameter) numeric_param_list[parameterIndex];
136 numeric_param_list[parameterIndex] = value;
140 public int Add (object value)
142 CheckSqliteParam (value);
143 SqliteParameter sqlp = (SqliteParameter) value;
144 if (named_param_hash.Contains (sqlp.ParameterName))
145 throw new DuplicateNameException ("Parameter collection already contains given value.");
147 named_param_hash[value] = numeric_param_list.Add (value);
149 return (int) named_param_hash[value];
154 public SqliteParameter Add (SqliteParameter param)
160 public SqliteParameter Add (string name, object value)
162 return Add (new SqliteParameter (name, value));
165 public SqliteParameter Add (string name, DbType type)
167 return Add (new SqliteParameter (name, type));
170 public bool IsFixedSize {
176 public bool IsReadOnly {
184 numeric_param_list.Clear ();
185 named_param_hash.Clear ();
188 public void Insert (int index, object value)
190 CheckSqliteParam (value);
191 if (numeric_param_list.Count == index) {
196 numeric_param_list.Insert (index, value);
197 RecreateNamedHash ();
200 public void Remove (object value)
202 CheckSqliteParam (value);
203 RemoveAt ((SqliteParameter) value);
210 return numeric_param_list.Count;
214 public bool IsSynchronized {
220 public object SyncRoot {
226 public void CopyTo (Array array, int index)
228 throw new NotImplementedException ();
231 private void CheckSqliteParam (object value)
233 if (!(value is SqliteParameter))
234 throw new InvalidCastException ("Can only use SqliteParameter objects");
237 private void RecreateNamedHash ()
239 for (int i = 0; i < numeric_param_list.Count; i++) {
240 named_param_hash[((SqliteParameter) numeric_param_list[i]).ParameterName] = i;