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

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

RE: Translate between DBI and SQL

2019-02-11 Thread Fennell, Brian
P.S. This may also help: http://www.dispersiondesign.com/articles/perl/perl_escape_characters Short answer: Use single-quoted strings whenever possible - they have the fewest characters to escape - only backslash and single quote - and you can escape both by preceding with a backslash. Use

Re: Translate between DBI and SQL

2019-02-11 Thread pali
On Friday 08 February 2019 22:37:17 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

RE: Translate between DBI and SQL

2019-02-11 Thread Fennell, Brian
P.P.S. My last answer used single-quote for a column with a space in it in PostgreSQL - this is wrong, it should have been a double-quote for the name of the column with a space and a single quote for a quoted string literal in PostgreSQL. Better example: (Adapted from answer to question here

RE: Translate between DBI and SQL

2019-02-11 Thread Fennell, Brian
Mike, If you have a complete example of what you are starting with and what you want to end up with your question would be clearer. If I understand you correctly: You start with raw SQL such as you might enter into a Postgres command line tool (for example psql). What you want is the equivalent

Re: Translate between DBI and SQL

2019-02-08 Thread John Scoles
Well not really much DBI can do for you. You usually start from scratch trying to write SQL that is not Driver Specific though that can be hard. you are usually stuck with something like this sub edit_sql { my ($self, $sql) = @_;​ ​ if ($self->isPostgres) {​ return