Пример #1
0
        Expression ParseAndExpression()
        {
            Expression lNode = ParseOrExpression();

            while (!AtEndOfSource && (fCurrentToken.Equals("AND") || fCurrentToken.Equals("&&")))
            {
                ReadNextToken(); // skip '&&'
                lNode = new AndExpression(lNode, ParseOrExpression());
            }

            return lNode;
        }
Пример #2
0
        private void execute(Statement statement, Context context)
        {
            if (statement is SelectStatement)
            {
                // Join'den tabloları al
                // her bir kayıt için hashtable oluştur, context'e ekle, where expressionı üzerinde excute ettir. true ise listeye ekle.
                // falan filan uzun iş bu. niye yapıyorum ki ben bunu?

                SelectStatement ss = statement as SelectStatement;
                Expression filter = null;
                if (ss.From[0].On == null && ss.Where == null) filter = null;
                else if (ss.From[0].On != null && ss.Where != null) filter = new AndExpression(ss.From[0].On, ss.Where);
                else if (ss.From[0].On != null) filter = ss.From[0].On;
                else filter = ss.Where;

                this.FieldNames = ss.Select;
                this.ResultSet = context.GetData(ss.From[0], filter, ss.Select);
                this.FieldTypes = new List<Type>();
                if (this.ResultSet.Count > 0)
                {
                    foreach (Select key in ss.Select)
                        if (this.ResultSet[0][key.Alias] != null)
                            this.FieldTypes.Add(this.ResultSet[0][key.Alias].GetType());
                        else
                            this.FieldTypes.Add(typeof(string));
                }
                if (ss.OrderBy.Count > 0)
                {
                    IOrderedEnumerable<Hashtable> orderedList = this.ResultSet.OrderBy(ht=>1);
                    for (int i = 0; i < ss.OrderBy.Count; i++)
                    {
                        object orderBy = null;
                        if (ss.OrderBy[i].By is IntegerConstant)
                            orderBy = ((IntegerConstant)ss.OrderBy[i].By).Value;
                        else
                            orderBy = ((DbObjectName)ss.OrderBy[i].By).Name;

                        if (orderBy.GetType() == typeof(int))
                        {
                            int fieldNo = (int)orderBy - 1;
                            if (!(fieldNo < 0 || fieldNo >= FieldNames.Count))
                            {
                                if (ss.OrderBy[i].Desc)
                                    orderedList = orderedList.ThenByDescending(ht => ht[FieldNames[(int)fieldNo].Alias]);
                                else
                                    orderedList = orderedList.ThenBy(ht => ht[FieldNames[(int)fieldNo].Alias]);
                            }
                        }
                        else
                        {
                            string alias = orderBy.ToString();
                            if (FieldNames.IndexOf(alias) > -1)
                            {
                                if (ss.OrderBy[i].Desc)
                                    orderedList = orderedList.ThenByDescending(ht => ht[alias]);
                                else
                                    orderedList = orderedList.ThenBy(ht => ht[alias]);
                            }
                        }
                    }
                    this.ResultSet = orderedList.ToList();
                }

                if (ss.Limit != null)
                {
                    int offset = ss.Offset == null ? 0 : Convert.ToInt32(ss.Offset.Calculate(context));
                    int limit = Convert.ToInt32(ss.Limit.Calculate(context));
                    this.ResultSet = this.ResultSet.Skip(offset).Take(limit).ToList();
                }
            }
        }