It is unsafe.
Hello lykich and welcome to the monastery.
Binding to placeholders '?' increases prevention of execution of malformed queries. Each '?' is replaced by the value relative to position in the execute statement.
Firstly, construct your statements.
#!perl; use strict; use warnings; use 5.10.1; # features my @quotes = ( q/'/, q/"/ ); push @quotes, map q/'/, 0 .. int(rand(10)); push @quotes, map q/"/, 0 .. int(rand(10)); say 'quotes ', join( ' ', @quotes); my @Various_Apostrophes = map { $_ .= ( int(rand(40)+2) % 2 == 1 ) ? q!'! : q!"! ; } @quotes; say 'V_A ', join( ' ', @Various_Apostrophes); my $scquery = join('', q/'SELECT CONCAT( /, q/ ?,/ x (scalar(@Various_Apostrophes)-1), q/ ? )'/ ); say 'scq ',$scquery;
Secondly, supply the preconstructed prepare and execute variables to the database methods.
my $sth = $dbh->prepare( $scquery ); $sth->execute( @Various_Apostrophes ); exit 0;
In this way you separate code that handles query statements from code handling database requests. This makes safer the script and quickly debugs.
In reply to Re^3: dbi mysql concat interpolation
by Don Coyote
in thread dbi mysql concat interpolation
by lykich
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |