I just spent an hour banging my head against the wall before I figured
out two annoying things about the COPY support in DBD::Pg.

1. In the call to pg_getline, do NOT pass in an undefined variable in.
 You will get warnings.  So instead of something like:

  while ($dbd->pg_getline(my $line, $size)) {
    # do stuff
  }

write

  my $line = "";
  while ($dbd->pg_getline($line, $size)) {
    # do stuff
  }

(I would complain about the $size part, but googling on the topic
suggests that a future release will remove that parameter, and take
care of the related potential for buffer overflows.)

2. You don't want to call pg_endcopy on a handle that you are using
pg_getline with.  Because pg_getline will do and end copy for you on
your last line.  Which means that your call to pg_endcopy will blow up
in a most annoying fashion.

Cheers,
Ben

Reply via email to