(n *pcast.InsertStmt)
| 479 | } |
| 480 | |
| 481 | func (c *cc) convertInsertStmt(n *pcast.InsertStmt) *ast.InsertStmt { |
| 482 | rels := c.convertTableRefsClause(n.Table) |
| 483 | if len(rels.Items) != 1 { |
| 484 | panic("expected one range var") |
| 485 | } |
| 486 | rel := rels.Items[0] |
| 487 | rangeVar, ok := rel.(*ast.RangeVar) |
| 488 | if !ok { |
| 489 | panic("expected range var") |
| 490 | } |
| 491 | |
| 492 | insert := &ast.InsertStmt{ |
| 493 | Relation: rangeVar, |
| 494 | Cols: c.convertColumnNames(n.Columns), |
| 495 | ReturningList: &ast.List{}, |
| 496 | } |
| 497 | if ss, ok := c.convert(n.Select).(*ast.SelectStmt); ok { |
| 498 | ss.ValuesLists = c.convertLists(n.Lists) |
| 499 | insert.SelectStmt = ss |
| 500 | } else { |
| 501 | insert.SelectStmt = &ast.SelectStmt{ |
| 502 | FromClause: &ast.List{}, |
| 503 | TargetList: &ast.List{}, |
| 504 | ValuesLists: c.convertLists(n.Lists), |
| 505 | } |
| 506 | } |
| 507 | |
| 508 | if n.OnDuplicate != nil { |
| 509 | targetList := &ast.List{} |
| 510 | for _, a := range n.OnDuplicate { |
| 511 | targetList.Items = append(targetList.Items, c.convertAssignment(a)) |
| 512 | } |
| 513 | insert.OnDuplicateKeyUpdate = &ast.OnDuplicateKeyUpdate{ |
| 514 | TargetList: targetList, |
| 515 | Location: n.OriginTextPosition(), |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | return insert |
| 520 | } |
| 521 | |
| 522 | func (c *cc) convertLists(lists [][]pcast.ExprNode) *ast.List { |
| 523 | list := &ast.List{Items: []ast.Node{}} |
no test coverage detected