Skip site navigation (1) Skip section navigation (2)

Re: [SQL] perl and postgres. . .

From: "Gene Selkov, Jr(dot)" <selkovjr(at)mcs(dot)anl(dot)gov>
To: JT Kirkpatrick <jt-kirkpatrick(at)mpsllc(dot)com>, pgsql-interfaces(at)hub(dot)org
Subject: Re: [SQL] perl and postgres. . .
Date: 1999-04-21 19:36:08
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-interfaces
> I am trying 
> $query="select max((userseq) from dataentry;";
> $result=$conn->exec("$query");
> $userseq=($result->getvalue(0,0));
> * I need the value in a variable name other than $result. . .
> If I try
> $query="select max((userseq) from dataentry;";
> $result->getvalue(0,0);
> $userseq=$result;
> it bombs.  Ahhh, the frustrations of being new to this!  

Now I see what your problem is. You missed the whole point. $result is
not a variable, it is an object reference, so is $conn. The exec()
method of $conn (or rather, that of the object referenced by $conn)
returns the result object. You normally access the object's data
through its methods, in this case, getvalue(), fetchrow(), etc. -- see
the Pg doc for the full list.

So the following simply copies the reference to the result object into
$userseq, and that may bomb, depending on how you use it further:

> $userseq=$result;

The following the value you need, but it since there is no explicit
assignment, it is getting lost:

> $result->getvalue(0,0);

What you needed was

$userseq = $result->getvalue(0,0);

And again, the manual for Pg has complete examples. Note the code you
need to add to check for errors that may result from each method call.


pgsql-interfaces by date

Next:From: Gene Selkov Jr.Date: 1999-04-21 20:45:16
Subject: Re: [INTERFACES] Detecting existance of table
Previous:From: Brett W. McCoyDate: 1999-04-21 19:10:28
Subject: Re: [SQL] perl and postgres. . .

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group