Re: PyDO How to question..

Jacob Smullyan <[email protected]> Tue, 17 May 2005 20:50:20 -0400
Newsgroups gmane.comp.web.skunkweb
Message-ID <[email protected]>
On Wed, May 18, 2005 at 10:11:06AM +1000, Steve Kieu wrote:
> 
> Hi,
> 
> I need to get the result from a table using SQL like
> 
> select count(*) from table_name
> Or use database function to process data,
> Or use group by in SQL.
> 
> How can I do it using PyDO? (and PyDO2)

For aggregrate data, calling functions and the like, you generally
need to bypass PyDO.  In PyDO1, you need to do something like

  cursor=MyObj.getDBI().conn.cursor()
  cursor.execute(sql, values)
  res=cursor.fetchone()
  cursor.close()
  
And in PyDO2:

  cursor=MyObj.getDBI().cursor()
  # etc.

For commonly used queries, you would normally define special methods
in your object to wrap them.

PyDO2 only: getSome() accepts SQL literals, so if the field list
doesn't contain an aggregate, you could create a field list with a
projection and then use a group by clause in the first (string)
parameter to getSome().  

A generalized way to deal with aggregates would be useful.  Certainly,
a count() method would end up getting used.  But how generalized this
should be, I don't know yet; the real question is whether it would
save enough work to be worthwhile.  Modelling all of SQL is not
something I see as terribly valuable, if the model is as complex as,
and isomorphic to, the original.

Thoughts?

js

-- 
Jacob Smullyan
signature.asc (application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFCipFMuqamFyFXXLIRAr+GAKCyQNNXmi+VmZ2oEpk3FoRlmNOUoACgwSve
NSFUXnGqYOgp10/YTKeoRDg=
=oc/J
-----END PGP SIGNATURE-----