RowIter implements the interface sql.ExecSourceRel.
(ctx *sql.Context, r sql.Row)
| 56 | |
| 57 | // RowIter implements the interface sql.ExecSourceRel. |
| 58 | func (s *ShowSchemas) RowIter(ctx *sql.Context, r sql.Row) (sql.RowIter, error) { |
| 59 | database := s.database |
| 60 | if database == "" { |
| 61 | database = ctx.GetCurrentDatabase() |
| 62 | if database == "" { |
| 63 | return nil, errors.New("no database selected (this is a bug)") |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | db, err := core.GetSqlDatabaseFromContext(ctx, database) |
| 68 | if err != nil { |
| 69 | return nil, err |
| 70 | } |
| 71 | |
| 72 | if db == nil { |
| 73 | return nil, errors.New("database not found: " + database) |
| 74 | } |
| 75 | |
| 76 | sdb, ok := db.(sql.SchemaDatabase) |
| 77 | if !ok { |
| 78 | // This handles any database that doesn't support schemas (such as some system databases) |
| 79 | // TODO: mirror the postgres behavior of returning, every database should have schemas |
| 80 | return sql.RowsToRowIter(), nil |
| 81 | } |
| 82 | |
| 83 | schemas, err := sdb.AllSchemas(ctx) |
| 84 | if err != nil { |
| 85 | return nil, err |
| 86 | } |
| 87 | |
| 88 | rows := make([]sql.Row, len(schemas)) |
| 89 | for i, schema := range schemas { |
| 90 | rows[i] = sql.Row{schema.SchemaName()} |
| 91 | } |
| 92 | |
| 93 | return sql.RowsToRowIter(rows...), nil |
| 94 | } |
| 95 | |
| 96 | // Schema implements the interface sql.ExecSourceRel. |
| 97 | func (s *ShowSchemas) Schema(ctx *sql.Context) sql.Schema { |
nothing calls this directly
no test coverage detected