2 // System.Data.ProviderBase.AbstractDbParameter
5 // Konstantin Triger <kostat@mainsoft.com>
6 // Boris Kirzner <borisk@mainsoft.com>
8 // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 using System
.Data
.Common
;
39 namespace System
.Data
.ProviderBase
41 public abstract class AbstractDbParameter
: DbParameter
, IDbDataParameter
, ICloneable
47 protected DataRowVersion _sourceVersion
;
48 private int _jdbcType
;
51 object _convertedValue
;
53 string _parameterName
;
54 ParameterDirection _direction
= ParameterDirection
.Input
;
60 DbParameterCollection _parent
= null;
67 protected AbstractDbParameter ()
71 #endregion // Constructors
75 public override ParameterDirection Direction
{
76 get { return _direction; }
78 if (_direction
!= value) {
80 case ParameterDirection
.Input
:
81 case ParameterDirection
.Output
:
82 case ParameterDirection
.InputOutput
:
83 case ParameterDirection
.ReturnValue
:
89 throw ExceptionHelper
.InvalidParameterDirection (value);
94 public override bool IsNullable
{
95 get { return _isNullable; }
96 set { _isNullable = value; }
100 public virtual int Offset
{
101 get { return _offset; }
102 set { _offset = value; }
105 public override string ParameterName
{
107 if (_parameterName
== null)
110 return _parameterName
;
113 if (_parameterName
!= value) {
114 _parameterName
= value;
119 public override int Size
{
120 get { return _size; }
123 if (_size
!= value) {
125 throw ExceptionHelper
.InvalidSizeValue (value);
133 public override string SourceColumn
{
135 if (_sourceColumn
== null)
138 return _sourceColumn
;
141 set { _sourceColumn = value; }
144 internal DbParameterCollection Parent
146 get { return _parent; }
147 set { _parent = value; }
150 public byte Precision
152 get { return _precision; }
153 set { _precision = value; }
158 get { return _scale; }
159 set { _scale = value; }
162 public override DataRowVersion SourceVersion
164 get { return _sourceVersion; }
165 set { _sourceVersion = value; }
168 protected internal int JdbcType
171 if (!IsJdbcTypeSet
) {
172 return JdbcTypeFromProviderType();
178 IsJdbcTypeSet
= true;
182 protected internal bool IsJdbcTypeSet
185 return _isJdbcTypeSet
;
189 _isJdbcTypeSet
= value;
193 protected internal bool IsDbTypeSet
195 get { return _isDbTypeSet; }
196 set { _isDbTypeSet = value; }
199 protected internal virtual bool IsSpecial
{
205 private bool IsFixedLength
208 return ((DbType
!= DbType
.AnsiString
) && (DbType
!= DbType
.Binary
) &&
209 (DbType
!= DbType
.String
) && (DbType
!= DbType
.VarNumeric
));
213 protected internal virtual string Placeholder
{
219 internal object ConvertedValue
222 if (_convertedValue
== null) {
223 object value = Value
;
224 _convertedValue
= ((value != null) && (value != DBNull
.Value
)) ? ConvertValue(value) : value;
226 return _convertedValue
;
230 public override object Value
{
231 get { return _value; }
233 _convertedValue
= null;
238 //DbParameter overrides
240 public override bool SourceColumnNullMapping
{
242 throw new NotImplementedException();
245 throw new NotImplementedException();
250 #endregion // Properties
254 public override String
ToString()
256 return ParameterName
;
259 protected internal abstract void SetParameterName(ResultSet res
);
261 protected internal abstract void SetParameterDbType(ResultSet res
);
263 protected internal abstract void SetSpecialFeatures(ResultSet res
);
265 public virtual object Clone()
267 AbstractDbParameter other
= (AbstractDbParameter
) MemberwiseClone ();
268 other
._parent
= null;
272 protected internal abstract int JdbcTypeFromProviderType();
274 protected internal abstract object ConvertValue(object value);
276 internal void SetParameterPrecisionAndScale(ResultSet res
)
278 int jdbcType
= res
.getInt("DATA_TYPE");
279 if(jdbcType
== java
.sql
.Types
.DECIMAL
|| jdbcType
== java
.sql
.Types
.NUMERIC
) {
280 Precision
= (byte)res
.getInt("PRECISION");
281 Scale
= (byte)res
.getInt("SCALE");
285 internal void SetParameterSize(ResultSet res
)
287 Size
= res
.getInt("LENGTH");
290 internal void SetParameterIsNullable(ResultSet res
)
292 IsNullable
= (res
.getInt("NULLABLE") == 1);
295 internal void Validate()
297 if (!IsFixedLength
&& ((Direction
& ParameterDirection
.Output
) != 0) && (Size
== 0)) {
298 throw ExceptionHelper
.ParameterSizeNotInitialized(Offset
,ParameterName
,DbType
.ToString(),Size
);
302 //DbParameter overrides
304 public override void ResetDbType() {
305 throw new NotImplementedException();
308 #endregion // Methods