2 // System.Data.SqlClient.SqlParameter
\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.
33 using System.Collections;
35 using System.Data.ProviderBase;
36 using System.Data.Common;
40 namespace System.Data.SqlClient
42 public sealed class SqlParameter : AbstractDbParameter
46 private SqlDbType _sqlDbType;
56 public SqlParameter(String parameterName, Object value)
57 : this(parameterName, SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, String.Empty, DataRowVersion.Current, value,false)
61 public SqlParameter(String parameterName, SqlDbType dbType)
62 : this(parameterName, dbType, 0, ParameterDirection.Input, false, 0, 0, String.Empty, DataRowVersion.Current, null, true)
67 public SqlParameter(String parameterName, SqlDbType dbType, int size)
68 : this(parameterName, dbType, size, ParameterDirection.Input, false, 0, 0, String.Empty, DataRowVersion.Current, null, true)
73 public SqlParameter(String parameterName, SqlDbType dbType, int size, String sourceColumn)
74 : this(parameterName, dbType, size, ParameterDirection.Input, false, 0, 0, sourceColumn, DataRowVersion.Current, null, true)
83 ParameterDirection direction,
88 DataRowVersion sourceVersion,
89 Object value) : this(parameterName,dbType,size,direction,isNullable,precision,scale,sourceColumn,sourceVersion,value,true)
97 ParameterDirection direction,
102 DataRowVersion sourceVersion,
106 ParameterName = parameterName;
109 Direction = direction;
110 IsNullable = isNullable;
111 Precision = precision;
113 SourceColumn = sourceColumn;
114 SourceVersion = sourceVersion;
115 if (!dbTypeExplicit) {
121 #endregion // Constructors
125 public override DbType DbType
\r
127 get { return SqlConvert.SqlDbTypeToDbType(_sqlDbType); }
\r
128 set { SqlDbType = SqlConvert.DbTypeToSqlDbType(value); }
\r
131 public SqlDbType SqlDbType
\r
133 get { return _sqlDbType; }
\r
135 _sqlDbType = value;
\r
136 IsDbTypeSet = true;
\r
140 public override int Size
143 int retVal = base.Size;
148 throw ExceptionHelper.InvalidSizeValue(value);
161 public new byte Precision
163 get { return base.Precision; }
\r
164 set { base.Precision = value; }
167 public new byte Scale
169 get { return base.Scale; }
\r
170 set { base.Scale = value; }
174 protected internal override string Placeholder {
\r
176 if (ParameterName.Length == 0 || ParameterName[0] == '@')
177 return ParameterName;
179 return String.Concat("@", ParameterName);
184 public override Object Value
186 get { return base.Value; }
188 if (!IsDbTypeSet && (value != null) && (value != DBNull.Value)) {
\r
189 _sqlDbType = SqlConvert.ValueTypeToSqlDbType(value.GetType());
\r
195 #endregion // Properties
199 protected internal sealed override object ConvertValue(object value)
\r
201 // can not convert null or DbNull to other types
\r
202 if (value == null || value == DBNull.Value) {
\r
205 // .NET throws an exception to the user.
\r
206 object convertedValue = Convert.ChangeType(value,SqlConvert.SqlDbTypeToValueType(SqlDbType));
\r
207 return convertedValue;
\r
210 protected internal sealed override void SetParameterName(ResultSet res)
\r
212 string name = res.getString("COLUMN_NAME");
\r
213 if (name != null && name.Length > 0 && name[0] != '@')
\r
214 name = String.Concat("@", name);
\r
215 ParameterName = name;
\r
218 protected internal sealed override void SetParameterDbType(ResultSet res)
\r
220 int dataType = res.getInt("DATA_TYPE");
\r
221 SqlDbType = SqlConvert.JdbcTypeToSqlDbType(dataType);
\r
222 JdbcType = dataType;
\r
225 protected internal sealed override void SetSpecialFeatures(ResultSet res)
\r
230 protected internal sealed override int JdbcTypeFromProviderType()
\r
232 return SqlConvert.SqlDbTypeToJdbcType(SqlDbType);
\r
235 #endregion // Methods
\r