Exemplo n.º 1
0
        public void AddParameter(string name, ParameterDirection direction, TkDataType type,
                                 int size, object value)
        {
            if (fParamCreated)
            {
                TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
                                                            "存储过程{0}已经执行过了,不能再添加参数了", ProcName), this);
                return;
            }

            StoredProcParameter param = Add(name, direction, type);

            if (size > 0)
            {
                param.Size = size;
            }
            if (value != null)
            {
                param.Value = value;
            }
            fParams.Add(param);
            if (DbUtil.IsInputParameter(direction))
            {
                fInputParams.Add(name, param);
            }
            if (direction != ParameterDirection.Input)
            {
                fOutputParams.Add(name, param);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the StoredProcParameter class.
 /// </summary>
 public StoredProcParameter(string name, ParameterDirection direction, TkDataType type, int size)
 {
     Name      = name;
     Direction = direction;
     Type      = type;
     Size      = size;
 }
Exemplo n.º 3
0
        internal StoredProcParameter Add(string name, ParameterDirection direction, TkDataType type)
        {
            TkDebug.AssertArgumentNullOrEmpty(name, "name", this);

            StoredProcParameter param = new StoredProcParameter(name, direction, type);

            return(param);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the FieldItem class.
        /// </summary>
        public FieldItem(string fieldName, string nickName, TkDataType dataType)
        {
            TkDebug.AssertArgumentNullOrEmpty(fieldName, "fieldName", null);
            TkDebug.AssertArgumentNullOrEmpty(nickName, "nickName", null);

            fFieldName = fieldName;
            fNickName  = nickName;
            DataType   = dataType;
        }
Exemplo n.º 5
0
        public static IParamBuilder CreateParamBuilder(string sql, string fieldName,
                                                       TkDataType dataType, object fieldValue)
        {
            TkDebug.AssertArgumentNullOrEmpty(fieldName, "fieldName", null);

            DbParameterList paramList = new DbParameterList();

            paramList.Add(fieldName, dataType, fieldValue);
            return(CreateParamBuilder(sql, paramList));
        }
Exemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the DbParameter class.
 /// </summary>
 public DbParameter(string fieldName, TkDataType dataType, object fieldValue)
 {
     FieldName  = fieldName;
     DataType   = dataType;
     FieldValue = fieldValue;
     if (fieldValue != null)
     {
         Value = ObjectUtil.ToString(fieldValue, ObjectUtil.WriteSettings);
     }
 }
Exemplo n.º 7
0
 private CodeTableFieldInfoEx(string fieldName, string displayName, TkDataType dataType, bool isKey, bool isEmpty)
 {
     FieldName   = fieldName;
     DisplayName = displayName;
     DataType    = dataType;
     IsKey       = isKey;
     IsEmpty     = isEmpty;
     NickName    = StringUtil.GetNickName(fieldName);
     if (dataType == TkDataType.String)
     {
         Length = 50;
     }
 }
Exemplo n.º 8
0
        internal static IParamBuilder InternalCreateSingleSql(TkDbContext context, string fieldName,
                                                              TkDataType type, string oper, string paramName, object fieldValue)
        {
            TkDebug.AssertArgumentNull(context, "context", null);
            TkDebug.AssertArgumentNullOrEmpty(fieldName, "fieldName", null);
            TkDebug.AssertArgumentNullOrEmpty(oper, "oper", null);
            TkDebug.AssertArgumentNullOrEmpty(paramName, "paramName", null);
            TkDebug.AssertArgumentNull(fieldValue, "fieldValue", null);

            InternalParamBuilder builder = new InternalParamBuilder
            {
                Sql = CreateSingleSql(context, fieldName, oper, paramName)
            };

            builder.Parameters.Add(paramName, type, fieldValue);
            return(builder);
        }
Exemplo n.º 9
0
        public static Type ConvertDataTypeToType(TkDataType type)
        {
            switch (type)
            {
            case TkDataType.Binary:
            case TkDataType.Blob:
                return(typeof(byte[]));

            case TkDataType.Bit:
                return(typeof(bool));

            case TkDataType.Byte:
                return(typeof(byte));

            case TkDataType.Date:
            case TkDataType.DateTime:
                return(typeof(DateTime));

            case TkDataType.Decimal:
            case TkDataType.Money:
                return(typeof(decimal));

            case TkDataType.Double:
                return(typeof(double));

            case TkDataType.Guid:
                return(typeof(Guid));

            case TkDataType.Int:
                return(typeof(int));

            case TkDataType.Long:
                return(typeof(long));

            case TkDataType.Short:
                return(typeof(short));

            case TkDataType.String:
            case TkDataType.Text:
            case TkDataType.Xml:
                return(typeof(string));

            default:
                return(typeof(string));
            }
        }
Exemplo n.º 10
0
 public KeyFieldItem(string fieldName, string nickName, TkDataType dataType)
     : base(fieldName, nickName, dataType)
 {
 }
Exemplo n.º 11
0
        public static DbType ConvertTkDataTypeToDbType(TkDataType type)
        {
            DbType result = DbType.AnsiString;

            switch (type)
            {
            case TkDataType.String:
            case TkDataType.Text:
                result = DbType.AnsiString;
                break;

            case TkDataType.Int:
                result = DbType.Int32;
                break;

            case TkDataType.Date:
                result = DbType.Date;
                break;

            case TkDataType.DateTime:
                result = DbType.DateTime;
                break;

            case TkDataType.Double:
                result = DbType.Double;
                break;

            case TkDataType.Money:
                result = DbType.Currency;
                break;

            case TkDataType.Blob:
            case TkDataType.Binary:
                result = DbType.Binary;
                break;

            case TkDataType.Guid:
                result = DbType.Guid;
                break;

            case TkDataType.Xml:
                result = DbType.AnsiString;
                break;

            case TkDataType.Bit:
                result = DbType.Boolean;
                break;

            case TkDataType.Byte:
                result = DbType.Byte;
                break;

            case TkDataType.Short:
                result = DbType.Int16;
                break;

            case TkDataType.Long:
                result = DbType.Int64;
                break;

            case TkDataType.Decimal:
                result = DbType.Decimal;
                break;
            }
            return(result);
        }
Exemplo n.º 12
0
 public IDbDataParameter CreateParameter(TkDataType dataType)
 {
     return(InternalDbProvider.CreateParameter(dataType));
 }
Exemplo n.º 13
0
 public static IParamBuilder CreateEqualSql(TkDbContext context, string fieldName,
                                            TkDataType type, string paramName, object fieldValue)
 {
     return(CreateSingleSql(context, fieldName, type, "=", paramName, fieldValue));
 }
Exemplo n.º 14
0
 public static IParamBuilder CreateSingleSql(TkDbContext context, string fieldName,
                                             TkDataType type, string oper, string paramName, object fieldValue)
 {
     return(InternalCreateSingleSql(context, fieldName, type, oper, paramName, fieldValue));
 }
Exemplo n.º 15
0
        protected sealed override void PrepareParameters()
        {
            PropertyInfo[] properties = GetType().GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            var            parameters = from memberInfo in properties
                                        from attribute in memberInfo.GetCustomAttributes(false)
                                        where attribute is ParameterAttribute
                                        select new { Property = memberInfo, Attribute = (ParameterAttribute)attribute };

            foreach (var item in parameters)
            {
                ParameterAttribute attribute = item.Attribute;
                string             name;
                if (string.IsNullOrEmpty(attribute.Name))
                {
                    name = item.Property.Name;
                    switch (attribute.LetterCase)
                    {
                    case CaseCategory.Uppercase:
                        name = name.ToUpper(ObjectUtil.SysCulture);
                        break;

                    case CaseCategory.Lowercase:
                        name = name.ToLower(ObjectUtil.SysCulture);
                        break;
                    }
                }
                else
                {
                    name = attribute.Name;
                }
                TkDataType dataType = attribute.UseDefaultType ?
                                      MetaDataUtil.ConvertTypeToDataType(item.Property.PropertyType) :
                                      attribute.DataType;
                StoredProcParameter param = Add(name, attribute.Direction, dataType);
                if (attribute.Size > 0)
                {
                    param.Size = attribute.Size;
                }
                else
                {
                    if (dataType == TkDataType.String)
                    {
                        param.Size = 255;
                    }
                }
                ParameterInfo info = new ParameterInfo {
                    Attribute = attribute, Parameter = param, Property = item.Property
                };
                if (DbUtil.IsInputParameter(attribute.Direction))
                {
                    fInputProperties.Add(info);
                }
                if (DbUtil.IsOutputParameter(attribute.Direction))
                {
                    fOutputProperties.Add(info);
                }

                IDbDataParameter parameter = CreateDataParameter(param);
                info.SetInputValue(this);
                Command.Parameters.Add(parameter);
            }
        }
Exemplo n.º 16
0
        IDbDataParameter IDbProvider.CreateParameter(TkDataType type)
        {
            SqlParameter param  = new SqlParameter();
            SqlDbType    dbType = SqlDbType.VarChar;

            switch (type)
            {
            case TkDataType.String:
                dbType = SqlDbType.VarChar;
                break;

            case TkDataType.Int:
                dbType = SqlDbType.Int;
                break;;

            case TkDataType.Date:
            case TkDataType.DateTime:
                dbType = SqlDbType.DateTime;
                break;

            case TkDataType.Double:
                dbType = SqlDbType.Float;
                break;

            case TkDataType.Text:
                dbType = SqlDbType.Text;
                break;

            case TkDataType.Money:
                dbType = SqlDbType.Money;
                break;

            case TkDataType.Blob:
                dbType = SqlDbType.Image;
                break;

            case TkDataType.Binary:
                dbType = SqlDbType.Binary;
                break;

            case TkDataType.Guid:
                dbType = SqlDbType.UniqueIdentifier;
                break;

            case TkDataType.Xml:
                dbType = SqlDbType.Xml;
                break;

            case TkDataType.Bit:
                dbType = SqlDbType.Bit;
                break;

            case TkDataType.Byte:
                dbType = SqlDbType.TinyInt;
                break;

            case TkDataType.Short:
                dbType = SqlDbType.SmallInt;
                break;

            case TkDataType.Long:
                dbType = SqlDbType.BigInt;
                break;

            case TkDataType.Decimal:
                dbType = SqlDbType.Decimal;
                break;
                //case TkDataType.Geography:
                //    dbType = SqlDbType.Udt;
                //    param.UdtTypeName = "geography";//"Hello.sys.geography";
                //    break;
            }
            param.SqlDbType = dbType;

            return(param);
        }
Exemplo n.º 17
0
 public FieldItem(string fieldName, TkDataType dataType)
     : this(fieldName, StringUtil.GetNickName(fieldName), dataType)
 {
 }
Exemplo n.º 18
0
        public void Add(string fieldName, TkDataType dataType, object fieldValue)
        {
            TkDebug.AssertArgumentNullOrEmpty(fieldName, "fieldName", this);

            List.Add(new DbParameter(fieldName, dataType, fieldValue));
        }
Exemplo n.º 19
0
 public IDbDataParameter CreateParameter(TkDataType dataType)
 {
     return(ContextConfig.CreateParameter(dataType));
 }
Exemplo n.º 20
0
        IDbDataParameter IDbProvider.CreateParameter(TkDataType type)
        {
            MySqlParameter param  = new MySqlParameter();
            MySqlDbType    dbType = MySqlDbType.VarChar;

            switch (type)
            {
            case TkDataType.String:
                dbType = MySqlDbType.VarChar;
                break;

            case TkDataType.Int:
                dbType = MySqlDbType.Int32;
                break;;

            case TkDataType.Date:
                dbType = MySqlDbType.Date;
                break;

            case TkDataType.DateTime:
                dbType = MySqlDbType.DateTime;
                break;

            case TkDataType.Double:
                dbType = MySqlDbType.Double;
                break;

            case TkDataType.Text:
                dbType = MySqlDbType.Text;
                break;

            case TkDataType.Money:
                dbType = MySqlDbType.Decimal;
                break;

            case TkDataType.Blob:
                dbType = MySqlDbType.Blob;
                break;

            case TkDataType.Binary:
                dbType = MySqlDbType.Binary;
                break;

            case TkDataType.Guid:
                dbType = MySqlDbType.Guid;
                break;

            case TkDataType.Bit:
                dbType = MySqlDbType.Bit;
                break;

            case TkDataType.Byte:
                dbType = MySqlDbType.Byte;
                break;

            case TkDataType.Short:
                dbType = MySqlDbType.Int16;
                break;

            case TkDataType.Long:
                dbType = MySqlDbType.Int64;
                break;

            case TkDataType.Decimal:
                dbType = MySqlDbType.Decimal;
                break;

            case TkDataType.Xml:
            case TkDataType.Geography:
                TkDebug.ThrowToolkitException(
                    string.Format(ObjectUtil.SysCulture,
                                  "MySql不支持{0}类型", type.ToString()), this);
                break;
            }
            param.MySqlDbType = dbType;

            return(param);
        }
Exemplo n.º 21
0
 public void AddParameter(string name, ParameterDirection direction, TkDataType type, int size)
 {
     AddParameter(name, direction, type, size, null);
 }
Exemplo n.º 22
0
 public void AddParameter(string name, ParameterDirection direction, TkDataType type)
 {
     AddParameter(name, direction, type, 0);
 }