http://www.perlmonks.org?node_id=744841


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.