Re: Question Concerning Z SQL Method and Class Bindings

Mark Phillips <[email protected]> Tue, 25 May 2010 12:21:11 -0700
Newsgroups gmane.comp.web.zope.database
Message-ID <[email protected]>
--===============4411188003241458766==
Content-Type: multipart/alternative; boundary=00c09f8996e66bc38f0487700f73

--00c09f8996e66bc38f0487700f73
Content-Type: text/plain; charset=ISO-8859-1

Peter,

I don't think I phrased my question very well. Also, I am coming from a Java
background, so I am thinking about result sets, which may not be applicable
to Python.

If I have a Z SQL Method query that returns multiple rows to a brains class,
how do I

(1) reference the returned object that has all the rows
(2) reference a particular row in the returned object
(3) reference a particular piece of data in the returned object.

What is the returned object - list, dictionary, some special object with
associated APIs?

Where is this documented? I can't seem to find it in the Zope 2 book.

Thanks!

Mark

On Tue, May 25, 2010 at 12:03 PM, Peter Sabaini <[email protected]> wrote:

> On Mon, 2010-05-24 at 21:33 -0700, Mark Phillips wrote:
> > I am reading the zope 2 book (relational database section) and it
> > talks about binding classes by putting them in the Extensions
> > directory and then associating them with a Z SQL Method. That seems to
> > be rather straight forward, but where can I find some examples of
> > accessing the values returned from the Z SQL Method in Python. For
> > example,
> >
> > Z SQL Method
> > select * from offense where gameID=<some input value from a form>
> >
> > This returns ~10 rows. Each row has columns playerID, PB, BB, SacBunt,
> > HBP as well as other columns, all containing integer values.
> >
> > class GameStats
> > """Reads the database for the stats for every player in a game and
> > calculates the stats"""
> >
> >     def AtBat(self, player_id):
> >         """Calculate the AB for a player. AB = PA - (BB + SacBunt +
> > HBP - SF)"""
> >         How do I get the columns PA, BB, etc for a particular playerID
> > to calculate the BA from the result returned by the Z SQL method? Is
> > there some documentation for how to access the results of the query
> > within this class?
>
> Individual columns should be accessible as attributes of the Brain
> object, eg. self.playerID etc. If there's a column PA, it should be
> named self.PA.
>
> Btw., usually when I'm in doubt which attributes or methods are
> available for a given object, I just put a breakpoint at the location in
> question and poke at it with pdb, the Python debugger. See eg.
> http://wiki.zope.org/zope2/DebuggingWithPdb , under "breakpoint in the
> code" how to invoke the debugger. See
> http://docs.python.org/library/pdb.html for pdb docs.
>
> hth,
> peter.
>
> >
> > Thanks!
> >
> > Mark
> > _______________________________________________
> > Zope-DB mailing list
> > [email protected]
> > https://mail.zope.org/mailman/listinfo/zope-db
>
>

--00c09f8996e66bc38f0487700f73
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Peter,<br><br>I don&#39;t think I phrased my question very well. Also, I am=
 coming from a Java background, so I am thinking about result sets, which m=
ay not be applicable to Python.<br><br>If I have a Z SQL Method query that =
returns multiple rows to a brains class, how do I <br>
<br>(1) reference the returned object that has all the rows<br>(2) referenc=
e a particular row in the returned object<br>(3) reference a particular pie=
ce of data in the returned object. <br><br>What is the returned object - li=
st, dictionary, some special object with associated APIs?<br>
<br>Where is this documented? I can&#39;t seem to find it in the Zope 2 boo=
k.<br><br>Thanks!<br><br>Mark<br><br><div class=3D"gmail_quote">On Tue, May=
 25, 2010 at 12:03 PM, Peter Sabaini <span dir=3D"ltr">&lt;<a href=3D"mailt=
o:[email protected]">[email protected]</a>&gt;</span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"border-left: 1px solid rgb(204, =
204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div></div><=
div class=3D"h5">On Mon, 2010-05-24 at 21:33 -0700, Mark Phillips wrote:<br=
>
&gt; I am reading the zope 2 book (relational database section) and it<br>
&gt; talks about binding classes by putting them in the Extensions<br>
&gt; directory and then associating them with a Z SQL Method. That seems to=
<br>
&gt; be rather straight forward, but where can I find some examples of<br>
&gt; accessing the values returned from the Z SQL Method in Python. For<br>
&gt; example,<br>
&gt;<br>
&gt; Z SQL Method<br>
&gt; select * from offense where gameID=3D&lt;some input value from a form&=
gt;<br>
&gt;<br>
&gt; This returns ~10 rows. Each row has columns playerID, PB, BB, SacBunt,=
<br>
&gt; HBP as well as other columns, all containing integer values.<br>
&gt;<br>
&gt; class GameStats<br>
&gt; &quot;&quot;&quot;Reads the database for the stats for every player in=
 a game and<br>
&gt; calculates the stats&quot;&quot;&quot;<br>
&gt;<br>
&gt; =A0 =A0 def AtBat(self, player_id):<br>
&gt; =A0 =A0 =A0 =A0 &quot;&quot;&quot;Calculate the AB for a player. AB =
=3D PA - (BB + SacBunt +<br>
&gt; HBP - SF)&quot;&quot;&quot;<br>
&gt; =A0 =A0 =A0 =A0 How do I get the columns PA, BB, etc for a particular =
playerID<br>
&gt; to calculate the BA from the result returned by the Z SQL method? Is<b=
r>
&gt; there some documentation for how to access the results of the query<br=
>
&gt; within this class?<br>
<br>
</div></div>Individual columns should be accessible as attributes of the Br=
ain<br>
object, eg. self.playerID etc. If there&#39;s a column PA, it should be<br>
named self.PA.<br>
<br>
Btw., usually when I&#39;m in doubt which attributes or methods are<br>
available for a given object, I just put a breakpoint at the location in<br=
>
question and poke at it with pdb, the Python debugger. See eg.<br>
<a href=3D"http://wiki.zope.org/zope2/DebuggingWithPdb" target=3D"_blank">h=
ttp://wiki.zope.org/zope2/DebuggingWithPdb</a> , under &quot;breakpoint in =
the<br>
code&quot; how to invoke the debugger. See<br>
<a href=3D"http://docs.python.org/library/pdb.html" target=3D"_blank">http:=
//docs.python.org/library/pdb.html</a> for pdb docs.<br>
<br>
hth,<br>
peter.<br>
<br>
&gt;<br>
&gt; Thanks!<br>
&gt;<br>
&gt; Mark<br>
&gt; _______________________________________________<br>
&gt; Zope-DB mailing list<br>
&gt; <a href=3D"mailto:[email protected]">[email protected]</a><br>
&gt; <a href=3D"https://mail.zope.org/mailman/listinfo/zope-db" target=3D"_=
blank">https://mail.zope.org/mailman/listinfo/zope-db</a><br>
<br>
</blockquote></div><br>

--00c09f8996e66bc38f0487700f73--

--===============4411188003241458766==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Zope-DB mailing list
[email protected]
https://mail.zope.org/mailman/listinfo/zope-db

--===============4411188003241458766==--