(req *SqlSelect)
| 1538 | } |
| 1539 | |
| 1540 | func (m *Sqlbridge) parseOrderBy(req *SqlSelect) (err error) { |
| 1541 | |
| 1542 | if m.Cur().T != lex.TokenOrderBy { |
| 1543 | return nil |
| 1544 | } |
| 1545 | m.Next() // Consume Order By |
| 1546 | |
| 1547 | var col *Column |
| 1548 | |
| 1549 | for { |
| 1550 | |
| 1551 | //u.Debugf("Order By? %v", m.Cur()) |
| 1552 | switch m.Cur().T { |
| 1553 | case lex.TokenUdfExpr: |
| 1554 | // we have a udf/functional expression column |
| 1555 | col = NewColumnFromToken(m.Cur()) |
| 1556 | exprNode, err := expr.ParseExprWithFuncs(m, m.funcs) |
| 1557 | if err != nil { |
| 1558 | return err |
| 1559 | } |
| 1560 | col.Expr = exprNode |
| 1561 | switch n := col.Expr.(type) { |
| 1562 | case *expr.FuncNode: |
| 1563 | col.As = expr.FindIdentityName(0, n, "") |
| 1564 | if col.As == "" { |
| 1565 | col.As = n.Name |
| 1566 | } |
| 1567 | case *expr.BinaryNode: |
| 1568 | col.As = expr.FindIdentityName(0, n, "") |
| 1569 | if col.As == "" { |
| 1570 | u.Errorf("could not find as name: %#v", n) |
| 1571 | } |
| 1572 | } |
| 1573 | case lex.TokenIdentity: |
| 1574 | col = NewColumnFromToken(m.Cur()) |
| 1575 | exprNode, err := expr.ParseExprWithFuncs(m, m.funcs) |
| 1576 | if err != nil { |
| 1577 | return err |
| 1578 | } |
| 1579 | col.Expr = exprNode |
| 1580 | } |
| 1581 | //u.Debugf("OrderBy after colstart?: %v ", m.Cur()) |
| 1582 | |
| 1583 | // since we can loop inside switch statement |
| 1584 | switch m.Cur().T { |
| 1585 | case lex.TokenAsc, lex.TokenDesc: |
| 1586 | col.Order = strings.ToUpper(m.Cur().V) |
| 1587 | |
| 1588 | case lex.TokenInto, lex.TokenLimit, lex.TokenEOS, lex.TokenEOF: |
| 1589 | // This indicates we have come to the End of the columns |
| 1590 | req.OrderBy = append(req.OrderBy, col) |
| 1591 | return nil |
| 1592 | case lex.TokenCommentSingleLine: |
| 1593 | m.Next() |
| 1594 | col.Comment = m.Cur().V |
| 1595 | case lex.TokenRightParenthesis: |
| 1596 | // loop on my friend |
| 1597 | case lex.TokenComma: |
no test coverage detected