Re: Translate between DBI and SQL

2019-02-12 Thread David Nicol
Tie::Function can be used to bind $dbh->quote to a syntactical hash, so you
can interpolate arbitrary strings easier. When I do that I name the hash
%Q, and then it's safe to do things like

$sql_text = "select id from mytable where foo=$Q{$foo}";

rather than counting placeholders.



On Fri, Feb 8, 2019 at 4:37 PM Mike Martin  wrote:

> Has anyone done any work on converting SQL queries between RDBMS and perl?
>
> My particular interest is DBD::Pg but anything would be of use
>
> It would be very useful when I am testing complex SQL, it's very easy to
> miss a \ or quote between the two
>
> Thanks
> Mike
>
>

-- 
"I don't know about that, as it is outside of my area of expertise." --
competent specialized practitioners, all the time


Re: Translate between DBI and SQL

2019-02-12 Thread Peter Vanroose
Short answer, assuming you are including hard-coded SQL into a Perl script:
Place the textual SQL, without any additional backslashes or extra quotes or 
whatsoever,
within the following:

my $sql_text = q(

);

Unless you have a closing ")" without a preceding opening "(" in that SQL text
(which would normally be invalid SQL)
the above should be valid Perl, resulting in a valid SQL statement in $sql_text
(to be passed to a DBI prepare or so).

In the unlikely event that you would have unbalanced quoted parentheses in your 
SQL,
you can replace the delimiters for the q operator by something else, viz. 
something not occurring in your SQL text, e.g.:

my $sql_text = q#
SELECT ')', "col_a"
FROM tblc
ORDER BY "col_a"
#;


-- Peter.


8 februari 2019 23:37:17 +01:00, skrev Mike Martin :

> Has anyone done any work on converting SQL queries between RDBMS and perl?
> 
> My particular interest is DBD::Pg but anything would be of use
> 
> It would be very useful when I am testing complex SQL, it's very easy to miss 
> a \ or quote between the two
>
> Thanks
> Mike
>
>