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.


cp1252:chr(14): You cannot optimise code you have not yet written.

In reply to Re^3: dbi mysql concat interpolation by Don Coyote
in thread dbi mysql concat interpolation by lykich

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.