hoyt has asked for the wisdom of the Perl Monks concerning the following question:
I have this inside of a for loop, but the sql itself should be the same, with only the variables changing. So I thought, well I can just move that getValueByMeaning() function as a parameter (like the download_id and update_time) and set the $sql_ins_log outside of the for loop to avoid setting the variable over and over to the same thing, like this:my $sql_ins_log = "insert into download_log (download_id,status,update +_time)" . " values(?,getValueByMeaning('$status_meaning','17') +,?)";
I tried a variety of things, but I'm having issues that I think relates to the fact that it's a function and there's a variable in it (meaning, it's not just a function like NOW()). To be clear, the getValueByMeaning is a user defined MySQL function, not a Perl function in this script. So I want the actual SQL to get passed into MySQL like this:my $sql_ins_log = "insert into download_log (download_id,status,update +_time)" . " values(?,?,?)"; foreach(@X){ $now = localtime->mysql_datetime; $sth = $dbh->prepare($sql_ins_log); $sth->execute($download_id,getValueByMeaning('$status_meaning','17') +,$now); }
Thanks for ay insight!insert into download_log (download_id,status,update_time) values(1,get +ValueByMeaning('DONE',17'),'2014-09-15 14:16:00')
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: MySQL Parameterized Query with Functions
by roboticus (Chancellor) on Sep 15, 2014 at 22:36 UTC | |
|
Re: MySQL Parameterized Query with Functions
by locked_user sundialsvc4 (Abbot) on Sep 15, 2014 at 22:54 UTC | |
by hoyt (Acolyte) on Sep 15, 2014 at 23:10 UTC | |
|
Re: MySQL Parameterized Query with Functions
by mje (Curate) on Sep 16, 2014 at 07:48 UTC |