-
Notifications
You must be signed in to change notification settings - Fork 376
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
Use escape function with custom query #304
Comments
For partial queries: Person.find().where("name LIKE ?", ["john"]).run(...) For complete queries it's less nice: var val = db.driver.query.escapeVal("john o'connor");
var sql = "SELECT * FROM person WHERE name LIKE "+val; We could provide something nicer like: var sql = db.driver.execQuery("SELECT * FROM person WHERE name LIKE ?", [val]) Thoughts? |
Yes, it should be fine, if backwards compliant this could be nice. Maybe then |
This would be a really nice feature! My app is pretty complex and there are quite a few queries I can't really do with the ORM directly, so I create Model and Instance methods and put my queries there. This keeps the app structure intact (MVC). Being able to escape my queries directly there would be very nice and more in line with my app structure. |
I'll work on this |
Many thanks for this!! It will save me a lot of time and uselessly long code! |
I didn't try it until today, and here is what I get with the latest git version :
And here is the SQL I see in the debug console :
Followed by this error:
Is there something I didn't do correctly? I followed the docs but I might still have done some error... |
Did you run |
Here is the result of
But I still have the same issue as in my last post |
Hey, you have this: var sql = "INSERT INTO object (id, name, object_subtype_id, object_type_id, client_id) VALUES (DEFAULT, '?', ?, ?, ?) RETURNING id;"; Can you provide a more complete example? Something like the test case I'm curious about how you're calling |
Well the code where I call execQuery is in the example I posted... Like this :
It's pretty much exactly like in the test case. I don't think anything more than this could really help. I write my SQL query, I call execQuery, I pass an array of values to the query (and the values are OK when console.logged before this) and I handle the callback in a third argument. I really don't see where it fails |
I'm sorry, I searched some more today to find what was wrong (cause your tests showed that the escaping indeed worked) and I found that when I updated to last version it wasn't properly done. Now it works... Sorry guys! All's good now! |
I have a few custom queries in my models and I would like to use the function you use for escaping strings to me inserted. Is there a way to call it to sanitize my inputs?
The text was updated successfully, but these errors were encountered: