[CDBI] Ima::DBI Statement Handles

Patrick Paskvan patrick_paskvan at yahoo.com
Thu Aug 11 16:59:40 BST 2005


I'm confused about the way Ima::DBI stores statement handles.
I was under the impression that when using set_sql(), the
statement created would be data of the class that called
set_sql().  The calling class would also inherit statement
handles from classes further up the inheritance hierarchy.

For instance, in the sample classes below (ripped from
the CDBI perldoc) Music::Artist and Music::CD are at the
same "level" in the inheritance tree.  I even removed the
has_many relationship between Artist and CD to be sure
HasMany wasn't performing any trickery I didn't see.
So, Music::Artist and Music::CD are essentially unrelated.

I then added a statement to Music::CD with set_sql().
The script sql_names.pl uses both classes, retrieves
their statement handles with sql_names() and displays
them.  I was not expecting the 'NewStatement' handle
to be returned when calling Music::Artist->sql_names().

So what am I missing?

Thanks,
Patrick

---------- BEGIN SAMPLE ------------
package Music::DBI;
use base 'Class::DBI';
__PACKAGE__->connection('dbi:mysql:dbname', 'username', 'password');

package Music::Artist;
use base 'Music::DBI';
__PACKAGE__->table('artist');
__PACKAGE__->columns(All => qw/artistid name/);
#__PACKAGE__->has_many(cds => 'Music::CD');

package Music::CD;
use base 'Music::DBI';
__PACKAGE__->table('cd');
__PACKAGE__->columns(All => qw/cdid artist title year/);
__PACKAGE__->set_sql(NewStatement => 'SELECT year FROM __TABLE__');


sql_names.pl:
-------------
#!/usr/bin/perl
use warnings;
use Music::Artist;
use Music::CD;

print "Music::Artist sql_names:\n".join("\n",
Music::Artist->sql_names)."\n\n";
print "Music::CD sql_names:\n".join("\n", Music::CD->sql_names)."\n";


sql_names.pl output:
--------------------
Music::Artist sql_names:
MakeNewObj
update
Nextval
SearchSQL
RetrieveAll
Retrieve
Flesh
single
DeleteMe
NewStatement

Music::CD sql_names:
MakeNewObj
update
Nextval
SearchSQL
RetrieveAll
Retrieve
Flesh
single
DeleteMe
NewStatement

---------- END SAMPLE ------------

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 




More information about the ClassDBI mailing list