-
Notifications
You must be signed in to change notification settings - Fork 36
Scalarrefs for verbatim values (for SQL function calls etc) #60
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
Conversation
(Previously you had to provide a WHERE clause as {}) ... not 100% sure I want this; it could make it easy to accidentally select all rows when you didn't mean to? Also, don't have a spurious extra space at the end of a SELECT query generated without a WHERE clause (or a double space if there is one)
Call _generate_sql() with a variety of inputs and test that the resulting SQL is as we expect.
This lets you say e.g.: ```perl $handle->quick_insert('tablename', { foo => 'bar', timestamp => \'NOW()' }); ``` ... and the scalarref will go into the query as-is (so be careful about SQL injection - if you've asked the module to put it in as-is, it will, and can't protect you...)
If you've supplied a scalarref to be interpolated into the VALUES() as-is, it shouldn't also get added to the @bind_params.
This passes now, showing the feature was implemented right \o/
Define the sqlgen tests along with the others, then declare our plan, then start testing.
+1 :-) |
ta :) One thing I'm concerned about is that some of the tests may be relying on the semi-random ordering of hash iteration - so could fail randomly - will probably need to look at the places we iterate over keys/values and sort by key or something. |
Just a note, +1 on the idea, did not review the code. Can do, though, it you like. |
If you have the time, I'd certainly appreciate code review :) Some of the code in there was pretty crufty to begin with - it's not my proudest work, but it does the job. |
…alls Scalarrefs for verbatim values (for SQL function calls etc)
This feature allows you to pass a scalarref when you want a value untouched by the normal parameterisation, so you could say e.g.:
(Obviously, if you do that, it's included in the SQL as you provide it, so only you can prevent wildfires^WSQL injection attacks - be careful.)
This also includes refactoring out of the SQL & bind values generation into its own method,
_generate_sql()
for testability, and a variety of tests exercising it (testing both previous expected functionality, and the new functionality).This was prompted by a question from @b100s on Freenode/#perl earlier.