[System.Net] Add support for .pac proxy config scripts on mac
[mono.git] / mcs / class / System.Data / System.Data.ProviderBase / DbParameterBase.cs
1 //
2 // System.Data.ProviderBase.DbParameterBase
3 //
4 // Author:
5 //   Sureshkumar T (tsureshkumar@novell.com)
6 //   Tim Coleman (tim@timcoleman.com)
7 //   Boris Kirzner <borisk@mainsoft.com>
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
35 #if NET_2_0 || TARGET_JVM
36
37 using System.Data.Common;
38
39 namespace System.Data.ProviderBase {
40         public abstract class DbParameterBase : DbParameter
41         {
42                 #region Fields
43                 string _parameterName;
44                 ParameterDirection _direction = ParameterDirection.Input;
45                 int _size;
46 #if NET_2_0
47                 byte _precision;
48                 byte _scale;
49                 DataRowVersion _sourceVersion;
50 #endif
51                 object _value;
52                 bool _isNullable;
53                 int _offset;
54                 string _sourceColumn;
55                 DbParameterCollection _parent = null;
56
57                 #endregion // Fields
58
59                 #region Constructors
60         
61                 [MonoTODO]
62                 protected DbParameterBase ()
63                 {
64                 }
65
66                 protected DbParameterBase (DbParameterBase source)
67                 {
68                         if (source == null) 
69                                 throw ExceptionHelper.ArgumentNull ("source");
70
71                         source.CopyTo (this);
72                         ICloneable cloneable = source._value as ICloneable;
73                         if (cloneable != null)
74                                 _value = cloneable.Clone ();
75                 }
76         
77                 #endregion // Constructors
78
79                 #region Properties
80
81                 [MonoTODO]
82                 protected object CoercedValue {
83                         get { throw new NotImplementedException (); }
84                 }
85
86                 public override ParameterDirection Direction {
87                         get { return _direction; }
88                         set {
89                                 if (_direction != value) {
90                                         switch (value) {
91                                                         case ParameterDirection.Input:
92                                                         case ParameterDirection.Output:
93                                                         case ParameterDirection.InputOutput:
94                                                         case ParameterDirection.ReturnValue:
95                                                         {
96                                                                 PropertyChanging ();
97                                                                 _direction = value;
98                                                                 return;
99                                                         }
100                                         }
101                                         throw ExceptionHelper.InvalidParameterDirection (value);
102                                 }
103                         }
104                 }
105
106                 public override bool IsNullable {
107                         get { return _isNullable; }
108                         set { _isNullable = value; }
109                 }
110
111                 
112                 public virtual int Offset {
113                         get { return _offset; }
114                         set { _offset = value; }                        
115                 }
116
117                 public override string ParameterName {
118                         get {
119                                 if (_parameterName == null)
120                                                 return String.Empty;
121
122                                 return _parameterName;
123                         }
124                         set {
125                                 if (_parameterName != value) {
126                                         PropertyChanging ();
127                                         _parameterName = value;
128                                 }
129                         }
130                 }
131
132                 public override int Size {
133                         get { return _size; }
134
135                         set {
136                                 if (_size != value) {
137                                         if (value < -1)
138                                                 throw ExceptionHelper.InvalidSizeValue (value);
139
140                                         PropertyChanging ();
141                                         _size = value;
142                                 }
143                         }
144                 }
145
146                 
147                 public override string SourceColumn {
148                         get { 
149                                 if (_sourceColumn == null)
150                                         return String.Empty;
151
152                                 return _sourceColumn;
153                         }
154
155                         set     { _sourceColumn = value; }
156                 }
157
158 #if NET_2_0             
159                 public override DataRowVersion SourceVersion {
160                         get { return _sourceVersion; }
161                         set { _sourceVersion = value; }
162                 }
163 #endif          
164
165                 
166                 public override object Value {
167                         get { return _value; }
168                         set { _value = value; }
169                 }
170
171                 internal DbParameterCollection Parent
172                 {
173                         get { return _parent; }
174                         set { _parent = value; }
175                 }
176
177                 #endregion // Properties
178
179                 #region Methods
180
181                 [MonoTODO]
182                 public virtual void CopyTo (DbParameter destination)
183                 {
184                         if (destination == null)
185                                 throw ExceptionHelper.ArgumentNull ("destination");
186
187                         DbParameterBase t = (DbParameterBase)destination;
188                         t._parameterName = _parameterName;                      
189                         t._size = _size;
190                         t._offset = _offset;
191                         t._isNullable = _isNullable;
192                         t._sourceColumn = _sourceColumn;
193                         t._direction = _direction;
194
195                         if (_value is ICloneable)
196                 t._value = ((ICloneable) _value).Clone ();
197             else
198                 t._value = this._value;
199                 }               
200
201                 public virtual void PropertyChanging ()
202                 {
203                 }
204
205 #if NET_2_0
206
207                 [MonoTODO]
208                 protected void ResetCoercedValue ()
209                 {
210                         throw new NotImplementedException ();
211                 }
212
213                 [MonoTODO]
214                 protected void ResetScale ()
215                 {
216                         throw new NotImplementedException ();
217                 }
218
219                 [MonoTODO]
220                 protected void SetCoercedValue ()
221                 {
222                         throw new NotImplementedException ();
223                 }
224
225                 [MonoTODO]
226                 protected bool ShouldSerializePrecision ()
227                 {
228                         throw new NotImplementedException ();
229                 }
230
231                 [MonoTODO]
232                 protected bool ShouldSerializeScale ()
233                 {
234                         throw new NotImplementedException ();
235                 }
236 #endif  
237         
238                 protected bool ShouldSerializeSize ()
239                 {
240                         return (_size != 0);
241                 }
242
243 #if NET_2_0
244                 [MonoTODO]
245                 public override string ToString ()
246                 {
247                         throw new NotImplementedException ();
248                 }
249
250                 [MonoTODO]
251                 protected virtual byte ValuePrecision (object value)
252                 {
253                         throw new NotImplementedException ();
254                 }
255
256                 [MonoTODO]
257                 protected virtual byte ValueScale (object value)
258                 {
259                         throw new NotImplementedException ();
260                 }
261
262                 [MonoTODO]
263                 protected virtual int ValueSize (object value)
264                 {
265                         throw new NotImplementedException ();
266                 }
267 #endif
268
269                 #endregion // Methods
270         }
271 }
272
273 #endif