RowIter implements the interface sql.ExecSourceRel.
(ctx *sql.Context, _ sql.Row)
| 89 | |
| 90 | // RowIter implements the interface sql.ExecSourceRel. |
| 91 | func (c *CreateProcedure) RowIter(ctx *sql.Context, _ sql.Row) (sql.RowIter, error) { |
| 92 | procCollection, err := core.GetProceduresCollectionFromContext(ctx, "") |
| 93 | if err != nil { |
| 94 | return nil, err |
| 95 | } |
| 96 | |
| 97 | paramTypes := make([]id.Type, len(c.Parameters)) |
| 98 | paramNames := make([]string, len(c.Parameters)) |
| 99 | paramModes := make([]procedures.ParameterMode, len(c.Parameters)) |
| 100 | paramDefaults := make([]string, len(c.Parameters)) |
| 101 | for i, param := range c.Parameters { |
| 102 | paramNames[i] = param.Name |
| 103 | paramTypes[i] = param.Type.ID |
| 104 | if param.Default != nil { |
| 105 | paramDefaults[i] = param.Default.String() |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | schemaName, err := core.GetSchemaName(ctx, nil, c.SchemaName) |
| 110 | if err != nil { |
| 111 | return nil, err |
| 112 | } |
| 113 | procID := id.NewProcedure(schemaName, c.ProcedureName, paramTypes...) |
| 114 | if c.Replace && procCollection.HasProcedure(ctx, procID) { |
| 115 | if err = procCollection.DropProcedure(ctx, procID); err != nil { |
| 116 | return nil, err |
| 117 | } |
| 118 | } |
| 119 | var extName string |
| 120 | if len(c.ExtensionName) > 0 { |
| 121 | ext, err := extensions.GetExtension(c.ExtensionName) |
| 122 | if err != nil { |
| 123 | return nil, err |
| 124 | } |
| 125 | ident := extensions.CreateLibraryIdentifier(c.ExtensionName, ext.Control.DefaultVersion) |
| 126 | _, err = extensions.GetExtensionFunction(extensions.CreateLibraryIdentifier(c.ExtensionName, ext.Control.DefaultVersion), c.ExtensionSymbol) |
| 127 | if err != nil { |
| 128 | return nil, err |
| 129 | } |
| 130 | extName = string(ident) |
| 131 | } |
| 132 | err = procCollection.AddProcedure(ctx, procedures.Procedure{ |
| 133 | ID: procID, |
| 134 | ParameterNames: paramNames, |
| 135 | ParameterTypes: paramTypes, |
| 136 | ParameterModes: paramModes, |
| 137 | ParameterDefaults: paramDefaults, |
| 138 | Definition: c.Definition, |
| 139 | ExtensionName: extName, |
| 140 | ExtensionSymbol: c.ExtensionSymbol, |
| 141 | Operations: c.Statements, |
| 142 | SQLDefinition: c.SqlDef, |
| 143 | }) |
| 144 | if err != nil { |
| 145 | return nil, err |
| 146 | } |
| 147 | return sql.RowsToRowIter(), nil |
| 148 | } |
nothing calls this directly
no test coverage detected