fix: Handle empty character set in MariaDB compatibility (#11082)

This commit is contained in:
ssongliu 2025-11-26 17:21:21 +08:00 committed by GitHub
parent 0a42d4942c
commit a39dc33770
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 12 additions and 5 deletions

View file

@ -3,6 +3,7 @@ package client
import (
"crypto/tls"
"crypto/x509"
"database/sql"
"errors"
"github.com/1Panel-dev/1Panel/agent/global"
@ -82,8 +83,8 @@ type BackupInfo struct {
}
type FormatCollation struct {
Format string `json:"format" gorm:"column:CHARACTER_SET_NAME"`
Collation string `json:"collation" gorm:"column:COLLATION_NAME"`
Format sql.NullString `json:"format" gorm:"column:CHARACTER_SET_NAME"`
Collation sql.NullString `json:"collation" gorm:"column:COLLATION_NAME"`
}
type RecoverInfo struct {

View file

@ -405,6 +405,9 @@ func (r *Local) LoadFormatCollation(timeout uint) ([]dto.MysqlFormatCollationOpt
if len(parts) != 2 {
continue
}
if parts[0] == "NULL" {
continue
}
if _, ok := formatMap[parts[0]]; !ok {
formatMap[parts[0]] = []string{parts[1]}
} else {

View file

@ -421,10 +421,13 @@ func (r *Remote) LoadFormatCollation(timeout uint) ([]dto.MysqlFormatCollationOp
if err := rows.Scan(&item.Format, &item.Collation); err != nil {
return nil, err
}
if _, ok := formatMap[item.Format]; !ok {
formatMap[item.Format] = []string{item.Collation}
if !item.Format.Valid {
continue
}
if _, ok := formatMap[item.Format.String]; !ok {
formatMap[item.Format.String] = []string{item.Collation.String}
} else {
formatMap[item.Format] = append(formatMap[item.Format], item.Collation)
formatMap[item.Format.String] = append(formatMap[item.Format.String], item.Collation.String)
}
}
options := []dto.MysqlFormatCollationOption{}