/// <summary>
        /// 格式化值项
        /// </summary>
        /// <param name="valueItem"></param>
        /// <returns></returns>
        private string FormatValueType(KeyWordInfomation info)
        {
            Type valueDataType = null;

            if (itemValue != null)
            {
                valueDataType = itemValue.GetType();
            }
            if (DefaultType.EqualType(valueDataType, DefaultType.StringType) || DefaultType.EqualType(valueDataType, DefaultType.GUIDType))
            {
                return(DataAccessCommon.FormatValue(itemValue, DbType.String, info.DBInfo));
            }
            else if (DefaultType.EqualType(valueDataType, DefaultType.DateTimeType))
            {
                return(DataAccessCommon.FormatValue(itemValue, DbType.DateTime, info.DBInfo));
            }
            else if (DefaultType.EqualType(valueDataType, DefaultType.BytesType))
            {
                return(DataAccessCommon.FormatValue(itemValue, DbType.Binary, info.DBInfo));
            }

            else if (DefaultType.EqualType(valueDataType, DefaultType.BooleanType))
            {
                return(DataAccessCommon.FormatValue(itemValue, DbType.Boolean, info.DBInfo));
            }
            else if (DefaultType.EqualType(valueDataType, DefaultType.GUIDType))
            {
                return(DataAccessCommon.FormatValue(itemValue, DbType.Guid, info.DBInfo));
            }
            else if (valueDataType == null)
            {
                return("null");
            }
            return(itemValue.ToString());
        }
Example #2
0
        /// <summary>
        /// 获取创建注释的SQL
        /// </summary>
        /// <param name="table">表</param>
        /// <param name="paramName">字段(如果为空则给表设置注释)</param>
        /// <param name="description">注释</param>
        /// <returns></returns>
        public string GetAddDescriptionSQL(KeyWordTableParamItem table, EntityParam pInfo, DBInfo info)
        {
            string description = pInfo == null ? table.Description : pInfo.Description;

            string descriptionValue = DataAccessCommon.FormatValue(description, DbType.AnsiString, info);

            if (pInfo == null)
            {
                return("comment on table " + FormatTableName(table.TableName) + " is " + descriptionValue);
            }
            return("comment on column " + FormatTableName(table.TableName) + "." + FormatParam(pInfo.ParamName) + " is " + descriptionValue);
        }
Example #3
0
        /// <summary>
        /// 获取param里边的值的信息
        /// </summary>
        /// <param name="db">数据库</param>
        /// <param name="showBinary">是否显示byte[]</param>
        /// <param name="hideTextLength">当字符串长度大于这个值时候,则隐藏值</param>
        /// <returns></returns>
        public string GetParamString(DBInfo db, bool showBinary, int hideTextLength)
        {
            StringBuilder ret = new StringBuilder(500);

            for (int i = 0; i < this.Count; i++)
            {
                DBParameter    prm  = this[i];
                IDataParameter dPrm = GetParameter(prm, db);

                string value = null;
                if (dPrm.Value != null)
                {
                    if (dPrm.DbType == DbType.Binary && !showBinary)
                    {
                        Array val = dPrm.Value as Array;
                        if (val != null)
                        {
                            value = "[Binary len=" + val.Length + "]";
                        }
                        else
                        {
                            value = "[Binary null]";
                        }
                    }
                    else if (hideTextLength > 0)
                    {
                        string strValue = dPrm.Value as string;
                        if (strValue != null && strValue.Length > hideTextLength)
                        {
                            value = "[String len=" + strValue.Length + "]";
                        }
                    }
                }
                if (value == null)
                {
                    value = DataAccessCommon.FormatValue(dPrm.Value, dPrm.DbType, db);
                }
                ret.Append(dPrm.ParameterName);
                ret.Append("(");
                ret.Append(dPrm.DbType);
                ret.Append(")");
                ret.Append("=");
                ret.Append(value);
                ret.Append(",");
            }

            if (ret.Length > 0)
            {
                ret.Remove(ret.Length - 1, 1);
            }
            return(ret.ToString());
        }
Example #4
0
        /// <summary>
        /// 获取创建注释的SQL
        /// </summary>
        /// <param name="table">表</param>
        /// <param name="paramName">字段(如果为空则给表设置注释)</param>
        /// <param name="description">注释</param>
        /// <returns></returns>
        public string GetAddDescriptionSQL(KeyWordTableParamItem table, EntityParam pInfo, DBInfo info)
        {
            string tableValue  = DataAccessCommon.FormatValue(table.TableName, DbType.AnsiString, info);
            string description = pInfo == null ? table.Description : pInfo.Description;

            string descriptionValue = DataAccessCommon.FormatValue(description, DbType.AnsiString, info);

            if (pInfo == null)
            {
                return("COMMENT ON TABLE " + FormatTableName(table.TableName) + " IS " + descriptionValue);
            }
            return("COMMENT ON COLUMN " + FormatTableName(table.TableName) + "." + FormatParam(pInfo.ParamName) + " IS " + descriptionValue);
        }
Example #5
0
        /// <summary>
        /// 获取创建注释的SQL
        /// </summary>
        /// <param name="table">表</param>
        /// <param name="paramName">字段(如果为空则给表设置注释)</param>
        /// <param name="description">注释</param>
        /// <returns></returns>
        public string GetAddDescriptionSQL(KeyWordTableParamItem table, EntityParam pInfo, DBInfo info)
        {
            string tableValue  = DataAccessCommon.FormatValue(table.TableName, DbType.AnsiString, info);
            string description = pInfo == null ? table.Description : pInfo.Description;

            string descriptionValue = DataAccessCommon.FormatValue(description, DbType.AnsiString, info);

            if (pInfo == null)
            {
                return("EXECUTE sp_addextendedproperty N'MS_Description', N" + descriptionValue + ", N'SCHEMA', N'dbo', N'TABLE', N" + tableValue + ", NULL, NULL");
            }
            return("EXECUTE sp_addextendedproperty N'MS_Description', N" + descriptionValue + ", N'SCHEMA', N'dbo', N'TABLE', N" + tableValue + ", N'COLUMN', N'" + pInfo.ParamName + "'");
        }
Example #6
0
        /// <summary>
        /// 返回Like的查询字符串
        /// </summary>
        /// <param name="scope">条件类</param>
        /// <param name="list">参数列表</param>
        /// <param name="paranName">所属的字段名</param>
        /// <param name="type">当前的数据库类型</param>
        /// <param name="lstIndex">当前索引的标识未辨别同名字段的参数,可设置为0</param>
        /// <param name="entityType">当前实体的类型</param>
        /// <param name="connectString">条件连接的字符串</param>
        /// <param name="isFreeText">是否全文检索</param>
        /// <returns></returns>
        public static string GetLikeSql(Scope scope, ParamList list, string paranName, DbType type, int lstIndex, Type entityType, string connectString, bool isFreeText)
        {
            //string fullName = entityType.FullName + "." + scope.PropertyName;
            DBInfo db       = EntityInfoManager.GetEntityHandle(entityType).DBInfo;
            string ret      = " " + connectString;
            string paramVal = db.CurrentDbAdapter.FormatValueName(DataAccessCommon.FormatParam(paranName, lstIndex));
            string paramKey = db.CurrentDbAdapter.FormatParamKeyName(DataAccessCommon.FormatParam(paranName, lstIndex));

            if (isFreeText && !NoiseWord.IsNoiseWord(scope.Value1.ToString()))
            {
                if (list != null)
                {
                    ret += db.CurrentDbAdapter.FreeTextLike(paranName, paramVal);

                    list.AddNew(paramKey, type, scope.Value1);
                }
                else
                {
                    ret += db.CurrentDbAdapter.FreeTextLike(paranName, DataAccessCommon.FormatValue(scope.Value1, type, db));
                }
            }
            else
            {
                if (list != null)
                {
                    string curValue = scope.Value1.ToString();
                    curValue = FilterLikeValue(curValue);
                    ret     += " (" + db.CurrentDbAdapter.FormatParam(paranName) + " like " + db.CurrentDbAdapter.ConcatString("'%'", paramVal, "'%'") + ")";
                    list.AddNew(paramKey, type, curValue);
                }
                else
                {
                    string curValue = scope.Value1.ToString();
                    curValue = FilterLikeValue(curValue);
                    ret     += " (" + db.CurrentDbAdapter.FormatParam(paranName) + " like '%" + curValue + "%')";
                }
            }
            return(ret);
        }
Example #7
0
        //private Dictionary<string, bool> _tables;
        ///// <summary>
        ///// 本次语句关联的表
        ///// </summary>
        //public Dictionary<string, bool> Tables
        //{
        //    get { return _tables; }
        //    internal set { _tables = value; }
        //}
        ///// <summary>
        ///// 初始化缓存表信息
        ///// </summary>
        ///// <returns></returns>
        //internal bool SetCacheTable(string tabelName)
        //{
        //    if (_tables == null)
        //    {
        //        _tables = new Dictionary<string, bool>();
        //    }
        //    _tables[tabelName] = true;
        //    return true;
        //}
        /// <summary>
        /// 新的数据库值
        /// </summary>
        /// <param name="type">数据库类型</param>
        /// <param name="paramValue">值类型</param>
        /// <returns></returns>
        public DBParameter NewParameter(DbType type, object paramValue, DBInfo db)
        {
            if (paramValue is byte[])
            {
                string      pKeyName = NewKeyName(db);
                string      valueKey = NewValueKeyName(db);
                DBParameter prmValue = AddNew(pKeyName, type, paramValue);
                prmValue.ValueName = valueKey;
                return(prmValue);
            }
            else
            {
                string strValue = paramValue as string;
                if (strValue != null && strValue.Length > 5000)
                {
                    string      pKeyName = NewKeyName(db);
                    string      valueKey = NewValueKeyName(db);
                    DBParameter prmValue = AddNew(pKeyName, type, paramValue);
                    prmValue.ValueName = valueKey;
                    return(prmValue);
                }
            }

            DBParameter prm = null;
            string      key = ((int)type).ToString() + ":" + DataAccessCommon.FormatValue(paramValue, type, db);

            if (!_dicExistsValue.TryGetValue(key, out prm))
            {
                string pKeyName  = NewKeyName(db);
                string valueName = NewValueKeyName(db);
                prm                  = AddNew(pKeyName, type, paramValue);
                prm.ValueName        = valueName;
                _dicExistsValue[key] = prm;
            }
            return(prm);
        }
Example #8
0
        /// <summary>
        /// 获取在字段添加SQL
        /// </summary>
        /// <param name="table">表</param>
        /// <param name="pInfo">字段(如果为空则设置表注释)</param>
        /// <returns></returns>
        public virtual string GetColumnDescriptionSQL(EntityParam pInfo, DBInfo info)
        {
            string comm = DataAccessCommon.FormatValue(pInfo.Description, DbType.String, info);

            return("COMMENT " + comm);
        }