Exemple #1
0
        private void BuildQuery()
        {
            if (Path != null)
            {
                __query = MemberExpression(Path);
            }

            foreach (object _element in __expression)
            {
                if (_element is DBMemberExpressionComparison other)
                {
                    if (Path != null && Path.Count > 1)
                    {
                        if (__lastOperatorLogicPos != -1)
                        {
                            if (other.Path != null)
                            {
                                int _parenthesis = Path.Count - Path.CommonMembersWith(other.Path) - 1;

                                if (_parenthesis > 0) // dans le cas ou Path et other.Path expriment le mêmes objets, _parenthesis == -1
                                {
                                    __query              = __query.Insert(__lastOperatorLogicPos, new string(')', _parenthesis));
                                    __openedParenthesis -= _parenthesis;
                                }
                            }
                            __lastOperatorLogicPos = -1;
                        }
                        other.Path = RemoveCommonMembers(other.Path);
                    }
                    __query += other.Query();
                }
                else
                if (_element is MemberPath _path)
                {
                    __query += _path.LastPropertyName.ToLower() + " ";
                }
                else
                if (_element is string s)
                {
                    if (DBExpressionBuilder.IsOperatorLogic(ref s))
                    {
                        __lastOperatorLogicPos = __query.Length;
                        __query += s + " ";
                    }
                    else
                    if (DBExpressionBuilder.IsSymbol(ref s))
                    {
                        __query += s + " ";
                        if (s == "(")
                        {
                            ++__openedParenthesis;
                        }
                        else
                        if (s == ")")
                        {
                            --__openedParenthesis;
                        }
                    }
                    else
                    {
                        __query += SqlCSharp.SqlValue(_element) + " ";
                    }
                }

                else
                {
                    __query += SqlCSharp.SqlValue(_element) + " ";
                }
            }
            __query += new string(')', __openedParenthesis);
        }
Exemple #2
0
        public override string Query()
        {
            string _query = "";

            foreach (object _o in Elements)
            {
                if (_o is MemberPath _path)
                {
                    Type _prType = _path.LastPropertyInfo.PropertyType;
                    if (_prType == typeof(Base) || _prType.IsSubclassOf(typeof(Base)))
                    {
                        __state = STATE.MEMBEROBJECT;
                    }
                    else
                    {
                        __state = STATE.MEMBERVALUE;
                    }

                    _query = string.Concat(_query, _path.LastPropertyName.ToLower(), " ");
                }

                else
                if (_o is DBSelect _select)
                {
                    if (__state == STATE.MEMBEROBJECT)
                    {
                        _select.Select("objectrepresentation");
                    }
                    _query = string.Concat(_query, "(", _select.Query(), ") ");
                }

                else
                if (_o is DBQueryable _queryable)
                {
                    _query = string.Concat(_query, _queryable.Query(), " ");
                }

                else
                if (_o is string s)
                {
                    if (__state == STATE.MEMBEROBJECT)
                    {
                        if (s == "=" || s == "in" || s == "IN")
                        {
                            _query = string.Concat(_query, "IN", " ");
                        }
                        else
                        {
                            _query = string.Concat(_query, s, " ");
                        }
                    }
                    else
                    {
                        DBExpressionBuilder.IsSymbol(ref s);// remplace == par =, && par and, etc

                        _query = string.Concat(_query, s, " ");
                    }
                }

                else
                {
                    throw new Exception("Type non attendu dans les éléments de cette expression.");
                }
            }
            return(_query);
        }