Can"t trap Pg warnings
am 24.03.2006 00:56:22 von tlm1905
------=_Part_12091_18080591.1143158182523
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
Consider the following short script:
use strict;
use warnings;
use DBI;
my $h =3D DBI->connect( 'dbi:Pg:dbname=3Dmytestdb', 'anonymous', '', );
# close( STDERR );
# open( STDERR, '>', \my $stderr );
warn 'before';
$h->prepare( 'CREATE TEMPORARY TABLE tmp ( i serial )' )->execute();
warn 'after';
$h->disconnect;
# print ">>\n$stderr<<\n";
__END__
The output I get from it looks like this:
before at test_script.pl line 10.
NOTICE: CREATE TABLE will create implicit sequence "tmp_i_seq" for serial
column " tmp.i"
after at test_script.pl line 12.
The output looks exactly the same if I pipe the command's standard output t=
o
/dev/null ( i.e. what we're seeing was sent to standard error).
Now, if I uncomment the commented lines, the output looks like this:
>>
before at script/test.pl line 10.
after at script/test.pl line 12.
<<
So, even though the messages given explicitly to warn in the script were
faithfully appended to the scalar $stderr, as intended, the notice from Pg
(about the implicitly created sequence) is gone: it shows up neither on the
screen, nor in the scalar $stderr.
How can I trap such notices?
Thanks!
tlm
P.S. It is tempting to blame the closing of STDERR for this problem, but
this a mandatory step. Without it, $stderr receives no output at all.
------=_Part_12091_18080591.1143158182523--
Re: Can"t trap Pg warnings
am 24.03.2006 08:46:50 von Alexander
Ripped out of some of my code working with DBD::Pg:
# DBI->connect() here
$SIG{'__WARN__'}=sub {
# Don't use REs (//) here, you would change some special variables!
warn @_ unless substr($_[0],0,7) eq 'NOTICE:';
};
# Rest of the application
Hope that helps.
Alexander
tlm wrote:
>Consider the following short script:
>
>use strict;
>use warnings;
>use DBI;
>
>my $h = DBI->connect( 'dbi:Pg:dbname=mytestdb', 'anonymous', '', );
>
># close( STDERR );
># open( STDERR, '>', \my $stderr );
>
>warn 'before';
>$h->prepare( 'CREATE TEMPORARY TABLE tmp ( i serial )' )->execute();
>warn 'after';
>$h->disconnect;
>
># print ">>\n$stderr<<\n";
>__END__
>
>The output I get from it looks like this:
>
>before at test_script.pl line 10.
>NOTICE: CREATE TABLE will create implicit sequence "tmp_i_seq" for serial
>column " tmp.i"
>after at test_script.pl line 12.
>
>The output looks exactly the same if I pipe the command's standard output to
>/dev/null ( i.e. what we're seeing was sent to standard error).
>
>Now, if I uncomment the commented lines, the output looks like this:
>
>
>
>before at script/test.pl line 10.
>after at script/test.pl line 12.
><<
>
>So, even though the messages given explicitly to warn in the script were
>faithfully appended to the scalar $stderr, as intended, the notice from Pg
>(about the implicitly created sequence) is gone: it shows up neither on the
>screen, nor in the scalar $stderr.
>
>How can I trap such notices?
>
>Thanks!
>
>tlm
>
>
>P.S. It is tempting to blame the closing of STDERR for this problem, but
>this a mandatory step. Without it, $stderr receives no output at all.
>
>
>
--
Alexander Foken
mailto:alexander@foken.de http://www.foken.de/alexander/
Re: Can"t trap Pg warnings
am 24.03.2006 13:19:40 von tlm1905
------=_Part_3766_31264128.1143202780460
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
On 3/24/06, Alexander Foken wrote:
>
> Ripped out of some of my code working with DBD::Pg:
>
> # DBI->connect() here
> $SIG{'__WARN__'}=3Dsub {
> # Don't use REs (//) here, you would change some special variables=
!
> warn @_ unless substr($_[0],0,7) eq 'NOTICE:';
> };
> # Rest of the application
Thanks, but unfortunately this doesn't work (I should have mentioned in my
original post that I had already tried something like this). For example,
this script:
use strict;
use warnings;
use DBI;
my $h =3D DBI->connect( 'dbi:Pg:dbname=3Dmytestdb', 'anonymous', '', );
$SIG{ __WARN__ } =3D sub {
if ( substr( $_[0], 0, 7 ) eq 'NOTICE:' ) {
warn "From Pg: $_[ 0 ]\n";
}
else {
warn "%%% $_[ 0 ]\n";
}
};
warn 'before';
$h->prepare( 'CREATE TEMPORARY TABLE tmp ( i serial )' )->execute();
warn 'after';
$h->disconnect;
__END__
produces the following output:
%%% before at test_script.pl line 17.
NOTICE: CREATE TABLE will create implicit sequence "tmp_i_seq" for serial
column "tmp.i"
%%% after at test_script.pl line 19.
As you can see, the warning from Pg never goes through the $SIG{ __WARN__ =
}
handler.
tlm
P.S. Is there a searchable archive for dbi-users@perl.org? The closest I'v=
e
found is http://www.nntp.perl.org/group/perl.dbi.users but it doesn't seem
to be searchable. (It also mangles Perl code: is there a way to prevent
this?)
Hope that helps.
>
> Alexander
>
> tlm wrote:
>
> >Consider the following short script:
> >
> >use strict;
> >use warnings;
> >use DBI;
> >
> >my $h =3D DBI->connect( 'dbi:Pg:dbname=3Dmytestdb', 'anonymous', '', );
> >
> ># close( STDERR );
> ># open( STDERR, '>', \my $stderr );
> >
> >warn 'before';
> >$h->prepare( 'CREATE TEMPORARY TABLE tmp ( i serial )' )->execute();
> >warn 'after';
> >$h->disconnect;
> >
> ># print ">>\n$stderr<<\n";
> >__END__
> >
> >The output I get from it looks like this:
> >
> >before at test_script.pl line 10.
> >NOTICE: CREATE TABLE will create implicit sequence "tmp_i_seq" for
> serial
> >column " tmp.i"
> >after at test_script.pl line 12.
> >
> >The output looks exactly the same if I pipe the command's standard outpu=
t
> to
> >/dev/null ( i.e. what we're seeing was sent to standard error).
> >
> >Now, if I uncomment the commented lines, the output looks like this:
> >
> >
> >
> >before at script/test.pl line 10.
> >after at script/test.pl line 12.
> ><<
> >
> >So, even though the messages given explicitly to warn in the script were
> >faithfully appended to the scalar $stderr, as intended, the notice from
> Pg
> >(about the implicitly created sequence) is gone: it shows up neither on
> the
> >screen, nor in the scalar $stderr.
> >
> >How can I trap such notices?
> >
> >Thanks!
> >
> >tlm
> >
> >
> >P.S. It is tempting to blame the closing of STDERR for this problem, but
> >this a mandatory step. Without it, $stderr receives no output at all.
> >
> >
> >
>
> --
> Alexander Foken
> mailto:alexander@foken.de http://www.foken.de/alexander/
>
>
------=_Part_3766_31264128.1143202780460--
Re: Can"t trap Pg warnings
am 24.03.2006 18:17:32 von slagel
Looks like prior to DBD::Pg 1.31 these warning messages where sent to
stderr and not via perl's warning mechanism.
http://www.mail-archive.com/dbi-announce@perl.org/msg00170.h tml
On Fri, 2006-03-24 at 07:19 -0500, tlm wrote:
> On 3/24/06, Alexander Foken wrote:
> >
> > Ripped out of some of my code working with DBD::Pg:
> >
> > # DBI->connect() here
> > $SIG{'__WARN__'}=sub {
> > # Don't use REs (//) here, you would change some special variables!
> > warn @_ unless substr($_[0],0,7) eq 'NOTICE:';
> > };
> > # Rest of the application
>
>
>
> Thanks, but unfortunately this doesn't work (I should have mentioned in my
> original post that I had already tried something like this). For example,
> this script:
>
>
> use strict;
> use warnings;
> use DBI;
>
> my $h = DBI->connect( 'dbi:Pg:dbname=mytestdb', 'anonymous', '', );
> $SIG{ __WARN__ } = sub {
> if ( substr( $_[0], 0, 7 ) eq 'NOTICE:' ) {
> warn "From Pg: $_[ 0 ]\n";
> }
> else {
> warn "%%% $_[ 0 ]\n";
> }
> };
>
> warn 'before';
> $h->prepare( 'CREATE TEMPORARY TABLE tmp ( i serial )' )->execute();
> warn 'after';
> $h->disconnect;
> __END__
>
> produces the following output:
>
> %%% before at test_script.pl line 17.
>
> NOTICE: CREATE TABLE will create implicit sequence "tmp_i_seq" for serial
> column "tmp.i"
> %%% after at test_script.pl line 19.
>
> As you can see, the warning from Pg never goes through the $SIG{ __WARN__ }
> handler.
> tlm
>
> P.S. Is there a searchable archive for dbi-users@perl.org? The closest I've
> found is http://www.nntp.perl.org/group/perl.dbi.users but it doesn't seem
> to be searchable. (It also mangles Perl code: is there a way to prevent
> this?)
>
> Hope that helps.
> >
> > Alexander
> >
> > tlm wrote:
> >
> > >Consider the following short script:
> > >
> > >use strict;
> > >use warnings;
> > >use DBI;
> > >
> > >my $h = DBI->connect( 'dbi:Pg:dbname=mytestdb', 'anonymous', '', );
> > >
> > ># close( STDERR );
> > ># open( STDERR, '>', \my $stderr );
> > >
> > >warn 'before';
> > >$h->prepare( 'CREATE TEMPORARY TABLE tmp ( i serial )' )->execute();
> > >warn 'after';
> > >$h->disconnect;
> > >
> > ># print ">>\n$stderr<<\n";
> > >__END__
> > >
> > >The output I get from it looks like this:
> > >
> > >before at test_script.pl line 10.
> > >NOTICE: CREATE TABLE will create implicit sequence "tmp_i_seq" for
> > serial
> > >column " tmp.i"
> > >after at test_script.pl line 12.
> > >
> > >The output looks exactly the same if I pipe the command's standard output
> > to
> > >/dev/null ( i.e. what we're seeing was sent to standard error).
> > >
> > >Now, if I uncomment the commented lines, the output looks like this:
> > >
> > >
> > >
> > >before at script/test.pl line 10.
> > >after at script/test.pl line 12.
> > ><<
> > >
> > >So, even though the messages given explicitly to warn in the script were
> > >faithfully appended to the scalar $stderr, as intended, the notice from
> > Pg
> > >(about the implicitly created sequence) is gone: it shows up neither on
> > the
> > >screen, nor in the scalar $stderr.
> > >
> > >How can I trap such notices?
> > >
> > >Thanks!
> > >
> > >tlm
> > >
> > >
> > >P.S. It is tempting to blame the closing of STDERR for this problem, but
> > >this a mandatory step. Without it, $stderr receives no output at all.
> > >
> > >
> > >
> >
> > --
> > Alexander Foken
> > mailto:alexander@foken.de http://www.foken.de/alexander/
> >
> >
--
Joe Slagel
Chief Software Architect
Geospiza Inc
www.geospiza.com
Re: Can"t trap Pg warnings
am 24.03.2006 19:27:50 von tlm1905
------=_Part_3141_4450765.1143224870516
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
On 3/24/06, Joe Slagel wrote:
>
> Looks like prior to DBD::Pg 1.31 these warning messages where sent to
> stderr and not via perl's warning mechanism.
>
> http://www.mail-archive.com/dbi-announce@perl.org/msg00170.h tml
Yep, that was it. (I'm amazed that our supposedly "brand-new" SuSE system
had v. 1.22 for its DBD::Pg...)
Thanks!
tlm
------=_Part_3141_4450765.1143224870516--