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: | 			case reflect.Bool: | ||||||
| 				vars[idx] = fmt.Sprintf("%t", reflectValue.Interface()) | 				vars[idx] = fmt.Sprintf("%t", reflectValue.Interface()) | ||||||
| 			case reflect.String: | 			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: | 			default: | ||||||
| 				if v != nil && reflectValue.IsValid() && ((reflectValue.Kind() == reflect.Ptr && !reflectValue.IsNil()) || reflectValue.Kind() != reflect.Ptr) { | 				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 { | 				} else { | ||||||
| 					vars[idx] = nullStr | 					vars[idx] = nullStr | ||||||
| 				} | 				} | ||||||
| @ -94,7 +94,7 @@ func ExplainSQL(sql string, numericPlaceholder *regexp.Regexp, escaper string, a | |||||||
| 		case float64, float32: | 		case float64, float32: | ||||||
| 			vars[idx] = fmt.Sprintf("%.6f", v) | 			vars[idx] = fmt.Sprintf("%.6f", v) | ||||||
| 		case string: | 		case string: | ||||||
| 			vars[idx] = escaper + strings.Replace(v, escaper, "\\"+escaper, -1) + escaper | 			vars[idx] = escaper + strings.ReplaceAll(v, escaper, "\\"+escaper) + escaper | ||||||
| 		default: | 		default: | ||||||
| 			rv := reflect.ValueOf(v) | 			rv := reflect.ValueOf(v) | ||||||
| 			if v == nil || !rv.IsValid() || rv.Kind() == reflect.Ptr && rv.IsNil() { | 			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 | 						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 { | 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) { | func TestExplainSQL(t *testing.T) { | ||||||
|  | |||||||
| @ -174,7 +174,7 @@ func (ns NamingStrategy) toDBName(name string) string { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (ns NamingStrategy) toSchemaName(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 { | 	for _, initialism := range commonInitialisms { | ||||||
| 		result = regexp.MustCompile(strings.Title(strings.ToLower(initialism))+"([A-Z]|$|_)").ReplaceAllString(result, initialism+"$1") | 		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 { | func replaceQuoteInSQL(sql string) string { | ||||||
| 	// convert single quote into double quote
 | 	// convert single quote into double quote
 | ||||||
| 	sql = strings.Replace(sql, `'`, `"`, -1) | 	sql = strings.ReplaceAll(sql, `'`, `"`) | ||||||
| 
 | 
 | ||||||
| 	// convert dialect speical quote into double quote
 | 	// convert dialect speical quote into double quote
 | ||||||
| 	switch DB.Dialector.Name() { | 	switch DB.Dialector.Name() { | ||||||
| 	case "postgres": | 	case "postgres": | ||||||
| 		sql = strings.Replace(sql, `"`, `"`, -1) | 		sql = strings.ReplaceAll(sql, `"`, `"`) | ||||||
| 	case "mysql", "sqlite": | 	case "mysql", "sqlite": | ||||||
| 		sql = strings.Replace(sql, "`", `"`, -1) | 		sql = strings.ReplaceAll(sql, "`", `"`) | ||||||
| 	case "sqlserver": | 	case "sqlserver": | ||||||
| 		sql = strings.Replace(sql, `'`, `"`, -1) | 		sql = strings.ReplaceAll(sql, `'`, `"`) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	return sql | 	return sql | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 codingxh
						codingxh