(n *chast.InsertQuery)
| 723 | } |
| 724 | |
| 725 | func (c *cc) convertInsertQuery(n *chast.InsertQuery) *ast.InsertStmt { |
| 726 | stmt := &ast.InsertStmt{ |
| 727 | Relation: &ast.RangeVar{ |
| 728 | Relname: &n.Table, |
| 729 | }, |
| 730 | } |
| 731 | |
| 732 | if n.Database != "" { |
| 733 | stmt.Relation.Schemaname = &n.Database |
| 734 | } |
| 735 | |
| 736 | // Convert column list |
| 737 | if len(n.Columns) > 0 { |
| 738 | stmt.Cols = &ast.List{} |
| 739 | for _, col := range n.Columns { |
| 740 | name := col.Name() |
| 741 | stmt.Cols.Items = append(stmt.Cols.Items, &ast.ResTarget{ |
| 742 | Name: &name, |
| 743 | }) |
| 744 | } |
| 745 | } |
| 746 | |
| 747 | // Convert SELECT subquery if present |
| 748 | if n.Select != nil { |
| 749 | stmt.SelectStmt = c.convert(n.Select) |
| 750 | } |
| 751 | |
| 752 | // Convert VALUES clause |
| 753 | if len(n.Values) > 0 { |
| 754 | selectStmt := &ast.SelectStmt{ |
| 755 | ValuesLists: &ast.List{}, |
| 756 | } |
| 757 | for _, row := range n.Values { |
| 758 | rowList := &ast.List{} |
| 759 | for _, val := range row { |
| 760 | rowList.Items = append(rowList.Items, c.convertExpr(val)) |
| 761 | } |
| 762 | selectStmt.ValuesLists.Items = append(selectStmt.ValuesLists.Items, rowList) |
| 763 | } |
| 764 | stmt.SelectStmt = selectStmt |
| 765 | } |
| 766 | |
| 767 | return stmt |
| 768 | } |
| 769 | |
| 770 | func (c *cc) convertCreateQuery(n *chast.CreateQuery) ast.Node { |
| 771 | // Handle CREATE DATABASE |
no test coverage detected