Re: perl Pg module and result status

From: Fernán Agüero <fernan(at)iib(dot)unsam(dot)edu(dot)ar>
To: Edward "Q(dot) Bridges" <ed(dot)bridges(at)buzznik(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: perl Pg module and result status
Date: 2000-09-22 13:54:46
Message-ID: 20000922.13544600@iib005.iib.unsam.edu.ar
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi folks!

Thanks for the advice. Excuse my delay in replying: I've been filled with
work.

And yes, I was using the Pg module that comes with pgsql, and not the DBI:Pg
one. Now I switched to DBI and is surprising how much cleaner code you get,
particularly since the checks for errors are done by DBI (PrintErrors => 1,
RaiseErrors => 1).

I have yet to get into more depth with DBI but, as you said, I find it
easier to get things done. Not to mention the possibility of moving from
one RDMS to another and just changing a couple of lines in the scripts.

Thanks again,

Fernan

>>>>>>>>>>>>>>>>>> Original Message <<<<<<<<<<<<<<<<<<

On 9/20/00, 7:27:40 PM, "Edward Q. Bridges" <ed(dot)bridges(at)buzznik(dot)com> wrote
regarding Re: [GENERAL] perl Pg module and result status:

> i can't seem to locate the reference to the documentation
> you mention in the perldoc for DBD::Pg, can you reference
> it?

> as a general note, you should be using the DBI interface
> with DBD::Pg and not calling the methods in DBD::Pg
> directly. they're "private" and likely to change.

> in other words your perl script should "use DBI;" and
> not mention DBD::Pg at all.

> try this:

> use DBI;
> $user = '';
> $pass = '';
> $dburl = ''; # should be: dbi:Pg:dbname=[your database name]
> $db = DBI->connect($dburl, $user, $pass, {AutoCommit=>0} )
> or die "Can't connect to db";
> $sth = $db->prepare( q{ select current_timestamp } )
> or die "Can't prepare statement: " . $db->errstr;
> $sth->execute()
> or die "Can't execute statement: " . $db->errstr;
> $result = $sth->fetchrow_array();

> ($result) ? print "$result\n" : print "error fetching: " . $db->errstr;

> __END__

> hope this helps
> --e--

> On Wed, 20 Sep 2000 23:59:41 GMT, Fern n Agero wrote:

> > Dear all: i am somewhat new to both perl and PostgreSQL. I am writing
> > some perl scripts to store and retrieve information in a pgsql database,
> > using the Pg perl module. However i am having trouble doing checks after
> > issuing queries or commands.
> >
> > According to the module documentation:
> > "
> > $result_status = $result->resultStatus
> > Returns the status of the result. For comparing the status you may use
> > one of the following constants depending upon the command executed:
> > - PGRES_EMPTY_QUERY
> > - PGRES_COMMAND_OK
> > - PGRES_TUPLES_OK
> > - PGRES_COPY_OUT
> > - PGRES_COPY_IN
> > - PGRES_BAD_RESPONSE
> > - PGRES_NONFATAL_ERROR
> > - PGRES_FATAL_ERROR
> > "
> >
> > When I check the contents of $result_status it is not any of the
> > mentioned constants, but a number (i am now getting 7 for a
> > $result->getvalue command after a failed select statement). If i issue
> > the same select statement in the pgsql terminal everything works. Thus i
> > don't understand what could be happening.
> >
> > However, comparisons of the kind of:
> > if ($result_status != PGRES_COMMAND_OK)
> > appear to work most of the times (am i comparing against a number?)
> >
> > Any help is appreciated.
> >
> > Thanks in advance,
> >
> >
> > Fernan
> >
> >
> >

Responses

Browse pgsql-general by date

  From Date Subject
Next Message root 2000-09-22 13:58:56 how to store a query, that results in a table
Previous Message Enrico Comini 2000-09-22 13:50:57 Triggers