/// <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());
        }
Exemple #2
0
        /// <summary>
        /// 查询表
        /// </summary>
        /// <typeparam name="E"></typeparam>
        /// <param name="lstScope">条件</param>
        /// <returns></returns>
        public List <E> SelectList <E>(ScopeList lstScope)
            where E : EntityBase, new()
        {
            Type                 eType   = typeof(E);
            List <E>             retlist = null;
            BQLEntityTableHandle table   = _oper.DBInfo.FindTable(eType);

            if (CommonMethods.IsNull(table))
            {
                _oper.DBInfo.ThrowNotFondTable(eType);
            }
            BQLQuery BQL = GetSelectSql(lstScope, table);

            if (!lstScope.HasPage)
            {
                retlist = QueryList <E>(BQL, lstScope.ShowEntity, lstScope.UseCache);
                DataAccessCommon.FillEntityChidList(retlist, lstScope);
                return(retlist);
            }
            using (BatchAction ba = _oper.StarBatchAction())
            {
                retlist = QueryPageList <E>(BQL, lstScope.PageContent, lstScope.ShowEntity, lstScope.UseCache);
                DataAccessCommon.FillEntityChidList(retlist, lstScope);
                return(retlist);
            }
        }
Exemple #3
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);
        }
Exemple #4
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());
        }
Exemple #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("COMMENT ON TABLE " + FormatTableName(table.TableName) + " IS " + descriptionValue);
            }
            return("COMMENT ON COLUMN " + FormatTableName(table.TableName) + "." + FormatParam(pInfo.ParamName) + " IS " + descriptionValue);
        }
Exemple #6
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 + "'");
        }
Exemple #7
0
        public override string GetSql(bool useCache)
        {
            DataAccessCommon.TrimHead(_condition);
            StringBuilder sql = new StringBuilder(500);

            sql.Append("Delete from ");
            sql.Append(_tables.ToString());
            if (_condition.Length > 0)
            {
                sql.Append(" where ");
                sql.Append(_condition.ToString());
            }
            return(sql.ToString());
        }
        public override string GetSql(bool useCache)
        {
            string ret = null;

            DataAccessCommon.TrimHead(_condition);
            if (_pageContente != null && _pageContente.PageSize > 0)
            {
                ret = _dbInfo.CurrentDbAdapter.CreatePageSql(_paramList, _oper, this, _pageContente, useCache);
            }
            else
            {
                ret = GetSelect();
            }

            return(ret);
        }
Exemple #9
0
        public override string GetSql(bool useCache)
        {
            DataAccessCommon.TrimHead(_condition);
            StringBuilder sbRet = new StringBuilder(2000);

            sbRet.Append("update  ");
            sbRet.Append(_tables.ToString());
            sbRet.Append(" set ");
            sbRet.Append(_updateSetValue.ToString());

            if (_condition.Length > 0)
            {
                sbRet.Append(" where ");
                sbRet.Append(_condition.ToString());
            }

            return(sbRet.ToString());
        }
Exemple #10
0
        public override string ToString()
        {
            BQLValueItem qvalue = value1 as BQLValueItem;

            if (!CommonMethods.IsNull(qvalue))
            {
                return(qvalue.DisplayValue(BQLValueItem.GetKeyInfo()));
            }
            else
            {
                string pName = propertyName;

                DbType dbType = DbType.AnsiString;
                if (value1 != null)
                {
                    dbType = DefaultType.ToDbType(value1.GetType());
                }
                return(DataAccessCommon.FormatScorp(this, null, pName, dbType, 0, null));
            }

            return(base.ToString());
        }
Exemple #11
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);
        }
Exemple #12
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);
        }
Exemple #13
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);
        }