Re: using bytea vartype non-prepared statements

From: Richard Huxton <dev(at)archonet(dot)com>
To: Tom Allison <tom(at)tacocat(dot)net>
Cc: General PostgreSQL List <pgsql-general(at)postgresql(dot)org>
Subject: Re: using bytea vartype non-prepared statements
Date: 2007-05-24 10:00:00
Message-ID: 46556220.6000906@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tilmann Singer 2007-05-24 10:12:00 Re: Geographic data sources, queries and questions
Previous Message Richard Huxton 2007-05-24 09:39:33 Re: why postgresql over other RDBMS