Skip to content

Commit d3d1c06

Browse files
committed
Add support for MySQL placeholders in
sqlalchemySQL function
1 parent 2249174 commit d3d1c06

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

internal/gen.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,15 @@ func sqlalchemySQL(s, engine string) string {
378378
s = strings.ReplaceAll(s, ":", `\\:`)
379379
if engine == "postgresql" {
380380
return postgresPlaceholderRegexp.ReplaceAllString(s, ":p$1")
381+
} else if engine == "mysql" {
382+
// All "?" in string s in string s are replaced with ":p1", ":p2", ... in that order
383+
parts := strings.Split(s, "?")
384+
for i := range parts {
385+
if i != 0 {
386+
parts[i] = fmt.Sprintf(":p%d%s", i, parts[i])
387+
}
388+
}
389+
return strings.Join(parts, "")
381390
}
382391
return s
383392
}

0 commit comments

Comments
 (0)