From 44007a7c8cbc65130cea12e64e8fed9f9bc1a583 Mon Sep 17 00:00:00 2001 From: Gani Georgiev Date: Sat, 15 Mar 2025 13:28:39 +0200 Subject: [PATCH] reorganized sqlLogReplacements --- core/base.go | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/core/base.go b/core/base.go index 87f10a47..530d18e9 100644 --- a/core/base.go +++ b/core/base.go @@ -1139,26 +1139,25 @@ func (app *BaseApp) initDataDB() error { return nil } -var sqlLogReplacements = map[*regexp.Regexp]string{ - regexp.MustCompile(`[^'"]\{\{`): "`", - regexp.MustCompile(`\}\}[^'"]`): "`", - regexp.MustCompile(`[^'"]\[\[`): "`", - regexp.MustCompile(`\]\][^'"]`): "`", - regexp.MustCompile(``): "NULL", +var sqlLogReplacements = []struct { + pattern *regexp.Regexp + replacement string +}{ + {regexp.MustCompile(`\[\[([^\[\]\{\}\.]+)\.([^\[\]\{\}\.]+)\]\]`), "`$1`.`$2`"}, + {regexp.MustCompile(`\{\{([^\[\]\{\}\.]+)\.([^\[\]\{\}\.]+)\}\}`), "`$1`.`$2`"}, + {regexp.MustCompile(`([^'"])\{\{`), "$1`"}, + {regexp.MustCompile(`\}\}([^'"])`), "`$1"}, + {regexp.MustCompile(`([^'"])\[\[`), "$1`"}, + {regexp.MustCompile(`\]\]([^'"])`), "`$1"}, + {regexp.MustCompile(``), "NULL"}, } -var sqlLogPrefixedTableIdentifierPattern = regexp.MustCompile(`\[\[([^\[\]\{\}\.]+)\.([^\[\]\{\}\.]+)\]\]`) -var sqlLogPrefixedColumnIdentifierPattern = regexp.MustCompile(`\{\{([^\[\]\{\}\.]+)\.([^\[\]\{\}\.]+)\}\}`) // normalizeSQLLog replaces common query builder charactes with their plain SQL version for easier debugging. // The query is still not suitable for execution and should be used only for log and debug purposes // (the normalization is done here to avoid breaking changes in dbx). func normalizeSQLLog(sql string) string { - sql = sqlLogPrefixedTableIdentifierPattern.ReplaceAllString(sql, "`$1`.`$2`") - - sql = sqlLogPrefixedColumnIdentifierPattern.ReplaceAllString(sql, "`$1`.`$2`") - - for pattern, replacement := range sqlLogReplacements { - sql = pattern.ReplaceAllString(sql, replacement) + for _, item := range sqlLogReplacements { + sql = item.pattern.ReplaceAllString(sql, item.replacement) } return sql