Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

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

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

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

That refers to modifying @_ only, not modifying copies of what's in @_ or SQL placeholders

Replies are listed 'Best First'.
Re^4: Can DBI modify queries on the fly?
by kyle (Abbot) on Feb 18, 2009 at 17:01 UTC

    That's kind of the whole point, though, isn't it? The callback can't return any values. The only way to make any changes to what's going on is to modify the parameters directly. Or am I missing something?

    As such, you have to worry about changing the application's data under its nose. You also have to watch out for the case where you're passed a read-only value.

      What does modifying variables in the caller got to do with overriding a method? You haven't specified why you want to override the method, but I'm guessing "the point" is to change the values passed to your override then call the original method. How does modifying a variable that probably won't ever be used again help you?

        The callback functionality that perrin referred to does not override the method. Instead, I can insert a callback that is called before the real method. The callback is not allowed to return any value (doing so causes an exception).

        The only way to modify the behavior of the original method is to change the parameters that it gets. To do that, I have to change (the contents of) @_. The side effect is that the original method's caller has its data changed also. The other problem I see is that I won't be allowed to do this at all if the parameter I'm interested in (the query) is a read-only value as in:

        my ($count) = $dbh->selectrow_array( 'SELECT count(*) FROM table' );

        Both of those are serious enough to make me want to go back to looking at some DBD subclass with an overridden method instead of using the callback, but I'm not sure it will be worth the effort.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://744616]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2018-06-22 06:11 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (121 votes). Check out past polls.