From 1a8977157df5b1e75af39829044d83f095107226 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 11 Sep 2025 07:58:46 +0000 Subject: [PATCH] Apply gci import order changes --- contrib/drivers/mysql/mysql_do_filter.go | 14 +++++++------- contrib/drivers/mysql/mysql_open.go | 4 ++-- .../drivers/mysql/mysql_z_unit_issue_4382_test.go | 10 +++++----- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/contrib/drivers/mysql/mysql_do_filter.go b/contrib/drivers/mysql/mysql_do_filter.go index af95dc7f3..5f96a04b1 100644 --- a/contrib/drivers/mysql/mysql_do_filter.go +++ b/contrib/drivers/mysql/mysql_do_filter.go @@ -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 } diff --git a/contrib/drivers/mysql/mysql_open.go b/contrib/drivers/mysql/mysql_open.go index 958801b2c..7c686638c 100644 --- a/contrib/drivers/mysql/mysql_open.go +++ b/contrib/drivers/mysql/mysql_open.go @@ -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) } diff --git a/contrib/drivers/mysql/mysql_z_unit_issue_4382_test.go b/contrib/drivers/mysql/mysql_z_unit_issue_4382_test.go index e234ce72f..81271c267 100644 --- a/contrib/drivers/mysql/mysql_z_unit_issue_4382_test.go +++ b/contrib/drivers/mysql/mysql_z_unit_issue_4382_test.go @@ -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") }) -} \ No newline at end of file +}