我有一个 Perl DBI 语句
my $sql_statement = "select c.* ".
"from meter_category c ".
"where c.category = ".$current_category." ".
"and c.effective_date <= ".
$DBHdl->quote($time_stamp)." ".
"and c.meter_size = ".$meter_size." ".
"order by c.effective_date desc ; ";
$DBHdl
是一个 Informix 数据库句柄。
该声明如下所示:
select c.*
from meter_category c
where c.category = 1
and c.effective_date <= '09/20/2013'
and c.meter_size = 0.63
order by c.effective_date desc ;
在我的函数中,我想设置$current_category
为 2,然后修改 $sql_statement。
后
$current_category = 2;
eval $sql_statement
不会改变 $sql_statement,所以c.category = 2
.
有没有办法执行替换,还是我必须重新发出声明?
我使用以下代码为 $current_category 的每个值准备和执行查询。
my $ptSelHdl = $DBHdl->prepare($sql_statement);
die("Could not prepare \$sql_statement for meter charge.\n")
if(!$ptSelHdl || !$ptSelHdl->execute);