[ZPatterns] Rack.getItem returning attributeless objects (ZPatterns newbie)

Steve Spicklemire steve@spvi.com
Thu, 05 Jul 2001 22:11:37 -0500


Phillip Crumpler wrote:
> 
> I tried what you suggested - still no banana :-(  So, I tried an example so
> simple even I would have trouble getting it wrong.
> 
> The rack has a single SQL query, SQL_get:
>   SELECT name FROM dskins WHERE dskin_id=<dtml-sqlvar dskin_id type="int">
> The table has two columns, dskin_id int and name text.
> The rack has a single skinscript method, with one line:
>   WITH QUERY SQL_get(dskin_id=self.id) COMPUTE name
> The load attribute of the rack is 'name'. The rack stores a zclass that is
> derived from DataSkin, with an index_html method added, nothing else.
> 
> Still, getItem with a non existant dskin_id will return an object. Is this
> suppposed to happen?
> 

Is 'name' in a propertysheet of the ZClass? If so.. it won't work! Try this:

SELECT name, dskin_id FROM dskins WHERE <dtml-sqltest dskin_id type="int">

set the 'attribute to load' to 'dskin_id'. Make sure that dskin_id is
*not* in any propertysheet of the ZClass.

-steve

> SQL_get is being called correctly and returning nil rows. Digging around a
> bit in Racky.py,  the line in Rack.retrieveItem
>         if hasattr(item.aq_base, a):
> succeeds, even though the query returned no rows (a is the loadAttribute of
> the Rack, 'name'). getattr(item.aq_base,a) returns an empty string.
> 
> Help!
> 
> Phillip
> 
> > -----Original Message-----
> > From: Phillip J. Eby [mailto:pje@telecommunity.com]
> > Sent: Friday, 6 July 2001 2:34 AM
> > To: Phillip Crumpler; zpatterns@eby-sarna.com
> > Subject: Re: [ZPatterns] Rack.getItem returning attributeless objects
> > (ZPatterns newbie)
> >
> >
> > At 12:41 AM 7/6/01 +1000, Phillip Crumpler wrote:
> > >
> > > I have a specialist, with the default rack, storing a zclass
> > derived from
> > >DataSkin. The rack is set to 'load by accessing attribute: id'.
> > Within the
> >
> > That won't work.  The object already *has* an 'id' attribute, so the
> > SkinScript that computes it will never be executed.
> >
> >
> > >specialist are a few sql methods: SQL_get, SQL_change, SQL_create,
> > >SQL_delete. The table has two columns, id (int) and name (text).
> > The zclass
> > >has a simple index_html method to show the instance's id and name
> > >attributes.
> > >
> > >The rack has a skinscript method like so:
> > >
> > >WITH SQL_get(id=self.id) COMPUTE id, name
> >
> > Try making this:
> >
> > WITH QUERY SQL_get(id=self.id) COMPUTE name
> >
> > And making the 'name' attribute be the "load" attribute.
> >
> >
> >
> >
> > >WHEN OBJECT ADDED CALL SQL_create(id=self.id, name=self.name)
> > >
> > >WHEN OBJECT CHANGED STORE id, name USING SQL_change(id=self.id,
> > >name=self.name)
> > >
> > >WHEN OBJECT DELETED CALL SQL_delete(id=self.id)
> >
> > The rest of this looks fine.
> >
> >
> > >I'm new to skinscript, so I'm not too sure about this. The only
> > other Data
> > >Plug-In in the rack is a SpecialistPlugIn (but the Specialist
> > itself has no
> > >Data Plug-Ins)
> > >
> > >My (first) problem is this: a call to Rack.getItem will _always_
> > return an
> > >instance - if SQL_get returns no rows then it just ends up with no
> > >attributes.
> >
> > Right, because the object already has an id.
> >
> >
> > > I could always just get brutal and insert it into the database
> > directly but
> > >I think that would really be missing the point ;^)  How do I make
> > >Rack.getItem return None in this case?
> >
> > Change to using a load attribute that's actually dependent on the
> > result of
> > the query.
> >
> 
> _______________________________________________
> ZPatterns mailing list
> ZPatterns@eby-sarna.com
> http://www.eby-sarna.com/mailman/listinfo/zpatterns