Re: Question Concerning Z SQL Method and Class Bindings
Peter Sabaini <[email protected]> Tue, 25 May 2010 21:03:35 +0200
| Newsgroups | gmane.comp.web.zope.database |
|---|---|
| Message-ID | <[email protected]> |
--===============5530093721269230480== Content-Type: multipart/signed; micalg="pgp-sha1"; protocol="application/pgp-signature"; boundary="=-y7+/dI1P4GucGJVKCVkJ" --=-y7+/dI1P4GucGJVKCVkJ Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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, >=20 > Z SQL Method > select * from offense where gameID=3D<some input value from a form> >=20 > This returns ~10 rows. Each row has columns playerID, PB, BB, SacBunt, > HBP as well as other columns, all containing integer values. >=20 > class GameStats > """Reads the database for the stats for every player in a game and > calculates the stats""" >=20 > def AtBat(self, player_id): > """Calculate the AB for a player. AB =3D 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.=20 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. > =20 > Thanks! >=20 > Mark > _______________________________________________ > Zope-DB mailing list > [email protected] > https://mail.zope.org/mailman/listinfo/zope-db --=-y7+/dI1P4GucGJVKCVkJ Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEABECAAYFAkv8HwYACgkQafAcTZYKVBz4oACcDGC9Yj0U2u6mvfKQfwk0uN8Q /ugAoIVI75l6wNHMWQlDaIltApoobwgI =J8fn -----END PGP SIGNATURE----- --=-y7+/dI1P4GucGJVKCVkJ-- --===============5530093721269230480== 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 --===============5530093721269230480==--