Skip to content

Commit

Permalink
Another fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tbantle22 committed Nov 15, 2024
1 parent fe665b1 commit df911d8
Showing 1 changed file with 4 additions and 29 deletions.
33 changes: 4 additions & 29 deletions sql/planbuilder/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,36 +48,11 @@ func (b *Builder) resolveDb(name string) sql.Database {
}

func (b *Builder) resolveDbForTable(table ast.TableName) sql.Database {
dbName := table.DbQualifier.String()
if dbName == "" {
dbName = b.ctx.GetCurrentDatabase()
}

if dbName == "" {
b.handleErr(sql.ErrNoDatabaseSelected.New())
}

database, err := b.cat.Database(b.ctx, dbName)
if err != nil {
b.handleErr(err)
}

schema := table.SchemaQualifier.String()
if schema != "" {
scd, ok := database.(sql.SchemaDatabase)
if !ok {
b.handleErr(fmt.Errorf("database %T does not support schemas", database))
}
database, ok, err = scd.GetSchema(b.ctx, schema)
if err != nil {
b.handleErr(err)
}
if !ok {
b.handleErr(sql.ErrDatabaseSchemaNotFound.New(schema))
}
db, ok := b.maybeResolveDbForTable(table)
if !ok {
b.handleErr(sql.ErrDatabaseSchemaNotFound.New(table.SchemaQualifier.String()))
}

return database
return db
}

func (b *Builder) maybeResolveDbForTable(table ast.TableName) (sql.Database, bool) {
Expand Down

0 comments on commit df911d8

Please sign in to comment.