From: | Antai Ning <aning(at)jetnet(dot)ca> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | The application dies when insertion fails. |
Date: | 2002-05-30 18:11:09 |
Message-ID: | F72CDFC92CAA204A9BE73476EED3821D015E5F@JETMAIL |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2653.12">
<TITLE>The application dies when insertion fails.</TITLE>
</HEAD>
<BODY>
<P><FONT SIZE=2>Hi Gurus,</FONT>
</P>
<P><FONT SIZE=2>This has been bothered me for a couple of days. I wrote a postgres db application in perl which parses a syslog file and inserts some data into a table. I put the actual insertion in a eval block, so the application won't die when insertion fails. But it doesn't work as I expected. When it encounter a "DBD::Pg::st execute failed: ERROR: Bad timestamp external representation 'Jan 11 18:05:50 at (eval 9) line 426, <MSGS> line 1." error, the whole program die.</FONT></P>
<P><FONT SIZE=2>I'm using DBD::Pg intereface, postgres 7.1.3. Here is the codes:</FONT>
</P>
<P><FONT SIZE=2>-----------------------------------------------------------------------</FONT>
<BR><FONT SIZE=2>my $dbh = DBI->connect("dbi:Pg:dbname=$dbname",$dbuser,$dbpass,{AutoCommit => 0,RaiseError => 1,PrintError => 0}) || die "Unable to connect to $dbname on $dbhost [$DBI::errstr]\n";</FONT></P>
<P><FONT SIZE=2>while(1)</FONT>
<BR><FONT SIZE=2>{</FONT>
<BR> <FONT SIZE=2># reading from MSGS and parsing here</FONT>
</P>
<P> <FONT SIZE=2>$sth = $dbh->prepare("insert into http_request</FONT>
<BR> <FONT SIZE=2>(INTERFACE_ID,INTERFACE_DIR,REQUEST_TIME,SRC,URL,result_id)</FONT>
<BR><FONT SIZE=2> values(?, ?, ?, ?, ?, ?)");</FONT>
</P>
<P> <FONT SIZE=2>eval {</FONT>
<BR><FONT SIZE=2> $sth->execute($ifid,$idir,$timestamp,$userip,$destip,$rid);</FONT>
<BR><FONT SIZE=2> $sth->finish;</FONT>
<BR><FONT SIZE=2> $dbh->commit;</FONT>
<BR> <FONT SIZE=2>};</FONT>
</P>
<P> <FONT SIZE=2>if($@)</FONT>
<BR> <FONT SIZE=2>{</FONT>
<BR><FONT SIZE=2> print "Insert failed\n";</FONT>
<BR><FONT SIZE=2> print "$@";</FONT>
<BR> <FONT SIZE=2>}</FONT>
<BR><FONT SIZE=2>}</FONT>
</P>
<P><FONT SIZE=2>---------------------------------------------------------------------------</FONT>
</P>
<P><FONT SIZE=2>I noticed that the timestamp is not valid, but the excution should continue. Strange thing is that it didn't die right away. After print"$@" prints out the error "DBD::Pg::st execute failed: ERROR: Bad timestamp external representation 'Jan 11 18:05:50 at (eval 9) line 426, <MSGS> line 1." it dies.</FONT></P>
<P><FONT SIZE=2>So what do I miss here?</FONT>
</P>
<P><FONT SIZE=2>Thanks in advance!</FONT>
</P>
<BR>
<P><FONT SIZE=2>Andy</FONT>
</P>
</BODY>
</HTML>
Attachment | Content-Type | Size |
---|---|---|
unknown_filename | text/html | 3.6 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2002-05-30 18:54:24 | Re: horrendous query challenge :-) |
Previous Message | Darren Ferguson | 2002-05-30 18:05:04 | Re: connection refused problem |