[Zope] ZSQL

Colin Fox cfox@crystalcherry.com
06 Apr 2002 12:25:24 -0800


--=-m4ARyBeNAyMhY+B9+NTs
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

Hey folks.

How do you use the <dtml-sqlgroup> & <dtml-where> clauses when you want
to do a join?

If I have a table of items, and a table of owners, and items have an
owner_id, then selecting all of them would be something like:

select
    o.name as ownername,
    i.name as itemname
from
    owners o,
    items i
where
    i.owner_id =3D o.id;

If you wanted to re-use this query for showing items owned by a single
owner, you can extend it as:

select
    o.name as ownername,
    i.name as itemname
from
    owners o,
    items i
where
    i.owner_id =3D o.id and
    o.id =3D 2; -- Assuming the owner you were interested in was #2

Is it possible to do the join always, but the "o.id =3D 2" only if an
owner id was provided as an optional argument?

Also - in some cases I want "limit 10", and others I don't want a limit.
Is the limit keyword optionable?

Thanks in advance!

--=20
Colin Fox                                       cfox@crystalcherry.com
CF Consulting Inc.                                    GPG Fingerprint:
                    D8F0 84E7 E7CC 5C6C 9982  F1A7 A3EB 6EA3 BC97 572F

--=-m4ARyBeNAyMhY+B9+NTs
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQA8r1m0o+tuo7yXVy8RApKsAKDoyykLF7A07mxro5Bxj1wIlkBusQCfbTfe
f+nAwnTZQKMJoiQmKiKbqFI=
=58Lx
-----END PGP SIGNATURE-----

--=-m4ARyBeNAyMhY+B9+NTs--