Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 7 additions & 4 deletions server/ast/create_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,19 @@ import (

// nodeCreateDatabase handles *tree.CreateDatabase nodes.
func nodeCreateDatabase(ctx *Context, node *tree.CreateDatabase) (*vitess.DBDDL, error) {
if len(node.Owner) > 0 {
return nil, errors.Errorf("OWNER clause is not yet supported")
}
var charsets []*vitess.CharsetAndCollate

if len(node.Template) > 0 {
// TODO: special casing "template0", as some tests make use of it and we need them to pass for now
if node.Template != "template0" {
return nil, errors.Errorf("TEMPLATE clause is not yet supported")
}
}
if len(node.Encoding) > 0 {
return nil, errors.Errorf("ENCODING clause is not yet supported")
charsets = append(charsets, &vitess.CharsetAndCollate{
Type: "CHARACTER SET",
Value: node.Encoding,
})
}
if len(node.Strategy) > 0 {
return nil, errors.Errorf("STRATEGY clause is not yet supported")
Expand Down Expand Up @@ -85,5 +87,6 @@ func nodeCreateDatabase(ctx *Context, node *tree.CreateDatabase) (*vitess.DBDDL,
SchemaOrDatabase: "database",
DBName: node.Name.String(),
IfNotExists: node.IfNotExists,
CharsetCollate: charsets,
}, nil
}
65 changes: 65 additions & 0 deletions testing/go/create_database_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright 2025 Dolthub, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package _go

import "testing"

func TestCreateDatabase(t *testing.T) {
RunScripts(t, []ScriptTest{
{
Name: "simple create database",
Assertions: []ScriptTestAssertion{
{
Query: "CREATE DATABASE testdb",
},
{
Query: "USE testdb",
},
},
},
{
Name: "encoding",
Assertions: []ScriptTestAssertion{
{
Query: "CREATE DATABASE testdb encoding=utf8",
},
{
Query: "USE testdb",
},
{
Query: "CREATE DATABASE testdb2 encoding=latin1",
},
{
Query: "USE testdb2",
},
{
Query: "CREATE DATABASE testdb encoding=notexist",
ExpectedErr: "Unknown character set: notexist",
},
},
},
{
Name: "multiple options",
Assertions: []ScriptTestAssertion{
{
Query: "CREATE DATABASE testdb OWNER=foo ENCODING=utf8",
},
{
Query: "USE testdb",
},
},
},
})
}
Loading