Menu

#303 [Perl]When do update use quote method, it doesn't work

open
nobody
None
5
2012-09-29
2012-09-29
Jira Trac
No

Repro steps:
After update by quote, the value isn't right.
{noformat}
my $data_source=dbi:cubrid:database=$db;host=localhost;port=$port;
my $dbh;
$dbh=DBI-connect($data_source, $user, $pass,{PrintError = 1, RaiseError=0}) or warn($DBI::errstr);
$dbh - do(drop table if EXISTS t1;) or warn(drop error: $DBI::errstr);
$dbh - do(create table t1(a string);) or warn(create error: $DBI::errstr);

sub escape_string_test{
my @inser_sql=@_;
#print insert: . $inser_sql[0] .\n\n;
my $sel_sql=select * from t1;
my $sth=$dbh-prepare($inser_sql[0]) or warn(prepare insert error: $DBI::errstr);
$sth-execute() or warn(insert error: $DBI::errstr);
my $sth=$dbh-prepare($sel_sql) or warn(create error: $DBI::errstr);
$sth-execute() or warn(create error: $DBI::errstr);

my $arry=$sth-fetchall_arrayref({}) or die Arry error:$dbh-errstr;

my $i=0;
my @id=(qq(single quote(') test),new line(\n) test,carrage return (\r) test,backslash (\\) test,backslash quote(\\') test);
foreach my $row(@$arry){
is($row-{'a'},$id[$i],fetchall_arrayref({}) ok);
$i++;
}

}

my $sql1=sprintfinsert into t1 values (%s);,$dbh-quote(single quote(') test);
my $sql2=sprintfinsert into t1 values (%s);,$dbh-quote(new line(\n) test);
my $sql3=sprintfinsert into t1 values (%s);,$dbh-quote(carrage return (\r) test);
my $sql4=sprintfinsert into t1 values (%s);,$dbh-quote(backslash (\\) test);
my $sql5=sprintfinsert into t1 values (%s);,$dbh-quote(backslash quote(\\') test);

my @arr_sql=($sql1, $sql2, $sql3, $sql4, $sql5);

for(my $i=0; $i@arr_sql; $i++){
#print arr_sql[$i]: . $arr_sql[$i].\n;
escape_string_test($arr_sql[$i]);
}

done_testing();
$dbh - disconnect();
{noformat}

Discussion

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.