Re: using bytea vartype non-prepared statements

Поиск
Список
Период
Сортировка
От Richard Huxton
Тема Re: using bytea vartype non-prepared statements
Дата
Msg-id 46556220.6000906@archonet.com
обсуждение исходный текст
Ответ на using bytea vartype non-prepared statements  (Tom Allison <tom@tacocat.net>)
Список 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 по дате отправления:

Предыдущее
От: Richard Huxton
Дата:
Сообщение: Re: why postgresql over other RDBMS
Следующее
От: Tilmann Singer
Дата:
Сообщение: Re: Geographic data sources, queries and questions