Пример #1
0
        private IList <R> ExecuteImpl <R>(int size, long page) where R : IDbReader, new()
        {
            if (_query.Query.Provider.SupperLimit)
            {
                DbQueryBuilder builder = _query.Build(_query.Query.DataSource, 0, false);
                builder.Append(" LIMIT ").Append(size).Append(" OFFSET ").Append((page - 1) * size);
                builder.Append(';');
                return(_query.Query.DataSource.ExecuteReader <R>(builder.Sql, builder.Parameters));
            }

            if (_query.Query.Provider.SupperTop)
            {
                DbQueryBuilder builder = _query.Build(_query.Query.DataSource, page * size, false);
                builder.Append(';');
                IList <R> list = _query.Query.DataSource.ExecuteReader <R>(builder.Sql, builder.Parameters);
                if (page == 1)
                {
                    return(list);
                }
                List <R> array = new List <R>(size);
                for (long i = ((page - 1) * size); i < list.Count; ++i)
                {
                    array.Add(list[(int)i]);
                }
                return(array);
            }

            throw new NotSupportedException();
        }
Пример #2
0
        protected override void OnBuild(DataSource ds, DbQueryBuilder builder, string column)
        {
            DataParameter dp = Query.Query.BuildParameter(_value);

            builder.Append(dp.GetParameterName());
            builder.Append(dp);
        }
Пример #3
0
        DbQueryBuilder IDbUpdateQuery.Build(DataSource ds, ref int count)
        {
            DbQueryBuilder builder = new DbQueryBuilder("UPDATE ");

            builder.Append(ds.Provider.EscapeName(DbTable.GetTableName <T>()));
            builder.Append(" SET ");
            return(builder);
        }
Пример #4
0
        private IList <dynamic> ExecuteImpl(int size, long page, out long count)
        {
            bool           group = false;
            DbQueryBuilder qb    = _query.BuildCount(_query.Query.DataSource, 0, false, ref group);

            if (group)
            {
                qb.Append(") AS T").Append(_query.Query.DataSource.PsCount);
            }
            count = Convert.ToInt64(_query.Query.DataSource.ExecuteScalar(qb.Sql, qb.Parameters));

            if (_query.Query.Provider.SupperRowNumber)
            {
                long half    = count / 2;
                long lower   = (page - 1) * size;
                long upper   = page * size;
                bool reverse = lower > half;
                DbQueryRowNumberBuilder builder = _query.BuildRowNumber(_query.Query.DataSource, reverse ? (count - lower) : upper, false, null, reverse);
                builder.Append(")SELECT * FROM CTE WHERE _RowNumber>");
                if (reverse)
                {
                    builder.Append(count - upper);
                }
                else
                {
                    builder.Append(lower);
                }
                if (builder.OrderBy != null)
                {
                    builder.Append(' ').Append(builder.OrderBy);
                }
                builder.Append(';');
                return(_query.Query.DataSource.ExecuteReader(builder.Sql, builder.Parameters));
            }

            if (_query.Query.Provider.SupperLimit)
            {
                DbQueryBuilder builder = _query.Build(_query.Query.DataSource, 0, false);
                builder.Append(" LIMIT ").Append(size).Append(" OFFSET ").Append((page - 1) * size);
                builder.Append(';');
                return(_query.Query.DataSource.ExecuteReader(builder.Sql, builder.Parameters));
            }

            if (_query.Query.Provider.SupperTop)
            {
                DbQueryBuilder builder = _query.Build(_query.Query.DataSource, page * size, false);
                builder.Append(';');
                IList <dynamic> list  = _query.Query.DataSource.ExecuteReader(builder.Sql, builder.Parameters);
                List <dynamic>  array = new List <dynamic>(size);
                for (long i = ((page - 1) * size); i < list.Count; ++i)
                {
                    array.Add(list[(int)i]);
                }
                return(array);
            }

            throw new NotSupportedException();
        }
Пример #5
0
        DbQueryBuilder IDbUpdateQuery.Build(DataSource ds, ref int count)
        {
            DbQueryBuilder builder    = _query.Build(ds, ref count);
            DbQueryBuilder subBuilder = _subQuery.Build(ds, 0, false);

            builder.Append('(');
            builder.Append(subBuilder.Sql);
            builder.Append(')');
            builder.Append(subBuilder.Parameters);
            return(builder);
        }
Пример #6
0
        DbQueryBuilder IDbSelectQuery.BuildCount(DataSource ds, long top, bool join, ref bool group)
        {
            DbQueryBuilder builder = new DbQueryBuilder("SELECT COUNT(*) FROM ");

            if (group)
            {
                builder.Append("(SELECT COUNT(*) AS C").Append(ds.PsCount).Append(" FROM ");
            }
            builder.Append(ds.Provider.EscapeName(DbTable.GetTableName <T>()));
            return(builder);
        }
Пример #7
0
        public long Execute()
        {
            bool           group   = false;
            DbQueryBuilder builder = _query.BuildCount(_query.Query.DataSource, 0, false, ref group);

            if (group)
            {
                builder.Append(") AS T").Append(_query.Query.DataSource.PsCount);
            }
            builder.Append(';');
            return(Convert.ToInt64(_query.Query.DataSource.ExecuteScalar(builder.Sql, builder.Parameters)));
        }
Пример #8
0
        DbQueryBuilder IDbUpdateQuery.Build(DataSource ds, ref int count)
        {
            string         name    = _column.Build(ds);
            DbQueryBuilder builder = _query.Build(ds, ref count);

            if (count++ > 0)
            {
                builder.Append(',');
            }
            builder.Append(name);
            builder.Append('=');
            OnBuild(ds, builder, name);
            return(builder);
        }
Пример #9
0
        DbQueryBuilder IDbJoinQuery <T, A, B> .Build(DataSource ds, long top, bool join)
        {
            DbQueryBuilder builder = _query.Build(ds, top, join);

            builder.Append(" GROUP BY ");
            for (int i = 0; i < _group.Length; ++i)
            {
                if (i > 0)
                {
                    builder.Append(',');
                }
                builder.Append(_group[i].Build(ds));
            }
            return(builder);
        }
Пример #10
0
        DbQueryBuilder IDbSelectQuery.Build(DataSource ds, long top, bool join)
        {
            DbQueryBuilder builder = _query.Build(ds, top, join);

            builder.Append(" ORDER BY ");
            for (int i = 0; i < _order.Length; ++i)
            {
                if (i > 0)
                {
                    builder.Append(',');
                }
                builder.Append(_order[i].Build(ds));
            }
            return(builder);
        }
Пример #11
0
        public IList <R> Execute <R>() where R : IDbReader, new()
        {
            DbQueryBuilder builder = _query.Build(_query.Query.DataSource, 0, false);

            builder.Append(';');
            return(_query.Query.DataSource.ExecuteReader <R>(builder.Sql, builder.Parameters));
        }
Пример #12
0
        public R Execute <R>()
        {
            DbQueryBuilder builder = _query.Build(_query.Query.DataSource, 0, false);

            builder.Append(';');
            return(_query.Query.DataSource.ExecuteScalar <R>(builder.Sql, builder.Parameters));
        }
Пример #13
0
        public object[] Execute()
        {
            DbQueryBuilder builder = _query.Build(_query.Query.DataSource, 0, false);

            builder.Append(';');
            return(_query.Query.DataSource.ExecuteArray(builder.Sql, builder.Parameters));
        }
Пример #14
0
        public dynamic Execute()
        {
            DbQueryBuilder builder = _query.Build(_query.Query.DataSource, 0, false);

            builder.Append(';');
            return(_query.Query.DataSource.ExecuteSingleRow(builder.Sql, builder.Parameters));
        }
Пример #15
0
        public IList <dynamic> Execute()
        {
            DbQueryBuilder builder = _query.Build(_query.Query.DataSource, 0, false);

            builder.Append(';');
            return(_query.Query.DataSource.ExecuteReader(builder.Sql, builder.Parameters));
        }
Пример #16
0
        DbQueryBuilder IDbJoinQuery <T, A, B> .Build(DataSource ds, long top, bool join)
        {
            DbQueryBuilder builder = new DbQueryBuilder("SELECT");

            if (top > 0)
            {
                builder.Append(" TOP ").Append(top);
            }
            builder.Append(' ');
            if (_select == null || _select.Length == 0)
            {
                if (join)
                {
                    builder.Append((new DbSelect <B>()).Build(ds));
                }
                else
                {
                    builder.Append((new DbSelect()).Build(ds));
                }
            }
            else
            {
                for (int i = 0; i < _select.Length; ++i)
                {
                    if (i > 0)
                    {
                        builder.Append(',');
                    }
                    builder.Append(_select[i].Build(ds));
                }
            }
            builder.Append(" FROM ").Append(ds.Provider.EscapeName(DbTable.GetTableName <B>()));
            return(builder);
        }
Пример #17
0
        DbQueryBuilder IDbSubQuery <R> .Build(DataSource ds, long top, bool join)
        {
            DbQueryBuilder builder = _query.Build(ds, top, join);

            if (_where != null)
            {
                builder.Append(" WHERE ").Append(_where.Build(ds));
            }
            return(builder);
        }
Пример #18
0
        DbQueryBuilder IDbUpdateQuery.Build(DataSource ds, ref int count)
        {
            DbQueryBuilder builder = _query.Build(ds, ref count);

            if (_where != null)
            {
                builder.Append(" WHERE ").Append(_where.Build(ds));
            }
            return(builder);
        }
Пример #19
0
        internal DbQueryBuilder Build(DataSource ds)
        {
            DbQueryBuilder builder = new DbQueryBuilder();

            foreach (object value in _queue)
            {
                if (value is DbWhere)
                {
                    builder.Append(((DbWhere)value).Build(ds));
                }
                else if (value is DbWhereQueue)
                {
                    builder.Append(((DbWhereQueue)value).Build(ds));
                }
                else
                {
                    builder.Append((string)value);
                }
            }
            return(builder);
        }
Пример #20
0
 internal override void OnBuild(DbQueryBuilder builder)
 {
     builder.Append(" WHEN ").Append(_when).Append(" THEN ").Append(Expression);
 }
Пример #21
0
 internal override void OnBuild(DbQueryBuilder builder)
 {
     builder.Append(" END");
 }
Пример #22
0
 internal override void OnBuild(DbQueryBuilder builder)
 {
     builder.Append(" ELSE ").Append(Expression);
 }