Hi mike
Am Montag, 14. M�rz 2005 18.38 schrieb mike:
> Anyone got any any idea what is happening here
Apart from your actual problem, it happens that the coding below will give big
chances to have undetected or hard to find errors.
- use "use strict; use warnings;" at the top of the code
- declare your variables (as local to the first usage as possible)
- check the results of methods/functions
I did not run your (and my) code; just some annotations:
> $dbh=DBI->connect("dbi:Pg:dbname=data_cc",$user,$pw);
my $dbh=DBI->connect("dbi:Pg:dbname=data_cc",$user,$pw) or die $DBI::errstr;
(an example for declaring $dbh and checking the result of connect())
> $dump_dir='/home/data_cc/dump';
> @names=$dbh->tables();
> #$dbh->execute;
> #print @names;
> foreach $names(@names){
sidenote: since $names contains a scalar, $name would be a better name for
this variable.
> if (substr($names,0,9) eq "public.tb")
> {
> $file1= "$dump_dir\/$names";
> $dbh->prepare("COPY $names TO ? WITH DELIMITER AS #");
The prepare method returns a statement handle for further usage, check the
manual of DBI.
my $sth=$dbh->prepare("COPY $names TO ? WITH DELIMITER AS #")
or die $DBI::errstr
> $dbh->bind_param(1,$file1);
> $dbh->execute();
and the statement handle has the bind_param and execute methods:
$sth->bind_param(1,$file1) or die $DBI::errstr;
$sth->execute() or die $DBI::errstr;
There are several methods to retrieve the results from the statement handle
(see man DBI) - at this place in the code, not outside of the foreach loop.
> }
> }
>
> results in output
> [Mon Mar 14 17:30:10 2005] [error] [client 127.0.0.1] Can't locate
> object method "bind_param" via package "DBI::db" at /home/www/cgi-
> bin/dump_all.pl line 25.
This is correct, since the database handle has no such methods.
> confused - it seems to be losing the connection to the db
No, this would not result in an object dropping a method.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>