On Thu, Mar 04, 2004 at 08:56:30AM -0800, Jeff Zucker wrote:
> Tim Bunce wrote:
> >On Thu, Mar 04, 2004 at 01:23:32AM -1000, Beau E. Cox wrote:
> >
> >>On Wednesday 03 March 2004 11:50 pm, Beau E. Cox wrote:
> >>
> >>
> >>>Hello folks,
> >>>
> >>>I noticed changed in DBD::DBM in the latest svn DBI source.
> >>>
> >>>When I try to test DBI (make is fine):
> >>>
> >>>
> >>>
> >>[TEST ERRORS]
> >>
> >>Here is what I did to clear the problen on my machine:
> >>
> >>1) added dbm to DBI registry (as noted in a prior reply).
> >>2) patched DBM.pm to allow additions of private attribs:
> >>
> >>--- trunk/lib/DBD/DBM.pm 2004-03-03 22:03:28.000000000 -1000
> >>+++ test-trunk/lib/DBD/DBM.pm 2004-03-04 01:02:38.000000000 -1000
> >>@@ -113,9 +113,9 @@
> >> #
> >> $var = 'dbm_' . $var unless $var =~ /^dbm_/
> >> or $var eq 'f_dir';
> >>- if (!$this->{f_valid_attrs}->{$var}) {
> >>- die "Invalid attribute in connect: '$var'!\n"
> >>- }
> >>+ #if (!$this->{f_valid_attrs}->{$var}) {
> >>+ # die "Invalid attribute in connect: '$var'!\n"
> >>+ #}
> >> $this->{$var} = $val;
> >> }
> >> }
> >
> >Here's a better way (driver authors please note):
> >
> >- # in the connect string the attr names
> >- # can either have dbm_ (or foo_) prepended or not
> >- # this will add the prefix if it's missing
> >- #
> >- $var = 'dbm_' . $var unless $var =~ /^dbm_/
> >- or $var eq 'f_dir';
> >- if (!$this->{f_valid_attrs}->{$var}) {
> >- die "Invalid attribute in connect: '$var'!\n"
> >- }
> >- $this->{$var} = $val;
> >
> >+ # Add dbm_ prefix to attributes that need it
> >+ # (attributes for DBD::Foo in the Driver DSN portion
> >+ # of the DSN string are allowed to skip the "foo_" prefix)
> >+ $var = 'dbm_' . $var if !$valid_attrs->{$var}
> >+ && $valid_attrs->{"dbm_$var"};
> >+
> >+ # place the attribute in $attr (possibly replacing an
> >exiting value)
> >+ # so DBI->connect will then call our STORE on it for us.
> >+ # Our STORE method (inherited from DBD::File's) should
> >validate it
> >+ $attr->{$var} = $val;
> >
> >That's a better approach I think. I've not checked the test to see
> >that they're exercising this code though.
>
> Yes, but it needs work in DBD::File. My aim is to make this available
> to all DBDs that subclass DBD::File without making them subclass STORE
> and FETCH. Basically if the DBD defines an f_valid_attributes hash,
> File will do a valid_attributes check on all lower case attributes that
> start with either foo_ (dbm_ in this case) OR (and this is important)
> with f_ (for attrs of DBD::File) or with sql_ (for attrs of
> SQL::Statement or of DBI::SQL::Nano). It will not check other
> lower-cased attributes since those might have been put in by Proxy or
> Multiplex, or some other thing. This still seems kind of sloppy to me,
I agree.
> there should be some way to make sure that all $dbh->{whatever} stores
> and fetches use valid keys, otherwise it's too easy to make a typo there
> and have the module behave unpredictably because you expected something
> to be set when what you set was something spelled similarly to what you
> wanted. Ideally all DBDs would check their own attributes for valid key
> names.
Right, which brings us back to "making them subclass STORE".
Drivers *should* subclass STORE to handle all attributes that 'belong
directly' to that driver and call $h->SUPER::STORE(...) for others.
So DBD::DBM's STORE could look something like:
sub STORE {
my ($h, $name, $value) = @_;
return shift->SUPER::STORE(@_) unless $name =~ /^dbm_/;
...
}
And DBD::File's STORE could look something like:
sub STORE {
my ($h, $name, $value) = @_;
return shift->SUPER::STORE(@_) unless $name =~ /^(f|sql)_/;
...
}
Tim.