Ejemplo n.º 1
0
		override internal IDataParameter CreateIDataParameter(string name, object value)
		{
			FbParameter p = new FbParameter();
			p.ParameterName = name;
			p.Value = value;
			return p;
		}
		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;
		}
Ejemplo n.º 3
0
        private Descriptor BuildPlaceHoldersDescriptor(short count)
        {
            Descriptor descriptor = new Descriptor(count);
            int        index      = 0;

            for (int i = 0; i < this.parameters.Count; i++)
            {
                FbParameter parameter = this.parameters[i];

                if (parameter.Direction == ParameterDirection.Input ||
                    parameter.Direction == ParameterDirection.InputOutput)
                {
                    if (!this.BuildParameterDescriptor(descriptor, parameter, index++))
                    {
                        return(null);
                    }
                }
            }

            return(descriptor);
        }
        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);
        }
Ejemplo n.º 5
0
		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;
		}
Ejemplo n.º 6
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;
        }
Ejemplo n.º 7
0
        private FbCommand BuildInsertCommand(DataRow row, DataTableMapping tableMapping)
        {
            if (this.commandBuilderBehavior == FbCommandBuilderBehavior.KeyAndTimestampFields &&
                (this.timestampColumnName == null ||
                 this.timestampColumnName.Length == 0))
            {
                throw new InvalidOperationException();
            }

            StringBuilder sql    = new StringBuilder();
            StringBuilder fields = new StringBuilder();
            StringBuilder values = new StringBuilder();

            this.BuildSchemaTable();

            this.CreateCommand(ref this.insertCommand);

            int i = 0;

            foreach (DataRow schemaRow in schemaTable.Rows)
            {
                if (this.IsUpdatable(schemaRow, row, tableMapping))
                {
                    if (fields.Length > 0)
                    {
                        fields.Append(this.separator);
                    }
                    if (values.Length > 0)
                    {
                        values.Append(this.separator);
                    }

                    fields.Append(this.GetQuotedIdentifier(schemaRow["BaseColumnName"]));

                    FbParameter parameter = this.CreateParameter(schemaRow, i, false);

                    values.Append(parameter.ParameterName);

                    if (row != null && tableMapping != null)
                    {
                        DataColumn column = this.GetDataColumn(
                            schemaRow["BaseColumnName"].ToString(),
                            tableMapping,
                            row);

                        if (column != null)
                        {
                            parameter.Value = row[column];
                        }
                    }

                    i++;

                    this.insertCommand.Parameters.Add(parameter);
                }
            }

            sql.AppendFormat(
                CultureInfo.CurrentCulture,
                this.sqlInsert,
                this.GetQuotedIdentifier(tableName),
                fields.ToString(),
                values.ToString());

            this.insertCommand.CommandText = sql.ToString();

            return(this.insertCommand);
        }
Ejemplo n.º 8
0
        /// <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(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;
		}
Ejemplo n.º 14
0
        private FbCommand BuildDeleteCommand(DataRow row, DataTableMapping tableMapping)
        {
            if (this.commandBuilderBehavior == FbCommandBuilderBehavior.KeyAndTimestampFields &&
                (this.timestampColumnName == null ||
                 this.timestampColumnName.Length == 0))
            {
                throw new InvalidOperationException();
            }

            StringBuilder sql = new StringBuilder();

            StringBuilder where = new StringBuilder();

            this.BuildSchemaTable();

            if (!this.hasPrimaryKey)
            {
                throw new InvalidOperationException("Dynamic SQL generation for the DeleteCommand is not supported against a SelectCommand that does not return any key column information.");
            }

            this.CreateCommand(ref this.deleteCommand);

            // Build where clausule
            int i = 0;

            foreach (DataRow schemaRow in schemaTable.Rows)
            {
                if (this.IncludedInWhereClause(schemaRow))
                {
                    if (where.Length > 0)
                    {
                        where.Append(" AND ");
                    }

                    string quotedId = this.GetQuotedIdentifier(schemaRow["BaseColumnName"]);

                    // Create parameters for this field
                    FbParameter parameter = this.CreateParameter(schemaRow, i, true);

                    if ((bool)schemaRow["IsKey"])
                    {
                        where.AppendFormat(
                            CultureInfo.CurrentCulture,
                            whereClausule2,
                            quotedId,
                            parameter.ParameterName);
                    }
                    else
                    {
                        if (this.usingCoalesce)
                        {
                            string typeName = TypeHelper.GetDataTypeName((DbDataType)parameter.FbDbType);

                            switch (typeName)
                            {
                            case "VARCHAR":
                            case "CHAR":
                                typeName = String.Format(
                                    CultureInfo.CurrentCulture,
                                    "{0}({1})",
                                    typeName,
                                    schemaRow["ColumnSize"]);
                                break;

                            case "DECIMAL":
                            case "NUMERIC":
                                typeName = String.Format(
                                    CultureInfo.CurrentCulture,
                                    "{0}({1},{2})",
                                    typeName,
                                    schemaRow["NumericPrecision"],
                                    schemaRow["NumericScale"]);
                                break;
                            }

                            where.AppendFormat(
                                CultureInfo.CurrentCulture,
                                whereClausule1,
                                quotedId,
                                parameter.ParameterName,
                                typeName);
                        }
                        else
                        {
                            where.AppendFormat(
                                CultureInfo.CurrentCulture,
                                whereClausule1,
                                quotedId,
                                parameter.ParameterName);
                        }
                    }

                    if (row != null && tableMapping != null)
                    {
                        DataColumn column = this.GetDataColumn(
                            schemaRow["BaseColumnName"].ToString(),
                            tableMapping,
                            row);

                        if (column != null)
                        {
                            parameter.Value = row[column, DataRowVersion.Original];
                        }
                    }

                    this.deleteCommand.Parameters.Add(parameter);

                    i++;
                }
            }

            sql.AppendFormat(
                CultureInfo.CurrentCulture,
                this.sqlDelete,
                this.GetQuotedIdentifier(tableName),
                where.ToString());

            this.deleteCommand.CommandText = sql.ToString();

            return(this.deleteCommand);
        }
Ejemplo n.º 15
0
        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);
        }
Ejemplo n.º 16
0
        /// <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));
        }
Ejemplo n.º 17
0
		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;
		}
Ejemplo n.º 18
0
        /// <include file='Doc/en_EN/FbParameterCollection.xml'	path='doc/class[@name="FbParameterCollection"]/method[@name="Add(System.String,FbDbType,System.Int32)"]/*'/>
        public FbParameter Add(string parameterName, FbDbType fbType, int size)
        {
            FbParameter param = new FbParameter(parameterName, fbType, size);

            return(this.Add(param));
        }
Ejemplo n.º 19
0
        /// <include file='Doc/en_EN/FbCommandBuilder.xml' path='doc/class[@name="FbCommandBuilder"]/method[@name="DeriveParameters(FbCommand)"]/*'/>
        public static void DeriveParameters(FbCommand command)
        {
            if (command.CommandType != CommandType.StoredProcedure)
            {
                throw new InvalidOperationException("The command text is not a valid stored procedure name.");
            }

            string spName      = command.CommandText.Trim();
            string quotePrefix = "\"";
            string quoteSuffix = "\"";

            if (spName.StartsWith(quotePrefix) && spName.EndsWith(quoteSuffix))
            {
                spName = spName.Substring(1, spName.Length - 2);
            }
            else
            {
                spName = spName.ToUpper(CultureInfo.CurrentCulture);
            }

            command.Parameters.Clear();

            DataView dataTypes = command.Connection.GetSchema("DataTypes").DefaultView;

            DataTable spSchema = command.Connection.GetSchema(
                "ProcedureParameters", new string[] { null, null, spName });

            int count = 1;

            foreach (DataRow row in spSchema.Rows)
            {
                dataTypes.RowFilter = String.Format(
                    CultureInfo.CurrentCulture,
                    "TypeName = '{0}'",
                    row["PARAMETER_DATA_TYPE"]);

                FbParameter parameter = command.Parameters.Add(
                    "@" + row["PARAMETER_NAME"].ToString().Trim(),
                    FbDbType.VarChar);

                parameter.FbDbType = (FbDbType)dataTypes[0]["ProviderDbType"];

                parameter.Direction = (ParameterDirection)row["PARAMETER_DIRECTION"];

                parameter.Size = Convert.ToInt32(row["PARAMETER_SIZE"], CultureInfo.InvariantCulture);

                if (parameter.FbDbType == FbDbType.Decimal ||
                    parameter.FbDbType == FbDbType.Numeric)
                {
                    if (row["NUMERIC_PRECISION"] != DBNull.Value)
                    {
                        parameter.Precision = Convert.ToByte(row["NUMERIC_PRECISION"], CultureInfo.InvariantCulture);
                    }
                    if (row["NUMERIC_SCALE"] != DBNull.Value)
                    {
                        parameter.Scale = Convert.ToByte(row["NUMERIC_SCALE"], CultureInfo.InvariantCulture);
                    }
                }

                count++;
            }
        }