예제 #1
0
 /// <summary>
 /// 构造函数
 /// </summary>
 public SubQuerySqlStatement()
     : base()
 {
     From         = new From();
     mainFromItem = new FromItem();
     From.ChildCollection.Add(mainFromItem);
     SelectList            = new SelectFieldListStatement();
     JoinCondition         = new JoinConditionStatement();
     FilterCondition       = new ConditionStatement();
     OrderByCondition      = new ConditionStatement();
     DictFieldAliasMapping = new Dictionary <string, string>();
 }
예제 #2
0
        /// <summary>
        /// 根据SQLDOM元素类型初始化SQLDOM元素对象
        /// </summary>
        /// <param name="sqlElementType">SQLDOM元素类型</param>
        /// <returns>SQLDOM元素对象</returns>
        public static SqlElement GetSQLElement(int sqlElementType)
        {
            SqlElement     element = null;
            SqlElementType type    = (SqlElementType)sqlElementType;

            switch (type)
            {
            case SqlElementType.InsertField:
                element = new InsertField();
                break;

            case SqlElementType.SqlPrimaryKeyField:
                element = new SqlPrimaryKeyField();
                break;

            case SqlElementType.SelectListField:
                element = new SelectListField();
                break;

            case SqlElementType.UpdateField:
                element = new UpdateField();
                break;

            case SqlElementType.From:
                element = new From();
                break;

            case SqlElementType.FromItem:
                element = new FromItem();
                break;

            case SqlElementType.JoinCondition:
                element = new JoinConditionStatement();
                break;

            case SqlElementType.OrderByCondition:
                element = new ConditionStatement();
                break;

            case SqlElementType.FilterCondition:
                element = new ConditionStatement();
                break;

            case SqlElementType.UnKnown:
                break;
            }

            return(element);
        }
예제 #3
0
        public static ConditionStatement ParseOrderByClauses(List<OrderByClause> orderByClauses, DomainObject domainObject, DataObject dataObject)
        {
            var orderbyCondition = new ConditionStatement();
            if (orderByClauses == null || orderByClauses.Count == 0)
                return orderbyCondition;

            var list = new List<string>();
            foreach (var orderByClause in orderByClauses)
            {
                var orderByString = ParseOrderByClause(orderByClause, domainObject, dataObject);
                if (!string.IsNullOrWhiteSpace(orderByString))
                    list.Add(orderByString);
            }

            if (list.Count > 0)
            {
                orderbyCondition.ConditionString = string.Format("ORDER BY {0}", string.Join(",", list));
            }

            return orderbyCondition;
        }
예제 #4
0
        private static ConditionStatement ParseConditionStatement(FilterClause filterClause, DomainObject domainObject, DataObject dataObject, SqlTable sqlTable)
        {
            var conditionStatement = new ConditionStatement();
            conditionStatement.SetLogicalOperator(filterClause.LogicalOperator);
            conditionStatement.ConditionField.Table = sqlTable;
            conditionStatement.RelationalOperator = filterClause.RelationalOperator;
            conditionStatement.ConditionFieldValue = new ConditionFieldValue()
            {
                ValueType = filterClause.FilterFieldValue.ValueType,
                IsNull = filterClause.FilterFieldValue.IsNull,
                Value = filterClause.FilterFieldValue.FiledValue,
            };

            DataColumn column = null;
            DomainObjectElement element = null;
            switch (filterClause.FilterField.FieldType)
            {
                case FieldType.Column:
                    column = dataObject.Columns.FirstOrDefault(i => i.ColumnName == filterClause.FilterField.Field);
                    conditionStatement.ConditionField.FieldName = column.ColumnName;
                    break;
                case FieldType.Element:
                    element = domainObject.Elements.FirstOrDefault(i => i.Name == filterClause.FilterField.Field || i.ID == filterClause.FilterField.Field);
                    column = dataObject.Columns.FirstOrDefault(i => i.ID == element.DataColumnID);
                    conditionStatement.ConditionField.FieldName = column.ColumnName;
                    break;
                case FieldType.FunctionExpression:
                    conditionStatement.IsExpression = true;
                    conditionStatement.ConditionField.FieldName = filterClause.FilterField.Field;
                    break;
                default:
                    break;
            }
            conditionStatement.ConditionFieldValue.ConditionFieldName = column.ColumnName;
            return conditionStatement;
        }