Movable Type / Perl Error

Sep 23, 2006 12:17 PM
Tags: bugs, movabletype, perl

Can anyone offer some insight on this error?

Can't call method "prepare" on an undefined value at lib/MT/ObjectDriver/DBI.pm line 103. at lib/MT.pm line 867
Content-Type: text/plain; charset=utf-8 Got an error: Can't call method "prepare" on an undefined value at lib/MT/ObjectDriver/DBI.pm line 103. at lib/MT/App/CMS.pm line 906

I've been getting it since I upgraded to MT version 3.32; Googling doesn't find much.

It happens when I save an entry after adding or editing it, but not when I preview those changes. I believe it's part of the page-rebuilding process (though simply rebuilding files, via adding a comment or on the command line, doesn't trigger it either).

I can't comment out the offending part of the code (below) without creating other errors:

    my($tbl, $sql, $bind) =
        $driver->_prepare_from_where($class, $terms, $args);
    my(%rec, @bind, @cols);
    my $cols = $class->column_names;
    for my $col (@$cols) {
        push @cols, $col;
        push @bind, \$rec{$col};
    }
    my $tmp = "select ";
    $tmp .= "distinct " if $args->{join} && $args->{join}[3]{unique};
    $tmp .= join(', ', map "${tbl}_$_", @cols) . "\n";
    $sql = $tmp . $sql;
    my $dbh = $driver->{dbh};
    warn "load - Preparing SQL: $sql" if $MT::DebugMode & 4;
    
my $sth = $dbh->prepare($sql) or return $driver->error(MT->translate("Loading data failed with SQL error [_1]", $dbh->errstr));

I'm no Perl guru, but it seems to me that $sql should be defined in the first line of the code snippet.

I ran mt-check and got the all-clear. I ran mt-upgrade and it did what it needed to (doing so subsequently confirms that the database schema is OK). I'm pretty much stumped at this point.

(Cross-posted on the SixApart forums and the DreamHost discussion forum.)

update

That submethod is called from the following code in CMS.pm:

my @perms = MT::Permission->load({ author_id => $auth->id });

And changing an earlier line to:

my $dbh = $driver->{dbh} or die "No database connection.";

Results in that die being called.

update

Wow, that was strange; I simply had to add (back?) the line DBPassword [foo] to my mt.cfg file.


Comments: Movable Type / Perl Error

I know that you have to have the connect statement above that line. Is the program running it before correctly. Two possible problems (from an ok perl developer)
1) you did not have the connect statement (or it was not working)
2) The location where the connect statement was done is not in the same namespace as where this code exists. http://perl.plover.com/FAQs/Namespaces.html

ex:
use strict;
use DBI;

my $dbh = DBI->connect( 'dbi:mysql:movetype',
'jeffrey',
'jeffspassword',
{
RaiseError => 1,
AutoCommit => 0
}
) || die "Database connection not made: $DBI::errstr";

my $sql = qq{ SELECT * FROM comments };
my $sth = $dbh->prepare( $sql );
$sth->execute();

Posted by: mph on September 23, 2006 2:32 PM | permalink

Pearls are never an error; I wear mine daily.

(I keed, I keed!!!)

Posted by: A N N A on September 26, 2006 11:05 AM | permalink

Phew ! Many thanks for this - I had the some problem after playing around with some plugins - all seemed fine until I went to add a new entry and I got this error - you saved my blog and probably what's left of my hair ! Thanks !

Posted by: Mark on April 21, 2007 3:12 AM | permalink

No more comments! Either someone has violated Godwin's Law, I'm tired of the discussion or, most likely, the ten-week window has closed. You can, however, contact me through email.