Apply gci import order changes

This commit is contained in:
github-actions[bot]
2025-09-11 07:58:46 +00:00
parent bae001b83b
commit 1a8977157d
3 changed files with 14 additions and 14 deletions

View File

@ -15,7 +15,7 @@ import (
// DoFilter handles the sql before posts it to database.
// This method helps handle MySQL-specific issues including key length limitations.
//
//
// For MySQL tables using utf8mb4 charset, this method automatically adds ROW_FORMAT=DYNAMIC
// to CREATE TABLE statements to prevent "Specified key was too long; max key length is 1000 bytes" errors.
// This is particularly important for compatibility when upgrading from older GoFrame versions.
@ -26,11 +26,11 @@ func (d *Driver) DoFilter(
if err != nil {
return newSql, newArgs, err
}
// Handle MySQL-specific SQL filtering to prevent key length issues
// This is particularly important for compatibility between GoFrame versions
newSql = d.handleMySQLKeyLengthCompatibility(newSql)
return newSql, newArgs, err
}
@ -41,9 +41,9 @@ func (d *Driver) handleMySQLKeyLengthCompatibility(sql string) string {
// This helps prevent "Specified key was too long; max key length is 1000 bytes" errors
sqlUpper := strings.ToUpper(sql)
sqlLower := strings.ToLower(sql)
if strings.Contains(sqlUpper, "CREATE TABLE") &&
(strings.Contains(sqlLower, "utf8mb4") || strings.Contains(sqlLower, "charset=utf8mb4")) {
if strings.Contains(sqlUpper, "CREATE TABLE") &&
(strings.Contains(sqlLower, "utf8mb4") || strings.Contains(sqlLower, "charset=utf8mb4")) {
// Add ROW_FORMAT=DYNAMIC to enable larger key prefixes when using utf8mb4
if !strings.Contains(sqlUpper, "ROW_FORMAT") {
// Insert ROW_FORMAT=DYNAMIC before ENGINE clause if it exists
@ -62,6 +62,6 @@ func (d *Driver) handleMySQLKeyLengthCompatibility(sql string) string {
}
}
}
return sql
}

View File

@ -47,14 +47,14 @@ func configNodeToSource(config *gdb.ConfigNode) string {
"%s:%s@%s(%s%s)/%s?charset=%s",
config.User, config.Pass, config.Protocol, config.Host, portStr, config.Name, config.Charset,
)
if config.Timezone != "" {
if strings.Contains(config.Timezone, "/") {
config.Timezone = url.QueryEscape(config.Timezone)
}
source = fmt.Sprintf("%s&loc=%s", source, config.Timezone)
}
if config.Extra != "" {
source = fmt.Sprintf("%s&%s", source, config.Extra)
}

View File

@ -16,7 +16,7 @@ func Test_Issue4382_KeyLengthLimit(t *testing.T) {
// when using proper MySQL configuration
table := createTable("test_key_length")
defer dropTable(table)
// Try to create a table with potentially long keys (using utf8mb4)
// This scenario could trigger the key length issue
longTableSQL := `
@ -27,10 +27,10 @@ func Test_Issue4382_KeyLengthLimit(t *testing.T) {
KEY idx_long_composite (long_field_1, long_field_2)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
`
_, err := db.Exec(ctx, "DROP TABLE IF EXISTS test_long_keys")
t.AssertNil(err)
// This should not fail with key length error in GoFrame 2.9
// Our DoFilter enhancement should automatically add ROW_FORMAT=DYNAMIC
_, err = db.Exec(ctx, longTableSQL)
@ -40,8 +40,8 @@ func Test_Issue4382_KeyLengthLimit(t *testing.T) {
t.Logf("Error creating table: %v", err)
}
t.AssertNil(err)
// Clean up
db.Exec(ctx, "DROP TABLE IF EXISTS test_long_keys")
})
}
}