DbParameterBase.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. //
  2. // System.Data.ProviderBase.DbParameterBase
  3. //
  4. // Author:
  5. // Sureshkumar T ([email protected])
  6. // Tim Coleman ([email protected])
  7. // Boris Kirzner <[email protected]>
  8. //
  9. // Copyright (C) Tim Coleman, 2003
  10. //
  11. //
  12. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  13. // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
  14. //
  15. // Permission is hereby granted, free of charge, to any person obtaining
  16. // a copy of this software and associated documentation files (the
  17. // "Software"), to deal in the Software without restriction, including
  18. // without limitation the rights to use, copy, modify, merge, publish,
  19. // distribute, sublicense, and/or sell copies of the Software, and to
  20. // permit persons to whom the Software is furnished to do so, subject to
  21. // the following conditions:
  22. //
  23. // The above copyright notice and this permission notice shall be
  24. // included in all copies or substantial portions of the Software.
  25. //
  26. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  27. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  28. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  29. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  30. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  31. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  32. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  33. //
  34. #if NET_2_0 || TARGET_JVM
  35. using System.Data.Common;
  36. namespace System.Data.ProviderBase {
  37. public abstract class DbParameterBase : DbParameter
  38. {
  39. #region Fields
  40. string _parameterName;
  41. ParameterDirection _direction = ParameterDirection.Input;
  42. int _size;
  43. #if NET_2_0
  44. byte _precision;
  45. byte _scale;
  46. DataRowVersion _sourceVersion;
  47. #endif
  48. object _value;
  49. bool _isNullable;
  50. int _offset;
  51. string _sourceColumn;
  52. DbParameterCollection _parent = null;
  53. #endregion // Fields
  54. #region Constructors
  55. [MonoTODO]
  56. protected DbParameterBase ()
  57. {
  58. }
  59. protected DbParameterBase (DbParameterBase source)
  60. {
  61. if (source == null)
  62. throw ExceptionHelper.ArgumentNull ("source");
  63. source.CopyTo (this);
  64. ICloneable cloneable = source._value as ICloneable;
  65. if (cloneable != null)
  66. _value = cloneable.Clone ();
  67. }
  68. #endregion // Constructors
  69. #region Properties
  70. [MonoTODO]
  71. protected object CoercedValue {
  72. get { throw new NotImplementedException (); }
  73. }
  74. public override ParameterDirection Direction {
  75. get { return _direction; }
  76. set {
  77. if (_direction != value) {
  78. switch (value) {
  79. case ParameterDirection.Input:
  80. case ParameterDirection.Output:
  81. case ParameterDirection.InputOutput:
  82. case ParameterDirection.ReturnValue:
  83. {
  84. PropertyChanging ();
  85. _direction = value;
  86. return;
  87. }
  88. }
  89. throw ExceptionHelper.InvalidParameterDirection (value);
  90. }
  91. }
  92. }
  93. public override bool IsNullable {
  94. get { return _isNullable; }
  95. set { _isNullable = value; }
  96. }
  97. public override int Offset {
  98. get { return _offset; }
  99. set { _offset = value; }
  100. }
  101. public override string ParameterName {
  102. get {
  103. if (_parameterName == null)
  104. return String.Empty;
  105. return _parameterName;
  106. }
  107. set {
  108. if (_parameterName != value) {
  109. PropertyChanging ();
  110. _parameterName = value;
  111. }
  112. }
  113. }
  114. #if NET_2_0
  115. public override byte Precision {
  116. get { return _precision; }
  117. set { _precision = value; }
  118. }
  119. public override byte Scale {
  120. get { return _scale; }
  121. set { _scale = value; }
  122. }
  123. #endif
  124. public override int Size {
  125. get { return _size; }
  126. set {
  127. if (_size != value) {
  128. if (value < -1)
  129. throw ExceptionHelper.InvalidSizeValue (value);
  130. PropertyChanging ();
  131. _size = value;
  132. }
  133. }
  134. }
  135. public override string SourceColumn {
  136. get {
  137. if (_sourceColumn == null)
  138. return String.Empty;
  139. return _sourceColumn;
  140. }
  141. set { _sourceColumn = value; }
  142. }
  143. #if NET_2_0
  144. public override DataRowVersion SourceVersion {
  145. get { return _sourceVersion; }
  146. set { _sourceVersion = value; }
  147. }
  148. #endif
  149. public override object Value {
  150. get { return _value; }
  151. set { _value = value; }
  152. }
  153. internal DbParameterCollection Parent
  154. {
  155. get { return _parent; }
  156. set { _parent = value; }
  157. }
  158. #endregion // Properties
  159. #region Methods
  160. [MonoTODO]
  161. public override void CopyTo (DbParameter destination)
  162. {
  163. if (destination == null)
  164. throw ExceptionHelper.ArgumentNull ("destination");
  165. DbParameterBase t = (DbParameterBase)destination;
  166. t._parameterName = _parameterName;
  167. t._size = _size;
  168. t._offset = _offset;
  169. t._isNullable = _isNullable;
  170. t._sourceColumn = _sourceColumn;
  171. t._direction = _direction;
  172. if (_value is ICloneable)
  173. t._value = ((ICloneable) _value).Clone ();
  174. else
  175. t._value = this._value;
  176. }
  177. public virtual void PropertyChanging ()
  178. {
  179. }
  180. #if NET_2_0
  181. [MonoTODO]
  182. protected void ResetCoercedValue ()
  183. {
  184. throw new NotImplementedException ();
  185. }
  186. [MonoTODO]
  187. protected void ResetScale ()
  188. {
  189. throw new NotImplementedException ();
  190. }
  191. [MonoTODO]
  192. protected void SetCoercedValue ()
  193. {
  194. throw new NotImplementedException ();
  195. }
  196. [MonoTODO]
  197. protected bool ShouldSerializePrecision ()
  198. {
  199. throw new NotImplementedException ();
  200. }
  201. [MonoTODO]
  202. protected bool ShouldSerializeScale ()
  203. {
  204. throw new NotImplementedException ();
  205. }
  206. #endif
  207. protected bool ShouldSerializeSize ()
  208. {
  209. return (_size != 0);
  210. }
  211. #if NET_2_0
  212. [MonoTODO]
  213. public override string ToString ()
  214. {
  215. throw new NotImplementedException ();
  216. }
  217. [MonoTODO]
  218. protected virtual byte ValuePrecision (object value)
  219. {
  220. throw new NotImplementedException ();
  221. }
  222. [MonoTODO]
  223. protected virtual byte ValueScale (object value)
  224. {
  225. throw new NotImplementedException ();
  226. }
  227. [MonoTODO]
  228. protected virtual int ValueSize (object value)
  229. {
  230. throw new NotImplementedException ();
  231. }
  232. #endif
  233. #endregion // Methods
  234. }
  235. }
  236. #endif