I've run into a peculiar bug when running some code under mod_perl
that doesn't show up outside the mod_perl environment.
I have some insert code that looks like this:
my $sth = $dbh->prepare(q{insert into metadata (id, property, value)
values (?,?,?)}) or die $dbh->errstr;
my $count = 0;
while (my ($property, $value) = each %{$self->{_meta}}) {
$sth->execute($self->{_id}, $property, $value) or return;
$count++;
}
Where $self->{_meta} is a hash of metadata values describing an
object.
Outside mod_perl, this code works as I'd expect, but I've been getting
errors running under mod_perl that seem to indicate the 3rd value
isn't being quoted properly. Setting $sth->trace(2), I see, for
example:
DBI::st=HASH(0x85a769c) trace level set to 2 in DBI 1.19-nothread
-> execute for DBD::mysql::st (DBI::st=HASH(0x85c2138)~0x85a769c '099AA11726'
'words' 2)
-> dbd_st_execute for 085b88d4
Binding parameters: insert into metadata (id, property, value)
values ('099AA11726','words',2)
<- dbd_st_execute 1 rows
<- execute= 1 at Article.pm line 66
-> trace for DBD::mysql::st (DBI::st=HASH(0x85c2138)~0x85a769c 2)
<- trace= 2 at Article.pm line 64
-> execute for DBD::mysql::st (DBI::st=HASH(0x85c2138)~0x85a769c '099AA11726'
'refnum' '555')
-> dbd_st_execute for 085b88d4
Binding parameters: insert into metadata (id, property, value)
values ('099AA11726','refnum',555)
<- dbd_st_execute 1 rows
<- execute= 1 at Article.pm line 66
-> trace for DBD::mysql::st (DBI::st=HASH(0x85c2138)~0x85a769c 2)
<- trace= 2 at Article.pm line 64
-> execute for DBD::mysql::st (DBI::st=HASH(0x85c2138)~0x85a769c '099AA11726'
'title' 'another test')
-> dbd_st_execute for 085b88d4
Binding parameters: insert into metadata (id, property, value)
values ('099AA11726','title',another test)
You have an error in your SQL syntax near 'test)' at line 2 error 1064 recorded: You
have an error in your SQL syntax near 'test)' at line 2
So, the 'title' property, passed in with a value of 'another test',
isn't quoted, leading to the syntax error.
If I do this instead:
$sth->bind_param(1, $self->{_id});
$sth->bind_param(2, $property);
$sth->bind_param(3, $value, {TYPE => SQL_VARCHAR} );
It works, but ... I shouldn't have to do that.
It's not clear to me what's going wrong here. Has anyone experienced
something similar, or have any insight into what's happening here?
My environment:
Red Hat Linux 7.1
mod_perl 1.26
Perl 5.6.0
DBI 1.19
Msql-Mysql-modules-1.2216
Regards,
Chad