Example #1
0
        /// <summary>
        /// 转换为字符串
        /// 前置条件:暂时仅支持整型,字符串,日期3种类型
        /// </summary>
        public override string ToString(object val)
        {
            if (val == null)
            {
                return("null");
            }

            // 运行1,000,000次,性能比较和选择
            // string 最快
            if (val is String) // 0.8微秒
            {
                string newVal = val.ToString();
                if (newVal.StartsWith("'") && newVal.EndsWith("'"))
                {
                    return(newVal);
                }

                return(string.Format("'{0}'", newVal.Replace("'", "''")));
            }
            else if (val is DateTime) // 2.0微秒
            {
                if (ParamUtil.GetEmptyDatetime().Equals((DateTime)val))
                {
                    return("null");
                }
                else
                {
                    return(string.Format("CONVERT(datetime,'{0}',120)", ((DateTime)val).ToString("yyyy-MM-dd HH:mm:ss")));
                }
            }
            else if (val is Enum)
            {
                DbType dbType = DbExecuteEngine.GetEnumDbType(val.GetType());
                if (dbType == DbType.Int32)
                {
                    return(((int)val).ToString());                   //取枚举整数值
                }
                else
                {
                    return(string.Format("'{0}'", val.ToString()));  //取枚举字符串
                }
            }
            else if (val is Byte[])
            {
                return(Convert.ToBase64String((Byte[])val, Base64FormattingOptions.None));
            }
            else // long 0.2微秒
            {
                return(val.ToString());
            }
        }
Example #2
0
 /// <summary>
 /// 获得映射的sql语句,sqlKey必须带'$'前缀
 /// </summary>
 public string GetMappedSqlString(string sqlKey, params object[] paramValues)
 {
     return(DbExecuteEngine.GetMappedSqlString(_DatabaseName, sqlKey, paramValues));
 }