Commit 42ac34aa authored by Vladimir Barsukov's avatar Vladimir Barsukov
Browse files

fix

parent d34b26e7
...@@ -353,8 +353,8 @@ func (d *Pool) IsAlive() bool { ...@@ -353,8 +353,8 @@ func (d *Pool) IsAlive() bool {
} }
func (d *Pool) prepare(sql string, param map[string]any) string { func (d *Pool) prepare(sql string, param map[string]any) string {
for n, t := range param { for n, t1 := range param {
switch tv := t.(type) { switch tv := t1.(type) {
case time.Time: case time.Time:
sql = strings.ReplaceAll(sql, ":"+n+":", fmt.Sprintf("'%s'", tv.UTC().Format(time.DateTime))) sql = strings.ReplaceAll(sql, ":"+n+":", fmt.Sprintf("'%s'", tv.UTC().Format(time.DateTime)))
case *time.Time: case *time.Time:
...@@ -366,25 +366,25 @@ func (d *Pool) prepare(sql string, param map[string]any) string { ...@@ -366,25 +366,25 @@ func (d *Pool) prepare(sql string, param map[string]any) string {
case nil: case nil:
sql = strings.ReplaceAll(sql, ":"+n+":", "NULL") sql = strings.ReplaceAll(sql, ":"+n+":", "NULL")
case bool: case bool:
if t.(bool) { if tv {
sql = strings.ReplaceAll(sql, ":"+n+":", "TRUE") sql = strings.ReplaceAll(sql, ":"+n+":", "TRUE")
} else { } else {
sql = strings.ReplaceAll(sql, ":"+n+":", "FALSE") sql = strings.ReplaceAll(sql, ":"+n+":", "FALSE")
} }
case *string: case *string:
if t.(*string) == nil || *t.(*string) == "NULL" { if tv == nil || *tv == "NULL" {
sql = strings.ReplaceAll(sql, ":"+n+":", "NULL") sql = strings.ReplaceAll(sql, ":"+n+":", "NULL")
} else { } else {
sql = strings.ReplaceAll(sql, ":"+n+":", fmt.Sprintf("'%v'", strings.ReplaceAll(*t.(*string), "'", "''"))) sql = strings.ReplaceAll(sql, ":"+n+":", fmt.Sprintf("'%v'", strings.ReplaceAll(*tv, "'", "''")))
} }
case string: case string:
if t.(string) == "NULL" { if tv == "NULL" {
sql = strings.ReplaceAll(sql, ":"+n+":", "NULL") sql = strings.ReplaceAll(sql, ":"+n+":", "NULL")
} else { } else {
sql = strings.ReplaceAll(sql, ":"+n+":", fmt.Sprintf("'%v'", strings.ReplaceAll(tv, "'", "''"))) sql = strings.ReplaceAll(sql, ":"+n+":", fmt.Sprintf("'%v'", strings.ReplaceAll(tv, "'", "''")))
} }
case *int: case *int:
if t.(*int) == nil { if tv == nil {
sql = strings.ReplaceAll(sql, ":"+n+":", "NULL") sql = strings.ReplaceAll(sql, ":"+n+":", "NULL")
} else { } else {
sql = strings.ReplaceAll(sql, ":"+n+":", fmt.Sprintf("%v", *tv)) sql = strings.ReplaceAll(sql, ":"+n+":", fmt.Sprintf("%v", *tv))
...@@ -412,14 +412,14 @@ func (d *Pool) prepare(sql string, param map[string]any) string { ...@@ -412,14 +412,14 @@ func (d *Pool) prepare(sql string, param map[string]any) string {
sql = strings.ReplaceAll(sql, ":"+n+":", fmt.Sprintf("%v", *tv)) sql = strings.ReplaceAll(sql, ":"+n+":", fmt.Sprintf("%v", *tv))
} }
case int, int64: case int, int64:
sql = strings.ReplaceAll(sql, ":"+n+":", fmt.Sprintf("%v", t)) sql = strings.ReplaceAll(sql, ":"+n+":", fmt.Sprintf("%v", tv))
default: default:
switch reflect.TypeOf(t).Kind() { switch reflect.TypeOf(tv).Kind() {
case reflect.Slice: case reflect.Slice:
sql = strings.ReplaceAll(sql, ":"+n+":", "'{"+strings.Trim(strings.Join(strings.Split(fmt.Sprint(t), " "), ","), "[]")+"}'") sql = strings.ReplaceAll(sql, ":"+n+":", "'{"+strings.Trim(strings.Join(strings.Split(fmt.Sprint(tv), " "), ","), "[]")+"}'")
} }
sql = strings.ReplaceAll(sql, ":"+n+":", fmt.Sprintf("'%v'", t)) sql = strings.ReplaceAll(sql, ":"+n+":", fmt.Sprintf("'%v'", tv))
} }
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment