mirror of https://github.com/go-gorm/gorm.git
strings.replace -> strings.replaceAll (#5095)
Co-authored-by: huquan<xxhh_quan_g@163.com>
This commit is contained in:
parent
f3547e00cc
commit
664c5fb767
|
@ -75,10 +75,10 @@ func ExplainSQL(sql string, numericPlaceholder *regexp.Regexp, escaper string, a
|
|||
case reflect.Bool:
|
||||
vars[idx] = fmt.Sprintf("%t", reflectValue.Interface())
|
||||
case reflect.String:
|
||||
vars[idx] = escaper + strings.Replace(fmt.Sprintf("%v", v), escaper, "\\"+escaper, -1) + escaper
|
||||
vars[idx] = escaper + strings.ReplaceAll(fmt.Sprintf("%v", v), escaper, "\\"+escaper) + escaper
|
||||
default:
|
||||
if v != nil && reflectValue.IsValid() && ((reflectValue.Kind() == reflect.Ptr && !reflectValue.IsNil()) || reflectValue.Kind() != reflect.Ptr) {
|
||||
vars[idx] = escaper + strings.Replace(fmt.Sprintf("%v", v), escaper, "\\"+escaper, -1) + escaper
|
||||
vars[idx] = escaper + strings.ReplaceAll(fmt.Sprintf("%v", v), escaper, "\\"+escaper) + escaper
|
||||
} else {
|
||||
vars[idx] = nullStr
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ func ExplainSQL(sql string, numericPlaceholder *regexp.Regexp, escaper string, a
|
|||
case float64, float32:
|
||||
vars[idx] = fmt.Sprintf("%.6f", v)
|
||||
case string:
|
||||
vars[idx] = escaper + strings.Replace(v, escaper, "\\"+escaper, -1) + escaper
|
||||
vars[idx] = escaper + strings.ReplaceAll(v, escaper, "\\"+escaper) + escaper
|
||||
default:
|
||||
rv := reflect.ValueOf(v)
|
||||
if v == nil || !rv.IsValid() || rv.Kind() == reflect.Ptr && rv.IsNil() {
|
||||
|
@ -111,7 +111,7 @@ func ExplainSQL(sql string, numericPlaceholder *regexp.Regexp, escaper string, a
|
|||
return
|
||||
}
|
||||
}
|
||||
vars[idx] = escaper + strings.Replace(fmt.Sprint(v), escaper, "\\"+escaper, -1) + escaper
|
||||
vars[idx] = escaper + strings.ReplaceAll(fmt.Sprint(v), escaper, "\\"+escaper) + escaper
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ func (s ExampleStruct) Value() (driver.Value, error) {
|
|||
}
|
||||
|
||||
func format(v []byte, escaper string) string {
|
||||
return escaper + strings.Replace(string(v), escaper, "\\"+escaper, -1) + escaper
|
||||
return escaper + strings.ReplaceAll(string(v), escaper, "\\"+escaper) + escaper
|
||||
}
|
||||
|
||||
func TestExplainSQL(t *testing.T) {
|
||||
|
|
|
@ -174,7 +174,7 @@ func (ns NamingStrategy) toDBName(name string) string {
|
|||
}
|
||||
|
||||
func (ns NamingStrategy) toSchemaName(name string) string {
|
||||
result := strings.Replace(strings.Title(strings.Replace(name, "_", " ", -1)), " ", "", -1)
|
||||
result := strings.ReplaceAll(strings.Title(strings.ReplaceAll(name, "_", " ")), " ", "")
|
||||
for _, initialism := range commonInitialisms {
|
||||
result = regexp.MustCompile(strings.Title(strings.ToLower(initialism))+"([A-Z]|$|_)").ReplaceAllString(result, initialism+"$1")
|
||||
}
|
||||
|
|
|
@ -460,16 +460,16 @@ func assertEqualSQL(t *testing.T, expected string, actually string) {
|
|||
|
||||
func replaceQuoteInSQL(sql string) string {
|
||||
// convert single quote into double quote
|
||||
sql = strings.Replace(sql, `'`, `"`, -1)
|
||||
sql = strings.ReplaceAll(sql, `'`, `"`)
|
||||
|
||||
// convert dialect speical quote into double quote
|
||||
switch DB.Dialector.Name() {
|
||||
case "postgres":
|
||||
sql = strings.Replace(sql, `"`, `"`, -1)
|
||||
sql = strings.ReplaceAll(sql, `"`, `"`)
|
||||
case "mysql", "sqlite":
|
||||
sql = strings.Replace(sql, "`", `"`, -1)
|
||||
sql = strings.ReplaceAll(sql, "`", `"`)
|
||||
case "sqlserver":
|
||||
sql = strings.Replace(sql, `'`, `"`, -1)
|
||||
sql = strings.ReplaceAll(sql, `'`, `"`)
|
||||
}
|
||||
|
||||
return sql
|
||||
|
|
Loading…
Reference in New Issue