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)
94 public SqlParameter (
\r
95 string parameterName,
\r
98 ParameterDirection direction,
\r
101 string sourceColumn,
\r
102 DataRowVersion sourceVersion,
\r
103 bool sourceColumnNullMapping,
\r
105 string xmlSchemaCollectionDatabase,
\r
106 string xmlSchemaCollectionOwningSchema,
\r
107 string xmlSchemaCollectionName
\r
108 ) : this (parameterName, dbType, size, direction, sourceColumnNullMapping, precision, scale, sourceColumn, sourceVersion, value, true)
\r
114 String parameterName,
117 ParameterDirection direction,
122 DataRowVersion sourceVersion,
126 ParameterName = parameterName;
129 Direction = direction;
130 IsNullable = isNullable;
131 Precision = precision;
133 SourceColumn = sourceColumn;
134 SourceVersion = sourceVersion;
135 if (!dbTypeExplicit) {
141 #endregion // Constructors
145 public override DbType DbType
\r
147 get { return SqlConvert.SqlDbTypeToDbType(_sqlDbType); }
\r
148 set { SqlDbType = SqlConvert.DbTypeToSqlDbType(value); }
\r
151 public SqlDbType SqlDbType
\r
153 get { return _sqlDbType; }
\r
155 _sqlDbType = value;
\r
156 IsDbTypeSet = true;
\r
160 public override int Size
163 int retVal = base.Size;
168 throw ExceptionHelper.InvalidSizeValue(value);
181 public new byte Precision
183 get { return base.Precision; }
\r
184 set { base.Precision = value; }
187 public new byte Scale
189 get { return base.Scale; }
\r
190 set { base.Scale = value; }
194 protected internal override string Placeholder {
\r
196 if (ParameterName.Length == 0 || ParameterName[0] == '@')
197 return ParameterName;
199 return String.Concat("@", ParameterName);
204 public override Object Value
206 get { return base.Value; }
208 if (!IsDbTypeSet && (value != null) && (value != DBNull.Value)) {
\r
209 _sqlDbType = SqlConvert.ValueTypeToSqlDbType(value.GetType());
\r
215 #endregion // Properties
219 protected internal sealed override object ConvertValue(object value)
\r
221 // can not convert null or DbNull to other types
\r
222 if (value == null || value == DBNull.Value) {
\r
225 // .NET throws an exception to the user.
\r
226 object convertedValue = Convert.ChangeType(value,SqlConvert.SqlDbTypeToValueType(SqlDbType));
\r
227 return convertedValue;
\r
230 protected internal sealed override void SetParameterName(ResultSet res)
\r
232 string name = res.getString("COLUMN_NAME");
\r
233 if (name != null && name.Length > 0 && name[0] != '@')
\r
234 name = String.Concat("@", name);
\r
235 ParameterName = name;
\r
238 protected internal sealed override void SetParameterDbType(ResultSet res)
\r
240 int dataType = res.getInt("DATA_TYPE");
\r
241 SqlDbType = SqlConvert.JdbcTypeToSqlDbType(dataType);
\r
242 JdbcType = dataType;
\r
245 protected internal sealed override void SetSpecialFeatures(ResultSet res)
\r
250 protected internal sealed override int JdbcTypeFromProviderType()
\r
252 return SqlConvert.SqlDbTypeToJdbcType(SqlDbType);
\r
255 #endregion // Methods
\r