コード例 #1
0
        private void ParseWhere(DataObject dobj)
        {
            var filter = dobj.Get <string>("filter");
            var clause = new List <string>();

            if (filter == null)
            {
                return;
            }

            filter = filter.Trim();

            while (filter.Length > 0)
            {
                var fieldName = GetNextToken(ref filter);

                if (ValidateFieldName(fieldName) == false)
                {
                    throw new ArgumentException($"Invalid field name: {fieldName}");
                }

                clause.Add($"[{fieldName}]");

                var op = GetNextToken(ref filter).ToLower();

                switch (op)
                {
                case "eq":
                    clause.Add("=");
                    break;

                case "lt":
                    clause.Add("<");
                    break;

                case "gt":
                    clause.Add(">");
                    break;

                case "le":
                    clause.Add("<=");
                    break;

                case "ge":
                    clause.Add(">=");
                    break;

                case "ne":
                    clause.Add("<>");
                    break;

                default:
                    throw new ArgumentException($"Invalid operator {op}");
                }

                var value = GetNextToken(ref filter);

                if (value == "")
                {
                    throw new ArgumentException($"Invalid value for {fieldName} {op}");
                }

                if (value.StartsWith("'") && value.EndsWith("'"))
                {
                    clause.Add(value);
                }
                else
                {
                    decimal dValue;

                    if (decimal.TryParse(value, NumberStyles.Float, _enUs, out dValue) == false)
                    {
                        throw new ArgumentOutOfRangeException($"Value {value} is not a numeric or string value");
                    }

                    clause.Add(dValue.ToString(_enUs));
                }

                var continuation = GetNextToken(ref filter);

                switch (continuation.ToLower())
                {
                case "":
                    break;

                case "and":
                    clause.Add("AND");
                    break;

                case "or":
                    clause.Add("OR");
                    break;

                default:
                    throw new ArgumentException($"Unexpected token {continuation}");
                }
            }

            _parsedWhere = string.Join(" ", clause);
        }
コード例 #2
0
ファイル: Step.cs プロジェクト: VegasoftTI/core
 internal abstract Task HandleAsync(DataObject dobj, IDictionary <string, object> endPointContext);
コード例 #3
0
 public SelectBuilder(DataObject dobj)
 {
     ParseOrderBy(dobj);
     ParseSelect(dobj);
     ParseWhere(dobj);
 }