diff --git a/placeholder.go b/placeholder.go index e812c7c..d728609 100644 --- a/placeholder.go +++ b/placeholder.go @@ -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) diff --git a/placeholder_test.go b/placeholder_test.go index 01075a5..0cebb4a 100644 --- a/placeholder_test.go +++ b/placeholder_test.go @@ -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)