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

Support arrays as parameters #96

Open
bridger opened this issue Jul 16, 2017 · 0 comments
Open

Support arrays as parameters #96

bridger opened this issue Jul 16, 2017 · 0 comments

Comments

@bridger
Copy link

bridger commented Jul 16, 2017

I've got an array of strings I'd like to use as a single parameter for for a WHERE IN clause.

let documentIds: [String] = [....]

When I tried:

let selectCreationDates = Select(documents.creationDate, from: documents).where(documents.documentId.in( arrayOfParameters ))
connection.execute(select, parameters: [documentIds]) { ...

I got no result from the database.

I was able to workaround by making each documentId a separate parameter like so:

let arrayOfParameters: [Parameter] = documentIds.map { _ = $0; return Parameter() }
let selectCreationDates = Select(documents.creationDate, from: documents).where(documents.documentId.in( arrayOfParameters ))
// Notice that documentIds here is no longer wrapped in the parameters array
connection.execute(select, parameters: documentIds) { ...

This approach was a little counter-intuitive and seems less efficient.

This works as expected, but is vulnerable to sql injection attacks:

let selectCreationDates = Select(documents.creationDate, from: documents).where(documents.documentId.in( documentIds ))
connection.execute(select) { ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants