|
From: Chris W. <ch...@cw...> - 2002-10-03 14:58:45
|
On Wed, 2002-10-02 at 11:02, Ray Zimmerman wrote:
> We are running into some problems due to the way that SPOPS handles
> field names. Specifically, it appears that keys($obj) always returns
> a lower-case version of the actual field names, rather than the case
> used in the configuration. Also, the db_discover_types() method in
> SQLInterface returns a hash whose keys are the lower-cased field
> names.
>
> Is there a good reason for this? It seems like a bug to me.
The reason, of course, is laziness: I don't want to deal with dissonance
between what the database and the user thinks fields should be named. So
I just lowercase everything when dealing with fields.
For instance, what happens if a person does this?
config: {
class => 'My::Foo',
field => [ 'FOO', 'BAR', 'BAZ' ],
}
but as a result of a query to get the field names and types the database
returns:
NAME TYPE
foo SQL_VARCHAR,
bar SQL_INTEGER
baz SQL_TIMESTAMP
It's no problem when the user accesses fields, SPOPS::Tie takes care of
this:
my $obj = My::Foo->fetch( 'quux' );
print "Foo is: $obj->{FOO} $obj->{bar} $obj->{bAz}\n";
But when we do an insert/update we want to match up the fields with
their types, so we do something like:
my $fields = $class->field_list;
# $fields = [ 'FOO', 'BAR', 'BAZ' ]
my $dbi_types = $class->db_discover_types;
# keys \%dbi_types = ( 'foo', 'bar', 'baz' )
foreach my $field ( @{ $fields } ) {
my $field_type = $dbi_types->{ $field }; # uh oh, type not found!
}
As a result, I don't know if we can change the return value of
'db_discover_types', but I think we can change the return value of 'keys
%{ $obj }' without too much difficulty.
Well now that I think about it... maybe we can make the return of
'db_discover_types' a tied hash as well. Unless, of course, you've got
something else up your sleeve :-)
Chris
--
Chris Winters (ch...@cw...)
Building enterprise-capable snack solutions since 1988.
|