Skip to content
Advertisement

Use of Complex (curly) Syntax in external file

I am having a problem with getting an sql query to interpolate as I would want, and would be grateful for some help please.

Within the manual page for pg_query_params,there is a code example for pg_query() passing a variable using curly braces. This appeared to be exactly what I need for my task. So, my code is as follows:

JavaScript

The sql file contains several queries, one per line, like this:

JavaScript

However, currently, my variable is not being replaced by the contents — and therefore although the query runs OK, it is returning zero rows. What do I need to do in order to get the expected result? (Note: each sql line varies, and the query parameters are not constant — hence using variable(s) within the sql file.)

Advertisement

Answer

OK. I have a solution (although it might not be the correct approach). This works — but it needs polish I think. Suggestions regarding a better regexp would be very much appreciated.

JavaScript

(Of course, the solution suggests that the question title is completely wrong. Is there any way to edit this?)

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement