mirror of
https://github.com/dolthub/dolt.git
synced 2026-05-12 11:29:01 -05:00
allow database alters and case insensitive check for info schema (#7816)
This commit is contained in:
@@ -1074,8 +1074,6 @@ func processParsedQuery(ctx *sql.Context, query string, qryist cli.Queryist, sql
|
||||
return nil, nil, err
|
||||
}
|
||||
return nil, nil, nil
|
||||
case *sqlparser.DBDDL:
|
||||
return dbddl(ctx, qryist, s, query)
|
||||
case *sqlparser.Load:
|
||||
if s.Local {
|
||||
return nil, nil, fmt.Errorf("LOCAL supported only in sql-server mode")
|
||||
@@ -1163,35 +1161,3 @@ func updateFileReadProgressOutput() {
|
||||
displayStr := fmt.Sprintf("Processed %.1f%% of the file", percent)
|
||||
fileReadProg.displayStrLen = cli.DeleteAndPrint(fileReadProg.displayStrLen, displayStr)
|
||||
}
|
||||
|
||||
func dbddl(ctx *sql.Context, queryist cli.Queryist, dbddl *sqlparser.DBDDL, query string) (sql.Schema, sql.RowIter, error) {
|
||||
action := strings.ToLower(dbddl.Action)
|
||||
var rowIter sql.RowIter = nil
|
||||
var err error = nil
|
||||
|
||||
if action != sqlparser.CreateStr && action != sqlparser.DropStr {
|
||||
return nil, nil, fmt.Errorf("Unhandled DBDDL action %v in Query %v", action, query)
|
||||
}
|
||||
|
||||
if action == sqlparser.DropStr {
|
||||
// Should not be allowed to delete repo name and information schema
|
||||
if dbddl.DBName == sql.InformationSchemaDatabaseName {
|
||||
return nil, nil, fmt.Errorf("DROP DATABASE isn't supported for database %s", sql.InformationSchemaDatabaseName)
|
||||
}
|
||||
}
|
||||
|
||||
sch, rowIter, err := queryist.Query(ctx, query)
|
||||
|
||||
if rowIter != nil {
|
||||
err = rowIter.Close(ctx)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
return sch, nil, nil
|
||||
}
|
||||
|
||||
@@ -598,8 +598,14 @@ func (p *DoltDatabaseProvider) DropDatabase(ctx *sql.Context, name string) error
|
||||
dbKey := formatDbMapKeyName(name)
|
||||
db := p.databases[dbKey]
|
||||
|
||||
ddb := db.(Database).ddb
|
||||
err := ddb.Close()
|
||||
var database *doltdb.DoltDB
|
||||
if ddb, ok := db.(Database); ok {
|
||||
database = ddb.ddb
|
||||
} else {
|
||||
return fmt.Errorf("unable to drop database: %s", name)
|
||||
}
|
||||
|
||||
err := database.Close()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -276,7 +276,11 @@ SQL
|
||||
@test "sql-create-database: sql drop database errors for info schema" {
|
||||
run dolt sql -q "DROP DATABASE information_schema"
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" =~ "DROP DATABASE isn't supported for database information_schema" ]] || false
|
||||
[[ "$output" =~ "unable to drop database: information_schema" ]] || false
|
||||
|
||||
run dolt sql -q "DROP DATABASE INFORMATION_SCHEMA"
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" =~ "unable to drop database: INFORMATION_SCHEMA" ]] || false
|
||||
}
|
||||
|
||||
@test "sql-create-database: create new database via SCHEMA alias" {
|
||||
@@ -353,3 +357,16 @@ SQL
|
||||
[ $status -eq 0 ]
|
||||
[[ $output =~ "| test- db _ |" ]] || false
|
||||
}
|
||||
|
||||
@test "sql-create-database: alter database collation" {
|
||||
run dolt sql -q "create database tmpdb"
|
||||
[ "$status" -eq 0 ]
|
||||
run dolt sql -q "show create database tmpdb"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_bin" ]] || false
|
||||
run dolt sql -q "alter database tmpdb collate utf8mb4_spanish_ci"
|
||||
[ "$status" -eq 0 ]
|
||||
run dolt sql -q "show create database tmpdb"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_spanish_ci" ]] || false
|
||||
}
|
||||
Reference in New Issue
Block a user