Skip to content

Commit

Permalink
slightly improved the way in queries are parsed
Browse files Browse the repository at this point in the history
  • Loading branch information
markbates committed Aug 16, 2016
1 parent 8f61b3a commit c002160
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions sql_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pop

import (
"fmt"
"regexp"
"strings"

"github.com/jmoiron/sqlx"
Expand Down Expand Up @@ -50,11 +51,14 @@ func (sq *SQLBuilder) compile() {
} else {
sq.sql = sq.buildSelectSQL()
}
s, _, err := sqlx.In(sq.sql, sq.Args())
if err != nil {
s = sq.sql
re := regexp.MustCompile(`(?i)in\s*\(\s*\?\s*\)`)
if re.MatchString(sq.sql) {
s, _, err := sqlx.In(sq.sql, sq.Args())
if err == nil {
sq.sql = s
}
}
sq.sql = sq.Query.Connection.Dialect.TranslateSQL(s)
sq.sql = sq.Query.Connection.Dialect.TranslateSQL(sq.sql)
}
}

Expand Down

0 comments on commit c002160

Please sign in to comment.