@@ -12,6 +12,7 @@ import (
1212 "strings"
1313 "time"
1414
15+ "github.com/1Panel-dev/1Panel/agent/app/dto"
1516 "github.com/1Panel-dev/1Panel/agent/buserr"
1617 "github.com/1Panel-dev/1Panel/agent/constant"
1718 "github.com/1Panel-dev/1Panel/agent/global"
@@ -31,7 +32,7 @@ func NewLocal(command []string, dbType, containerName, password, database string
3132}
3233
3334func (r * Local ) Create (info CreateInfo ) error {
34- createSql := fmt .Sprintf ("create database `%s` default character set %s collate %s" , info .Name , info .Format , formatMap [ info .Format ] )
35+ createSql := fmt .Sprintf ("create database `%s` default character set %s collate %s" , info .Name , info .Format , info .Collation )
3536 if err := r .ExecSQL (createSql , info .Timeout ); err != nil {
3637 if strings .Contains (strings .ToLower (err .Error ()), "error 1007" ) {
3738 return buserr .New ("ErrDatabaseIsExist" )
@@ -385,3 +386,33 @@ func (r *Local) ExecSQLForRows(command string, timeout uint) ([]string, error) {
385386 }
386387 return strings .Split (stdStr , "\n " ), nil
387388}
389+
390+ func (r * Local ) LoadFormatCollation (timeout uint ) ([]dto.MysqlFormatCollationOption , error ) {
391+ std , err := r .ExecSQLForRows ("SELECT CHARACTER_SET_NAME, COLLATION_NAME FROM INFORMATION_SCHEMA.COLLATIONS ORDER BY CHARACTER_SET_NAME, COLLATION_NAME;" , timeout )
392+ if err != nil {
393+ return nil , err
394+ }
395+ formatMap := make (map [string ][]string )
396+ for _ , item := range std {
397+ if strings .ToLower (item ) == "character_set_name\t collation_name" {
398+ continue
399+ }
400+ parts := strings .Split (item , "\t " )
401+ if len (parts ) != 2 {
402+ continue
403+ }
404+ if _ , ok := formatMap [parts [0 ]]; ! ok {
405+ formatMap [parts [0 ]] = []string {parts [1 ]}
406+ } else {
407+ formatMap [parts [0 ]] = append (formatMap [parts [0 ]], parts [1 ])
408+ }
409+ }
410+ options := []dto.MysqlFormatCollationOption {}
411+ for key , val := range formatMap {
412+ options = append (options , dto.MysqlFormatCollationOption {
413+ Format : key ,
414+ Collations : val ,
415+ })
416+ }
417+ return options , nil
418+ }
0 commit comments