Hi all,
I have a queries that reside in multiple methods each (query) of which can contain multiple paramaters. I am trying to reduce file size and linecount to make it more maintainable. Below is such an occurence:
$sql_update = qq { UPDATE database.table
SET column = 'UPDATE!'
WHERE id = ?
};
$sth_update = $dbh->prepare($sql_update);
if ($dbh->err) {
my $error = "Could not prepare statement. Error: ". $dbh->errstr ." Exiting at line " . __LINE__;
print "$error\n";
die;
}
$sth_rnupdate->execute($parameter);
if ($dbh->err) {
my $error = "Could not execute statement. Error: ". $dbh->errstr ." Exiting at line " . __LINE__;
print "$error\n";
die;
}
This is just one example, however, there are various other select examples that contain just the one parameter to be passed in, however there is also some with two or more parameters. I guess I am just wondering would it be possible to encapsulate this all into a function/method, passs in an array of parameters, how would the parameters be populated into the execute() function?
If this was possible I could write a method that you simply just pass in the sql query and parameters and get back a reference to teh fetched records. Does this sound safe at all?
All opinions and thoughts are much appreciated.
Regards, BorisTheBulletDodgingDodger
---------------------------- [RESPONSE TO BUBAKER] ----------------------------------- Sorry I mis-interpreted what the function was doing. Everything is okay now!