2 // System.Data.OleDb.OleDbParameter
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.
36 using System
.Data
.Common
;
37 using System
.Data
.ProviderBase
;
41 using System
.Globalization
;
43 namespace System
.Data
.OleDb
45 public sealed class OleDbParameter
: AbstractDbParameter
50 private OleDbType _oleDbType
= OleDbType
.VarWChar
;
51 private bool _isOracleRefCursor
= false;
57 public OleDbParameter()
61 public OleDbParameter(String parameterName
, Object
value)
62 : this (parameterName
, OleDbType
.VarWChar
, 0, ParameterDirection
.Input
,
63 false, 0, 0, String
.Empty
, DataRowVersion
.Current
, value)
68 public OleDbParameter(String parameterName
, OleDbType dbType
)
69 : this (parameterName
, dbType
, 0, ParameterDirection
.Input
,
70 false, 0, 0, String
.Empty
, DataRowVersion
.Current
, null)
74 public OleDbParameter(String parameterName
, OleDbType dbType
, int size
)
75 : this (parameterName
, dbType
, size
, ParameterDirection
.Input
,
76 false, 0, 0, String
.Empty
, DataRowVersion
.Current
, null)
80 public OleDbParameter(String parameterName
, OleDbType dbType
, int size
,
82 : this (parameterName
, dbType
, size
, ParameterDirection
.Input
,
83 false, 0, 0, sourceColumn
, DataRowVersion
.Current
, null)
88 public OleDbParameter(String parameterName
,
91 ParameterDirection direction
,
96 DataRowVersion sourceVersion
,
99 ParameterName
= parameterName
;
102 Direction
= direction
;
103 IsNullable
= isNullable
;
104 Precision
= precision
;
106 SourceColumn
= sourceColumn
;
107 SourceVersion
= sourceVersion
;
111 #endregion // Constructors
115 public override DbType DbType
117 get { return OleDbConvert.OleDbTypeToDbType(_oleDbType); }
118 set { OleDbType = OleDbConvert.DbTypeToOleDbType(value); }
121 public OleDbType OleDbType
123 get { return _oleDbType; }
131 public new byte Precision
133 get { return base.Precision; }
134 set { base.Precision = value; }
137 public new byte Scale
139 get { return base.Scale; }
140 set { base.Scale = value; }
144 public new Object Value
146 get { return base.Value; }
148 if (!IsDbTypeSet
&& (value != null) && (value != DBNull
.Value
)) {
149 _oleDbType
= OleDbConvert
.ValueTypeToOleDbType(value.GetType());
155 protected internal sealed override bool IsSpecial
{
157 return (Direction
== ParameterDirection
.Output
) && IsOracleRefCursor
;
162 internal bool IsOracleRefCursor
164 get { return _isOracleRefCursor; }
165 set { _isOracleRefCursor = value; }
168 #endregion // Properties
172 protected internal sealed override object ConvertValue(object value)
174 // can not convert null or DbNull to other types
175 if (value == null || value == DBNull
.Value
) {
179 // FIXME : some other way to do this?
180 if (OleDbType
== OleDbType
.Binary
) {
183 // .NET throws an exception to the user.
184 object convertedValue
= value;
186 // note : if we set user parameter jdbc type inside prepare interbal, the db type is not set
187 if (value is IConvertible
&& (IsDbTypeSet
|| IsJdbcTypeSet
)) {
188 OleDbType oleDbType
= (IsDbTypeSet
) ? OleDbType
: OleDbConvert
.JdbcTypeToOleDbType((int)JdbcType
);
189 Type to
= OleDbConvert
.OleDbTypeToValueType(oleDbType
);
190 if (!(value is DateTime
&& to
== DbTypes
.TypeOfTimespan
)) //anyway will go by jdbc type
191 convertedValue
= Convert
.ChangeType(value,to
);
193 return convertedValue
;
196 protected internal sealed override void SetParameterName(ResultSet res
)
198 ParameterName
= res
.getString("COLUMN_NAME");
200 if (ParameterName
.StartsWith("@")) {
201 ParameterName
= ParameterName
.Remove(0,1);
205 protected internal sealed override void SetParameterDbType(ResultSet res
)
207 int jdbcType
= res
.getInt("DATA_TYPE");
208 // FIXME : is that correct?
209 if (jdbcType
== Types
.OTHER
) {
210 string typeName
= res
.getString("TYPE_NAME");
211 if (String
.Compare ("BLOB", typeName
, true, CultureInfo
.InvariantCulture
) == 0) {
212 jdbcType
= Types
.BLOB
;
214 else if (String
.Compare ("CLOB", typeName
, true, CultureInfo
.InvariantCulture
) == 0) {
215 jdbcType
= Types
.CLOB
;
217 else if (String
.Compare ("FLOAT", typeName
, true, CultureInfo
.InvariantCulture
) == 0) {
218 jdbcType
= Types
.FLOAT
;
220 else if (String
.Compare ("NVARCHAR2", typeName
, true, CultureInfo
.InvariantCulture
) == 0) {
221 jdbcType
= Types
.VARCHAR
;
223 else if (String
.Compare ("NCHAR", typeName
, true, CultureInfo
.InvariantCulture
) == 0) {
224 jdbcType
= Types
.VARCHAR
;
227 OleDbType
= OleDbConvert
.JdbcTypeToOleDbType(jdbcType
);
232 public void ResetOleDbType ()
237 public override void ResetDbType ()
243 protected internal sealed override void SetSpecialFeatures(ResultSet res
)
245 IsOracleRefCursor
= (res
.getString("TYPE_NAME") == "REF CURSOR");
248 protected internal sealed override int JdbcTypeFromProviderType()
250 return OleDbConvert
.OleDbTypeToJdbcType(OleDbType
);
253 #endregion // Methods