(res *ast.ResTarget, tables []*Table, node *ast.ColumnRef)
| 648 | } |
| 649 | |
| 650 | func outputColumnRefs(res *ast.ResTarget, tables []*Table, node *ast.ColumnRef) ([]*Column, error) { |
| 651 | parts := stringSlice(node.Fields) |
| 652 | var schema, name, alias string |
| 653 | switch { |
| 654 | case len(parts) == 1: |
| 655 | name = parts[0] |
| 656 | case len(parts) == 2: |
| 657 | alias = parts[0] |
| 658 | name = parts[1] |
| 659 | case len(parts) == 3: |
| 660 | schema = parts[0] |
| 661 | alias = parts[1] |
| 662 | name = parts[2] |
| 663 | default: |
| 664 | return nil, fmt.Errorf("unknown number of fields: %d", len(parts)) |
| 665 | } |
| 666 | var cols []*Column |
| 667 | var found int |
| 668 | for _, t := range tables { |
| 669 | if schema != "" && t.Rel.Schema != schema { |
| 670 | continue |
| 671 | } |
| 672 | if alias != "" && t.Rel.Name != alias { |
| 673 | continue |
| 674 | } |
| 675 | for _, c := range t.Columns { |
| 676 | |
| 677 | if c.Name == name { |
| 678 | found += 1 |
| 679 | cname := c.Name |
| 680 | if res.Name != nil { |
| 681 | cname = *res.Name |
| 682 | } |
| 683 | cols = append(cols, &Column{ |
| 684 | Name: cname, |
| 685 | Type: c.Type, |
| 686 | Table: c.Table, |
| 687 | TableAlias: alias, |
| 688 | DataType: c.DataType, |
| 689 | NotNull: c.NotNull, |
| 690 | Unsigned: c.Unsigned, |
| 691 | IsArray: c.IsArray, |
| 692 | ArrayDims: c.ArrayDims, |
| 693 | Length: c.Length, |
| 694 | EmbedTable: c.EmbedTable, |
| 695 | OriginalName: c.Name, |
| 696 | }) |
| 697 | } |
| 698 | } |
| 699 | } |
| 700 | if found == 0 { |
| 701 | return nil, &sqlerr.Error{ |
| 702 | Code: "42703", |
| 703 | Message: fmt.Sprintf("column %q does not exist", name), |
| 704 | Location: res.Location, |
| 705 | } |
| 706 | } |
| 707 | if found > 1 { |
no test coverage detected