1

I'd like to bind param types during the selectrow/selectall function calls.

Is it possible to change something like:

$sth = $dbh->prepare($sql);
$sth->bind_param(1, undef, {pg_type => DBD::Pg::PG_BYTEA});
$sth->execute($byteavalue);

To a selectrow statement:

$dbh->selectrow_arrayref( $sql, undef, $byteavalue );

1 Answer 1

2

The first param of selectrow_* can be a statement handle, so you could use:

$sth = $dbh->prepare($sql)
and $sth->bind_param(1, undef, { pg_type => DBD::Pg::PG_BYTEA })
and $dbh->selectrow_arrayref($sth, undef, $byteavalue);

Otherwise, you'll have to create your own version of selectrow_arrayref. The existing version is:

sub selectrow_arrayref {
    my ($dbh, $stmt, $attr, @bind) = @_;
    my $sth = ((ref $stmt) ? $stmt : $dbh->prepare($stmt, $attr))
        or return;
    $sth->execute(@bind)
        or return;
    my $row = $sth->fetchrow_arrayref()
        and $sth->finish;
    return $row;
}
Sign up to request clarification or add additional context in comments.

2 Comments

A little better, but I guess you would need to create the statement handle anyhow.
No, it you wrote your own version of selectrow_arrayref, you could pass the information needed for binding in a new field of the $attr hash. (e.g. bind_params => [ [ 1, undef, { pg_type => DBD::Pg::PG_BYTEA } ] ]) But it's probably clearer if you don't.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.