> -----Original Message-----
> From: Bob Hunter [mailto:[EMAIL PROTECTED]
> Sent: Tue 2/27/2007 5:07 PM
> To: Garrett, Philip (MAN-Corporate); [email protected]
> Cc: [EMAIL PROTECTED]
> Subject: RE: (Fwd) DBI's method for reading [row x,field y]
> 
> The same example, using Pg...
> 
> # use Pg;
> # my $dbh = Pg::connectdb("dbname=<dbname>");
> # my $sth = $dbh->exec("<SQL STATEMENT>");
> # for (my $i = 0; $i < $sth->ntuples; $i++) {
> # for (my $j = 0; $j < $sth->nfields; $j++) {
> #    print "Value at ($i,$j):
> $sth->getvalue($i,$j)\n";
> # }}
> 
> It is more concise, and more intuitive. 
> It is a pity that DBI is so cumbersome.
> Yes, DBI is faster and independent from specific
> databases, but Pg is far more elegant. Too bad one
> cannot have both worlds.

Beauty is in the eye of the beholder.  Your code example is not very
"Perlish" -- it is accessing database records at a low level like
a C-style multidimensional array, rather than as named fields in records.

I, for one, think this is more intuitive than your example, since it
treats the data by name rather than by some computer-assigned
numeric index:

  my $dbh = DBI->connect;
  my $sth = $dbh->prepare("SELECT * FROM BOOKS");
  $sth->execute;
  while (my $book = $sth->fetchrow_hashref) {
    print "$book->{ISBN}: $book->{TITLE}\n";
  }

or
  my $sth = $dbh->prepare("SELECT TITLE, ISBN FROM BOOKS");
  $sth->execute;
  while (my ($title,$isbn) = $sth->fetchrow) {
    print "$isbn: $title\n";
  }

Regards,
Philip

Reply via email to