2 // System.Data.ProviderBase.AbstractDbParameter
\r
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;
\r
39 namespace System.Data.ProviderBase
\r
41 public abstract class AbstractDbParameter : DbParameter, IDbDataParameter, ICloneable
\r
47 protected DataRowVersion _sourceVersion;
\r
48 private int _jdbcType;
\r
50 bool _isJdbcTypeSet;
\r
51 object _convertedValue;
\r
53 string _parameterName;
54 ParameterDirection _direction = ParameterDirection.Input;
60 DbParameterCollection _parent = null;
\r
62 #endregion // Fields
\r
67 protected AbstractDbParameter ()
71 #endregion // Constructors
\r
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; }
\r
153 set { _precision = value; }
158 get { return _scale; }
\r
159 set { _scale = value; }
162 public override DataRowVersion SourceVersion
\r
164 get { return _sourceVersion; }
\r
165 set { _sourceVersion = value; }
\r
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
\r
222 if (_convertedValue == null) {
\r
223 object value = Value;
\r
224 _convertedValue = ((value != null) && (value != DBNull.Value)) ? ConvertValue(value) : value;
\r
226 return _convertedValue;
\r
230 public override object Value {
231 get { return _value; }
233 _convertedValue = null;
238 //DbParameter overrides
240 public override bool SourceColumnNullMapping {
\r
242 throw new NotImplementedException();
\r
245 throw new NotImplementedException();
\r
250 #endregion // Properties
254 public override String ToString()
\r
256 return ParameterName;
\r
259 protected internal abstract void SetParameterName(ResultSet res);
\r
261 protected internal abstract void SetParameterDbType(ResultSet res);
\r
263 protected internal abstract void SetSpecialFeatures(ResultSet res);
265 public virtual object Clone()
267 AbstractDbParameter other = (AbstractDbParameter) MemberwiseClone ();
\r
268 other._parent = null;
\r
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");
\r
279 if(jdbcType == java.sql.Types.DECIMAL || jdbcType == java.sql.Types.NUMERIC) {
\r
280 Precision = (byte)res.getInt("PRECISION");
\r
281 Scale = (byte)res.getInt("SCALE");
\r
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() {
\r
305 throw new NotImplementedException();
\r
308 #endregion // Methods
\r