Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions enginetest/queries/script_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,52 @@ type ScriptTestAssertion struct {
// Unlike other engine tests, ScriptTests must be self-contained. No other tables are created outside the definition of
// the tests.
var ScriptTests = []ScriptTest{
{
// https://github.com/dolthub/dolt/pull/9830
Name: "CREATE SCHEMA without database selection falls back to CREATE DATABASE",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like it might be a better fit in the TestCreateDatabase test.

SetUpScript: []string{
"CREATE DATABASE tmp",
"USE tmp",
},
Dialect: "mysql",
Assertions: []ScriptTestAssertion{
{
Query: "DROP DATABASE tmp",
},
{
Query: "CREATE SCHEMA NewDatabase",
Expected: []sql.Row{{types.OkResult{RowsAffected: 1}}},
},
{
Query: "SHOW DATABASES",
Expected: []sql.Row{{"NewDatabase"}, {"information_schema"}, {"mydb"}, {"mysql"}},
},
{
Query: "USE NewDatabase",
Expected: []sql.Row{},
},
{
Query: "SELECT DATABASE()",
Expected: []sql.Row{{"NewDatabase"}},
},
{
Query: "CREATE TABLE test_table (id INT PRIMARY KEY)",
Expected: []sql.Row{{types.OkResult{RowsAffected: 0}}},
},
{
Query: "SHOW TABLES",
Expected: []sql.Row{{"test_table"}},
},
{
Query: "USE mydb",
Expected: []sql.Row{},
},
{
Query: "DROP DATABASE NewDatabase",
Expected: []sql.Row{{types.OkResult{RowsAffected: 1}}},
},
},
},
{
// https://github.com/dolthub/go-mysql-server/issues/3216
Name: "UNION ALL with BLOB columns",
Expand Down
11 changes: 10 additions & 1 deletion sql/rowexec/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,17 @@ func (b *BaseBuilder) buildCreateDB(ctx *sql.Context, n *plan.CreateDB, row sql.

func (b *BaseBuilder) buildCreateSchema(ctx *sql.Context, n *plan.CreateSchema, row sql.Row) (sql.RowIter, error) {
database := ctx.GetCurrentDatabase()

// If no database is selected, first try to fall back to CREATE DATABASE
// since CREATE SCHEMA is a synonym for CREATE DATABASE in MySQL
// https://dev.mysql.com/doc/refman/8.4/en/create-database.html
if database == "" {
return nil, sql.ErrNoDatabaseSelected.New()
return b.buildCreateDB(ctx, &plan.CreateDB{
Catalog: n.Catalog,
DbName: n.DbName,
IfNotExists: n.IfNotExists,
Collation: n.Collation,
}, row)
}

db, err := n.Catalog.Database(ctx, database)
Expand Down
Loading