Re: Can DBI modify queries on the fly?
by perrin (Chancellor) on Feb 17, 2009 at 23:42 UTC
|
| [reply] |
|
is ref $attr, 'HASH', 'param modified by callback - not recommended!';
Modifying params by callback is exactly what I want to do. So why is it not recommended? I'm guessing this means that the solution I eventually come up with will stop working at some point in the future, but I guess I'll curse that bridge when I come to it. | [reply] [d/l] |
|
That refers to modifying @_ only, not modifying copies of what's in @_ or SQL placeholders
| [reply] [d/l] [select] |
|
|
|
Re: Can DBI modify queries on the fly?
by jfroebe (Parson) on Feb 17, 2009 at 22:58 UTC
|
Check out SQL Library. It will allow you to easily keep your SQL code in another file that you can modify at will.
Another option is to use the Perl debugger to replace the query strings.
| [reply] |
|
I want to modify the queries of a running application so that what's passed to the database includes a comment that tells where in the Perl code the request originated. SQL::Library (or Data::Phrasebook) is a nice idea, but it solves a completely different problem.
Likewise, I don't want to step through my code in the debugger and modify queries by hand. Rather, this is a tedious task that I think the computer should do for me. More to the point, I can't sit at the debugger in production.
| [reply] |
|
Curently the DBI only defines two trace flags:
ALL - turn on all DBI and driver flags (not recommended)
SQL - trace SQL statements executed (not yet implemented)
Update: actually, I bet that turning on trace level 1 is pretty close to what you're asking for. It will echo your prepare statements (including the SQL), and label them with line number and file of your code:
$dbh->trace(1, $trace_log_file);
| [reply] [d/l] [select] |
|
| [reply] |
|
|
Re: Can DBI modify queries on the fly?
by ikegami (Patriarch) on Feb 17, 2009 at 23:14 UTC
|
Writing a DBD that proxies/wraps the real DBD sounds more appropriate to me. | [reply] |
|
| [reply] |
|
I muled over this, and I still can't figure what Log4perl (note the lowercase 'p') and error logs have to do with the OP's question. Do you know more about what the OP is attempting to do than he is telling us?
I'm just very blind X_X
| [reply] |
|
DBD::Proxy would be a good place to start. It might be as simple as making a copy of it, and replacing the prepare() function with one that adds a SQL comment to queries.
| [reply] |
Re: Can DBI modify queries on the fly? (solution)
by kyle (Abbot) on Feb 18, 2009 at 19:16 UTC
|
This is the solution I eventually came up with uses callbacks on methods that make a request to the database.
The important clues came from these two notes.
Thanks to everyone for their patient replies!
| [reply] [d/l] |
Re: Can DBI modify queries on the fly?
by kyle (Abbot) on Oct 14, 2009 at 18:41 UTC
|
Here's a solution that doesn't use the callback mechanism, so it works with older versions of DBI. To use it, give it as the RootClass to DBI->connect. Since we were already using DBIx::ContextualFetch there, the code below uses that as its base, but it's not otherwise required.
| [reply] [d/l] [select] |