set_sql

[prev] [thread] [next] [Date index for 2005/06/14]

From: ian.goldstein
Subject: set_sql
Date: 11:55 on 14 Jun 2005
Good Morning.
 
First let me say thanks to all the contributors for Class::DBI, very cool product.
My question is on set_sql.  I have a sql statement for a class that works with a single place holder, but if I introduce a second place holder, I get an error:
 
Can't bind a reference (EQ::machine=HASH(0xcb3d14)) at /home/goldstia/lib/DBIx/ContextualFetch.pm line 51.
 at /home/goldstia/lib/DBIx/ContextualFetch.pm line 51
        DBIx::ContextualFetch::st::_untaint_execute('DBIx::ContextualFetch::st=HASH(0xde74f4)', 'EQ::machine=HASH(0xcb3d14)', 67) called at /home/goldstia/lib/DBIx/ContextualFetch.pm line 31
        DBIx::ContextualFetch::st::execute('DBIx::ContextualFetch::st=HASH(0xde74f4)', 'EQ::machine=HASH(0xcb3d14)', 67) called at /home/goldstia/tmp/PRISM/PRISM.pm line 88
        EQ::machine_file::machine_file_latest('EQ::machine_file', 'EQ::machine=HASH(0xcb3d14)', 67) called at ./get_hostsbyproj line 21

=============================================================================================
 
The class itself looks like this  ( it is the second placeholder that causes the error message f== file_name_key = ?
 
package EQ::machine_file;
use base "EQ::prismDB";
EQ::machine_file->table('machine_file');
EQ::machine_file->columns(All=> qw/machine_key file_content_key file_name_key version ctime userid groupid fmode/);
EQ::machine_file->columns(Primary=> qw/machine_key file_name_key version/);
EQ::machine_file->has_a('machine_key' => 'EQ::machine');
EQ::machine_file->has_a('file_name_key' => 'EQ::file_name');
EQ::machine_file->has_a('file_content_key' => 'EQ::file_content');
EQ::machine_file->has_a('ctime' => 'Time::Piece',
                   inflate => sub { Time::Piece->strptime(shift, "%m:%d:%Y:%H:%M:%S")},
                   deflate => 'ymd');
#
#  Creates a nice method to extract data from a view that has an object type of machine_file
#
__PACKAGE__->set_sql(machinefilelatest =>
        qq( SELECT *
              from machine_file_latest
              where machine_key = ? and file_name_key = ?));
 
sub machine_file_latest {
        my $class = shift;
        my $machine_key = shift;
        my $file_name_key = shift;
        my $sth = $class->sql_machinefilelatest;
           $sth->execute($machine_key,$file_name_key);
        return $class->sth_to_objects($sth);
}

 
The calling program looks like this:
 
my $fobj = EQ::file_name->search('name'=>"/etc/hosts")->next;
$fnk = $fobj->file_name_key;

$mfo = EQ::machine_file->machine_file_latest($a->machine_key ,$fnk);
 
Any thoughts or suggestions would be greatly appreciated.
 
-- Ian


set_sql
ian.goldstein 11:55 on 14 Jun 2005

Re: set_sql
yoorobot 13:00 on 14 Jun 2005

Re: set_sql
sriha 15:46 on 14 Jun 2005

Re: set_sql
Tony Bowden 16:07 on 14 Jun 2005

RE: set_sql
Ian.Goldstein 20:29 on 14 Jun 2005

Generated at 16:36 on 28 Jul 2005 by mariachi v0.52