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

fix

parent d34b26e7
......@@ -353,8 +353,8 @@ func (d *Pool) IsAlive() bool {
}
func (d *Pool) prepare(sql string, param map[string]any) string {
for n, t := range param {
switch tv := t.(type) {
for n, t1 := range param {
switch tv := t1.(type) {
case time.Time:
sql = strings.ReplaceAll(sql, ":"+n+":", fmt.Sprintf("'%s'", tv.UTC().Format(time.DateTime)))
case *time.Time:
......@@ -366,25 +366,25 @@ func (d *Pool) prepare(sql string, param map[string]any) string {
case nil:
sql = strings.ReplaceAll(sql, ":"+n+":", "NULL")
case bool:
if t.(bool) {
if tv {
sql = strings.ReplaceAll(sql, ":"+n+":", "TRUE")
} else {
sql = strings.ReplaceAll(sql, ":"+n+":", "FALSE")
}
case *string:
if t.(*string) == nil || *t.(*string) == "NULL" {
if tv == nil || *tv == "NULL" {
sql = strings.ReplaceAll(sql, ":"+n+":", "NULL")
} 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:
if t.(string) == "NULL" {
if tv == "NULL" {
sql = strings.ReplaceAll(sql, ":"+n+":", "NULL")
} else {
sql = strings.ReplaceAll(sql, ":"+n+":", fmt.Sprintf("'%v'", strings.ReplaceAll(tv, "'", "''")))
}
case *int:
if t.(*int) == nil {
if tv == nil {
sql = strings.ReplaceAll(sql, ":"+n+":", "NULL")
} else {
sql = strings.ReplaceAll(sql, ":"+n+":", fmt.Sprintf("%v", *tv))
......@@ -412,14 +412,14 @@ func (d *Pool) prepare(sql string, param map[string]any) string {
sql = strings.ReplaceAll(sql, ":"+n+":", fmt.Sprintf("%v", *tv))
}
case int, int64:
sql = strings.ReplaceAll(sql, ":"+n+":", fmt.Sprintf("%v", t))
sql = strings.ReplaceAll(sql, ":"+n+":", fmt.Sprintf("%v", tv))
default:
switch reflect.TypeOf(t).Kind() {
switch reflect.TypeOf(tv).Kind() {
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