LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-09-2008, 06:36 PM   #1
urzumph
Member
 
Registered: Jan 2004
Location: Australia
Distribution: Debian
Posts: 168

Rep: Reputation: 30
Perl Noob + DBI : Can't call method without a package or object ref


The following code:

Code:
use DBI;
<snip>
my %preparedStatements;
<snip>
$preparedStatements{"latest_config_id"} = $db_handle->prepare("SELECT MAX(sequence) FROM configs WHERE id = ?")
    or die $db_handle->errstr;
<snip>
sub get_latest_config_id($) {
    my ($id) = @_;
    my $ps = $preparedStatements{"latest_config_id"};
    
    my $result = $ps->execute(($id))
        or die $ps->errstr;
    
    my @row = $result->fetchrow_array();
    return $row[0];
}
Dies with "Can't call method "fetchrow_array" without a package or object reference at /usr/lib/perl5/liblegacydb.pl line 38."

Do I need to cast $result somehow?

Thanks in advance.
 
Old 09-09-2008, 07:13 PM   #2
nadroj
Senior Member
 
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,539

Rep: Reputation: 58
first, ive used perl only for the past few months (and not very often) and i have never used DBI--only did basic perl stuff. however, the execute function i believe returns a true or false value. you then try to call the "fetchrow_array()" function on this variable, but i think you should be using $ps not $result.

Last edited by nadroj; 09-09-2008 at 07:16 PM.
 
Old 09-09-2008, 07:47 PM   #3
urzumph
Member
 
Registered: Jan 2004
Location: Australia
Distribution: Debian
Posts: 168

Original Poster
Rep: Reputation: 30
Ah, I understand now. You're quite right -

"For SELECT statements, execute simply ``starts'' the query within the database engine. Use one of the fetch methods to retrieve the data after calling execute. The execute method does not return the number of rows that will be returned by the query (because most databases can't tell in advance), it simply returns a true value."

(from http://www.mathematik.uni-ulm.de/hel...5/doc/DBI.html)

Thanks.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't call method "title" on undefined title in Perl script scuzzman Programming 12 12-11-2009 04:40 AM
Can't locate object method "splitpath" via package "PACK001" at /usr/lib/perl5/5.8.8/ sajigeorge Linux - Software 1 01-11-2009 06:33 AM
perl install error: Can't locate object method "new" via package "Module::Build::Vers powah Linux - Software 0 10-24-2006 01:57 PM
Perl undefined subroutine /can't locate object method cobien Programming 1 11-17-2003 10:47 AM
Can't locate object method "splitpath" via package "File::Spec" RobJohnston Linux - General 2 06-28-2003 09:59 AM


All times are GMT -5. The time now is 05:50 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration