Peter,<br><br>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.<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) reference a particular row in the returned object<br>(3) reference a particular piece of data in the returned object. <br><br>What is the returned object - list, dictionary, some special object with associated APIs?<br>
<br>Where is this documented? I can't seem to find it in the Zope 2 book.<br><br>Thanks!<br><br>Mark<br><br><div class="gmail_quote">On Tue, May 25, 2010 at 12:03 PM, Peter Sabaini <span dir="ltr"><<a href="mailto:peter@sabaini.at">peter@sabaini.at</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div></div><div class="h5">On Mon, 2010-05-24 at 21:33 -0700, Mark Phillips wrote:<br>
> I am reading the zope 2 book (relational database section) and it<br>
> talks about binding classes by putting them in the Extensions<br>
> directory and then associating them with a Z SQL Method. That seems to<br>
> be rather straight forward, but where can I find some examples of<br>
> accessing the values returned from the Z SQL Method in Python. For<br>
> example,<br>
><br>
> Z SQL Method<br>
> select * from offense where gameID=<some input value from a form><br>
><br>
> This returns ~10 rows. Each row has columns playerID, PB, BB, SacBunt,<br>
> HBP as well as other columns, all containing integer values.<br>
><br>
> class GameStats<br>
> """Reads the database for the stats for every player in a game and<br>
> calculates the stats"""<br>
><br>
> def AtBat(self, player_id):<br>
> """Calculate the AB for a player. AB = PA - (BB + SacBunt +<br>
> HBP - SF)"""<br>
> How do I get the columns PA, BB, etc for a particular playerID<br>
> to calculate the BA from the result returned by the Z SQL method? Is<br>
> there some documentation for how to access the results of the query<br>
> within this class?<br>
<br>
</div></div>Individual columns should be accessible as attributes of the Brain<br>
object, eg. self.playerID etc. If there's a column PA, it should be<br>
named self.PA.<br>
<br>
Btw., usually when I'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="http://wiki.zope.org/zope2/DebuggingWithPdb" target="_blank">http://wiki.zope.org/zope2/DebuggingWithPdb</a> , under "breakpoint in the<br>
code" how to invoke the debugger. See<br>
<a href="http://docs.python.org/library/pdb.html" target="_blank">http://docs.python.org/library/pdb.html</a> for pdb docs.<br>
<br>
hth,<br>
peter.<br>
<br>
><br>
> Thanks!<br>
><br>
> Mark<br>
> _______________________________________________<br>
> Zope-DB mailing list<br>
> <a href="mailto:Zope-DB@zope.org">Zope-DB@zope.org</a><br>
> <a href="https://mail.zope.org/mailman/listinfo/zope-db" target="_blank">https://mail.zope.org/mailman/listinfo/zope-db</a><br>
<br>
</blockquote></div><br>