parseOrderByCommand - Return ast.OrderByCommand created from tokens and validate the syntax Example of input parsable to the ast.OrderByCommand: ORDER BY colName ASC
()
| 443 | // Example of input parsable to the ast.OrderByCommand: |
| 444 | // ORDER BY colName ASC |
| 445 | func (parser *Parser) parseOrderByCommand() (ast.Command, error) { |
| 446 | // token.ORDER already at current position in parser |
| 447 | orderCommand := &ast.OrderByCommand{Token: parser.currentToken} |
| 448 | |
| 449 | // token.ORDER no longer needed |
| 450 | parser.nextToken() |
| 451 | |
| 452 | err := validateTokenAndSkip(parser, []token.Type{token.BY}) |
| 453 | if err != nil { |
| 454 | return nil, err |
| 455 | } |
| 456 | |
| 457 | // ensure that loop below will execute at least once |
| 458 | err = validateToken(parser.currentToken.Type, []token.Type{token.IDENT}) |
| 459 | if err != nil { |
| 460 | return nil, err |
| 461 | } |
| 462 | |
| 463 | // array of SortPattern |
| 464 | for parser.currentToken.Type == token.IDENT { |
| 465 | // Get column name |
| 466 | err = validateToken(parser.currentToken.Type, []token.Type{token.IDENT}) |
| 467 | if err != nil { |
| 468 | return nil, err |
| 469 | } |
| 470 | columnName := parser.currentToken |
| 471 | parser.nextToken() |
| 472 | |
| 473 | // Get ASC or DESC |
| 474 | err = validateToken(parser.currentToken.Type, []token.Type{token.ASC, token.DESC}) |
| 475 | if err != nil { |
| 476 | return nil, err |
| 477 | } |
| 478 | order := parser.currentToken |
| 479 | parser.nextToken() |
| 480 | |
| 481 | // append sortPattern |
| 482 | orderCommand.SortPatterns = append(orderCommand.SortPatterns, ast.SortPattern{ColumnName: columnName, Order: order}) |
| 483 | |
| 484 | if parser.currentToken.Type != token.COMMA { |
| 485 | break |
| 486 | } |
| 487 | // Ignore token.COMMA |
| 488 | parser.nextToken() |
| 489 | } |
| 490 | |
| 491 | parser.skipIfCurrentTokenIsSemicolon() |
| 492 | |
| 493 | return orderCommand, nil |
| 494 | } |
| 495 | |
| 496 | // parseLimitCommand - Return ast.LimitCommand created from tokens and validate the syntax |
| 497 | // |
no test coverage detected