RE: [GENERAL] pg_result
От | dj@pelf.harvard.edu (Diab Jerius) |
---|---|
Тема | RE: [GENERAL] pg_result |
Дата | |
Msg-id | 199806252105.RAA20580@pelf обсуждение исходный текст |
Список | 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@cfa.harvard.edu vox: 617 496 7575 fax: 617 495 7356
В списке pgsql-general по дате отправления: