Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi

How would i turn the following query in to a parameterised query as it uses a database function

my $querystrCon = ("update table set Details= CONCAT(Details, \"$i + lines inserted") where id=$RunID");
thanks

Replies are listed 'Best First'.
Re: parameterised query using database functions
by ikegami (Patriarch) on Nov 24, 2010 at 17:47 UTC
    my $querystrCon = " UPDATE table SET Details=CONCAT(Details, ?) WHERE id=? "; ->execute("$i lines inserted", $RunID)
      thanks. didn;t think you could do that :)
        Which part? Use placeholders (question marks)? They are documented under the header "Placeholders and Bind Values".
Re: parameterised query using database functions
by locked_user sundialsvc4 (Abbot) on Nov 24, 2010 at 19:13 UTC

    Notice that the placeholders are not enclosed in quotes.   ("?" is a literal string consisting of one question-mark.)

    The database driver will recognize that these are bound parameters and will insist that the execute call (etc...) must have the corresponding number of parameter-values supplied.

    Nice thing about parameters is that you only have to prepare the query once.