MCPcopy
hub / github.com/sqlc-dev/sqlc / Cmd

Function Cmd

internal/sql/validate/cmd.go:65–94  ·  view source on GitHub ↗
(n ast.Node, name, cmd string)

Source from the content-addressed store, hash-verified

63}
64
65func Cmd(n ast.Node, name, cmd string) error {
66 if cmd == metadata.CmdCopyFrom {
67 return validateCopyfrom(n)
68 }
69 if (cmd == metadata.CmdBatchExec || cmd == metadata.CmdBatchMany) || cmd == metadata.CmdBatchOne {
70 if err := validateBatch(n); err != nil {
71 return err
72 }
73 }
74 if !(cmd == metadata.CmdMany || cmd == metadata.CmdOne || cmd == metadata.CmdBatchMany || cmd == metadata.CmdBatchOne) {
75 return nil
76 }
77 var list *ast.List
78 switch stmt := n.(type) {
79 case *ast.SelectStmt:
80 return nil
81 case *ast.DeleteStmt:
82 list = stmt.ReturningList
83 case *ast.InsertStmt:
84 list = stmt.ReturningList
85 case *ast.UpdateStmt:
86 list = stmt.ReturningList
87 default:
88 return nil
89 }
90 if list == nil || len(list.Items) == 0 {
91 return fmt.Errorf("query %q specifies parameter %q without containing a RETURNING clause", name, cmd)
92 }
93 return nil
94}

Callers 1

parseQueryMethod · 0.92

Calls 2

validateCopyfromFunction · 0.85
validateBatchFunction · 0.85

Tested by

no test coverage detected