public void ConstructorsTest()
		{
			FbParameter ctor01 = new FbParameter();
			FbParameter ctor02 = new FbParameter("ctor2", 10);
			FbParameter ctor03 = new FbParameter("ctor3", FbDbType.Char);
			FbParameter ctor04 = new FbParameter("ctor4", FbDbType.Integer, 4);
			FbParameter ctor05 = new FbParameter("ctor5", FbDbType.Integer, 4, "int_field");
			FbParameter ctor06 = new FbParameter(
				"ctor6", 
				FbDbType.Integer, 
				4, 
				ParameterDirection.Input, 
				false, 
				0, 
				0, 
				"int_field", 
				DataRowVersion.Original, 
				100);

            ctor01 = null;
            ctor02 = null;
            ctor03 = null;
            ctor04 = null;
            ctor05 = null;
            ctor06 = null;
		}
		override internal IDataParameter CreateIDataParameter(string name, object value)
		{
			FbParameter p = new FbParameter();
			p.ParameterName = name;
			p.Value = value;
			return p;
		}
        public void CloneTest()
        {
            FbParameter p = new FbParameter("@p1", FbDbType.Integer);
            p.Value = 1;
            p.Charset = FbCharset.Dos850;

            FbParameter p1 = ((ICloneable)p).Clone() as FbParameter;

            Assert.AreEqual(p1.ParameterName, p.ParameterName);
            Assert.AreEqual(p1.FbDbType     , p.FbDbType);
            Assert.AreEqual(p1.DbType       , p.DbType);
            Assert.AreEqual(p1.Direction    , p.Direction);
            Assert.AreEqual(p1.SourceColumn , p.SourceColumn);
            Assert.AreEqual(p1.SourceVersion, p.SourceVersion);
            Assert.AreEqual(p1.Charset      , p.Charset);
            Assert.AreEqual(p1.IsNullable   , p.IsNullable);
            Assert.AreEqual(p1.Size         , p.Size);
            Assert.AreEqual(p1.Scale        , p.Scale);
            Assert.AreEqual(p1.Precision    , p.Precision);
            Assert.AreEqual(p1.Value        , p.Value);
        }
		object ICloneable.Clone()
		{
			FbParameter p = new FbParameter(
				this.parameterName,
				this.fbType,
				this.size,
				this.direction,
				this.isNullable,
				this.precision,
				this.scale,
				this.sourceColumn,
				this.sourceVersion,
				this.value);

			// Set extra properties
			p.Charset = this.charset;

			return p;
		}
Exemple #5
0
        internal override IDbCommand _LoadFromRawSql(string rawSql, params object[] parameters)
        {
            int i = 0;
            string token  = "";
            string sIndex = "";
            string param  = "";

            FbCommand cmd = new FbCommand();

            foreach(object o in parameters)
            {
                sIndex = i.ToString();
                token = '{' + sIndex + '}';
                param = "@p" + sIndex;

                rawSql = rawSql.Replace(token, param);

                FbParameter p = new FbParameter(param, o);
                cmd.Parameters.Add(p);
                i++;
            }

            cmd.CommandText = rawSql;
            return cmd;
        }
		private bool BuildParameterDescriptor(
			Descriptor descriptor, FbParameter parameter, int index)
		{
			Charset charset = this.connection.InnerConnection.Database.Charset;
			FbDbType type = parameter.FbDbType;

			// Check the parameter character set
			if (parameter.Charset != FbCharset.Default)
			{
				int idx = Charset.SupportedCharsets.IndexOf((int)parameter.Charset);
				charset = Charset.SupportedCharsets[idx];
			}
			else
			{
				if (type == FbDbType.Guid)
				{
					charset = Charset.SupportedCharsets["OCTETS"];
				}
			}

			// Set parameter Data Type
			descriptor[index].DataType = 
				(short)TypeHelper.GetFbType((DbDataType)type, parameter.IsNullable);

			// Set parameter Sub Type
			switch (type)
			{
				case FbDbType.Binary:
					descriptor[index].SubType = 0;
					break;

				case FbDbType.Text:
					descriptor[index].SubType = 1;
					break;

				case FbDbType.Guid:
					descriptor[index].SubType = (short)charset.ID;
					break;

				case FbDbType.Char:
				case FbDbType.VarChar:
					descriptor[index].SubType = (short)charset.ID;
					if (parameter.Size > 0)
					{
						short len = (short)(parameter.Size * charset.BytesPerCharacter);
						descriptor[index].Length = len;
					}
					break;
			}

			// Set parameter length
			if (descriptor[index].Length == 0)
			{
				descriptor[index].Length = TypeHelper.GetSize((DbDataType)type);
			}

			// Verify parameter
			if (descriptor[index].SqlType == 0 || descriptor[index].Length == 0)
			{
				return false;
			}

			return true;
		}
		/// <include file='Doc/en_EN/FbParameterCollection.xml'	path='doc/class[@name="FbParameterCollection"]/method[@name="Add(FbParameter)"]/*'/>
		public FbParameter Add(FbParameter value)
		{
			lock (this.parameters.SyncRoot)
			{
				if (value == null)
				{
					throw new ArgumentException("The value parameter is null.");
				}
				if (value.Parent != null)
				{
					throw new ArgumentException("The FbParameter specified in the value parameter is already added to this or another FbParameterCollection.");
				}
				if (value.ParameterName == null ||
					value.ParameterName.Length == 0)
				{
					value.ParameterName = this.GenerateParameterName();
				}
				else
				{
					if (this.IndexOf(value) != -1)
					{
						throw new ArgumentException("FbParameterCollection already contains FbParameter with ParameterName '" + value.ParameterName + "'.");
					}
				}

				this.parameters.Add(value);

				return value;
			}
		}
		/// <include file='Doc/en_EN/FbParameterCollection.xml'	path='doc/class[@name="FbParameterCollection"]/method[@name="Add(System.String,FbDbType,System.Int32,System.String)"]/*'/>
		public FbParameter Add(
			string parameterName, FbDbType fbType, int size, string sourceColumn)
		{
			FbParameter param = new FbParameter(parameterName, fbType, size, sourceColumn);

			return this.Add(param);
		}
		/// <include file='Doc/en_EN/FbParameterCollection.xml'	path='doc/class[@name="FbParameterCollection"]/method[@name="Add(System.String,FbDbType)"]/*'/>
		public FbParameter Add(string parameterName, FbDbType type)
		{
			FbParameter param = new FbParameter(parameterName, type);

			return this.Add(param);
		}
		/// <include file='Doc/en_EN/FbParameterCollection.xml'	path='doc/class[@name="FbParameterCollection"]/method[@name="Add(System.String,System.Object)"]/*'/>
		public FbParameter Add(string parameterName, object value)
		{
			FbParameter param = new FbParameter(parameterName, value);

			return this.Add(param);
		}
		private FbParameter CreateParameter(
			DataRow schemaRow, int index, bool isWhereParameter)
		{
			string pname = String.Format(CultureInfo.CurrentCulture, "@p{0}", index + 1);
			FbParameter parameter = new FbParameter(pname, (FbDbType)schemaRow["ProviderType"]);

			parameter.Size = Convert.ToInt32(schemaRow["ColumnSize"], CultureInfo.InvariantCulture);
			if (schemaRow["NumericPrecision"] != DBNull.Value)
			{
				parameter.Precision = Convert.ToByte(schemaRow["NumericPrecision"], CultureInfo.InvariantCulture);
			}
			if (schemaRow["NumericScale"] != DBNull.Value)
			{
				parameter.Scale = Convert.ToByte(schemaRow["NumericScale"], CultureInfo.InvariantCulture);
			}
			parameter.SourceColumn = schemaRow["BaseColumnName"].ToString();
			parameter.IsNullable = Convert.ToBoolean(schemaRow["AllowDbNull"], CultureInfo.InvariantCulture);

			if (isWhereParameter)
			{
				parameter.SourceVersion = DataRowVersion.Original;
			}
			else
			{
				parameter.SourceVersion = DataRowVersion.Current;
			}

			return parameter;
		}