Пример #1
0
 public DefaultQuery(IDbConnection connection, IDbTransaction transaction, Session session, string tablePrefix)
 {
     _connection  = connection;
     _transaction = transaction;
     _session     = session;
     _dialect     = SqlDialectFactory.For(connection);
     _queryState  = new QueryState(_dialect.CreateBuilder(tablePrefix));
 }
Пример #2
0
 public DefaultQuery(IDbConnection connection, IDbTransaction transaction, Session session, string tablePrefix)
 {
     _documentTable = CollectionHelper.Current.GetPrefixedName(Store.DocumentTable);
     _connection    = connection;
     _transaction   = transaction;
     _session       = session;
     _dialect       = SqlDialectFactory.For(connection);
     _sqlBuilder    = _dialect.CreateBuilder(tablePrefix);
 }
Пример #3
0
        private string EvaluateSelectStatement(ParseTreeNode selectStatement)
        {
            _limit   = null;
            _offset  = null;
            _select  = null;
            _from    = null;
            _where   = null;
            _having  = null;
            _groupBy = null;
            _orderBy = null;

            var previousContent = _builder.Length > 0 ? _builder.ToString() : null;

            _builder.Clear();

            var sqlBuilder = _dialect.CreateBuilder(_tablePrefix);

            EvaluateSelectRestriction(selectStatement.ChildNodes[1]);
            EvaluateSelectorList(selectStatement.ChildNodes[2]);

            sqlBuilder.Select();
            sqlBuilder.Selector(_select);

            EvaluateFromClause(selectStatement.ChildNodes[3]);

            if (!String.IsNullOrEmpty(_from))
            {
                sqlBuilder.From(_from);
            }

            EvaluateWhereClause(selectStatement.ChildNodes[4]);

            if (!String.IsNullOrEmpty(_where))
            {
                sqlBuilder.WhereAlso(_where);
            }

            EvaluateGroupClause(selectStatement.ChildNodes[5]);

            if (!String.IsNullOrEmpty(_groupBy))
            {
                sqlBuilder.GroupBy(_groupBy);
            }

            EvaluateHavingClause(selectStatement.ChildNodes[6]);

            if (!String.IsNullOrEmpty(_having))
            {
                sqlBuilder.Having(_having);
            }

            EvaluateOrderClause(selectStatement.ChildNodes[7]);

            if (!String.IsNullOrEmpty(_orderBy))
            {
                sqlBuilder.OrderBy(_orderBy);
            }

            EvaluateLimitClause(selectStatement.ChildNodes[8]);

            if (!String.IsNullOrEmpty(_limit))
            {
                sqlBuilder.Take(_limit);
            }

            EvaluateOffsetClause(selectStatement.ChildNodes[9]);

            if (!String.IsNullOrEmpty(_offset))
            {
                sqlBuilder.Skip(_offset);
            }

            if (previousContent != null)
            {
                _builder.Clear();
                _builder.Append(new StringBuilder(previousContent));
            }

            return(sqlBuilder.ToSqlString());
        }
Пример #4
0
 public DefaultQuery(IDbConnection connection, IDbTransaction transaction, Session session, string tablePrefix)
 {
     _session    = session;
     _dialect    = session.Store.Dialect;
     _queryState = new QueryState(_dialect.CreateBuilder(tablePrefix));
 }