[Cleanup] Removed JavaEE csproj and sln files
[mono-project.git] / mcs / class / System.Data / System.Data.ProviderBase.jvm / AbstractDBParameter.cs
blob17a4601268b8c120fddc488a564be59fb5b28393
1 //
2 // System.Data.ProviderBase.AbstractDbParameter
3 //
4 // Authors:
5 // Konstantin Triger <kostat@mainsoft.com>
6 // Boris Kirzner <borisk@mainsoft.com>
7 //
8 // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
9 //
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:
19 //
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 //
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.
33 using System;
34 using System.Data;
35 using System.Data.Common;
37 using java.sql;
39 namespace System.Data.ProviderBase
41 public abstract class AbstractDbParameter : DbParameter, IDbDataParameter, ICloneable
43 #region Fields
45 byte _precision;
46 byte _scale;
47 protected DataRowVersion _sourceVersion;
48 private int _jdbcType;
49 bool _isDbTypeSet;
50 bool _isJdbcTypeSet;
51 object _convertedValue;
53 string _parameterName;
54 ParameterDirection _direction = ParameterDirection.Input;
55 int _size;
56 object _value;
57 bool _isNullable;
58 int _offset;
59 string _sourceColumn;
60 DbParameterCollection _parent = null;
62 #endregion // Fields
64 #region Constructors
66 [MonoTODO]
67 protected AbstractDbParameter ()
71 #endregion // Constructors
73 #region Properties
75 public override ParameterDirection Direction {
76 get { return _direction; }
77 set {
78 if (_direction != value) {
79 switch (value) {
80 case ParameterDirection.Input:
81 case ParameterDirection.Output:
82 case ParameterDirection.InputOutput:
83 case ParameterDirection.ReturnValue:
85 _direction = value;
86 return;
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 {
106 get {
107 if (_parameterName == null)
108 return String.Empty;
110 return _parameterName;
112 set {
113 if (_parameterName != value) {
114 _parameterName = value;
119 public override int Size {
120 get { return _size; }
122 set {
123 if (_size != value) {
124 if (value < -1)
125 throw ExceptionHelper.InvalidSizeValue (value);
127 _size = value;
133 public override string SourceColumn {
134 get {
135 if (_sourceColumn == null)
136 return String.Empty;
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; }
156 public byte Scale
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
170 get {
171 if (!IsJdbcTypeSet) {
172 return JdbcTypeFromProviderType();
174 return _jdbcType;
176 set {
177 _jdbcType = value;
178 IsJdbcTypeSet = true;
182 protected internal bool IsJdbcTypeSet
184 get {
185 return _isJdbcTypeSet;
188 set {
189 _isJdbcTypeSet = value;
193 protected internal bool IsDbTypeSet
195 get { return _isDbTypeSet; }
196 set { _isDbTypeSet = value; }
199 protected internal virtual bool IsSpecial {
200 get {
201 return false;
205 private bool IsFixedLength
207 get {
208 return ((DbType != DbType.AnsiString) && (DbType != DbType.Binary) &&
209 (DbType != DbType.String) && (DbType != DbType.VarNumeric));
213 protected internal virtual string Placeholder {
214 get {
215 return "?";
219 internal object ConvertedValue
221 get {
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; }
232 set {
233 _convertedValue = null;
234 _value = value;
238 //DbParameter overrides
240 public override bool SourceColumnNullMapping {
241 get {
242 throw new NotImplementedException();
244 set {
245 throw new NotImplementedException();
250 #endregion // Properties
252 #region Methods
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;
269 return other;
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