Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^7: Can DBI modify queries on the fly?

by ikegami (Pope)
on Feb 18, 2009 at 18:36 UTC ( #744841=note: print w/ replies, xml ) Need Help??


in reply to Re^6: Can DBI modify queries on the fly?
in thread Can DBI modify queries on the fly?

Notice the call to ->connect in the callback, overriding Sybase's? The callback mechanism provides a means of (conditional) overriding.

$sybase_drh->{Callbacks} = { selectrow_array => sub { # Protect against recursion when calling overriden method. return if $in_callback; local $in_callback = 1; my ($drh, $sql, $attrs, @bind_values) = @_; # Do something to $sql, $attrs and/or @bind_values here... # Tell DBI not to call original connect method undef $_; return $drh->selectrow_array($sql, $attrs, @bind_values); }, };

Note that it would probably make more sense to override prepare and/or execute than convenience methods such as selectrow_array.

Update: Added code.


Comment on Re^7: Can DBI modify queries on the fly?
Select or Download Code
Re^8: Can DBI modify queries on the fly?
by kyle (Abbot) on Feb 18, 2009 at 18:53 UTC

    Thank you!! I remember reading about the conditional override that you're using, but I somehow forgot it when I sat down to try to meet my goal. That works beautifully and saves me the trouble of trying to subclass a DBD. Thanks!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (14)
As of 2014-07-25 20:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (175 votes), past polls