(n ast.Node)
| 11 | ) |
| 12 | |
| 13 | func validateCopyfrom(n ast.Node) error { |
| 14 | stmt, ok := n.(*ast.InsertStmt) |
| 15 | if !ok { |
| 16 | return errors.New(":copyfrom requires an INSERT INTO statement") |
| 17 | } |
| 18 | if stmt.OnConflictClause != nil { |
| 19 | return errors.New(":copyfrom is not compatible with ON CONFLICT") |
| 20 | } |
| 21 | if stmt.WithClause != nil { |
| 22 | return errors.New(":copyfrom is not compatible with WITH clauses") |
| 23 | } |
| 24 | if stmt.ReturningList != nil && len(stmt.ReturningList.Items) > 0 { |
| 25 | return errors.New(":copyfrom is not compatible with RETURNING") |
| 26 | } |
| 27 | sel, ok := stmt.SelectStmt.(*ast.SelectStmt) |
| 28 | if !ok { |
| 29 | return nil |
| 30 | } |
| 31 | if len(sel.FromClause.Items) > 0 { |
| 32 | return errors.New(":copyfrom is not compatible with INSERT INTO ... SELECT") |
| 33 | } |
| 34 | if sel.ValuesLists == nil || len(sel.ValuesLists.Items) != 1 { |
| 35 | return errors.New(":copyfrom requires exactly one example row to be inserted") |
| 36 | } |
| 37 | sublist, ok := sel.ValuesLists.Items[0].(*ast.List) |
| 38 | if !ok { |
| 39 | return nil |
| 40 | } |
| 41 | for _, v := range sublist.Items { |
| 42 | _, ok := v.(*ast.ParamRef) |
| 43 | ok = ok || named.IsParamFunc(v) |
| 44 | ok = ok || named.IsParamSign(v) |
| 45 | if !ok { |
| 46 | return errors.New(":copyfrom doesn't support non-parameter values") |
| 47 | } |
| 48 | } |
| 49 | return nil |
| 50 | } |
| 51 | |
| 52 | func validateBatch(n ast.Node) error { |
| 53 | funcs := astutils.Search(n, named.IsParamFunc) |
no test coverage detected