Exemplo n.º 1
0
        public static DbType ToDbType(Type type, ref object realValue)
        {
            DbType dbType = DbType.AnsiString;

            if (type.Equals(typeof(string)))
            {
                dbType = DbType.AnsiString;
            }
            else if (type.Equals(typeof(short)))
            {
                dbType = DbType.Int16;
            }
            else if (type.Equals(typeof(int)))
            {
                dbType = DbType.Int32;
            }
            else if (type.Equals(typeof(long)))
            {
                dbType = DbType.Int64;
            }
            else if (type.Equals(typeof(DateTime)))
            {
                dbType = DbType.DateTime;
            }
            else if (type.Equals(typeof(bool)))
            {
                dbType    = DbType.Boolean;
                realValue = (bool.Parse(realValue.ToString()) ? 1 : 0);
            }
            else if (type.Equals(typeof(double)))
            {
                dbType = DbType.Double;
            }
            else if (type.Equals(typeof(float)))
            {
                dbType = DbType.Single;
            }
            else if (type.Equals(typeof(byte)))
            {
                dbType = DbType.Byte;
            }
            else if (type.Equals(typeof(byte[])))
            {
                dbType = DbType.Binary;
            }
            else if (type.GetTypeInfo().IsSubclassOf(typeof(ICode)))
            {
                dbType = DbType.AnsiString;
            }
            else if (type.GetTypeInfo().IsSubclassOf(typeof(INumericCode)))
            {
                dbType = DbType.Int32;
            }
            MapperParameter.ChangeToSqlValue(dbType, ref realValue);
            return(dbType);
        }
Exemplo n.º 2
0
        public T[] ToDbParameter <T>()
            where T : DbParameter, new()
        {
            int num = 0;

            T[] tArray = new T[base.Count];
            foreach (MapperParameterItem value in base.Values)
            {
                T parameterName = Activator.CreateInstance <T>();
                parameterName.ParameterName = value.ParameterName;
                parameterName.Direction     = value.Direction;
                object obj = value.Value;
                if (value.SqlType.HasValue)
                {
                    object      dbType  = parameterName;
                    SqlDataType?sqlType = value.SqlType;
                    ((DbParameter)dbType).DbType = MapperParameter.ToDbType(sqlType.Value, ref obj);
                }
                else if (value.Type != null)
                {
                    parameterName.DbType = MapperParameter.ToDbType(value.Type, ref obj);
                }
                if (value.Size > 0)
                {
                    parameterName.Size = value.Size;
                }
                else if (parameterName.DbType != DbType.String && parameterName.DbType != DbType.StringFixedLength)
                {
                    if (parameterName.DbType == DbType.AnsiString || parameterName.DbType == DbType.AnsiStringFixedLength)
                    {
                        if (parameterName.Direction == ParameterDirection.Input)
                        {
                            ((DbParameter)parameterName).Size = (obj != null ? obj.ToString().Length : 1);
                        }
                        else
                        {
                            parameterName.Size = 4000;
                        }
                    }
                }
                else if (parameterName.Direction == ParameterDirection.Input)
                {
                    ((DbParameter)parameterName).Size = (obj != null ? obj.ToString().Length : 1);
                }
                else
                {
                    parameterName.Size = 8000;
                }
                parameterName.Value = obj;
                tArray[num]         = parameterName;
                num++;
            }
            return(tArray);
        }
Exemplo n.º 3
0
 private void UpdateParameter(MapperParameter parameter, SqlParameter[] dbParameter)
 {
     SqlParameter[] sqlParameterArray = dbParameter;
     for (int i = 0; i < (int)sqlParameterArray.Length; i++)
     {
         SqlParameter value = sqlParameterArray[i];
         if (value.Direction != ParameterDirection.Input)
         {
             parameter[value.ParameterName].Value = value.Value;
         }
     }
 }
Exemplo n.º 4
0
        public static DbType ToDbType(SqlDataType type, ref object realValue)
        {
            DbType dbType = DbType.AnsiString;

            if (type == SqlDataType.NVarChar)
            {
                dbType = DbType.String;
            }
            else if (type == SqlDataType.Char)
            {
                dbType = DbType.AnsiStringFixedLength;
                if (realValue is bool)
                {
                    realValue = ((bool)realValue ? "Y" : "N");
                }
            }
            else if (type == SqlDataType.NChar)
            {
                dbType = DbType.StringFixedLength;
            }
            else if (type == SqlDataType.Int)
            {
                dbType = DbType.Int32;
            }
            else if (type == SqlDataType.SmallInt)
            {
                dbType = DbType.Int16;
            }
            else if (type == SqlDataType.BigInt)
            {
                dbType = DbType.Int64;
            }
            else if (type == SqlDataType.DateTime)
            {
                dbType = DbType.DateTime;
            }
            else if (type == SqlDataType.Bit)
            {
                dbType    = DbType.Boolean;
                realValue = (bool.Parse(realValue.ToString()) ? 1 : 0);
            }
            else if (type == SqlDataType.Decimal)
            {
                dbType = DbType.Decimal;
            }
            else if (type == SqlDataType.Binary)
            {
                dbType = DbType.Binary;
            }
            MapperParameter.ChangeToSqlValue(dbType, ref realValue);
            return(dbType);
        }
Exemplo n.º 5
0
        public override ValueSet QueryForValueSet(string commandText, MapperParameter parameter, Test.Core.CommandType type)
        {
            if (parameter == null)
            {
                parameter = new MapperParameter();
            }
            SqlParameter[] dbParameter = parameter.ToDbParameter <SqlParameter>();
            ValueSet       valueSet    = SqlHelper.ExecuteDataset(this.connectionString, (System.Data.CommandType)type, commandText, dbParameter);

            if (type != Test.Core.CommandType.Text)
            {
                this.UpdateParameter(parameter, dbParameter);
            }
            return(valueSet);
        }
Exemplo n.º 6
0
        public override object QueryForScalar(string commandText, MapperParameter parameter, Test.Core.CommandType type)
        {
            if (parameter == null)
            {
                parameter = new MapperParameter();
            }
            SqlParameter[] dbParameter = parameter.ToDbParameter <SqlParameter>();
            object         obj         = SqlHelper.ExecuteScalar(this.connectionString, (System.Data.CommandType)type, commandText, dbParameter);

            if (type != Test.Core.CommandType.Text)
            {
                this.UpdateParameter(parameter, dbParameter);
            }
            return(obj);
        }
Exemplo n.º 7
0
        public override int Query(string commandText, MapperParameter parameter, Test.Core.CommandType type)
        {
            if (parameter == null)
            {
                parameter = new MapperParameter();
            }
            SqlParameter[] dbParameter = parameter.ToDbParameter <SqlParameter>();
            int            num         = SqlHelper.ExecuteNonQuery(this.connectionString, (System.Data.CommandType)type, commandText, dbParameter);

            if (type != Test.Core.CommandType.Text)
            {
                this.UpdateParameter(parameter, dbParameter);
            }
            return(num);
        }
Exemplo n.º 8
0
 public ValueTable QueryForValueTable(string commandText, MapperParameter parameter = null, CommandType commandType = CommandType.Text)
 {
     return(this.QueryForValueSet(commandText, parameter, commandType).Tables[0]);
 }
Exemplo n.º 9
0
 public abstract ValueSet QueryForValueSet(string commandText, MapperParameter parameter = null, CommandType commandType = CommandType.Text);
Exemplo n.º 10
0
 public ValueRow QueryForValueRow(string commandText, MapperParameter parameter = null, CommandType commandType = CommandType.Text)
 {
     return(this.QueryForValueSet(commandText, parameter, commandType).FirstRow());
 }
Exemplo n.º 11
0
 public abstract object QueryForScalar(string commandText, MapperParameter parameter = null, CommandType commandType = CommandType.Text);
Exemplo n.º 12
0
 public abstract int Query(string commandText, MapperParameter parameter = null, CommandType commandType = CommandType.Text);