OleDbParameterCollection.cs 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. bool IList.IsFixedSize {
  80. get { return false; }
  81. }
  82. bool IList.IsReadOnly {
  83. get { return false; }
  84. }
  85. bool ICollection.IsSynchronized {
  86. get { return list.IsSynchronized; }
  87. }
  88. object ICollection.SyncRoot {
  89. get { return list.SyncRoot; }
  90. }
  91. object IList.this[int index] {
  92. get { return list[index]; }
  93. set { list[index] = value; }
  94. }
  95. object IDataParameterCollection.this[string name]
  96. {
  97. [MonoTODO]
  98. get {
  99. throw new NotImplementedException ();
  100. }
  101. [MonoTODO]
  102. set {
  103. throw new NotImplementedException ();
  104. }
  105. }
  106. internal IntPtr GdaParameterList {
  107. [MonoTODO]
  108. get {
  109. IntPtr param_list;
  110. param_list = libgda.gda_parameter_list_new ();
  111. // FIXME: add parameters to list
  112. return param_list;
  113. }
  114. }
  115. #endregion // Properties
  116. #region Methods
  117. public int Add (object value) {
  118. if (!(value is OleDbParameter))
  119. throw new InvalidCastException ("The parameter was not an OleDbParameter.");
  120. Add ((OleDbParameter) value);
  121. return IndexOf (value);
  122. }
  123. public OleDbParameter Add (OleDbParameter parameter)
  124. {
  125. if (parameter.Container != null)
  126. throw new ArgumentException ("The OleDbParameter specified in the value parameter is already added to this or another OleDbParameterCollection.");
  127. parameter.Container = this;
  128. list.Add (parameter);
  129. return parameter;
  130. }
  131. #if NET_2_0
  132. [Obsolete("OleDbParameterCollection.Add(string, value) is now obsolete. Use OleDbParameterCollection.AddWithValue(string, object) instead.")]
  133. #endif
  134. public OleDbParameter Add (string name, object value)
  135. {
  136. return Add (new OleDbParameter (name, value));
  137. }
  138. #if NET_2_0
  139. public OleDbParameter AddWithValue (string parameterName, object value)
  140. {
  141. return Add (new OleDbParameter (parameterName, value));
  142. }
  143. #endif // NET_2_0
  144. public OleDbParameter Add (string name, OleDbType type)
  145. {
  146. return Add (new OleDbParameter (name, type));
  147. }
  148. public OleDbParameter Add (string name, OleDbType type, int width)
  149. {
  150. return Add (new OleDbParameter (name, type, width));
  151. }
  152. public OleDbParameter Add (string name, OleDbType type,
  153. int width, string src_col)
  154. {
  155. return Add (new OleDbParameter (name, type, width, src_col));
  156. }
  157. public void Clear() {
  158. foreach (OleDbParameter p in list)
  159. p.Container = null;
  160. list.Clear ();
  161. }
  162. public bool Contains (object value) {
  163. if (!(value is OleDbParameter))
  164. throw new InvalidCastException ("The parameter was not an OleDbParameter.");
  165. return Contains (((OleDbParameter) value).ParameterName);
  166. }
  167. public bool Contains (string value) {
  168. foreach (OleDbParameter p in list)
  169. if (p.ParameterName.Equals (value))
  170. return true;
  171. return false;
  172. }
  173. public void CopyTo (Array array, int index) {
  174. list.CopyTo (array, index);
  175. }
  176. public IEnumerator GetEnumerator() {
  177. return list.GetEnumerator ();
  178. }
  179. public int IndexOf (object value) {
  180. if (!(value is OleDbParameter))
  181. throw new InvalidCastException ("The parameter was not an OleDbParameter.");
  182. return IndexOf (((OleDbParameter) value).ParameterName);
  183. }
  184. public int IndexOf (string parameterName) {
  185. for (int i = 0; i < Count; i += 1)
  186. if (this [i].ParameterName.Equals (parameterName))
  187. return i;
  188. return -1;
  189. }
  190. public void Insert (int index, object value) {
  191. list.Insert (index, value);
  192. }
  193. public void Remove (object value) {
  194. ((OleDbParameter) value).Container = null;
  195. list.Remove (value);
  196. }
  197. public void RemoveAt (int index) {
  198. this [index].Container = null;
  199. list.RemoveAt (index);
  200. }
  201. public void RemoveAt (string parameterName) {
  202. RemoveAt (IndexOf (parameterName));
  203. }
  204. #endregion // Methods
  205. }
  206. }