RowIter implements the interface sql.ExecSourceRel.
(ctx *sql.Context, r sql.Row)
| 110 | |
| 111 | // RowIter implements the interface sql.ExecSourceRel. |
| 112 | func (c *CreateFunction) RowIter(ctx *sql.Context, r sql.Row) (sql.RowIter, error) { |
| 113 | funcCollection, err := core.GetFunctionsCollectionFromContext(ctx, "") |
| 114 | if err != nil { |
| 115 | return nil, err |
| 116 | } |
| 117 | paramNames := make([]string, len(c.Parameters)) |
| 118 | paramTypes := make([]id.Type, len(c.Parameters)) |
| 119 | paramDefaults := make([]string, len(c.Parameters)) |
| 120 | for i, param := range c.Parameters { |
| 121 | paramNames[i] = param.Name |
| 122 | paramTypes[i] = param.Type.ID |
| 123 | if param.Default != nil { |
| 124 | paramDefaults[i] = param.Default.String() |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | schemaName, err := core.GetSchemaName(ctx, nil, c.SchemaName) |
| 129 | if err != nil { |
| 130 | return nil, err |
| 131 | } |
| 132 | funcID := id.NewFunction(schemaName, c.FunctionName, paramTypes...) |
| 133 | if c.Replace && funcCollection.HasFunction(ctx, funcID) { |
| 134 | if err = funcCollection.DropFunction(ctx, funcID); err != nil { |
| 135 | return nil, err |
| 136 | } |
| 137 | } |
| 138 | var extName string |
| 139 | if len(c.ExtensionName) > 0 { |
| 140 | ext, err := extensions.GetExtension(c.ExtensionName) |
| 141 | if err != nil { |
| 142 | return nil, err |
| 143 | } |
| 144 | ident := extensions.CreateLibraryIdentifier(c.ExtensionName, ext.Control.DefaultVersion) |
| 145 | _, err = extensions.GetExtensionFunction(extensions.CreateLibraryIdentifier(c.ExtensionName, ext.Control.DefaultVersion), c.ExtensionSymbol) |
| 146 | if err != nil { |
| 147 | return nil, err |
| 148 | } |
| 149 | extName = string(ident) |
| 150 | } |
| 151 | err = funcCollection.AddFunction(ctx, functions.Function{ |
| 152 | ID: funcID, |
| 153 | ReturnType: c.ReturnType.ID, |
| 154 | ParameterNames: paramNames, |
| 155 | ParameterTypes: paramTypes, |
| 156 | ParameterDefaults: paramDefaults, |
| 157 | Variadic: false, // TODO: implement this |
| 158 | IsNonDeterministic: true, |
| 159 | Strict: c.Strict, |
| 160 | Definition: c.Definition, |
| 161 | ExtensionName: extName, |
| 162 | ExtensionSymbol: c.ExtensionSymbol, |
| 163 | Operations: c.Statements, |
| 164 | SQLDefinition: c.SqlDef, |
| 165 | SetOf: c.SetOf, |
| 166 | }) |
| 167 | if err != nil { |
| 168 | return nil, err |
| 169 | } |
nothing calls this directly
no test coverage detected