Fork me on GitHub
#sql
<
2017-06-28
>
mattly23:06:10

does anyone know of a library that will take a vector of a querystring and parameters such as ["select ? from foo" "bar"] and render "select bar from foo"

mattly23:06:45

I feel like this would be simple enough to write but the itch isn't big enough at the moment

seancorfield23:06:01

Can I ask why you want/need this?

mattly23:06:58

@seancorfield debugging purposes mainly

mattly23:06:44

I'd like to be able to copy and paste the generated query into a SQL client and run the query without having to splice the parameters myself

seancorfield23:06:22

Ah… there’s a JIRA issue to provide a way to retrieve the actual SQL that is run but it’s non-trivial (at least, it seemed so, last time I looked).

seancorfield23:06:50

There’s also an explain option that can help with debugging (so you can at least get the query plan being used).

mattly23:06:21

in my case it's actually more of a problem with the source data than with the query that's being generated 😄

seancorfield23:06:05

Remember that the JDBC driver can do coercion on data so the parameters in the [ ... ] vector aren’t always what ends up in the SQL query to the DB.

seancorfield23:06:41

For example, you can pass strings where numbers are expected and they’ll get converted (at least with some drivers).

seancorfield23:06:11

so ["select * from foo where id = ?" "42"] will work, even if foo.id is unsigned int.

mattly23:06:17

wouldn't be a problem in my case, but I see the issue

mattly23:06:24

maybe I'll just roll my own hacky version

mattly23:06:22

s/hacky/naïve/