예제 #1
0
                public Clause(string f, ClauseType <T> t, T v)
                {
                    field = f;
                    type  = t;

                    value = v;
                }
예제 #2
0
        internal ClauseType GetDefaultOperationCore(IBoundProperty property, ClauseType operation)
        {
            GetDefaultOperationEventArgs args = new GetDefaultOperationEventArgs(property, operation);

            RaiseGetDefaultOperation(args);
            return(args.ClauseType);
        }
예제 #3
0
 private void ClearSqlText(ClauseType clauseType)
 {
     if (this.dicSqlText.TryGetValue(clauseType, out List <string> listText))
     {
         this.dicSqlText.Remove(clauseType);
     }
 }
예제 #4
0
        internal void SetFieldUsable <T>(Expression <T> predicate, ClauseType type)
        {
            try
            {
                var    result      = _translateQuery.Translate(predicate, type);
                string commandText = TranslateToNativeColumn(result.CommandText);

                TableSchema tableSchema = TableSchemaResolver.GetTableSchema(typeof(TTable));
                var         fieldIndex  = tableSchema.FieldsSchema.FindIndex(x => x.ToString() == commandText);
                if (fieldIndex != -1)
                {
                    var field = tableSchema.FieldsSchema[fieldIndex];
                    if (field.IsPrimaryKey || field.IsUpdCount)
                    {
                        this._fieldsUsable[fieldIndex] = true;
                    }
                    else
                    {
                        this._fieldsUsable[fieldIndex] = type == ClauseType.Take;
                    }
                }
            }
            catch (Exception e)
            {
                this._dbError.Code = ErrorCode.InvalidOperation;
                this._dbError.Text = e.Message;
            }
        }
예제 #5
0
 public HavingClause(ClauseType type, Column column, Is op, object value, Conditional condition)
 {
     _type      = type;
     _column    = column;
     _operator  = op;
     _value     = value;
     _condition = condition;
     _query     = null;
 }
예제 #6
0
 public WhereClause(ClauseType type, Column column, Is op, object value, Conditional condition, bool not)
 {
     _type        = type;
     _column      = column;
     _operator    = op;
     _value       = value;
     _condition   = condition;
     _not         = not;
     _nestedQuery = null;
 }
예제 #7
0
 public void Initialize(ClauseType _gameMode)
 {
     SetMode(_gameMode);
     Signals.ResetWordComposingMenu.AddListener(() =>
     {
         if (MainMenuUIControl.Mode == MenuMode.Play)
         {
             resetAction();
         }
     });
 }
예제 #8
0
 internal void AddClause(Clause clause, ClauseType clause_type)
 {
     if (clause_type == ClauseType.Case)
     {
         case_clauses.Add(clause);
     }
     else if (clause_type == ClauseType.CaseAfterDefault)
     {
         sec_case_clauses.Add(clause);
     }
 }
예제 #9
0
        public WhereClause(ClauseType type, Column column, Conditional condition)
        {
            _type      = type;
            _column    = column;
            _condition = condition;

            _operator    = Is.EqualTo;
            _value       = null;
            _not         = false;
            _nestedQuery = null;
        }
        private static Clause GetClause(string q, string clauseAlias, ClauseType clauseType)
        {
            string[] operands = Regex.Split(q, clauseAlias, RegexOptions.IgnoreCase);
            var      criteria = new Clause
            {
                Value      = operands[1],
                ClauseType = clauseType
            };

            return(criteria);
        }
예제 #11
0
        /// <summary>
        /// Clauses the specified clause.
        /// </summary>
        /// <param name="clause">The clause.</param>
        /// <param name="key">The key.</param>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        /// <exception cref="Exception">
        /// WHERE clause already provided once
        /// or
        /// WHERE or HAVING clause not provided
        /// or
        /// HAVING clause already provided once
        /// or
        /// Invalid clause
        /// </exception>
        public QueryBuilder Clause(ClauseType clause, string key, object value)
        {
            string clausesTemp = string.Empty;

            switch (clause)
            {
            case ClauseType.Where:
                if (this.whereClauseProvided && !this.havingClauseProvided)
                {
                    throw new Exception("WHERE clause already provided once");
                }
                this.whereClauses       += $" WHERE {key} = @{key} ";
                this.whereClauseProvided = true;
                break;

            case ClauseType.And:
                if (!this.whereClauseProvided || !this.havingClauseProvided)
                {
                    throw new Exception("WHERE or HAVING clause not provided");
                }
                this.whereClauses += $" AND {key} = @{key} ";
                break;

            case ClauseType.Or:
                if (!this.whereClauseProvided || !this.havingClauseProvided)
                {
                    throw new Exception("WHERE or HAVING clause not provided");
                }
                this.whereClauses += $" OR {key} = @{key} ";
                break;

            case ClauseType.Having:
                if (!this.havingClauseProvided)
                {
                    throw new Exception("HAVING clause already provided once");
                }
                this.whereClauses += $" HAVING {key} = @{key} ";
                break;

            default:
                throw new Exception("Invalid clause");
            }

            if (this.Parameters == null)
            {
                this.Parameters = new Dictionary <string, object>();
            }
            this.Parameters.Add($"@{key}", value);

            return(this);
        }
예제 #12
0
 public static Clause New(ClauseType type, string sqlPart = null, string name = null, string aliace = null,
                          string condition = null, string direction           = null, string extra  = null)
 {
     return(new Clause
     {
         ClauseType = type,
         SqlPart = sqlPart,
         Name = name,
         Aliace = aliace,
         Condition = condition,
         Direction = direction,
         Extra = extra
     });
 }
예제 #13
0
        private static string BuildSql <T>(ClauseType clauseType, Expression <Func <T, bool> > expression)
        {
            Type type    = GetType(typeof(T));
            var  columns = GetColumnsCache(type).Keys.ToList();

            var where = new StringBuilder();
            expression.Body.WalkThrough((name, oper, _) =>
            {
                where.AppendIf(name != null, $"{name} {oper} @{name}");
                where.AppendIf(name is null, $" {oper} ");
            });

            return(BuildSql(clauseType, GetTypeName(type), columns.ToClause(), where.ToString()));
        }
예제 #14
0
        private static bool IsValidLookupClause(ClauseType operation)
        {
            switch (operation)
            {
            case ClauseType.Equals:
            case ClauseType.IsNotNull:
            case ClauseType.IsNull:
            case ClauseType.DoesNotEqual:
                return(true);

            default:
                return(false);
            }
        }
예제 #15
0
        private static string BuildSql <T>(ClauseType clauseType, IDictionary <string, object> parameters)
        {
            Type type    = GetType(typeof(T));
            var  keys    = GetKeysCache(type).Keys.ToList();
            var  columns = GetColumnsCache(type).Keys.ToList();

            if (clauseType == ClauseType.Update)
            {
                columns.Reduce(keys);
                return(BuildSql(clauseType, GetTypeName(type), columns.ToSetClause(), keys.ToWhereClause()));
            }

            return(BuildSql(clauseType, GetTypeName(type), columns.ToClause(), parameters.ToWhereClause()));
        }
예제 #16
0
 public static Clause New(ClauseType type, string sqlPart = null, string name = null, string aliace = null,
                          string condition = null, string direction = null, string extra = null)
 {
     return new Clause
         {
             ClauseType = type,
             SqlPart = sqlPart,
             Name = name,
             Aliace = aliace,
             Condition = condition,
             Direction = direction,
             Extra = extra
         };
 }
예제 #17
0
 private void AppenSqlText(ClauseType clauseType, string sqlText)
 {
     if (this.dicSqlText.TryGetValue(clauseType, out List <string> listText))
     {
         listText.Add(sqlText);
     }
     else
     {
         listText = new List <string>()
         {
             sqlText
         };
         this.dicSqlText.Add(clauseType, listText);
     }
 }
예제 #18
0
        internal TranslateResult Translate <T>(Expression <T> expression, ClauseType clauseType)
        {
            this.clauseBuilder    = new ClauseBuilder();
            this.parameterBuilder = new ParameterBuilder();

            this.clauseType = clauseType;

            this.Visit(expression);

            return(new TranslateResult
            {
                CommandText = clauseBuilder.GetExpressionText(),
                Parameters = clauseBuilder.GetExpressionParameters(),
            });
        }
예제 #19
0
        protected QueryBuilder AddDatabaseWhere(ClauseType type, Column column, Is op, object value, Conditional condition)
        {
            WhereClause where = new WhereClause()
            {
                Type      = type,
                Column    = column,
                Operator  = op,
                Value     = value,
                Condition = condition
            };

            _wheres.Add(where);
            AddBinding(BindingType.Where, value);

            return(this);
        }
예제 #20
0
        private static Clause GetClause(string q, string clauseAlias, ClauseType clauseType)
        {
            string res = Regex.Replace(
                q,
                Regex.Escape(clauseAlias),
                "",
                RegexOptions.IgnoreCase
                );
            var criteria = new Clause
            {
                Value      = res,
                ClauseType = clauseType
            };

            return(criteria);
        }
        public bool IsClauseAllowed(ClauseType clauseType)
        {
            var isClauseAllowed = true;
            var isAllowed       = AllowedClauses?.HasFlag(clauseType);
            var isDisallowed    = DisAllowedClauses?.HasFlag(clauseType);

            if (isAllowed.HasValue && !isAllowed.Value)
            {
                isClauseAllowed = false;
            }

            if (isDisallowed.HasValue && isDisallowed.Value)
            {
                isClauseAllowed = false;
            }
            return(isClauseAllowed);
        }
예제 #22
0
        public static bool IsClauseAllowed(this AutoQueryableProfile profile, ClauseType clauseType)
        {
            bool isClauseAllowed = true;
            bool?isAllowed       = profile?.AllowedClauses?.HasFlag(clauseType);
            bool?isDisallowed    = profile?.DisAllowedClauses?.HasFlag(clauseType);

            if (isAllowed.HasValue && !isAllowed.Value)
            {
                isClauseAllowed = false;
            }

            if (isDisallowed.HasValue && isDisallowed.Value)
            {
                isClauseAllowed = false;
            }
            return(isClauseAllowed);
        }
예제 #23
0
        private void TestNullDeviceId(ClauseType filterType)
        {
            var devicesWithNullDeviceId = GetListWithOneSpecialDeviceIdValue(null);

            var filters = new List <Clause>
            {
                new Clause
                {
                    ColumnName  = "DeviceID",
                    ClauseType  = filterType,
                    ClauseValue = "x"
                }
            };

            var filtered = FilterHelper.FilterDeviceList(devicesWithNullDeviceId, filters);

            Assert.Equal(0, filtered.Count());
        }
예제 #24
0
        private static bool IsValidDefaultClause(ClauseType operation)
        {
            switch (operation)
            {
            case ClauseType.Equals:
            case ClauseType.IsNotNull:
            case ClauseType.IsNull:
            case ClauseType.DoesNotEqual:
            case ClauseType.Less:
            case ClauseType.LessOrEqual:
            case ClauseType.Greater:
            case ClauseType.GreaterOrEqual:
                return(true);

            default:
                return(false);
            }
        }
예제 #25
0
        //=========================================================================================
        /// <summary>Возвращает список вариантов для автоподстановки.</summary>
        public override CompletionVariantList GetVariants()
        {
            ClauseType clauseType = this.GetClauseType();

            if (clauseType == ClauseType.Unknown)
            {
                return(null);
            }

            var components       = this.GetIdComponents();
            int iComponentsCount = components == null ? 0 : components.Count;

            switch (clauseType)
            {
            case ClauseType.From:
                switch (iComponentsCount)
                {
                case 0:
                    return(this.Get_Variants_For_Sources_1());

                case 1:
                    return(this.Get_Variants_For_Sources_2(components[0]));
                }
                break;

            case ClauseType.Select:
                var sources = this.GetSources();
                switch (iComponentsCount)
                {
                case 0:
                    return(this.Get_Variants_For_Items_1(sources));

                case 1:
                    return(this.Get_Variants_For_Items_2(components[0], sources));

                case 2:
                    return(this.Get_Variants_For_Items_3(components[1], components[0], sources));
                }
                break;
            }

            return(null);
        }
예제 #26
0
            public ClauseCompiler(
                Rule rule,
                int clauseNumber,
                int clauseCount,
                ImmutableDictionary <Sig, int> procedures,
                ImmutableDictionary <string, int> symbols
                )
            {
                _rule = rule;

                _choiceType = (clauseCount, clauseNumber) switch
                {
                    (1, _) => ClauseType.NoChoice,
                    (_, 0) => ClauseType.FirstClause,
                    (var x, var y)when y == x - 1 => ClauseType.LastClause,
                    _ => ClauseType.NextClause
                };

                _procedures = procedures;
                _symbols    = symbols;
            }
예제 #27
0
        private static bool IsValidDateClause(ClauseType operation)
        {
            switch (operation)
            {
            case ClauseType.Between:
            case ClauseType.NotBetween:
            case ClauseType.Like:
            case ClauseType.NotLike:
            case ClauseType.AnyOf:
            case ClauseType.NoneOf:
            case ClauseType.IsLaterThisMonth:
            case ClauseType.IsLaterThisWeek:
            case ClauseType.IsLaterThisYear:
            case ClauseType.IsTomorrow:
            case ClauseType.IsNextWeek:
            case ClauseType.IsBeyondThisYear:
                return(false);

            default:
                return(true);
            }
        }
예제 #28
0
 public static Clause New(ClauseType type, string select = null
                          , string rowRumberOrderBy      = null //, string selectCounts = null
                          , string selectColumn          = null, string fromJoin = null
                          , string seletTable            = null //, string jointable = null, string aliace = null
                          , string condition             = null, DynamicParameters conditionParms = null
                          , string order  = null, string extra      = null
                          , string insert = null, string addcolumn  = null, DynamicParameters insertParms    = null
                          , string update = null, string editcolumn = null, DynamicParameters updateParms    = null
                          , string delete = null, string sqlclause  = null, DynamicParameters sqlClauseParms = null)
 {
     return(new Clause
     {
         ClauseType = type,
         Select = select,
         //SelectCounts = selectCounts,
         SeletTable = seletTable, // 无用
         RowRumberOrderBy = rowRumberOrderBy,
         SelectColumn = selectColumn,
         FromJoin = fromJoin,
         //JoinTable = jointable,
         //Aliace = aliace,
         Condition = condition,
         ConditionParms = conditionParms,
         Order = order,
         Extra = extra,
         //添加 ------------
         Insert = insert,
         AddColumn = addcolumn,
         InsertParms = insertParms,
         //修改 ------------
         Update = update,
         EditColumn = editcolumn,
         UpdateParms = updateParms,
         Delete = delete,
         // 任意位置sql
         SqlClause = sqlclause,
         SqlClauseParms = sqlClauseParms
     });
 }
예제 #29
0
    public void SetMode(ClauseType _gameMode)
    {
        switch (_gameMode)
        {
        case ClauseType.OneWord:
            resetAction = ConfigurateForOneWord;
            break;

        case ClauseType.TwoWord:
            resetAction = ConfigurateForTwoWord;
            break;

        case ClauseType.ThreeWord:
            resetAction = ConfigurateForTreeWord;
            break;

        default:
            break;
        }

        resetAction();
    }
예제 #30
0
        private void TestNullDeviceProperties(ClauseType filterType)
        {
            var device = DeviceCreatorHelper.BuildDeviceStructure(Guid.NewGuid().ToString(), true, null);

            device.DeviceProperties = null;

            var list = new List <DeviceModel> {
                device
            };

            var filters = new List <Clause>
            {
                new Clause
                {
                    ColumnName  = "DeviceID",
                    ClauseType  = filterType,
                    ClauseValue = "x"
                }
            };

            var filtered = FilterHelper.FilterDeviceList(list.AsQueryable(), filters);

            Assert.Equal(0, filtered.Count());
        }
예제 #31
0
        private static bool IsValidStringClause(ClauseType operation)
        {
            switch (operation)
            {
            case ClauseType.Equals:
            case ClauseType.DoesNotEqual:
            case ClauseType.Greater:
            case ClauseType.GreaterOrEqual:
            case ClauseType.Less:
            case ClauseType.LessOrEqual:
            case ClauseType.Contains:
            case ClauseType.DoesNotContain:
            case ClauseType.BeginsWith:
            case ClauseType.EndsWith:
            case ClauseType.Like:
            case ClauseType.NotLike:
            case ClauseType.IsNotNull:
            case ClauseType.IsNull:
                return(true);

            default:
                return(false);
            }
        }
예제 #32
0
파일: Statement.cs 프로젝트: nickchal/pash
		internal void AddClause (Clause clause, ClauseType clause_type)
		{
			if (clause_type == ClauseType.Case)
				case_clauses.Add (clause);
			else if (clause_type == ClauseType.CaseAfterDefault)
				sec_case_clauses.Add (clause);
		}
예제 #33
0
 public override string GetMenuStringByType(ClauseType type) {
     return Enum.IsDefined(typeof(ClauseType), type) ? base.GetMenuStringByType(type) :
         ClauseTypeEnumHelper.GetMenuStringByClauseType((int)type);
 }
예제 #34
0
        /// <summary>
        /// Converts data into parameters and adds to the dictionary collection
        /// </summary>
        /// <param name="Data"></param>
        private void ConvertDataToParams(string[] Data, ClauseType operation, ClauseNode ClauseNode)
        {
            for (int i = 0; i < Data.Length; i++)
            {
                string s = Data[i];
                string paramName = string.Format("@PM{0}", _params.Count + 1);
                // Strip the single quotes when adding parameters.
                if (s.StartsWith("'") || s.EndsWith("'"))
                    _params.Add(paramName, s.Substring(1, s.Length - 2));
                else
                    _params.Add(paramName, s);

                object value = ((DevExpress.Data.Filtering.OperandValue)ClauseNode.AdditionalOperands[0]).Value;
                _paramDataTypes.Add(paramName, value);

                if (HelpDBExt.GetDbType(value) == System.Data.DbType.String)
                {
                    switch (operation)
                    {
                        case ClauseType.BeginsWith:
                            _params[paramName] = string.Format("{0}%", _params[paramName]);
                            _paramDataTypes[paramName] = string.Format("{0}%", _paramDataTypes[paramName].ToString());
                            break;
                        case ClauseType.EndsWith:
                            _params[paramName] = string.Format("%{0}", _params[paramName]);
                            _paramDataTypes[paramName] = string.Format("%{0}", _paramDataTypes[paramName].ToString());
                            break;
                        case ClauseType.Contains:
                            _params[paramName] = string.Format("%{0}%", _params[paramName]);
                            _paramDataTypes[paramName] = string.Format("%{0}%", _paramDataTypes[paramName].ToString());
                            break;
                        case ClauseType.DoesNotContain:
                            _params[paramName] = string.Format("%{0}%", _params[paramName]);
                            _paramDataTypes[paramName] = string.Format("%{0}%", _paramDataTypes[paramName].ToString());
                            break;
                        case ClauseType.Like:
                            break;
                        case ClauseType.NotLike:
                            break;
                    }
                }

                Data[i] = paramName;
            }
        }