mysql-simple
mysql-simple copied to clipboard
closes bos#21 and bos #12
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.
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.
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:
- Find index of "values" substring in template, break template after that index (cf.
(6+) <$>
) - Go through the substitution group, counting how deep I'm inside (possibly nested) brackets -- unfortunately we have to enter the domain of context-free expressions here :(
- Break the template again after the index of a closing bracket at depth 0.
- Since all this is a Maybe monad, failure at any point leads to "no valid substitution group found"
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.
... also I haven't had much time... leaving for a 3 week vacation today :)