Re: Need help with finding solution to CDBI bug

[prev] [thread] [next] [Date index for 2004/06/25]

From: Charles Bailey
Subject: Re: Need help with finding solution to CDBI bug
Date: 16:12 on 25 Jun 2004
--On Thursday, June 24, 2004 3:55 PM +0100 Tony Bowden 
<tony-cdbitalk@xxxxx.xxx> wrote:

> On Thu, Jun 24, 2004 at 09:50:44AM -0400, Charles Bailey wrote:
>> Fair enough.  Given that, I'd have two suggestions:
>> 1. Deprecate id() in favor of db_id() or somesuch, so that there's no
>> confusion that it takes a DB-level view, not an object-level view.
>
> That's extremely unlikely to happen. I really don't see how there's any
> confusion here and id() is a fairly fundamental method.
>
>> 2. Add a separate method, say key() or key_value(), which returns the
>> "object-level" primary key value, since this is what the outside world
>> should deal with (the point of Class::DBI being to hide the details of
>> the  database table).  (It follows, of course, that db_id() is Tim's
>> one-liner applied to the return value(s) of key().)
>
> I'm obviously missing something crucial here. Class::DBI has never
> actually supported your primary key value being anything other than
> a simple value. The docs have warned against inflating them for quite
> some time.
>
>
> What's the problem that you're proposing to fix?

Hmm.  Perhaps I've wandered way off track.  Here's my line of reasoning:

0. CDBI's goal is to present an object-based interface to a data store, 
representing each record as an object, and the values in the record as 
attributes of the object.  Values returned by accessors may be any Perl 
scalar type, including objects.  (As an implementation detail, the data 
store happens to be a relational DB with a SQL-driven interface, but CDBI's 
trying to insulate the user from that.  It does make available ways to 
execute custom SQL queries, but even there tries to insulate the user from 
the details of the SQL.)

1. id() is a shortcut accessor which returns the values of the primary key 
attributes.

2. Therefore id() should return a collection comprising what the 
attribute-specific accessors for each component of the primary key would 
return.

3. One of the places CDBI uses id() internally is to compose a primary key 
value when interacting with the underlying DBI.  In this internal 
circumstance, attribute values need to be flattened into types the DB 
driver can deal with.  This is where the problem crops up: id() returned an 
object, and  CDBI/DBIx::CF/DBD::foo assume that if the object can stringify 
itself, it will stringify to the flat representation of its PK.  If the 
class has redefined the Stringify group, things break.  (Things will also 
break if it has a multi-column PK, but since CDBI doesn't do compound FKs, 
that's not a practical issue.)  Limiting id() to just db-level information 
fixes the problem, but seems like swatting a fly with a sledge.

As an interesting side note, trying to maintain backwards compatibility 
doesn't lead me to favor either approach: the entire problem occurs only 
when one has an inflated primary key (else there would be no issue with 
different Stringify schemes), but Tim's patch, in helping people with this 
inflated primary key problem, only hurts people who were using inflated 
primary keys (without Stringify problems) for other things.

I hope that helps explain the confusion to which I keep referring.  To 
summarize briefly: It seems to me that deciding id() (as a public object 
method) should return only the SQL-level PK breaks the encapsulation CDBI 
is trying to create, and is only in service of internal use, for which case 
another function which is aware of CBDI <-> DBI internals would suffice.

I'd favor a scheme in which id() was the object-level PK, and db_id() or 
somesuch was the flattened PK value, but if I'm way off on the fringe, and 
most people have historically understood id() to refer to the flat PK (as 
opposed to not even considering the difference), then I'd suggest as an 
alternative that id() be so documented, and a new method, such as key() or 
obj_id(), be introduced to return the object-level PK.

Does this make more sense?

--
Regards,
Charles Bailey  < bailey _at_ newman _dot_ upenn _dot_ edu >
Newman Center at the University of Pennsylvania

(message missing)

Need help with finding solution to CDBI bug
William McKee 11:40 on 19 Jun 2004

Re: Need help with finding solution to CDBI bug
William McKee 13:19 on 21 Jun 2004

Re: Need help with finding solution to CDBI bug
Tony Bowden 14:06 on 21 Jun 2004

Re: Need help with finding solution to CDBI bug
William McKee 15:14 on 21 Jun 2004

Re: Need help with finding solution to CDBI bug
Charles Bailey 15:23 on 21 Jun 2004

Re: Need help with finding solution to CDBI bug
William McKee 17:07 on 21 Jun 2004

Re: Need help with finding solution to CDBI bug
Yuval Kogman 15:30 on 21 Jun 2004

Re: Need help with finding solution to CDBI bug
Yuval Kogman 15:37 on 21 Jun 2004

Re: Need help with finding solution to CDBI bug
Charles Bailey 16:12 on 25 Jun 2004

Re: Need help with finding solution to CDBI bug
Tony Bowden 16:33 on 25 Jun 2004

Re: Need help with finding solution to CDBI bug
Charles Bailey 21:47 on 25 Jun 2004

Re: Need help with finding solution to CDBI bug
Tony Bowden 08:34 on 26 Jun 2004

Re: Need help with finding solution to CDBI bug
Takes Tea at Half Past Three 17:06 on 25 Jun 2004

Re: Need help with finding solution to CDBI bug
Charles Bailey 22:13 on 25 Jun 2004

Re: Need help with finding solution to CDBI bug
Tony Bowden 00:10 on 26 Jun 2004

RE: Need help with finding solution to CDBI bug
robert_creager 04:34 on 03 Jul 2004

Re: Need help with finding solution to CDBI bug
William McKee 17:17 on 05 Jul 2004

Re: Need help with finding solution to CDBI bug
Robert Creager 20:57 on 05 Jul 2004

Re: Need help with finding solution to CDBI bug
Robert Creager 00:22 on 06 Jul 2004

Re: Need help with finding solution to CDBI bug
William McKee 12:50 on 06 Jul 2004

Re: Need help with finding solution to CDBI bug
William McKee 17:05 on 21 Jun 2004

Re: Need help with finding solution to CDBI bug
Yuval Kogman 17:18 on 21 Jun 2004

Re: Need help with finding solution to CDBI bug
William McKee 17:41 on 21 Jun 2004

Re: Need help with finding solution to CDBI bug
Yuval Kogman 18:04 on 21 Jun 2004

Re: Need help with finding solution to CDBI bug
William McKee 19:20 on 21 Jun 2004

Re: Need help with finding solution to CDBI bug
Yuval Kogman 20:16 on 21 Jun 2004

Re: Need help with finding solution to CDBI bug
Tony Bowden 07:34 on 22 Jun 2004

Re: Need help with finding solution to CDBI bug
Yuval Kogman 14:25 on 21 Jun 2004

Re: Need help with finding solution to CDBI bug
William McKee 20:03 on 22 Jun 2004

Re: Need help with finding solution to CDBI bug
William McKee 22:44 on 22 Jun 2004

Re: Need help with finding solution to CDBI bug
Tony Bowden 15:16 on 24 Oct 2004

Re: Need help with finding solution to CDBI bug
Charles Bailey 22:15 on 22 Jun 2004

Re: Need help with finding solution to CDBI bug
William McKee 12:33 on 23 Jun 2004

Re: Need help with finding solution to CDBI bug
Charles Bailey 17:17 on 23 Jun 2004

Re: Need help with finding solution to CDBI bug
William McKee 11:38 on 22 Jun 2004

Re: Need help with finding solution to CDBI bug
merlyn (Randal L. Schwartz) 16:10 on 22 Jun 2004

Re: Need help with finding solution to CDBI bug
William McKee 13:19 on 22 Jun 2004

Re: Need help with finding solution to CDBI bug
Charles Bailey 22:04 on 22 Jun 2004

Re: Need help with finding solution to CDBI bug
Tony Bowden 12:43 on 23 Jun 2004

Re: Need help with finding solution to CDBI bug
Yuval Kogman 19:52 on 22 Jun 2004

Re: Need help with finding solution to CDBI bug
Tony Bowden 19:56 on 23 Jun 2004

Re: Need help with finding solution to CDBI bug
William McKee 12:48 on 23 Jun 2004

Re: Need help with finding solution to CDBI bug
Charles Bailey 22:12 on 23 Jun 2004

Re: Need help with finding solution to CDBI bug
Yuval Kogman 23:30 on 22 Jun 2004

Re: Need help with finding solution to CDBI bug
Tony Bowden 07:08 on 24 Jun 2004

Re: Need help with finding solution to CDBI bug
Charles Bailey 13:53 on 24 Jun 2004

Re: Need help with finding solution to CDBI bug
Tony Bowden 14:51 on 24 Jun 2004

Re: Need help with finding solution to CDBI bug
Tony Bowden 07:12 on 24 Jun 2004

Re: Need help with finding solution to CDBI bug
Charles Bailey 13:50 on 24 Jun 2004

Re: Need help with finding solution to CDBI bug
Tony Bowden 14:55 on 24 Jun 2004

Re: Need help with finding solution to CDBI bug
Tony Bowden 16:04 on 27 Jun 2004

Re: Need help with finding solution to CDBI bug
Charles Bailey 17:53 on 27 Jun 2004

Re: Need help with finding solution to CDBI bug
William McKee 12:58 on 06 Jul 2004

Generated at 11:35 on 01 Dec 2004 by mariachi v0.52