RowIter implements the interface sql.ExecSourceRel.
(ctx *sql.Context, r sql.Row)
| 68 | |
| 69 | // RowIter implements the interface sql.ExecSourceRel. |
| 70 | func (c *DropDomain) RowIter(ctx *sql.Context, r sql.Row) (sql.RowIter, error) { |
| 71 | currentDb := ctx.GetCurrentDatabase() |
| 72 | if len(c.database) > 0 && c.database != currentDb { |
| 73 | return nil, errors.Errorf("DROP DOMAIN is currently only supported for the current database") |
| 74 | } |
| 75 | schema, err := core.GetSchemaName(ctx, nil, c.schema) |
| 76 | if err != nil { |
| 77 | return nil, err |
| 78 | } |
| 79 | collection, err := core.GetTypesCollectionFromContext(ctx, "") |
| 80 | if err != nil { |
| 81 | return nil, err |
| 82 | } |
| 83 | typeID := id.NewType(schema, c.domain) |
| 84 | domain, err := collection.GetDomainType(ctx, typeID) |
| 85 | if err != nil { |
| 86 | return nil, err |
| 87 | } |
| 88 | if domain == nil { |
| 89 | if c.ifExists { |
| 90 | // TODO: issue a notice |
| 91 | return sql.RowsToRowIter(), nil |
| 92 | } else { |
| 93 | return nil, types.ErrTypeDoesNotExist.New(c.domain) |
| 94 | } |
| 95 | } |
| 96 | if c.cascade { |
| 97 | // TODO: handle cascade |
| 98 | return nil, errors.Errorf(`cascading domain drops are not yet supported`) |
| 99 | } |
| 100 | |
| 101 | // iterate on all table columns to check if this domain is currently used. |
| 102 | db, err := core.GetSqlDatabaseFromContext(ctx, "") |
| 103 | if err != nil { |
| 104 | return nil, err |
| 105 | } |
| 106 | tableNames, err := db.GetTableNames(ctx) |
| 107 | if err != nil { |
| 108 | return nil, err |
| 109 | } |
| 110 | for _, tableName := range tableNames { |
| 111 | t, ok, err := db.GetTableInsensitive(ctx, tableName) |
| 112 | if err != nil { |
| 113 | return nil, err |
| 114 | } |
| 115 | if ok { |
| 116 | for _, col := range t.Schema(ctx) { |
| 117 | if dt, isDoltgresType := col.Type.(*types.DoltgresType); isDoltgresType && dt.TypType == types.TypeType_Domain { |
| 118 | if dt.Name() == domain.Name() { |
| 119 | // TODO: issue a detail (list of all columns and tables that uses this domain) |
| 120 | // and a hint (when we support CASCADE) |
| 121 | return nil, errors.Errorf(`cannot drop type %s because other objects depend on it - column %s of table %s depends on type %s'`, c.domain, col.Name, t.Name(), c.domain) |
| 122 | } |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 |
nothing calls this directly
no test coverage detected