Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pop WHERE arguments makes it impossible to OR multiple IN clauses. #610

Open
Jwonsever opened this issue Dec 19, 2020 · 0 comments
Open
Labels
f: sql about SQL support

Comments

@Jwonsever
Copy link

Jwonsever commented Dec 19, 2020

I am trying to use the Where query builder built in to pop, however I've run into a case where you cannot provide the correct arguments to the query.

A simple example is:
q.Where("id in (?) or b in (?)", args...)

Builds the query:
select from model where id in ($1, $2) or b in ($3). However, as I only supplied two argument placeholders, I would only expect two args, select from model where id in ($1) or b in ($2).

The code causing this is in query.go. The where logic should not change the amount of ? placeholders the caller expected, as then the caller may not be able to supply the correct arguments.

....
	if inRegex.MatchString(stmt) {
		var inq []string
		for i := 0; i < len(args); i++ {
			inq = append(inq, "?")
		}
		qs := fmt.Sprintf("(%s)", strings.Join(inq, ","))
		stmt = strings.Replace(stmt, "(?)", qs, 1)
	}
...
@Jwonsever Jwonsever changed the title Pop WHERE arguments makes it impossible to use multiple IN clauses. Pop WHERE arguments makes it impossible to OR multiple IN clauses. Dec 19, 2020
@sio4 sio4 added this to the Backlog milestone Sep 20, 2022
@sio4 sio4 added the f: sql about SQL support label Sep 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
f: sql about SQL support
Projects
None yet
Development

No branches or pull requests

2 participants