paul-rouse / mysql-simple

A mid-level client library for the MySQL database, intended to be fast and easy to use.
Other
91 stars 35 forks source link

closes bos#21 and bos #12 #23

Open mgmeier opened 8 years ago

mgmeier commented 8 years ago

Take actual parsing or regex matching out of the equation for extracting substitution groups from query templates. Makes substitution groups more permissive wrt. to MySQL functions and removes pcre-light dependency.

bos commented 8 years ago

Are you sure this is correct? There are no tests, your code is quite complex, and I see several uses of B.map toLower that raise yellow flags for me. Because the code is difficult to follow, I worry that parts of the query are being lowercased, which was not the pre-existing behaviour.

mgmeier commented 8 years ago

Thanks for looking into it. B.map toLower just lowercases the template to case-insensitively search for the "values" substring (as did the regex). The original template is never affected by that; you can see that the lowercased version doesn't even get bound to a variable. Anyway I'm sorry if it seems quite complex, maybe I should have commented more.

The approach is:

INSERT INTO test VALUES (?, ?, SUBSTRING(?, 2, 2)) becomes Just ("INSERT INTO test VALUES", "(?, ?, SUBSTRING(?, 2, 2))", "")

I'm sorry I didn't write any test; since I didn't know if you wanted to change the substitution group logic at all, my implementation was meant more as a proposal on how I'd thought to do it, so you could see what I meant.

If the code is less expressive than I hoped it to be (aka yellow flags), please don't hesitate to ask again.

mgmeier commented 8 years ago

... also I haven't had much time... leaving for a 3 week vacation today :)