(n *chast.SelectQuery)
| 79 | } |
| 80 | |
| 81 | func (c *cc) convertSelectQuery(n *chast.SelectQuery) *ast.SelectStmt { |
| 82 | stmt := &ast.SelectStmt{} |
| 83 | |
| 84 | // Convert target list (SELECT columns) |
| 85 | if len(n.Columns) > 0 { |
| 86 | stmt.TargetList = &ast.List{} |
| 87 | for _, col := range n.Columns { |
| 88 | target := c.convertToResTarget(col) |
| 89 | if target != nil { |
| 90 | stmt.TargetList.Items = append(stmt.TargetList.Items, target) |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | // Convert FROM clause |
| 96 | if n.From != nil { |
| 97 | stmt.FromClause = c.convertTablesInSelectQuery(n.From) |
| 98 | } |
| 99 | |
| 100 | // Convert WHERE clause |
| 101 | if n.Where != nil { |
| 102 | stmt.WhereClause = c.convertExpr(n.Where) |
| 103 | } |
| 104 | |
| 105 | // Convert GROUP BY clause |
| 106 | if len(n.GroupBy) > 0 { |
| 107 | stmt.GroupClause = &ast.List{} |
| 108 | for _, expr := range n.GroupBy { |
| 109 | stmt.GroupClause.Items = append(stmt.GroupClause.Items, c.convertExpr(expr)) |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | // Convert HAVING clause |
| 114 | if n.Having != nil { |
| 115 | stmt.HavingClause = c.convertExpr(n.Having) |
| 116 | } |
| 117 | |
| 118 | // Convert ORDER BY clause |
| 119 | if len(n.OrderBy) > 0 { |
| 120 | stmt.SortClause = &ast.List{} |
| 121 | for _, orderBy := range n.OrderBy { |
| 122 | stmt.SortClause.Items = append(stmt.SortClause.Items, c.convertOrderByElement(orderBy)) |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | // Convert LIMIT clause |
| 127 | if n.Limit != nil { |
| 128 | stmt.LimitCount = c.convertExpr(n.Limit) |
| 129 | } |
| 130 | |
| 131 | // Convert OFFSET clause |
| 132 | if n.Offset != nil { |
| 133 | stmt.LimitOffset = c.convertExpr(n.Offset) |
| 134 | } |
| 135 | |
| 136 | // Convert DISTINCT clause |
| 137 | if n.Distinct { |
| 138 | stmt.DistinctClause = &ast.List{} |
no test coverage detected