crusty_collins:
If I'm going to be updating the database, I like to just call stored procedures to do the work. This way there's a consistent method for performing various tasks and you don't have to worry about your different scripts from getting out of synchronization with each other. It also allows you to ensure that error checking is done consistently. That way it gets to be pretty easy and the code is short, so it doesn't get in the way:
my $ST = $DB->prepare("foo.bar.baz(?, ?, ?)");
$ST->execute($arg1, $arg2, $arg3);
Having said that--I frequently have to do a quickie reports or database fixit scripts with no stored procedures that perform the tasks I want to do. In those cases, I generally keep the SQL inline with the code, as I like to use placeholders. That way if I have to change the SQL, it's near the execute statement I need to update if I change the parameter bindings:
my $ST = $DB->prepare(<<EOSQL);
UPDATE TABLE1 SET FOO=?, BAR=?, BAZ=?
WHERE KEYCOL1=? AND KEYCOL2=?
EOSQL
$ST->execute($foo, $bar, $baz, $key1, $key2);
...roboticus
When your only tool is a hammer, all problems look like your thumb. |