Here's a patch against DBD::Pg 0.95, which fixes a couple of small problems I've been 
having.

First, I hate that error messages from DBD::Pg have newlines on the ends. This 
prevents any warnings which might get generated from including the line number of the 
perl program which caused it. The first part of the patch removes all trailing 
newlines in pg_error(). This behaviour matches that of the other DBD modules I have 
used (one of which I wrote myself, admittedly).

Second, as I reported a year ago on dbi-users, but never got any response, Perl and 
DBD::Pg occassionally decide that my date placeholders are actually numbers, and 
doesn't quote the values. This causes all kinds of merry hell, which I wouldn't mind, 
but there seems to be no way of predicting when this will happen. The second part of 
the patch changes the autoquoting rules slightly. Previously, quoting was only done to 
Perl non-numbers in text-type placeholders. My patch changes this to Perl non-numbers 
or text-type placeholders. I had to change test.pl as well, so this might be a change 
in behaviour which affects some existing applications. However, I think that quoting 
is generally safer than not quoting.

-- 
        Peter Haworth   [EMAIL PROTECTED]
"However, real-world X.400 gateways might be considered to significantly
 increase the hazard that mail containing a human being will be rejected
 with a message so cryptic that the recipient deletes it without ever
 realizing that an embedded human being is enclosed."
                -- RFC1437
diff -c ../DBD-Pg-0.95/dbdimp.c ./dbdimp.c
*** ../DBD-Pg-0.95/dbdimp.c     Mon Jul 10 18:47:51 2000
--- ./dbdimp.c  Fri Mar 23 15:08:58 2001
***************
*** 73,78 ****
--- 73,87 ----
  {
      D_imp_xxh(h);
  
+     /* Remove trailing newlines */
+     if (error_msg) {
+       char *end=error_msg+strlen(error_msg);
+ 
+       while (end > error_msg && end[-1] == '\n') {
+       --end;
+       }
+       *end = 0;
+     }
      sv_setiv(DBIc_ERR(imp_xxh), (IV)error_num);               /* set err early */
      sv_setpv(DBIc_ERRSTR(imp_xxh), (char*)error_msg);
      DBIh_EVENT2(h, ERROR_event, DBIc_ERR(imp_xxh), DBIc_ERRSTR(imp_xxh));
***************
*** 1086,1092 ****
                  val = SvPV(phs->sv, len);
              }
              /* quote string attribute */
!             if(!SvNIOK(phs->sv) && SvOK(phs->sv) && phs->ftype > 1000) { /* avoid 
quoting NULL, tpf: bind_param as numeric  */
                *dest++ = '\''; 
              }
              while (len--) {
--- 1095,1101 ----
                  val = SvPV(phs->sv, len);
              }
              /* quote string attribute */
!           if(SvOK(phs->sv) && (!SvNIOK(phs->sv) || phs->ftype > 1000)) { /* avoid 
quoting NULL, tpf: bind_param as numeric  */
                *dest++ = '\''; 
              }
              while (len--) {
***************
*** 1104,1110 ****
                  *dest++ = *val++;
              }
              /* quote string attribute */
!             if(!SvNIOK(phs->sv) && SvOK(phs->sv) && phs->ftype > 1000) { /* avoid 
quoting NULL,  tpf: bind_param as numeric */
                  *dest++ = '\''; 
              }
          }
--- 1113,1119 ----
                  *dest++ = *val++;
              }
              /* quote string attribute */
!           if(SvOK(phs->sv) && (!SvNIOK(phs->sv) || phs->ftype > 1000)) { /* avoid 
quoting NULL, tpf: bind_param as numeric  */
                  *dest++ = '\''; 
              }
          }
diff -c ../DBD-Pg-0.95/test.pl ./test.pl
*** ../DBD-Pg-0.95/test.pl      Mon Jun 12 16:12:17 2000
--- ./test.pl   Fri Mar 23 15:07:50 2001
***************
*** 228,237 ****
  
  $sth = $dbh->prepare("SELECT * FROM builtin where int4_ < ? + ?") or die 
$DBI::errstr;
  
! ( $sth->bind_param(1, '4000', DBI::SQL_INTEGER) )
      and print "\$sth->bind_param ........... ok\n"
      or  die   "\$sth->bind_param ........... not ok: ", $DBI::errstr;
! $sth->bind_param(2, '6000', DBI::SQL_INTEGER);
  
  $sth->execute or die $DBI::errstr;
  
--- 228,237 ----
  
  $sth = $dbh->prepare("SELECT * FROM builtin where int4_ < ? + ?") or die 
$DBI::errstr;
  
! ( $sth->bind_param(1, 4000, DBI::SQL_INTEGER) )
      and print "\$sth->bind_param ........... ok\n"
      or  die   "\$sth->bind_param ........... not ok: ", $DBI::errstr;
! $sth->bind_param(2, 6000, DBI::SQL_INTEGER);
  
  $sth->execute or die $DBI::errstr;
  

Reply via email to