(stmt *ast.CreateFunctionStmt)
| 51 | } |
| 52 | |
| 53 | func (c *Catalog) createFunction(stmt *ast.CreateFunctionStmt) error { |
| 54 | ns := stmt.Func.Schema |
| 55 | if ns == "" { |
| 56 | ns = c.DefaultSchema |
| 57 | } |
| 58 | s, err := c.getSchema(ns) |
| 59 | if err != nil { |
| 60 | return err |
| 61 | } |
| 62 | fn := &Function{ |
| 63 | Name: stmt.Func.Name, |
| 64 | Args: make([]*Argument, len(stmt.Params.Items)), |
| 65 | ReturnType: stmt.ReturnType, |
| 66 | } |
| 67 | types := make([]*ast.TypeName, len(stmt.Params.Items)) |
| 68 | for i, item := range stmt.Params.Items { |
| 69 | arg := item.(*ast.FuncParam) |
| 70 | var name string |
| 71 | if arg.Name != nil { |
| 72 | name = *arg.Name |
| 73 | } |
| 74 | fn.Args[i] = &Argument{ |
| 75 | Name: name, |
| 76 | Type: arg.Type, |
| 77 | Mode: arg.Mode, |
| 78 | HasDefault: arg.DefExpr != nil, |
| 79 | } |
| 80 | types[i] = arg.Type |
| 81 | } |
| 82 | |
| 83 | _, idx, err := s.getFunc(stmt.Func, types) |
| 84 | if err == nil && !stmt.Replace { |
| 85 | return sqlerr.RelationExists(stmt.Func.Name) |
| 86 | } |
| 87 | |
| 88 | if idx >= 0 { |
| 89 | s.Funcs[idx] = fn |
| 90 | } else { |
| 91 | s.Funcs = append(s.Funcs, fn) |
| 92 | } |
| 93 | return nil |
| 94 | } |
| 95 | |
| 96 | func (c *Catalog) dropFunction(stmt *ast.DropFunctionStmt) error { |
| 97 | for _, spec := range stmt.Funcs { |
no test coverage detected