OleDbParameterCollection.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. public OleDbParameter Add (string name, object value)
  132. {
  133. return Add (new OleDbParameter (name, value));
  134. }
  135. public OleDbParameter Add (string name, OleDbType type)
  136. {
  137. return Add (new OleDbParameter (name, type));
  138. }
  139. public OleDbParameter Add (string name, OleDbType type, int width)
  140. {
  141. return Add (new OleDbParameter (name, type, width));
  142. }
  143. public OleDbParameter Add (string name, OleDbType type,
  144. int width, string src_col)
  145. {
  146. return Add (new OleDbParameter (name, type, width, src_col));
  147. }
  148. public void Clear() {
  149. foreach (OleDbParameter p in list)
  150. p.Container = null;
  151. list.Clear ();
  152. }
  153. public bool Contains (object value) {
  154. if (!(value is OleDbParameter))
  155. throw new InvalidCastException ("The parameter was not an OleDbParameter.");
  156. return Contains (((OleDbParameter) value).ParameterName);
  157. }
  158. public bool Contains (string value) {
  159. foreach (OleDbParameter p in list)
  160. if (p.ParameterName.Equals (value))
  161. return true;
  162. return false;
  163. }
  164. public void CopyTo (Array array, int index) {
  165. list.CopyTo (array, index);
  166. }
  167. public IEnumerator GetEnumerator() {
  168. return list.GetEnumerator ();
  169. }
  170. public int IndexOf (object value) {
  171. if (!(value is OleDbParameter))
  172. throw new InvalidCastException ("The parameter was not an OleDbParameter.");
  173. return IndexOf (((OleDbParameter) value).ParameterName);
  174. }
  175. public int IndexOf (string parameterName) {
  176. for (int i = 0; i < Count; i += 1)
  177. if (this [i].ParameterName.Equals (parameterName))
  178. return i;
  179. return -1;
  180. }
  181. public void Insert (int index, object value) {
  182. list.Insert (index, value);
  183. }
  184. public void Remove (object value) {
  185. ((OleDbParameter) value).Container = null;
  186. list.Remove (value);
  187. }
  188. public void RemoveAt (int index) {
  189. this [index].Container = null;
  190. list.RemoveAt (index);
  191. }
  192. public void RemoveAt (string parameterName) {
  193. RemoveAt (IndexOf (parameterName));
  194. }
  195. #endregion // Methods
  196. }
  197. }