bigpresh / Dancer-Plugin-Database

Dancer::Plugin::Database - easy database support for Dancer applications
http://search.cpan.org/dist/Dancer-Plugin-Database
37 stars 36 forks source link

Scalarrefs for verbatim values (for SQL function calls etc) #60

Closed bigpresh closed 9 years ago

bigpresh commented 9 years ago

This feature allows you to pass a scalarref when you want a value untouched by the normal parameterisation, so you could say e.g.:

$handle->quick_update($table, { id => 42 }, { foo => 'One', timestamp => \'NOW()' });

(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.

ambs commented 9 years ago

+1 :-)

bigpresh commented 9 years ago

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.

ambs commented 9 years ago

Just a note, +1 on the idea, did not review the code. Can do, though, it you like.

bigpresh commented 9 years ago

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.