OleDbParameterCollection.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. //
  2. // System.Data.OleDb.OleDbParameterCollection
  3. //
  4. // Author:
  5. // Rodrigo Moya ([email protected])
  6. // Tim Coleman ([email protected])
  7. // Umadevi S ([email protected])
  8. //
  9. // Copyright (C) Rodrigo Moya, 2002
  10. // Copyright (C) Tim Coleman, 2002
  11. // Copyright (C) Novell Inc.
  12. //
  13. //
  14. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  15. //
  16. // Permission is hereby granted, free of charge, to any person obtaining
  17. // a copy of this software and associated documentation files (the
  18. // "Software"), to deal in the Software without restriction, including
  19. // without limitation the rights to use, copy, modify, merge, publish,
  20. // distribute, sublicense, and/or sell copies of the Software, and to
  21. // permit persons to whom the Software is furnished to do so, subject to
  22. // the following conditions:
  23. //
  24. // The above copyright notice and this permission notice shall be
  25. // included in all copies or substantial portions of the Software.
  26. //
  27. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  28. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  29. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  30. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  31. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  32. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  33. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  34. //
  35. using System.Collections;
  36. using System.Data;
  37. using System.Data.Common;
  38. using System.ComponentModel;
  39. namespace System.Data.OleDb
  40. {
  41. [ListBindable (false)]
  42. [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBParametersEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
  43. public sealed class OleDbParameterCollection : MarshalByRefObject,
  44. IDataParameterCollection, IList, ICollection, IEnumerable
  45. {
  46. #region Fields
  47. ArrayList list = new ArrayList ();
  48. #endregion // Fields
  49. #region Constructors
  50. internal OleDbParameterCollection () {
  51. }
  52. #endregion // Constructors
  53. #region Properties
  54. [Browsable (false)]
  55. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  56. public int Count {
  57. get { return list.Count; }
  58. }
  59. [Browsable (false)]
  60. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  61. public OleDbParameter this[int index] {
  62. get { return (OleDbParameter) list[index]; }
  63. set { list[index] = value; }
  64. }
  65. [Browsable (false)]
  66. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  67. public OleDbParameter this[string parameterName] {
  68. get {
  69. foreach (OleDbParameter p in list)
  70. if (p.ParameterName.Equals (parameterName))
  71. return p;
  72. throw new IndexOutOfRangeException ("The specified name does not exist: " + parameterName);
  73. }
  74. set {
  75. if (!Contains (parameterName)) throw new IndexOutOfRangeException("The specified name does not exist: " + parameterName);
  76. this [IndexOf (parameterName)] = value;
  77. }
  78. }
  79. int ICollection.Count {
  80. get { return list.Count; }
  81. }
  82. bool IList.IsFixedSize {
  83. get { return false; }
  84. }
  85. bool IList.IsReadOnly {
  86. get { return false; }
  87. }
  88. bool ICollection.IsSynchronized {
  89. get { return list.IsSynchronized; }
  90. }
  91. object ICollection.SyncRoot {
  92. get { return list.SyncRoot; }
  93. }
  94. object IList.this[int index] {
  95. get { return list[index]; }
  96. set { list[index] = value; }
  97. }
  98. object IDataParameterCollection.this[string name]
  99. {
  100. [MonoTODO]
  101. get {
  102. throw new NotImplementedException ();
  103. }
  104. [MonoTODO]
  105. set {
  106. throw new NotImplementedException ();
  107. }
  108. }
  109. internal IntPtr GdaParameterList {
  110. [MonoTODO]
  111. get {
  112. IntPtr param_list;
  113. param_list = libgda.gda_parameter_list_new ();
  114. // FIXME: add parameters to list
  115. return param_list;
  116. }
  117. }
  118. #endregion // Properties
  119. #region Methods
  120. public int Add (object value) {
  121. if (!(value is OleDbParameter))
  122. throw new InvalidCastException ("The parameter was not an OleDbParameter.");
  123. Add ((OleDbParameter) value);
  124. return IndexOf (value);
  125. }
  126. public OleDbParameter Add (OleDbParameter parameter)
  127. {
  128. if (parameter.Container != null)
  129. throw new ArgumentException ("The OleDbParameter specified in the value parameter is already added to this or another OleDbParameterCollection.");
  130. parameter.Container = this;
  131. list.Add (parameter);
  132. return parameter;
  133. }
  134. public OleDbParameter Add (string name, object value)
  135. {
  136. return Add (new OleDbParameter (name, value));
  137. }
  138. public OleDbParameter Add (string name, OleDbType type)
  139. {
  140. return Add (new OleDbParameter (name, type));
  141. }
  142. public OleDbParameter Add (string name, OleDbType type, int width)
  143. {
  144. return Add (new OleDbParameter (name, type, width));
  145. }
  146. public OleDbParameter Add (string name, OleDbType type,
  147. int width, string src_col)
  148. {
  149. return Add (new OleDbParameter (name, type, width, src_col));
  150. }
  151. int IList.Add (object value)
  152. {
  153. if (!(value is IDataParameter))
  154. throw new InvalidCastException ();
  155. list.Add (value);
  156. return list.IndexOf (value);
  157. }
  158. void IList.Clear ()
  159. {
  160. list.Clear ();
  161. }
  162. bool IList.Contains (object value)
  163. {
  164. return list.Contains (value);
  165. }
  166. bool IDataParameterCollection.Contains (string value)
  167. {
  168. for (int i = 0; i < list.Count; i++) {
  169. IDataParameter parameter;
  170. parameter = (IDataParameter) list[i];
  171. if (parameter.ParameterName == value)
  172. return true;
  173. }
  174. return false;
  175. }
  176. void ICollection.CopyTo (Array array, int index)
  177. {
  178. ((OleDbParameter[])(list.ToArray ())).CopyTo (array, index);
  179. }
  180. IEnumerator IEnumerable.GetEnumerator ()
  181. {
  182. return list.GetEnumerator ();
  183. }
  184. int IList.IndexOf (object value)
  185. {
  186. return list.IndexOf (value);
  187. }
  188. int IDataParameterCollection.IndexOf (string name)
  189. {
  190. return list.IndexOf (((IDataParameterCollection) this)[name]);
  191. }
  192. void IList.Insert (int index, object value)
  193. {
  194. list.Insert (index, value);
  195. }
  196. void IList.Remove (object value)
  197. {
  198. list.Remove (value);
  199. }
  200. void IList.RemoveAt (int index)
  201. {
  202. list.Remove ((object) list[index]);
  203. }
  204. void IDataParameterCollection.RemoveAt (string name)
  205. {
  206. list.Remove (((IDataParameterCollection) this)[name]);
  207. }
  208. public void Clear() {
  209. foreach (OleDbParameter p in list)
  210. p.Container = null;
  211. list.Clear ();
  212. }
  213. public bool Contains (object value) {
  214. if (!(value is OleDbParameter))
  215. throw new InvalidCastException ("The parameter was not an OleDbParameter.");
  216. return Contains (((OleDbParameter) value).ParameterName);
  217. }
  218. public bool Contains (string value) {
  219. foreach (OleDbParameter p in list)
  220. if (p.ParameterName.Equals (value))
  221. return true;
  222. return false;
  223. }
  224. public void CopyTo (Array array, int index) {
  225. list.CopyTo (array, index);
  226. }
  227. public IEnumerator GetEnumerator() {
  228. return list.GetEnumerator ();
  229. }
  230. public int IndexOf (object value) {
  231. if (!(value is OleDbParameter))
  232. throw new InvalidCastException ("The parameter was not an OleDbParameter.");
  233. return IndexOf (((OleDbParameter) value).ParameterName);
  234. }
  235. public int IndexOf (string parameterName) {
  236. for (int i = 0; i < Count; i += 1)
  237. if (this [i].ParameterName.Equals (parameterName))
  238. return i;
  239. return -1;
  240. }
  241. public void Insert (int index, object value) {
  242. list.Insert (index, value);
  243. }
  244. public void Remove (object value) {
  245. ((OleDbParameter) value).Container = null;
  246. list.Remove (value);
  247. }
  248. public void RemoveAt (int index) {
  249. this [index].Container = null;
  250. list.RemoveAt (index);
  251. }
  252. public void RemoveAt (string parameterName) {
  253. RemoveAt (IndexOf (parameterName));
  254. }
  255. #endregion // Methods
  256. }
  257. }