I am writing the answer to my original question,
as I go along and learn DBI. This is a list of
minimal string replacements that shoul do it.
The resulting code will not be efficient, but
it can always be optimized at a later time.

Be kind, and help me out.

# [1]: use Pg;
# [2]: use DBI;
#
# [1]: $dbh = Pg::connectdb("dbname=$dbname");        
                         
# [2]: $dbh = DBI->connect("DBI:Pg:dbname=$dbname",
"", "", {AutoCommit => 1}); 
#                                                     
                         
# [1]: $dbh->exec("<SQL STATEMENT>");                 
                         
# [2]: $dbh->do("<SQL STATEMENT>");                   
                         
#                                                     
                         
# [1]: $dbh->status == 1                              
                         
# [2]: $dbh eq "undef"                                
                         
#                                                     
                         
# [1]: $sth->nfields                                  
                         
# [2]: $sth->{NUM_OF_FIELDS} 


This is work in progress, as I keep going.

The last string replacement triggers an error, because
$sth->{NUM_OF_FIELDS} is actually a string, while
$sth->nfields is a number. Using the above in loops
returns the following error:

Can't use string ("1496") as a HASH ref while "strict
refs" in use at
        <.....> line <...> (#2)
    (F) Only hard references are allowed by "strict
refs".  Symbolic
    references are disallowed.  See perlref.

This is odd, however. In the manual "Programming the
Perl DBI" I see this example:

for ( $i = 1 ; $i <= $sth->{NUM_OF_FIELDS} ; $i++ ) {
print "Column $i is called $sth->{NAME}->[$i-1]\n";
}

In my code, in the above line error, I have 

  for ($i=0; $i < $result->{NUM_OF_FIELDS} ; $i++)

which is hardly controversial. So, why am I having
that error at all?

Bob


 
____________________________________________________________________________________
Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail beta.
http://new.mail.yahoo.com

Reply via email to