예제 #1
0
        protected override SqlSelectAll VisitSqlSelectAll(SqlSelectAll sqlSelectStar)
        {
            if (sqlSelectStar.Table != null)
            {
                this.QuoteAppend(sqlSelectStar.Table.GetName());
                _sql.Append(".*");
            }
            else
            {
                _sql.Append("*");
            }

            return sqlSelectStar;
        }
예제 #2
0
 protected virtual SqlSelectAll VisitSqlSelectAll(SqlSelectAll sqlSelectStar)
 {
     return sqlSelectStar;
 }
예제 #3
0
 protected virtual SqlSelectAll VisitSqlSelectAll(SqlSelectAll sqlSelectStar)
 {
     return(sqlSelectStar);
 }
예제 #4
0
        private static ISqlSelect MakePagingTree_ReserveMethod(SqlSelect raw, int startRow, int endRow)
        {
            /*********************** 代码块解释 *********************************
             * 源格式:
             *     SELECT *
             *     FROM A
             *     WHERE A.Id > 0
             *     ORDER BY A.NAME ASC
             *
             * 目标格式:
             *      SELECT * FROM
             *      (SELECT A.*, ROWNUM RN
             *     FROM A
             *     WHERE A.Id > 0 AND ROWNUM <= 20
             *     ORDER BY A.NAME ASC)
             *     WHERE RN >= 10
             *
             * 这种方法可能存在问题:
             * 因为源 Sql 可能是:Select * From A Join B,这时表示结果集需要显示 A 和 B 的所有字段,
             * 但是此方法会转换为:Select A.* From A Join B。比较麻烦,暂不处理
            **********************************************************************/
            var innerSelect = new SqlSelect
            {
                IsDistinct = raw.IsDistinct,
                From = raw.From,
                Where = AppendWhere(raw.Where, new SqlLiteral("ROWNUM <= " + endRow)),
                OrderBy = raw.OrderBy
            };

            //内部的 Select 子句中,不能简单地使用 "*, ROWNUM",而是需要使用 "A.*, ROWNUM"
            var rawSelection = raw.Selection;
            if (rawSelection == null)
            {
                //默认约定第一张表,就是
                var table = new FirstTableFinder().Find(raw.From);
                rawSelection = new SqlSelectAll
                {
                    Table = table
                };
            }
            innerSelect.Selection = new SqlNodeList
            {
                rawSelection,
                new SqlLiteral(", ROWNUM RN")
            };

            var res = new SqlSelect
            {
                Selection = SqlSelectAll.Default,
                From = new SqlSubSelect
                {
                    Select = innerSelect
                },
                Where = new SqlLiteral("RN >= " + startRow)
            };
            return res;
        }