CC: | gnatyna [...] ya.ru |
Subject: | Commented placeholders in sql statement. |
With mysql_server_prepare=0 line $dbh->do(qq[update t1 set id=id+1 where /
col1=? and/ id=?],undef,1) gives error "You have an error in your SQL
syntax;".
$dbh->prepare->execute works fine.
Test script in attachement.
Subject: | ph_in_comment.pl |
#!/usr/bin/perl -l
use strict;
use warnings;
use DBI;
=head2 SQL
create table t1( id int);
=cut
t_ph();
sub t_ph{
my $dbh = DBI->connect("DBI:mysql:database=test;host=localhost;mysql_server_prepare=0;",
undef,
undef,
{AutoCommit => 1, PrintError=>0, RaiseError => 0},
);
my $query = q[update t1 set id=id+1 where /* col1 = ? and */ id=?];
if($dbh->do($query, undef, 1)){
print "comment do ok";
}else{
warn "comment DO: ".$dbh->errstr;
}
my $query_nocom = q[update t1 set id=id+1 where id=?];
if($dbh->do($query_nocom, undef, 1)){
print "nocomment do ok";
}else{
warn "no comment DO: ".$dbh->errstr;
}
my $sth = $dbh->prepare($query,undef);
if($sth->execute(1)){
print "Execute-prepare ok";
}else{
warn "execute-prepare: ".$dbh->errstr;
}
$dbh->disconnect();
}