&main::execute undefined?

Started by Andrew Magnusover 23 years ago6 messagesgeneral
Jump to latest
#1Andrew Magnus
xanadian99@yahoo.com

Ok, I'm running Postgres and RH8 right out-of-the-box. DBD::Pg is installed, and I'm using Perl 5.8 -- all right out-of-the-box. When my script gets to this line:

$statementH = execute() || die $statementH->errstr ; # this is line 10 btw

I get:

Undefined subroutine &main::execute called at ./test.pl line 10.

As far as I can tell, it should work --but doesn't so I must be missing something. If you want to tackle this one, everything is right below: (PS: the query going into $sql I got with help of you all, so thanks!)

========

#! /usr/bin/perl -w

use DBI ;

$dbH = (DBI->connect("DBI:Pg:dbname=lanparty-reservations","andrew","shrp1234")) ;
$sql = "select c.relname as table from pg_class c where c.relkind = 'r' and c.relname !~ '^pga_' and c.relname !~ '^pg_'" ;

$statementH = $dbH->prepare($sql) ;
$statementH = execute() || warn $statementH->errstr ;

---------------------------------
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now

#2Oliver Elphick
olly@lfix.co.uk
In reply to: Andrew Magnus (#1)
Re: &main::execute undefined?

On Thu, 2002-11-21 at 05:37, Andrew Magnus wrote:

Ok, I'm running Postgres and RH8 right out-of-the-box. DBD::Pg is

installed, and I'm using Perl 5.8 -- all right out-of-the-box. When my
...

Undefined subroutine &main::execute called at ./test.pl line 10.

...

========

#! /usr/bin/perl -w

use DBI ;

$dbH = (DBI->connect("DBI:Pg:dbname=lanparty-reservations","andrew","shrp1234")) ;
$sql = "select c.relname as table from pg_class c where c.relkind = 'r' and c.relname !~ '^pga_' and c.relname !~ '^pg_'" ;

$statementH = $dbH->prepare($sql) ;
$statementH = execute() || warn $statementH->errstr ;

$statementH->execute() || warn $statementH->errstr ;
$relname = $statementH->fetchrow_array();
$statementH->finish();

--
Oliver Elphick Oliver.Elphick@lfix.co.uk
Isle of Wight, UK
http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C
========================================
"A new commandment I give unto you; That ye love one
another. As I have loved you, so ye also must love one
another. By this shall all men know that ye are my
disciples, if ye have love one to another."
John 13:34,35

#3Andrew Magnus
xanadian99@yahoo.com
In reply to: Oliver Elphick (#2)

Thanks, but it still doesn't work. :-(

For everyone else, the error I'm getting is:

Undefined subroutine &main::execute called at ./test.pl line 10.

where line 10 is:

$statementH = execute() || warn $statementH->errstr ;

Oliver Elphick <olly@lfix.co.uk> wrote:On Thu, 2002-11-21 at 05:37, Andrew Magnus wrote:

Ok, I'm running Postgres and RH8 right out-of-the-box. DBD::Pg is

installed, and I'm using Perl 5.8 -- all right out-of-the-box. When my
...

Undefined subroutine &main::execute called at ./test.pl line 10.

...

========

#! /usr/bin/perl -w

use DBI ;

$dbH = (DBI->connect("DBI:Pg:dbname=lanparty-reservations","andrew","shrp1234")) ;
$sql = "select c.relname as table from pg_class c where c.relkind = 'r' and c.relname !~ '^pga_' and c.relname !~ '^pg_'" ;

$statementH = $dbH->prepare($sql) ;
$statementH = execute() || warn $statementH->errstr ;

$statementH->execute() || warn $statementH->errstr ;
$relname = $statementH->fetchrow_array();
$statementH->finish();

--
Oliver Elphick Oliver.Elphick@lfix.co.uk
Isle of Wight, UK
http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C
========================================
"A new commandment I give unto you; That ye love one
another. As I have loved you, so ye also must love one
another. By this shall all men know that ye are my
disciples, if ye have love one to another."
John 13:34,35

---------------------------------
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now

#4Mike Beachy
beachy@marketboy.com
In reply to: Andrew Magnus (#3)
Re: &main::execute undefined?

On Thu, Nov 21, 2002 at 10:46:09AM -0800, Andrew Magnus wrote:

Thanks, but it still doesn't work. :-(

For everyone else, the error I'm getting is:

Undefined subroutine &main::execute called at ./test.pl line 10.

where line 10 is:

$statementH = execute() || warn $statementH->errstr ;

You need to read the documentation for DBI. What Oliver's terse example
was saying is that you are using the wrong syntax. execute() is a
statement handle method, not a method for creating a statement handle.

Read the docs - perldoc DBI

mike

Show quoted text

Oliver Elphick <olly@lfix.co.uk> wrote:
$statementH->execute() || warn $statementH->errstr ;
$relname = $statementH->fetchrow_array();
$statementH->finish();

#5Richard Huxton
dev@archonet.com
In reply to: Andrew Magnus (#3)
Re: &main::execute undefined?

Thanks, but it still doesn't work. :-(

For everyone else, the error I'm getting is:

Undefined subroutine &main::execute called at ./test.pl line 10.

where line 10 is:

$statementH = execute() || warn $statementH->errstr ;

Read Oliver's message again. The execute() is a method not a function in
main's namespace.

$statementH->execute() is the way to call it. Read the DBI documentation
for examples.

- Richard Huxton

Show quoted text

Oliver Elphick <olly@lfix.co.uk> wrote:On Thu, 2002-11-21 at 05:37,
Andrew Magnus wrote:

Ok, I'm running Postgres and RH8 right out-of-the-box. DBD::Pg is

installed, and I'm using Perl 5.8 -- all right out-of-the-box. When my
...

Undefined subroutine &main::execute called at ./test.pl line 10.

...

========

#! /usr/bin/perl -w

use DBI ;

$dbH =
(DBI->connect("DBI:Pg:dbname=lanparty-reservations","andrew","shrp1234"))
;
$sql = "select c.relname as table from pg_class c where c.relkind = 'r'
and c.relname !~ '^pga_' and c.relname !~ '^pg_'" ;

$statementH = $dbH->prepare($sql) ;
$statementH = execute() || warn $statementH->errstr ;

$statementH->execute() || warn $statementH->errstr ;
$relname = $statementH->fetchrow_array();
$statementH->finish();

--
Oliver Elphick Oliver.Elphick@lfix.co.uk

#6Oliver Elphick
olly@lfix.co.uk
In reply to: Andrew Magnus (#3)
Re: &main::execute undefined?

On Thu, 2002-11-21 at 18:46, Andrew Magnus wrote:

Thanks, but it still doesn't work. :-(

In what way?

For everyone else, the error I'm getting is:

Undefined subroutine &main::execute called at ./test.pl line 10.

where line 10 is:

$statementH = execute() || warn $statementH->errstr ;

You can't do that. execute is part of the DBI package, so you can't
just call it as if it were declared in your own program. The way I said
is the standard way to do it, so what goes wrong with that?

Oliver Elphick <olly@lfix.co.uk> wrote:On Thu, 2002-11-21 at 05:37, Andrew Magnus wrote:

...

$statementH->execute() || warn $statementH->errstr ;

From "man 3 DBI":

The typical method call sequence for a "SELECT" statement is:

prepare,
execute, fetch, fetch, ...
execute, fetch, fetch, ...
execute, fetch, fetch, ...

for example:

$sth = $dbh->prepare("SELECT foo, bar FROM table WHERE baz=?");

$sth->execute( $baz );

while ( @row = $sth->fetchrow_array ) {
print "@row\n";
}

--
Oliver Elphick Oliver.Elphick@lfix.co.uk
Isle of Wight, UK
http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C
========================================
"Can two walk together, except they be agreed?"
Amos 3:3