Skip to content

Commit a39dc33

Browse files
authored
fix: Handle empty character set in MariaDB compatibility (#11082)
1 parent 0a42d49 commit a39dc33

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

agent/utils/mysql/client/info.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package client
33
import (
44
"crypto/tls"
55
"crypto/x509"
6+
"database/sql"
67
"errors"
78

89
"github.com/1Panel-dev/1Panel/agent/global"
@@ -82,8 +83,8 @@ type BackupInfo struct {
8283
}
8384

8485
type FormatCollation struct {
85-
Format string `json:"format" gorm:"column:CHARACTER_SET_NAME"`
86-
Collation string `json:"collation" gorm:"column:COLLATION_NAME"`
86+
Format sql.NullString `json:"format" gorm:"column:CHARACTER_SET_NAME"`
87+
Collation sql.NullString `json:"collation" gorm:"column:COLLATION_NAME"`
8788
}
8889

8990
type RecoverInfo struct {

agent/utils/mysql/client/local.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,9 @@ func (r *Local) LoadFormatCollation(timeout uint) ([]dto.MysqlFormatCollationOpt
405405
if len(parts) != 2 {
406406
continue
407407
}
408+
if parts[0] == "NULL" {
409+
continue
410+
}
408411
if _, ok := formatMap[parts[0]]; !ok {
409412
formatMap[parts[0]] = []string{parts[1]}
410413
} else {

agent/utils/mysql/client/remote.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,10 +421,13 @@ func (r *Remote) LoadFormatCollation(timeout uint) ([]dto.MysqlFormatCollationOp
421421
if err := rows.Scan(&item.Format, &item.Collation); err != nil {
422422
return nil, err
423423
}
424-
if _, ok := formatMap[item.Format]; !ok {
425-
formatMap[item.Format] = []string{item.Collation}
424+
if !item.Format.Valid {
425+
continue
426+
}
427+
if _, ok := formatMap[item.Format.String]; !ok {
428+
formatMap[item.Format.String] = []string{item.Collation.String}
426429
} else {
427-
formatMap[item.Format] = append(formatMap[item.Format], item.Collation)
430+
formatMap[item.Format.String] = append(formatMap[item.Format.String], item.Collation.String)
428431
}
429432
}
430433
options := []dto.MysqlFormatCollationOption{}

0 commit comments

Comments
 (0)