OleDbParameterCollection.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  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 :
  44. #if NET_2_0
  45. DbParameterCollection, IList, ICollection, IDataParameterCollection
  46. #else
  47. MarshalByRefObject, IDataParameterCollection, IList, ICollection, IEnumerable
  48. #endif
  49. {
  50. #region Fields
  51. ArrayList list = new ArrayList ();
  52. #endregion // Fields
  53. #region Constructors
  54. internal OleDbParameterCollection ()
  55. {
  56. }
  57. #endregion // Constructors
  58. #region Properties
  59. #if ONLY_1_1
  60. [Browsable (false)]
  61. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  62. #endif
  63. public
  64. #if NET_2_0
  65. override
  66. #endif
  67. int Count {
  68. get { return list.Count; }
  69. }
  70. [Browsable (false)]
  71. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  72. public new OleDbParameter this[int index] {
  73. get { return (OleDbParameter) list [index]; }
  74. set { list[index] = (OleDbParameter) value; }
  75. }
  76. [Browsable (false)]
  77. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  78. public new OleDbParameter this[string parameterName] {
  79. get {
  80. foreach (OleDbParameter p in list)
  81. if (p.ParameterName.Equals (parameterName))
  82. return p;
  83. throw new IndexOutOfRangeException ("The specified name does not exist: " + parameterName);
  84. }
  85. set {
  86. if (!Contains (parameterName))
  87. throw new IndexOutOfRangeException("The specified name does not exist: " + parameterName);
  88. this [IndexOf (parameterName)] = (OleDbParameter) value;
  89. }
  90. }
  91. #if NET_2_0
  92. public override bool IsFixedSize {
  93. get {
  94. return list.IsFixedSize;
  95. }
  96. }
  97. public override bool IsReadOnly {
  98. get {
  99. return list.IsReadOnly;
  100. }
  101. }
  102. public override bool IsSynchronized {
  103. get {
  104. return list.IsSynchronized;
  105. }
  106. }
  107. public override object SyncRoot {
  108. get {
  109. return list.SyncRoot;
  110. }
  111. }
  112. #endif
  113. bool IList.IsFixedSize {
  114. get { return false; }
  115. }
  116. bool IList.IsReadOnly {
  117. get { return false; }
  118. }
  119. bool ICollection.IsSynchronized {
  120. get { return list.IsSynchronized; }
  121. }
  122. object ICollection.SyncRoot {
  123. get { return list.SyncRoot; }
  124. }
  125. object IList.this[int index] {
  126. get { return list[index]; }
  127. set { list[index] = value; }
  128. }
  129. object IDataParameterCollection.this[string name] {
  130. [MonoTODO]
  131. get {
  132. throw new NotImplementedException ();
  133. }
  134. [MonoTODO]
  135. set {
  136. throw new NotImplementedException ();
  137. }
  138. }
  139. internal IntPtr GdaParameterList {
  140. [MonoTODO]
  141. get {
  142. IntPtr param_list;
  143. param_list = libgda.gda_parameter_list_new ();
  144. // FIXME: add parameters to list
  145. return param_list;
  146. }
  147. }
  148. #endregion // Properties
  149. #region Methods
  150. #if NET_2_0
  151. [EditorBrowsable(EditorBrowsableState.Never)]
  152. #endif
  153. public
  154. #if NET_2_0
  155. override
  156. #endif
  157. int Add (object value)
  158. {
  159. if (!(value is OleDbParameter))
  160. throw new InvalidCastException ("The parameter was not an OleDbParameter.");
  161. Add ((OleDbParameter) value);
  162. return IndexOf (value);
  163. }
  164. public OleDbParameter Add (OleDbParameter parameter)
  165. {
  166. if (parameter.Container != null)
  167. throw new ArgumentException ("The OleDbParameter specified in the value parameter is already added to this or another OleDbParameterCollection.");
  168. parameter.Container = this;
  169. list.Add (parameter);
  170. return parameter;
  171. }
  172. #if NET_2_0
  173. [Obsolete("OleDbParameterCollection.Add(string, value) is now obsolete. Use OleDbParameterCollection.AddWithValue(string, object) instead.")]
  174. [EditorBrowsable(EditorBrowsableState.Never)]
  175. #endif
  176. public OleDbParameter Add (string name, object value)
  177. {
  178. return Add (new OleDbParameter (name, value));
  179. }
  180. #if NET_2_0
  181. public OleDbParameter AddWithValue (string parameterName, object value)
  182. {
  183. return Add (new OleDbParameter (parameterName, value));
  184. }
  185. #endif
  186. public OleDbParameter Add (string name, OleDbType type)
  187. {
  188. return Add (new OleDbParameter (name, type));
  189. }
  190. public OleDbParameter Add (string name, OleDbType type, int width)
  191. {
  192. return Add (new OleDbParameter (name, type, width));
  193. }
  194. public OleDbParameter Add (string name, OleDbType type, int width, string src_col)
  195. {
  196. return Add (new OleDbParameter (name, type, width, src_col));
  197. }
  198. #if NET_2_0
  199. public override void AddRange(Array values)
  200. {
  201. if (values == null)
  202. throw new ArgumentNullException ("values");
  203. foreach (object value in values)
  204. Add (value);
  205. }
  206. public void AddRange(OleDbParameter[] values)
  207. {
  208. if (values == null)
  209. throw new ArgumentNullException ("values");
  210. foreach (OleDbParameter value in values)
  211. Add (value);
  212. }
  213. #endif
  214. public
  215. #if NET_2_0
  216. override
  217. #endif
  218. void Clear()
  219. {
  220. foreach (OleDbParameter p in list)
  221. p.Container = null;
  222. list.Clear ();
  223. }
  224. public
  225. #if NET_2_0
  226. override
  227. #endif
  228. bool Contains (object value)
  229. {
  230. if (!(value is OleDbParameter))
  231. throw new InvalidCastException ("The parameter was not an OleDbParameter.");
  232. return Contains (((OleDbParameter) value).ParameterName);
  233. }
  234. public
  235. #if NET_2_0
  236. override
  237. #endif
  238. bool Contains (string value)
  239. {
  240. foreach (OleDbParameter p in list)
  241. if (p.ParameterName.Equals (value))
  242. return true;
  243. return false;
  244. }
  245. #if NET_2_0
  246. public bool Contains (OleDbParameter value)
  247. {
  248. return IndexOf (value) != -1;
  249. }
  250. #endif
  251. public
  252. #if NET_2_0
  253. override
  254. #endif
  255. void CopyTo (Array array, int index)
  256. {
  257. list.CopyTo (array, index);
  258. }
  259. #if NET_2_0
  260. public void CopyTo(OleDbParameter[] array, int index)
  261. {
  262. CopyTo (array, index);
  263. }
  264. #endif
  265. public
  266. #if NET_2_0
  267. override
  268. #endif
  269. IEnumerator GetEnumerator()
  270. {
  271. return list.GetEnumerator ();
  272. }
  273. #if NET_2_0
  274. [MonoTODO]
  275. protected override DbParameter GetParameter (int index)
  276. {
  277. throw new NotImplementedException ();
  278. }
  279. [MonoTODO]
  280. protected override DbParameter GetParameter (string parameterName)
  281. {
  282. throw new NotImplementedException ();
  283. }
  284. #endif
  285. public
  286. #if NET_2_0
  287. override
  288. #endif
  289. int IndexOf (object value)
  290. {
  291. if (!(value is OleDbParameter))
  292. throw new InvalidCastException ("The parameter was not an OleDbParameter.");
  293. return IndexOf (((OleDbParameter) value).ParameterName);
  294. }
  295. #if NET_2_0
  296. public int IndexOf(OleDbParameter value)
  297. {
  298. return IndexOf (value);
  299. }
  300. #endif
  301. public
  302. #if NET_2_0
  303. override
  304. #endif
  305. int IndexOf (string parameterName)
  306. {
  307. for (int i = 0; i < Count; i += 1)
  308. if (this [i].ParameterName.Equals (parameterName))
  309. return i;
  310. return -1;
  311. }
  312. public
  313. #if NET_2_0
  314. override
  315. #endif
  316. void Insert (int index, object value)
  317. {
  318. list.Insert (index, value);
  319. }
  320. #if NET_2_0
  321. public void Insert (int index, OleDbParameter value)
  322. {
  323. Insert (index, value);
  324. }
  325. #endif
  326. public
  327. #if NET_2_0
  328. override
  329. #endif
  330. void Remove (object value)
  331. {
  332. ((OleDbParameter) value).Container = null;
  333. list.Remove (value);
  334. }
  335. #if NET_2_0
  336. public void Remove (OleDbParameter value)
  337. {
  338. Remove (value);
  339. }
  340. #endif
  341. public
  342. #if NET_2_0
  343. override
  344. #endif
  345. void RemoveAt (int index)
  346. {
  347. this [index].Container = null;
  348. list.RemoveAt (index);
  349. }
  350. public
  351. #if NET_2_0
  352. override
  353. #endif
  354. void RemoveAt (string parameterName)
  355. {
  356. RemoveAt (IndexOf (parameterName));
  357. }
  358. #if NET_2_0
  359. [MonoTODO]
  360. protected override void SetParameter (int index, DbParameter value)
  361. {
  362. throw new NotImplementedException ();
  363. }
  364. [MonoTODO]
  365. protected override void SetParameter (string parameterName, DbParameter value)
  366. {
  367. throw new NotImplementedException ();
  368. }
  369. #endif
  370. #endregion // Methods
  371. }
  372. }