RE: [GENERAL] pg_result

From: dj(at)pelf(dot)harvard(dot)edu (Diab Jerius)
To: davez(at)istand(dot)com
Cc: pgsql-general(at)postgreSQL(dot)org
Subject: RE: [GENERAL] pg_result
Date: 1998-06-25 21:05:48
Message-ID: 199806252105.RAA20580@pelf
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

--------- Received message begins Here ---------

> I am trying to get back 10 lines of information that each contain
> 11 fields. Do you know what variable I should set up. Do I need to set
> up and array call since there are more than 1 line of data that I am
> trying to call?
>
>
> This is what I have:
>
> #!/usr/local/bin/perl
>
> use Pg;
>
>
> $database = "inquiries";
> $conn = Pg::connectdb("dbname = $database");
>
> $query = "select * from sales where acctid = 'dave'";
> $result = $conn->exec("$query");
> # should check to see if status is ok if not fail it
> $status = $conn->status;
> $errorMessage = $conn->errorMessage;
> $cmdStatus = $result->cmdStatus;
>
> $result_status = $result->resultStatus;
> $ntuples = $result->ntuples;
> $nfields = $result->nfields;

All of the data selected is returned in the result object.
At this point you need to iterate through it to get the data:

Here's an example:

for ( my $tuple = 0 ; $tuple < $result->ntuples ; $tuple++ )
{
for ( my $field = 0 ; $field < $result->nfields ; $field++ )
{
printf( "%d: %s = %s\n", $tuple, $result->fname( $field ),
$result->getvalue( $tuple, $field ) );
}
}

-------------
Diab Jerius Harvard-Smithsonian Center for Astrophysics
60 Garden St, MS 70, Cambridge MA 02138 USA
djerius(at)cfa(dot)harvard(dot)edu vox: 617 496 7575 fax: 617 495 7356

Browse pgsql-general by date

  From Date Subject
Next Message Rob den Boer 1998-06-26 07:30:14 RE: [GENERAL] pg_result
Previous Message Stephan Doliov 1998-06-25 20:35:16 re support.