Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Vladimir Barsukov
zGo
Commits
42ac34aa
Commit
42ac34aa
authored
Nov 18, 2023
by
Vladimir Barsukov
Browse files
fix
parent
d34b26e7
Changes
1
Hide whitespace changes
Inline
Side-by-side
zdb/pool.go
View file @
42ac34aa
...
...
@@ -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
,
t
1
:=
range
param
{
switch
tv
:=
t
1
.
(
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
t
v
{
sql
=
strings
.
ReplaceAll
(
sql
,
":"
+
n
+
":"
,
"TRUE"
)
}
else
{
sql
=
strings
.
ReplaceAll
(
sql
,
":"
+
n
+
":"
,
"FALSE"
)
}
case
*
string
:
if
t
.
(
*
string
)
==
nil
||
*
t
.
(
*
string
)
==
"NULL"
{
if
t
v
==
nil
||
*
t
v
==
"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
(
*
t
v
,
"'"
,
"''"
)))
}
case
string
:
if
t
.
(
string
)
==
"NULL"
{
if
t
v
==
"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
t
v
==
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"
,
t
v
))
default
:
switch
reflect
.
TypeOf
(
t
)
.
Kind
()
{
switch
reflect
.
TypeOf
(
t
v
)
.
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
(
t
v
),
" "
),
","
),
"[]"
)
+
"}'"
)
}
sql
=
strings
.
ReplaceAll
(
sql
,
":"
+
n
+
":"
,
fmt
.
Sprintf
(
"'%v'"
,
t
))
sql
=
strings
.
ReplaceAll
(
sql
,
":"
+
n
+
":"
,
fmt
.
Sprintf
(
"'%v'"
,
t
v
))
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment