Author: turnstep
Date: Sun Oct  5 20:11:56 2008
New Revision: 11939

Modified:
   DBD-Pg/trunk/Pg.pm
   DBD-Pg/trunk/dbdimp.c
   DBD-Pg/trunk/t/07copy.t

Log:
Better error output for COPY methods.


Modified: DBD-Pg/trunk/Pg.pm
==============================================================================
--- DBD-Pg/trunk/Pg.pm  (original)
+++ DBD-Pg/trunk/Pg.pm  Sun Oct  5 20:11:56 2008
@@ -4013,14 +4013,14 @@
 one data row at a time. The first argument to pg_getcopydata 
 is the variable into which the data will be stored (this variable should not 
 be undefined, or it may throw a warning, although it may be a reference). This 
-argument returns a number greater than 1 indicating the new size of the 
variable, 
+method returns a number greater than 1 indicating the new size of the 
variable, 
 or a -1 when the COPY has finished. Once a -1 has been returned, no other 
action is 
 necessary, as COPY mode will have already terminated. Example:
 
   $dbh->do("COPY mytable TO STDOUT");
   my @data;
   my $x=0;
-  1 while $dbh->pg_getcopydata($data[$x++]) > 0;
+  1 while $dbh->pg_getcopydata($data[$x++]) >= 0;
 
 There is also a variation of this method called B<pg_getcopydata_async>, 
which, 
 as the name suggests, returns immediately. The only difference from the 
original 

Modified: DBD-Pg/trunk/dbdimp.c
==============================================================================
--- DBD-Pg/trunk/dbdimp.c       (original)
+++ DBD-Pg/trunk/dbdimp.c       Sun Oct  5 20:11:56 2008
@@ -2684,6 +2684,7 @@
 
        imp_dbh->copystate = 0; /* Assume not in copy mode until told otherwise 
*/
 
+       if (TRACE4) TRC(DBILOGFP, "%sGot a status of %d\n", THEADER, status);
        switch (status) {
        case PGRES_TUPLES_OK:
                TRACE_PQNTUPLES;
@@ -3696,7 +3697,7 @@
 
        /* We must be in COPY OUT state */
        if (PGRES_COPY_OUT != imp_dbh->copystate)
-               croak("pg_getcopydata can only be called directly after issuing 
a COPY command\n");
+               croak("pg_getcopydata can only be called directly after issuing 
a COPY FROM command\n");
 
        tempbuf = NULL;
 
@@ -3755,7 +3756,7 @@
 
        /* We must be in COPY IN state */
        if (PGRES_COPY_IN != imp_dbh->copystate)
-               croak("pg_putcopydata can only be called directly after issuing 
a COPY command\n");
+               croak("pg_putcopydata can only be called directly after issuing 
a COPY TO command\n");
 
        TRACE_PQPUTCOPYDATA;
        copystatus = PQputCopyData

Modified: DBD-Pg/trunk/t/07copy.t
==============================================================================
--- DBD-Pg/trunk/t/07copy.t     (original)
+++ DBD-Pg/trunk/t/07copy.t     Sun Oct  5 20:11:56 2008
@@ -171,23 +171,23 @@
 
 $dbh->do("DELETE FROM $table");
 
-$t='pg_putcopydata fails if not after a COPY statement';
+$t='pg_putcopydata fails if not after a COPY TO statement';
 eval {
        $dbh->pg_putcopydata("pizza\tpie");
 };
-like ($@, qr{COPY command}, $t);
+like ($@, qr{COPY TO command}, $t);
 
-$t='pg_getcopydata fails if not after a COPY statement';
+$t='pg_getcopydata fails if not after a COPY TO statement';
 eval {
        $dbh->pg_getcopydata($data[0]);
 };
-like ($@, qr{COPY command}, $t);
+like ($@, qr{COPY FROM command}, $t);
 
-$t='pg_getcopydata_async fails if not after a COPY statement';
+$t='pg_getcopydata_async fails if not after a COPY TO statement';
 eval {
        $dbh->pg_getcopydata_async($data[0]);
 };
-like ($@, qr{COPY command}, $t);
+like ($@, qr{COPY FROM command}, $t);
 
 $t='pg_putcopyend warns but does not die if not after a COPY statement';
 eval { require Test::Warn; };
@@ -204,7 +204,7 @@
 eval {
        $dbh->pg_getcopydata($data[0]);
 };
-like ($@, qr{COPY command}, $t);
+like ($@, qr{COPY FROM command}, $t);
 
 $t='pg_putcopydata does not work if we are using COPY .. TO';
 $dbh->rollback();
@@ -212,7 +212,7 @@
 eval {
        $dbh->pg_putcopydata("pizza\tpie");
 };
-like ($@, qr{COPY command}, $t);
+like ($@, qr{COPY TO command}, $t);
 
 $t='pg_putcopydata works and returns a 1 on success';
 $dbh->rollback();
@@ -238,7 +238,7 @@
 eval {
        $dbh->pg_getcopydata($data[0]);
 };
-like ($@, qr{COPY command}, $t);
+like ($@, qr{COPY FROM command}, $t);
 
 $t='Calling do() gives an error when in the middle of COPY .. FROM';
 eval {
@@ -265,7 +265,7 @@
 eval {
        $result = $dbh->pg_putcopydata('root');
 };
-like ($@, qr{COPY command}, $t);
+like ($@, qr{COPY TO command}, $t);
 
 $t='Normal queries work after pg_putcopyend is called';
 eval {
@@ -310,7 +310,7 @@
 eval {
        $dbh->pg_putcopydata('pie');
 };
-like ($@, qr{COPY command}, $t);
+like ($@, qr{COPY TO command}, $t);
 
 $t='pg_getcopydata returns 0 when no more data';
 $dbh->pg_getcopydata(\$data[0]);

Reply via email to