Amp-Client

 view release on metacpan or  search on metacpan

lib/Amp/DbPoolClient.pm  view on Meta::CPAN

    my $self = shift;
    my $sql = shift;
    my (@params) = @_;
    my @replacements;

    # find all the ? positions to replace
    while ($sql =~ m/\?/g) {
        push @replacements, pos($sql);
    }

    # validate the params given match the number of ? to replace
    if (scalar(@replacements) != scalar(@params)) {
        die "SQL has " . scalar(@replacements) . " parameters but " . scalar(@params) . " were given\n";
    }

    # Set the index mark to match the size of the @params for iterating through the replacements
    my $i = (scalar(@params) - 1);
    for my $pos (reverse @replacements) {
        my $val = $self->quote($params[$i]);
        substr($sql, $pos - 1, 1, $val);
        $i--;



( run in 0.237 second using v1.01-cache-2.11-cpan-a5abf4f5562 )