You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

238 lines
8.4 KiB

4 years ago
  1. #if MYSQL_6_9
  2. // Copyright © 2004, 2013, Oracle and/or its affiliates. All rights reserved.
  3. //
  4. // MySQL Connector/NET is licensed under the terms of the GPLv2
  5. // <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
  6. // MySQL Connectors. There are special exceptions to the terms and
  7. // conditions of the GPLv2 as it is applied to this software, see the
  8. // FLOSS License Exception
  9. // <http://www.mysql.com/about/legal/licensing/foss-exception.html>.
  10. //
  11. // This program is free software; you can redistribute it and/or modify
  12. // it under the terms of the GNU General Public License as published
  13. // by the Free Software Foundation; version 2 of the License.
  14. //
  15. // This program is distributed in the hope that it will be useful, but
  16. // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  17. // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  18. // for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License along
  21. // with this program; if not, write to the Free Software Foundation, Inc.,
  22. // 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  23. using Externals.MySql.Data.MySqlClient.Properties;
  24. using System;
  25. using System.Collections;
  26. using System.ComponentModel;
  27. using System.Data.Common;
  28. namespace Externals.MySql.Data.MySqlClient
  29. {
  30. [Editor("Externals.MySql.Data.MySqlClient.Design.DBParametersEditor,MySql.Design", typeof(System.Drawing.Design.UITypeEditor))]
  31. [ListBindable(true)]
  32. internal sealed partial class MySqlParameterCollection : DbParameterCollection
  33. {
  34. /// <summary>
  35. /// Adds a <see cref="MySqlParameter"/> to the <see cref="MySqlParameterCollection"/> with the parameter name, the data type, the column length, and the source column name.
  36. /// </summary>
  37. /// <param name="parameterName">The name of the parameter.</param>
  38. /// <param name="dbType">One of the <see cref="MySqlDbType"/> values. </param>
  39. /// <param name="size">The length of the column.</param>
  40. /// <param name="sourceColumn">The name of the source column.</param>
  41. /// <returns>The newly added <see cref="MySqlParameter"/> object.</returns>
  42. public MySqlParameter Add(string parameterName, MySqlDbType dbType, int size, string sourceColumn)
  43. {
  44. return Add(new MySqlParameter(parameterName, dbType, size, sourceColumn));
  45. }
  46. #region DbParameterCollection Implementation
  47. /// <summary>
  48. /// Adds an array of values to the end of the <see cref="MySqlParameterCollection"/>.
  49. /// </summary>
  50. /// <param name="values"></param>
  51. public override void AddRange(Array values)
  52. {
  53. foreach (DbParameter p in values)
  54. Add(p);
  55. }
  56. /// <summary>
  57. /// Retrieve the parameter with the given name.
  58. /// </summary>
  59. /// <param name="parameterName"></param>
  60. /// <returns></returns>
  61. protected override DbParameter GetParameter(string parameterName)
  62. {
  63. return (DbParameter)InternalGetParameter(parameterName);
  64. }
  65. protected override DbParameter GetParameter(int index)
  66. {
  67. return (DbParameter)InternalGetParameter(index);
  68. }
  69. protected override void SetParameter(string parameterName, DbParameter value)
  70. {
  71. InternalSetParameter(parameterName, value as MySqlParameter);
  72. }
  73. protected override void SetParameter(int index, DbParameter value)
  74. {
  75. InternalSetParameter(index, value as MySqlParameter);
  76. }
  77. /// <summary>
  78. /// Adds the specified <see cref="MySqlParameter"/> object to the <see cref="MySqlParameterCollection"/>.
  79. /// </summary>
  80. /// <param name="value">The <see cref="MySqlParameter"/> to add to the collection.</param>
  81. /// <returns>The index of the new <see cref="MySqlParameter"/> object.</returns>
  82. public override int Add(object value)
  83. {
  84. MySqlParameter parameter = value as MySqlParameter;
  85. if (parameter == null)
  86. throw new MySqlException("Only MySqlParameter objects may be stored");
  87. parameter = Add(parameter);
  88. return IndexOf(parameter);
  89. }
  90. /// <summary>
  91. /// Gets a value indicating whether a <see cref="MySqlParameter"/> with the specified parameter name exists in the collection.
  92. /// </summary>
  93. /// <param name="parameterName">The name of the <see cref="MySqlParameter"/> object to find.</param>
  94. /// <returns>true if the collection contains the parameter; otherwise, false.</returns>
  95. public override bool Contains(string parameterName)
  96. {
  97. return IndexOf(parameterName) != -1;
  98. }
  99. /// <summary>
  100. /// Gets a value indicating whether a MySqlParameter exists in the collection.
  101. /// </summary>
  102. /// <param name="value">The value of the <see cref="MySqlParameter"/> object to find. </param>
  103. /// <returns>true if the collection contains the <see cref="MySqlParameter"/> object; otherwise, false.</returns>
  104. /// <overloads>Gets a value indicating whether a <see cref="MySqlParameter"/> exists in the collection.</overloads>
  105. public override bool Contains(object value)
  106. {
  107. MySqlParameter parameter = value as MySqlParameter;
  108. if (null == parameter)
  109. throw new ArgumentException("Argument must be of type DbParameter", "value");
  110. return items.Contains(parameter);
  111. }
  112. /// <summary>
  113. /// Copies MySqlParameter objects from the MySqlParameterCollection to the specified array.
  114. /// </summary>
  115. /// <param name="array"></param>
  116. /// <param name="index"></param>
  117. public override void CopyTo(Array array, int index)
  118. {
  119. items.ToArray().CopyTo(array, index);
  120. }
  121. /// <summary>
  122. /// Returns an enumerator that iterates through the <see cref="MySqlParameterCollection"/>.
  123. /// </summary>
  124. /// <returns></returns>
  125. public override IEnumerator GetEnumerator()
  126. {
  127. return items.GetEnumerator();
  128. }
  129. /// <summary>
  130. /// Inserts a MySqlParameter into the collection at the specified index.
  131. /// </summary>
  132. /// <param name="index"></param>
  133. /// <param name="value"></param>
  134. public override void Insert(int index, object value)
  135. {
  136. MySqlParameter parameter = value as MySqlParameter;
  137. if (parameter == null)
  138. throw new MySqlException("Only MySqlParameter objects may be stored");
  139. InternalAdd(parameter, index);
  140. }
  141. /// <summary>
  142. /// Gets a value that indicates whether the <see cref="MySqlParameterCollection"/>
  143. /// has a fixed size.
  144. /// </summary>
  145. public override bool IsFixedSize
  146. {
  147. get { return (items as IList).IsFixedSize; }
  148. }
  149. /// <summary>
  150. /// Gets a value that indicates whether the <see cref="MySqlParameterCollection"/>
  151. /// is read-only.
  152. /// </summary>
  153. public override bool IsReadOnly
  154. {
  155. get { return (items as IList).IsReadOnly; }
  156. }
  157. /// <summary>
  158. /// Gets a value that indicates whether the <see cref="MySqlParameterCollection"/>
  159. /// is synchronized.
  160. /// </summary>
  161. public override bool IsSynchronized
  162. {
  163. get { return (items as IList).IsSynchronized; }
  164. }
  165. /// <summary>
  166. /// Removes the specified MySqlParameter from the collection.
  167. /// </summary>
  168. /// <param name="value"></param>
  169. public override void Remove(object value)
  170. {
  171. MySqlParameter p = (value as MySqlParameter);
  172. p.Collection = null;
  173. int index = IndexOf(p);
  174. items.Remove(p);
  175. indexHashCS.Remove(p.ParameterName);
  176. indexHashCI.Remove(p.ParameterName);
  177. AdjustHashes(index, false);
  178. }
  179. /// <summary>
  180. /// Removes the specified <see cref="MySqlParameter"/> from the collection using the parameter name.
  181. /// </summary>
  182. /// <param name="parameterName">The name of the <see cref="MySqlParameter"/> object to retrieve. </param>
  183. public override void RemoveAt(string parameterName)
  184. {
  185. DbParameter p = GetParameter(parameterName);
  186. Remove(p);
  187. }
  188. /// <summary>
  189. /// Removes the specified <see cref="MySqlParameter"/> from the collection using a specific index.
  190. /// </summary>
  191. /// <param name="index">The zero-based index of the parameter. </param>
  192. /// <overloads>Removes the specified <see cref="MySqlParameter"/> from the collection.</overloads>
  193. public override void RemoveAt(int index)
  194. {
  195. object o = items[index];
  196. Remove(o);
  197. }
  198. /// <summary>
  199. /// Gets an object that can be used to synchronize access to the
  200. /// <see cref="MySqlParameterCollection"/>.
  201. /// </summary>
  202. public override object SyncRoot
  203. {
  204. get { return (items as IList).SyncRoot; }
  205. }
  206. #endregion
  207. }
  208. }
  209. #endif