[prev] [thread] [next] [Date index for 2004/11/26]
Anyone have any luck using Class::DBI with DBD::AnyData as the underlying DBD? I love the idea of something self-contained like that for quick prototyping and such, so I played around a bit and came up with a simple example (attached) that almost works. I say almost, because it seems to produce warnings about active statement handles when I try to traverse the has_a relationship. Poking around a bit has revealed that this would be solved if Class::DBI::set_sql were to call Ima::DBI::set_sql with $cached set to 0, but overriding set_sql in my Class::DBI subclass doesn't come into effect until *after* use base 'Class::DBI' has called set_sql a bunch of times already, thus defeating the override. Anyone have any suggestions, other than perhaps contacting DBD::AnyData's author and asking if he'll have time to fix the handling of statement handle caching (which I've already done, but a workaround sooner would help)? Thanks! Dan Friedman -- #!/usr/bin/perl -lw # If this worked correctly, we'd see: # Shakespeare # To be or not to be, that is the question # Pants # ...but instead we get warnings before 'Pants'. use strict; package MyDBI; use base 'Class::DBI'; __PACKAGE__->connection('dbi:AnyData(RaiseError=>1):'); local $/; our $data = <DATA>; our ($phrases, $author) = split /\n--\n/, $data; package Authors; use base 'MyDBI'; __PACKAGE__->db_Main->func( 'authors', 'Pipe', [$MyDBI::author], 'ad_import'); __PACKAGE__->table('authors'); __PACKAGE__->columns(All => qw/id name/); print __PACKAGE__->retrieve(13)->name; # should print 'Shakespeare' package Phrases; use base 'MyDBI'; __PACKAGE__->db_Main->func( 'phrases', 'Pipe', [$MyDBI::phrases], 'ad_import'); __PACKAGE__->table('phrases'); __PACKAGE__->columns(All => qw/id phrase author/); __PACKAGE__->has_a(author => 'Authors'); print __PACKAGE__->retrieve(1)->phrase; # should print 'To be or not to be...' print __PACKAGE__->retrieve(2)->author->name; # should print 'Pants', but warn()s package MyDBI; # we go back to package MyDBI so that its <DATA> reads from here: __DATA__ id|phrase|author 1|To be or not to be, that is the question|13 2|HLAUGH|23 -- id|name 13|Shakespeare 23|Pants
Class::DBI over DBD::AnyData?
|
Generated at 11:35 on 01 Dec 2004 by mariachi v0.52