Re: using bytea vartype non-prepared statements - Mailing list pgsql-general

From Richard Huxton
Subject Re: using bytea vartype non-prepared statements
Date
Msg-id 46556220.6000906@archonet.com
Whole thread Raw
In response to using bytea vartype non-prepared statements  (Tom Allison <tom@tacocat.net>)
List pgsql-general
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

pgsql-general by date:

Previous
From: Richard Huxton
Date:
Subject: Re: why postgresql over other RDBMS
Next
From: Tilmann Singer
Date:
Subject: Re: Geographic data sources, queries and questions