Tom Allison wrote:
> In order to address this I was using a SQL statement previously where I
> knew that the number of parameters was only two and I could write the
> perl to handle this:
> my $sth = $dbh->prepare("insert into quarantine values (?,?)");
> $sth->bind_param(1, $idx);
> $sth->bind_param(2, $text, { pg_type => DBD::Pg::PG_BYTEA });
> $sth->execute();
>
> In this case, I don't actually know before hand just how many variables
> I need to bind. Rather, I don't know at compile time.
I always have a small wrapper function that builds my queries for me.
Assuming you have a list of values and their types (or a list of
structures)...
1. Build a list of comma-separated qmarks: join(',', map {'?'} @params)
2. loop through your params looking up the corresponding pg_type for
your internal type - bind the param accordingly
3. execute
Or am I missing something here?
--
Richard Huxton
Archonet Ltd