Example #1
0
        protected override void PrepareParameters()
        {
            // Prepare parameters
            SQLParameter parameter;

            for (int index = 0; index < _parameterIndexes.Length; index++)
            {
                parameter = Parameters[_parameterIndexes[index]];
                OleDbParameter oLEDBParameter = (OleDbParameter)_command.CreateParameter();
                oLEDBParameter.ParameterName = String.Format("@{0}", parameter.Name);
                switch (parameter.Direction)
                {
                case SQLDirection.Out: oLEDBParameter.Direction = System.Data.ParameterDirection.Output; break;

                case SQLDirection.InOut: oLEDBParameter.Direction = System.Data.ParameterDirection.InputOutput; break;

                case SQLDirection.Result: oLEDBParameter.Direction = System.Data.ParameterDirection.ReturnValue; break;

                default: oLEDBParameter.Direction = System.Data.ParameterDirection.Input; break;
                }

                if (parameter.Type is SQLStringType)
                {
                    oLEDBParameter.OleDbType = OleDbType.VarChar;
                    oLEDBParameter.Size      = ((SQLStringType)parameter.Type).Length;
                }
                else if (parameter.Type is SQLBooleanType)
                {
                    oLEDBParameter.OleDbType = OleDbType.Boolean;
                }
                else if (parameter.Type is SQLByteArrayType)
                {
                    oLEDBParameter.OleDbType = OleDbType.Binary;
                    oLEDBParameter.Size      = ((SQLByteArrayType)parameter.Type).Length;
                }
                else if (parameter.Type is SQLIntegerType)
                {
                    switch (((SQLIntegerType)parameter.Type).ByteCount)
                    {
                    case 1: oLEDBParameter.OleDbType = OleDbType.UnsignedTinyInt; break;

                    case 2: oLEDBParameter.OleDbType = OleDbType.SmallInt; break;

                    case 8: oLEDBParameter.OleDbType = OleDbType.BigInt; break;

                    default: oLEDBParameter.OleDbType = OleDbType.Integer; break;
                    }
                }
                else if (parameter.Type is SQLNumericType)
                {
                    SQLNumericType type = (SQLNumericType)parameter.Type;
                    oLEDBParameter.OleDbType = OleDbType.Numeric;
                    oLEDBParameter.Scale     = type.Scale;
                    oLEDBParameter.Precision = type.Precision;
                }
                else if (parameter.Type is SQLFloatType)
                {
                    SQLFloatType type = (SQLFloatType)parameter.Type;
                    if (type.Width == 1)
                    {
                        oLEDBParameter.OleDbType = OleDbType.Single;
                    }
                    else
                    {
                        oLEDBParameter.OleDbType = OleDbType.Double;
                    }
                }
                else if (parameter.Type is SQLBinaryType)
                {
                    oLEDBParameter.OleDbType = OleDbType.LongVarBinary;
                }
                else if (parameter.Type is SQLTextType)
                {
                    oLEDBParameter.OleDbType = OleDbType.LongVarChar;
                }
                else if (parameter.Type is SQLDateType)
                {
                    oLEDBParameter.OleDbType = OleDbType.DBDate;
                }
                else if (parameter.Type is SQLTimeType)
                {
                    oLEDBParameter.OleDbType = OleDbType.Date;
                }
                else if (parameter.Type is SQLDateTimeType)
                {
                    oLEDBParameter.OleDbType = OleDbType.Date;
                }
                else if (parameter.Type is SQLGuidType)
                {
                    oLEDBParameter.OleDbType = OleDbType.Guid;
                }
                else if (parameter.Type is SQLMoneyType)
                {
                    oLEDBParameter.OleDbType = OleDbType.Currency;
                }
                else
                {
                    throw new ConnectionException(ConnectionException.Codes.UnknownSQLDataType, parameter.Type.GetType().Name);
                }
                _command.Parameters.Add(oLEDBParameter);
            }
        }
Example #2
0
        protected override void PrepareParameters()
        {
            // Prepare parameters
            SQLParameter parameter;

            for (int index = 0; index < _parameterIndexes.Length; index++)
            {
                parameter = Parameters[_parameterIndexes[index]];
                SQLiteParameter sQLiteParameter = (SQLiteParameter)_command.CreateParameter();
                sQLiteParameter.ParameterName = String.Format("@{0}", parameter.Name);
                switch (parameter.Direction)
                {
                case SQLDirection.Out: sQLiteParameter.Direction = System.Data.ParameterDirection.Output; break;

                case SQLDirection.InOut: sQLiteParameter.Direction = System.Data.ParameterDirection.InputOutput; break;

                case SQLDirection.Result: sQLiteParameter.Direction = System.Data.ParameterDirection.ReturnValue; break;

                default: sQLiteParameter.Direction = System.Data.ParameterDirection.Input; break;
                }

                if (parameter.Type is SQLStringType)
                {
                    sQLiteParameter.DbType = DbType.String;
                    sQLiteParameter.Size   = ((SQLStringType)parameter.Type).Length;
                }
                else if (parameter.Type is SQLBooleanType)
                {
                    sQLiteParameter.DbType = DbType.Boolean;
                }
                else if (parameter.Type is SQLByteArrayType)
                {
                    sQLiteParameter.DbType = DbType.Binary;
                    sQLiteParameter.Size   = ((SQLByteArrayType)parameter.Type).Length;
                }
                else if (parameter.Type is SQLIntegerType)
                {
                    switch (((SQLIntegerType)parameter.Type).ByteCount)
                    {
                    case 1: sQLiteParameter.DbType = DbType.Byte; break;

                    case 2: sQLiteParameter.DbType = DbType.Int16; break;

                    case 8: sQLiteParameter.DbType = DbType.Int64; break;

                    default: sQLiteParameter.DbType = DbType.Int32; break;
                    }
                }
                else if (parameter.Type is SQLNumericType)
                {
                    SQLNumericType type = (SQLNumericType)parameter.Type;
                    sQLiteParameter.DbType = DbType.Decimal;
                    //LSQLiteParameter.Scale = LType.Scale;
                    //LSQLiteParameter.Precision = LType.Precision;
                }
                else if (parameter.Type is SQLFloatType)
                {
                    SQLFloatType type = (SQLFloatType)parameter.Type;
                    if (type.Width == 1)
                    {
                        sQLiteParameter.DbType = DbType.Single;
                    }
                    else
                    {
                        sQLiteParameter.DbType = DbType.Double;
                    }
                }
                else if (parameter.Type is SQLBinaryType)
                {
                    sQLiteParameter.DbType = DbType.Binary;
                }
                else if (parameter.Type is SQLTextType)
                {
                    sQLiteParameter.DbType = DbType.String;
                }
                else if (parameter.Type is SQLDateType)
                {
                    sQLiteParameter.DbType = DbType.Date;
                }
                else if (parameter.Type is SQLTimeType)
                {
                    sQLiteParameter.DbType = DbType.Time;
                }
                else if (parameter.Type is SQLDateTimeType)
                {
                    sQLiteParameter.DbType = DbType.DateTime;
                }
                else if (parameter.Type is SQLGuidType)
                {
                    sQLiteParameter.DbType = DbType.Guid;
                }
                else if (parameter.Type is SQLMoneyType)
                {
                    sQLiteParameter.DbType = DbType.Currency;
                }
                else
                {
                    throw new ConnectionException(ConnectionException.Codes.UnknownSQLDataType, parameter.Type.GetType().Name);
                }
                _command.Parameters.Add(sQLiteParameter);
            }
        }
Example #3
0
        /// <summary> Creates non-internal parameters on the provider. </summary>
        protected override void PrepareParameters()
        {
            // Prepare parameters
            for (int index = 0; index < _parameterIndexes.Length; index++)
            {
                SQLParameter parameter      = Parameters[_parameterIndexes[index]];
                SqlParameter mSSQLParameter = (SqlParameter)_command.CreateParameter();
                mSSQLParameter.ParameterName = String.Format("@{0}", ConvertParameterName(parameter.Name));
                switch (parameter.Direction)
                {
                case SQLDirection.Out:
                    mSSQLParameter.Direction = System.Data.ParameterDirection.Output;
                    break;

                case SQLDirection.InOut:
                    mSSQLParameter.Direction = System.Data.ParameterDirection.InputOutput;
                    break;

                case SQLDirection.Result:
                    mSSQLParameter.Direction = System.Data.ParameterDirection.ReturnValue;
                    break;

                default:
                    mSSQLParameter.Direction = System.Data.ParameterDirection.Input;
                    break;
                }

                if (parameter.Type is SQLStringType)
                {
                    mSSQLParameter.SqlDbType = SqlDbType.VarChar;
                    mSSQLParameter.Size      = ((SQLStringType)parameter.Type).Length;
                }
                else if (parameter.Type is SQLBooleanType)
                {
                    mSSQLParameter.SqlDbType = SqlDbType.Bit;
                }
                else if (parameter.Type is SQLByteArrayType)
                {
                    mSSQLParameter.SqlDbType = SqlDbType.Binary;
                    mSSQLParameter.Size      = ((SQLByteArrayType)parameter.Type).Length;
                }
                else if (parameter.Type is SQLIntegerType)
                {
                    switch (((SQLIntegerType)parameter.Type).ByteCount)
                    {
                    case 1:
                        mSSQLParameter.SqlDbType = SqlDbType.TinyInt;
                        break;

                    case 2:
                        mSSQLParameter.SqlDbType = SqlDbType.SmallInt;
                        break;

                    case 8:
                        mSSQLParameter.SqlDbType = SqlDbType.BigInt;
                        break;

                    default:
                        mSSQLParameter.SqlDbType = SqlDbType.Int;
                        break;
                    }
                }
                else if (parameter.Type is SQLNumericType)
                {
                    SQLNumericType type = (SQLNumericType)parameter.Type;
                    mSSQLParameter.SqlDbType = SqlDbType.Decimal;
                    mSSQLParameter.Scale     = type.Scale;
                    mSSQLParameter.Precision = type.Precision;
                }
                else if (parameter.Type is SQLFloatType)
                {
                    SQLFloatType type = (SQLFloatType)parameter.Type;
                    if (type.Width == 1)
                    {
                        mSSQLParameter.SqlDbType = SqlDbType.Real;
                    }
                    else
                    {
                        mSSQLParameter.SqlDbType = SqlDbType.Float;
                    }
                }
                else if (parameter.Type is SQLBinaryType)
                {
                    mSSQLParameter.SqlDbType = SqlDbType.Image;
                }
                else if (parameter.Type is SQLTextType)
                {
                    mSSQLParameter.SqlDbType = SqlDbType.Text;
                }
                else if (parameter.Type is SQLDateType)
                {
                    mSSQLParameter.SqlDbType = SqlDbType.DateTime;
                }
                else if (parameter.Type is SQLTimeType)
                {
                    mSSQLParameter.SqlDbType = SqlDbType.DateTime;
                }
                else if (parameter.Type is SQLDateTimeType)
                {
                    mSSQLParameter.SqlDbType = SqlDbType.DateTime;
                }
                else if (parameter.Type is SQLGuidType)
                {
                    mSSQLParameter.SqlDbType = SqlDbType.UniqueIdentifier;
                }
                else if (parameter.Type is SQLMoneyType)
                {
                    mSSQLParameter.SqlDbType = SqlDbType.Money;
                }
                else
                {
                    throw new ConnectionException(ConnectionException.Codes.UnknownSQLDataType, parameter.Type.GetType().Name);
                }
                _command.Parameters.Add(mSSQLParameter);
            }
        }
        protected override void PrepareParameters()
        {
            // Prepare parameters
            SQLParameter parameter;

            for (int index = 0; index < _parameterIndexes.Length; index++)
            {
                parameter = Parameters[_parameterIndexes[index]];
                DbParameter dBParameter = Connection.ProviderFactory.CreateParameter();
                dBParameter.ParameterName = String.Format("@{0}", parameter.Name);
                switch (parameter.Direction)
                {
                case SQLDirection.Out: dBParameter.Direction = System.Data.ParameterDirection.Output; break;

                case SQLDirection.InOut: dBParameter.Direction = System.Data.ParameterDirection.InputOutput; break;

                case SQLDirection.Result: dBParameter.Direction = System.Data.ParameterDirection.ReturnValue; break;

                default: dBParameter.Direction = System.Data.ParameterDirection.Input; break;
                }

                if (parameter.Type is SQLStringType)
                {
                    dBParameter.DbType = DbType.String;
                    dBParameter.Size   = ((SQLStringType)parameter.Type).Length;
                }
                else if (parameter.Type is SQLBooleanType)
                {
                    dBParameter.DbType = DbType.Boolean;
                }
                else if (parameter.Type is SQLByteArrayType)
                {
                    dBParameter.DbType = DbType.Binary;
                    dBParameter.Size   = ((SQLByteArrayType)parameter.Type).Length;
                }
                else if (parameter.Type is SQLIntegerType)
                {
                    switch (((SQLIntegerType)parameter.Type).ByteCount)
                    {
                    case 1: dBParameter.DbType = DbType.Byte; break;

                    case 2: dBParameter.DbType = DbType.Int16; break;

                    case 8: dBParameter.DbType = DbType.Int64; break;

                    default: dBParameter.DbType = DbType.Int32; break;
                    }
                }
                else if (parameter.Type is SQLNumericType)
                {
                    SQLNumericType type = (SQLNumericType)parameter.Type;
                    dBParameter.DbType = DbType.Decimal;
                    // No ability to specify scale and precision generically. Gracias.
                    //LDBParameter.Scale = LType.Scale;
                    //LDBParameter.Precision = LType.Precision;
                }
                else if (parameter.Type is SQLFloatType)
                {
                    SQLFloatType type = (SQLFloatType)parameter.Type;
                    if (type.Width == 1)
                    {
                        dBParameter.DbType = DbType.Single;
                    }
                    else
                    {
                        dBParameter.DbType = DbType.Double;
                    }
                }
                else if (parameter.Type is SQLBinaryType)
                {
                    dBParameter.DbType = DbType.Binary;
                }
                else if (parameter.Type is SQLTextType)
                {
                    dBParameter.DbType = DbType.String;                     // Hmmmm.... seems like this mapping is wrong. Can't find a clob type in the DbType enumeration.
                }
                else if (parameter.Type is SQLDateType)
                {
                    dBParameter.DbType = DbType.Date;
                }
                else if (parameter.Type is SQLTimeType)
                {
                    dBParameter.DbType = DbType.Time;
                }
                else if (parameter.Type is SQLDateTimeType)
                {
                    dBParameter.DbType = DbType.DateTime;
                }
                else if (parameter.Type is SQLGuidType)
                {
                    dBParameter.DbType = DbType.Guid;
                }
                else if (parameter.Type is SQLMoneyType)
                {
                    dBParameter.DbType = DbType.Currency;
                }
                else
                {
                    throw new ConnectionException(ConnectionException.Codes.UnknownSQLDataType, parameter.Type.GetType().Name);
                }
                _command.Parameters.Add(dBParameter);
            }
        }
Example #5
0
        /// <summary> Generates a SQL Server type descriptor given a parameter definition. </summary>
        private static string GetParamTypeDescriptor(SQLParameter parameter)
        {
            if (parameter.Type is SQLStringType)
            {
                return("varchar(" + ((SQLStringType)parameter.Type).Length.ToString() + ")");
            }
            else if (parameter.Type is SQLBooleanType)
            {
                return("bit");
            }
            else if (parameter.Type is SQLByteArrayType)
            {
                return("binary(" + ((SQLByteArrayType)parameter.Type).Length.ToString() + ")");
            }
            else if (parameter.Type is SQLIntegerType)
            {
                switch (((SQLIntegerType)parameter.Type).ByteCount)
                {
                case 1:
                    return("tinyint");

                case 2:
                    return("smallint");

                case 8:
                    return("bigint");

                default:
                    return("int");
                }
            }
            else if (parameter.Type is SQLNumericType)
            {
                SQLNumericType type = (SQLNumericType)parameter.Type;
                return("decimal(" + type.Precision.ToString() + "," + type.Scale.ToString() + ")");
            }
            else if (parameter.Type is SQLFloatType)
            {
                SQLFloatType type = (SQLFloatType)parameter.Type;
                if (type.Width == 1)
                {
                    return("real");
                }
                else
                {
                    return("float");
                }
            }
            else if (parameter.Type is SQLBinaryType)
            {
                return("image");
            }
            else if (parameter.Type is SQLTextType)
            {
                return("text");                         // Q: Should this be NText or text
            }
            else if ((parameter.Type is SQLDateType) || (parameter.Type is SQLTimeType) || (parameter.Type is SQLDateTimeType))
            {
                return("datetime");
            }
            else if (parameter.Type is SQLGuidType)
            {
                return("uniqueidentifier");
            }
            else if (parameter.Type is SQLMoneyType)
            {
                return("money");
            }
            else
            {
                throw new ConnectionException(ConnectionException.Codes.UnknownSQLDataType, parameter.Type.GetType().Name);
            }
        }