private void ReplaceWithCountFunc(SelectStmt stmt) { if (stmt.Query.Type == QueryType.Compound) { // メインクエリが複合クエリの場合はSELECT COUNT(*)文でラッピングする // (複合クエリのOrderBy句は変換処理なしにSELECT COUNT(*)のOrderByに使える) var singleQueryClause = SingleQuery.WrapInSelectStar(new AliasedQuery((IQueryClause)stmt.Query, false, "COUNT_")); // Limit句にはColumnを指定できないので変換処理は必要ない var singleQuery = new SingleQuery(singleQueryClause, stmt.Query.OrderBy, stmt.Query.Limit); stmt.Query = singleQuery; } this.ReplaceWithCountFunc((IQueryClause)stmt.Query); }
public void WrapInSelectStar(Dictionary <string, IEnumerable <string> > tableColumns, string AliasName = "V0_") { var stmt = this.GetStmt(); if (stmt.Type == StmtType.Select) { var selectStmt = (SelectStmt)stmt; var bestcaseTableColumns = new BestCaseDictionary <IEnumerable <string> >(tableColumns); var visitor = new NormalizeOrderByVisitor(bestcaseTableColumns); selectStmt.Accept(visitor); var singleQueryClause = SingleQuery.WrapInSelectStar(new AliasedQuery((IQueryClause)selectStmt.Query, false, AliasName)); // Limit句にはColumnを指定できないので変換処理は必要ない selectStmt.Query = new SingleQuery(singleQueryClause, selectStmt.Query.OrderBy, selectStmt.Query.Limit); } }