Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Concrete SQL from SQL::Abstract?

by metaperl (Curate)
on Aug 23, 2010 at 15:17 UTC ( [id://856733]=note: print w/replies, xml ) Need Help??


in reply to Concrete SQL from SQL::Abstract?

UPDATE on this topic - you can simply use the DBI quote method instead of SQL::DB like so:
sub query_as_string { my ($sql, @bind)=@_; # [14:50] <ilmari> metaperl: s/\?/$dbh->quote(shift @bind)/ge $_ = $sql; s/\?/$dbh->quote(shift @bind)/ge ; $_; }




The mantra of every experienced web application developer is the same: thou shalt separate business logic from display. Ironically, almost all template engines allow violation of this separation principle, which is the very impetus for HTML template engine development.

-- Terence Parr, "Enforcing Strict Model View Separation in Template Engines"

Replies are listed 'Best First'.
Re^2: Concrete SQL from SQL::Abstract?
by benizi (Hermit) on Sep 26, 2010 at 07:11 UTC

    Thanks. Hadn't logged on in a while (unfortunately).

    You should localize $_ there.

    local $_ = $sql;

    instead of:

    $_ = $sql;

    This has some quoting problems, but it's not your code's fault. Since SQL::Abstract doesn't use $dbh->quote_identifier, it can return invalid SQL. E.g. MySQL (at least) allows question marks in table names: mysql -Dtest -e 'create table `o rly?` (a int)'

    In the end, it didn't matter much anyway, as I was stuck doing most of my work in PHP. In that realm, nothing holds a candle to DBI

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://856733]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-26 00:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found