Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: Concrete SQL from SQL::Abstract?

by metaperl (Curate)
on Aug 23, 2010 at 15:17 UTC ( #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?

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2022-10-04 13:34 GMT
Find Nodes?
    Voting Booth?
    My preferred way to holiday/vacation is:

    Results (17 votes). Check out past polls.