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

websql.lite adapter - SQL escaping error on get #118

Closed
Vassi opened this issue Aug 14, 2012 · 0 comments · Fixed by #130
Closed

websql.lite adapter - SQL escaping error on get #118

Vassi opened this issue Aug 14, 2012 · 0 comments · Fixed by #130

Comments

@Vassi
Copy link

Vassi commented Aug 14, 2012

I ran into an issue today where I was trying to save an object with a text Key that included an apostrophe, such as: MIKE'S FAVORITE

At first I thought save was the problem but as it turns out, the issue is with GET, because it looks like the adapter first checks whether the record exists so it knows whether to insert or update. The code starts on line 118:

if (this.isArray(keyOrArray)) {
    sql = 'SELECT id, value FROM ' + this.record + " WHERE id IN ('" + keyOrArray.join("','") + "')"
} else {
    sql = 'SELECT id, value FROM ' + this.record + " WHERE id = '" + keyOrArray + "'"
}

The key is just concatenated into the SQL. When I replaced + keyOrArray + with the ? and passed keyOrArray into the objectArguments on the executeSQL call at the end of the function, my insert suddenly worked as expected.

That alone is enough for me, but I'm sure it breaks the batch insert. Luckily, I don't need it, but I wanted to point it out in case there was a better way to do this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant