| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- //
- // System.Data.SqlClient.SqlParameter.cs
- //
- // Author:
- // Rodrigo Moya ([email protected])
- // Daniel Morgan ([email protected])
- // Tim Coleman ([email protected])
- //
- // (C) Ximian, Inc. 2002
- // Copyright (C) Tim Coleman, 2002
- //
- using System;
- using System.ComponentModel;
- using System.Data;
- using System.Data.Common;
- using System.Runtime.InteropServices;
- using System.Text;
- namespace System.Data.SqlClient {
- /// <summary>
- /// Represents a parameter to a Command object, and optionally,
- /// its mapping to DataSet columns; and is implemented by .NET
- /// data providers that access data sources.
- /// </summary>
- public sealed class SqlParameter : MarshalByRefObject, IDbDataParameter, IDataParameter, ICloneable
- {
- #region Fields
- string parmName;
- SqlDbType dbtype;
- DbType theDbType;
- object objValue;
- int size;
- string sourceColumn;
- ParameterDirection direction = ParameterDirection.Input;
- bool isNullable;
- byte precision;
- byte scale;
- DataRowVersion sourceVersion;
- int offset;
- bool sizeSet = false;
- #endregion // Fields
- #region Constructors
- [MonoTODO]
- public SqlParameter ()
- {
- }
- [MonoTODO]
- public SqlParameter (string parameterName, object value)
- {
- this.parmName = parameterName;
- this.objValue = value;
- }
-
- [MonoTODO]
- public SqlParameter (string parameterName, SqlDbType dbType)
- {
- this.parmName = parameterName;
- this.dbtype = dbType;
- }
- [MonoTODO]
- public SqlParameter (string parameterName, SqlDbType dbType, int size)
- {
- this.parmName = parameterName;
- this.dbtype = dbType;
- this.size = size;
- }
-
- [MonoTODO]
- public SqlParameter(string parameterName, SqlDbType dbType, int size, string sourceColumn)
- {
- this.parmName = parameterName;
- this.dbtype = dbType;
- this.size = size;
- this.sourceColumn = sourceColumn;
- }
-
- [MonoTODO]
- public SqlParameter(string parameterName, SqlDbType dbType, int size, ParameterDirection direction, bool isNullable, byte precision, byte scale, string sourceColumn, DataRowVersion sourceVersion, object value)
- {
-
- this.parmName = parameterName;
- this.dbtype = dbType;
- this.size = size;
- this.sourceColumn = sourceColumn;
- this.direction = direction;
- this.isNullable = isNullable;
- this.precision = precision;
- this.scale = scale;
- this.sourceVersion = sourceVersion;
- this.objValue = value;
- }
- #endregion // Constructors
- #region Properties
- [MonoTODO]
- public DbType DbType {
- get { return theDbType; }
- set { theDbType = value; }
- }
- [MonoTODO]
- public ParameterDirection Direction {
- get { return direction; }
- set { direction = value; }
- }
- [MonoTODO]
- public bool IsNullable {
- get { return isNullable; }
- }
- [MonoTODO]
- public int Offset {
- get { return offset; }
- set { offset = value; }
- }
-
- string IDataParameter.ParameterName {
- get { return parmName; }
- set { parmName = value; }
- }
-
- public string ParameterName {
- get { return parmName; }
- set { parmName = value; }
- }
- [MonoTODO]
- public string SourceColumn {
- get { return sourceColumn; }
- set { sourceColumn = value; }
- }
- [MonoTODO]
- public DataRowVersion SourceVersion {
- get { return sourceVersion; }
- set { sourceVersion = value; }
- }
-
- [MonoTODO]
- public SqlDbType SqlDbType {
- get { return dbtype; }
- set { dbtype = value; }
- }
- [MonoTODO]
- public object Value {
- get { return objValue; }
- set { objValue = value; }
- }
- [MonoTODO]
- public byte Precision {
- get { return precision; }
- set { precision = value; }
- }
- [MonoTODO]
- public byte Scale {
- get { return scale; }
- set { scale = value; }
- }
- [MonoTODO]
- public int Size {
- get { return size; }
- set {
- sizeSet = true;
- size = value;
- }
- }
- #endregion // Properties
- #region Methods
- [MonoTODO]
- object ICloneable.Clone ()
- {
- throw new NotImplementedException ();
- }
- internal string Prepare ()
- {
- StringBuilder result = new StringBuilder ();
- result.Append (parmName);
- result.Append (" ");
- result.Append (dbtype.ToString ());
- switch (dbtype) {
- case SqlDbType.Image :
- case SqlDbType.NVarChar :
- case SqlDbType.VarBinary :
- case SqlDbType.VarChar :
- if (!sizeSet || size == 0)
- throw new InvalidOperationException ("All variable length parameters must have an explicitly set non-zero size.");
- result.Append ("(");
- result.Append (size.ToString ());
- result.Append (")");
- break;
- case SqlDbType.Decimal :
- case SqlDbType.Money :
- case SqlDbType.SmallMoney :
- result.Append ("(");
- result.Append (precision.ToString ());
- result.Append (",");
- result.Append (scale.ToString ());
- result.Append (")");
- break;
- default:
- break;
- }
- return result.ToString ();
- }
- public override string ToString()
- {
- return parmName;
- }
- #endregion // Methods
- }
- }
|