fix: atp placeholder conversion

This commit is contained in:
Reinaldy Rafli 2021-07-21 17:16:38 +07:00
parent 6186e8aa9a
commit b6fad37b7a
2 changed files with 2 additions and 2 deletions

View File

@ -28,7 +28,7 @@ func ReplacePlaceholder(sql string, format string) string {
format = Question
}
if format == Dollar || format == Colon {
if format == Dollar || format == Colon || format == AtP {
separate := strings.SplitAfter(sql, "?")
for i := 0; i < len(separate); i++ {
separate[i] = strings.Replace(separate[i], "?", format+strconv.Itoa(i+1), 1)

View File

@ -30,7 +30,7 @@ func TestReplacePlaceholder(t *testing.T) {
t.Run("should be able to replace placeholder to @p", func(t *testing.T) {
sql := "INSERT INTO table_name (`col1`, `col2`, `col3`) VALUES (?, ?, ?), (?, ?, ?), (?, ?, ?);"
result := bob.ReplacePlaceholder(sql, bob.AtP)
should := "INSERT INTO table_name (`col1`, `col2`, `col3`) VALUES (@p, @p, @p), (@p, @p, @p), (@p, @p, @p);"
should := "INSERT INTO table_name (`col1`, `col2`, `col3`) VALUES (@p1, @p2, @p3), (@p4, @p5, @p6), (@p7, @p8, @p9);"
if result != should {
t.Fatal("result string doesn't match:", result)