reorganized sqlLogReplacements
This commit is contained in:
parent
613af90fac
commit
44007a7c8c
27
core/base.go
27
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(`<nil>`): "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(`<nil>`), "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
|
||||
|
|
Loading…
Reference in New Issue