[Dbix-class] 08100: branch roundup, owners please respond.
John Napiorkowski
jjn1056 at yahoo.com
Tue Apr 8 15:24:03 BST 2008
--- Matt S Trout <dbix-class at trout.me.uk> wrote:
> On Mon, Mar 31, 2008 at 06:17:26PM -0700, John
> Napiorkowski wrote:
> > Okay, so I think this is actually much easier than
> I
> > first thought. Basically since I know that each
> > storage specific subclass inherits from
> > DBIx::Class::Storage::DBI I just put a stublike
> method
> > there which performs the connection and
> redispatches
> > to the subclass on an as needed basis.
> >
> > So for example, if a storage specific subclass
> needs
> > to define bind parameters, such as how the Pg
> Storage
> > subclasses needs to set bytea bind parameters to
> > support using bytea for long/blob storage, it
> > overrides the method "bind_attribute_by_data_type"
> > from DBIx::Class::Storage::DBI like so:
> >
> > sub bind_attribute_by_data_type {
> > my ($self,$data_type) = @_;
> >
> > my $bind_attributes = {
> > bytea => { pg_type => DBD::Pg::PG_BYTEA },
> > };
> >
> > if( defined $bind_attributes->{$data_type} ) {
> > return $bind_attributes->{$data_type};
> > }
> > else {
> > return;
> > }
> > }
> >
> > and in the parent class I have a version which, if
> > executed, performs the connection and then sends
> it
> > off to the storage specific subclass:
> >
> > sub bind_attribute_by_data_type {
> > my ($self, $data_type, $storage) = @_;
> > if($storage) {
> > $storage->ensure_connected;
> > return
> > $storage->bind_attribute_by_data_type($data_type)
> > }
> > return;
> > }
>
> You need to trap the case where it isn't overrided
> in the subclass. So
> something like
>
> our $NO_SUBCLASS;
> return if $NO_SUBCLASS;
> $self->ensure_connected;
> local $NO_SUBCLASS = 1;
> $self->bind_...
>
> or similar. Or maybe
>
> sub bind_... {
> $self->ensure_connected;
> $self->_bind_... # note the _
>
> which is probably simpler and harder to get wrong.
Yeah, I was worried about that as well. I tested it
on a few databases without trouble, but was concerned
it's starting to be a little too much action at a
distance and the kind of thing that will lead us to
troublesome bugs. Since this fix is for such a tiny
edge case I don't want to make things worse.
>
> The other thing to consider is: Can we not just do
> ensure_connected on the
> way in to anything that's going to use the dbh
> (insert, select etc.) so
> specific methods don't have to worry about it at
> all?
>
>From my testing I found by the time we get to
insert/update, etc it's too late. Let me give it
another look, since I'd rather have a more general
solution than one that just solves this particular
problem.
--john
> --
> Matt S Trout Need help with your
> Catalyst or DBIx::Class project?
> Technical Director
> http://www.shadowcat.co.uk/catalyst/
> Shadowcat Systems Ltd. Want a managed development
> or deployment platform?
> http://chainsawblues.vox.com/
> http://www.shadowcat.co.uk/servers/
>
> _______________________________________________
> List:
>
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN:
> http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive:
>
http://www.grokbase.com/group/dbix-class@lists.rawmode.org
>
____________________________________________________________________________________
You rock. That's why Blockbuster's offering you one month of Blockbuster Total Access, No Cost.
http://tc.deals.yahoo.com/tc/blockbuster/text5.com
More information about the DBIx-Class
mailing list