[Zope] Understand ZODB Query?

Heri htan@gmx.de
Wed, 12 Mar 2003 18:26:30 +0800


This is a multi-part message in MIME format.

------=_NextPart_000_0081_01C2E8C4.E6F2C8A0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

you're right, i'm still thinking tabularly.

I'm basically looking for ways how to do database query (select, update, =
create, etc).
Of course i'm still thinkin in 'relation database' way as I'm just =
starting with OODB.

>From my latest reading, the ZODB works like a 'dictionary':
-In this way, I can save any objects into this dictionary.
-the key for the dictionary is the 'unique key' while the value is the =
object.
-In order to perform any query, I need to parse through the dictionary

My questions:
-wouldn't it be too slow?
-How if I don't need any key?
-How if I have multiple keys?

This doesn't seem so easy.

Probably I need to read ZCatalog and get some understanding from its =
query.
thanks.
Heri



>
> - I can easily perform SQL statement to lookup for some information=20
> such as, total employee, who are above 30 years old, and who has the=20
> Lastname of 'Smith'.
> - I can easily retrieve information from multiple tables and combine=20
> it as data objects.
> =20
> But how can I do this in ZODB?

1) If your data set is not too big, you can do it programmatically =
Python:

set =3D folder.objectValues()
results =3D []
for elt in set:
  if (elt.age > 30) and (elt.lastname=3D=3D'Smith'):
    results.append(elt)
return elt

One can easily replace '30' and 'Smith' with parameters to get a more=20
useful script.

2) Use ZCatalog for this if you have larger sets to avoid unnecessary=20
traversals.



But I suspect the larger problem is that you're thinking tabularly.=20
Trying to make a 1-to-1 translation between an object-storage scheme and =

a relational-storage scheme isn't always (or maybe usually) going to=20
work. I know no magic processes for this, unfortunately.

       --jcc

------=_NextPart_000_0081_01C2E8C4.E6F2C8A0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1141" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial>you're right, i'm still thinking =
tabularly.</FONT></DIV>
<DIV><FONT face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial>I'm basically looking for ways how to do =
database query=20
(select, update, create, etc).</FONT></DIV>
<DIV><FONT face=3DArial>Of course i'm still thinkin in 'relation =
database' way as=20
I'm just starting with OODB.</FONT></DIV>
<DIV><FONT face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial>From my latest reading, the ZODB works like a=20
'dictionary':</FONT></DIV>
<DIV><FONT face=3DArial>-In this way, I can save any objects into this=20
dictionary.</FONT></DIV>
<DIV><FONT face=3DArial>-the key for the dictionary is the 'unique key' =
while the=20
value is the object.</FONT></DIV>
<DIV><FONT face=3DArial>-In order to perform any query, I need to parse =
through=20
the dictionary</FONT></DIV>
<DIV><FONT face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial color=3D#ff0000>My questions:</FONT></DIV>
<DIV><FONT face=3DArial>-wouldn't it be too slow?</FONT></DIV>
<DIV><FONT face=3DArial>-How if I don't need any key?</FONT></DIV>
<DIV><FONT face=3DArial>-How if I have multiple keys?</FONT></DIV>
<DIV><FONT face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial>This doesn't seem so easy.</FONT></DIV>
<DIV><FONT face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial>Probably I need to read ZCatalog and get some=20
understanding from its query.</FONT></DIV>
<DIV><FONT face=3DArial>thanks.<BR>Heri</FONT></DIV>
<DIV><FONT face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial>&gt;<I><BR></I>&gt;<I> - I can easily perform =
SQL=20
statement to lookup for some information <BR></I>&gt;<I> such as, total=20
employee, who are above 30 years old, and who has the </DIV></I>&gt;<I> =
Lastname=20
of 'Smith'.<BR></I>&gt;<I> - I can easily retrieve information from =
multiple=20
tables and combine <BR></I>&gt;<I> it as data =
objects.<BR></I>&gt;<I>&nbsp;=20
<BR></I>&gt;<I> But how can I do this in ZODB?<BR></I><BR>1) If your =
data set is=20
not too big, you can do it programmatically Python:<BR><BR>set =3D=20
folder.objectValues()<BR>results =3D []<BR>for elt in set:<BR>&nbsp; if =
(elt.age=20
&gt; 30) and (elt.lastname=3D=3D'Smith'):<BR>&nbsp;&nbsp;&nbsp;=20
results.append(elt)<BR>return elt<BR><BR>One can easily replace '30' and =
'Smith'=20
with parameters to get a more <BR>useful script.<BR><BR>2) Use ZCatalog =
for this=20
if you have larger sets to avoid unnecessary =
<BR>traversals.<BR><BR><BR><BR>But=20
I suspect the larger problem is that you're thinking tabularly. =
<BR>Trying to=20
make a 1-to-1 translation between an object-storage scheme and <BR>a=20
relational-storage scheme isn't always (or maybe usually) going to =
<BR>work. I=20
know no magic processes for this,=20
unfortunately.<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
--jcc<BR></FONT></BODY></HTML>

------=_NextPart_000_0081_01C2E8C4.E6F2C8A0--