[Zope-DB] How can I dynamically generate a Z Search Interface?
Mon, 9 Sep 2002 16:58:23 -0400
On Mon, Sep 09, 2002 at 09:45:30PM +0200, Luis Gregorio Muniz Rodriguez wrote:
> On Fri, Aug 30, 2002 at 12:00:03PM -0400, email@example.com wrote:
> > From: "Tena Sakai" <firstname.lastname@example.org>
> a) If you only need to "select", then simply put:
> select * from mytable
> And, in the DMTL or ZPT code that iterates through the results of
> the search, choose what fields to show. It should be easier and
> safer than the next method. And if you have been using a form
> to select which data to retrieve, you have half the work done.
> Or, if the attributes you are going to supply are muthual exclusive,
> then you can sort _always_:
> <dtml-sqlgroup where>
> <dtml-sqltest research type=nb optional> ORDER BY (research)
> <dtml-sqlgroup where>
> <dtml-sqltest login type=nb optional> ORDER BY (login)
Note: not only can you use plain dtml-var, you can also use dtml-if
(or any other dtml-construct). A slight generalization could also be
select * from mytable
<dtml-if "research and login">
where research=<dtml-sqlvar research type=string> and
login=<dtml-sqlvar login type=string> order by (research, login)
where research=<dtml-sqlvar research type=string> order by (research)
where login=<dtml-sqlvar login type=string> order by (login)
This gets rid of the mutually exclusive condition.
I have no real objection to this kind of usage, and do it myself. The
key is that, as long as the method remains simple enough that you can
explain what it does with cursory inspection, you are fine. Typically
you will define four to six methods per table; one for select,
one for update, one for insert, and one for delete. Sometimes you need
a couple selects, or a couple of updates.
A more questionable usage (which I have also used) is something like
insert into my_table values
<dtml-sqlvar research type=string>,
<dtml-sqlvar login type=string>
This is objectionable mainly because SQL has horrible syntax. Updates
work much better with this format.
> Finally, I also agree that it is best to have a couple small, fixed
> Z SQL methods than using a more complex solution, like the generic
> "list" method. However, as the number of small methods increase I've
> found this dynamic solution more elegant and less confusing.
> - email@example.com
> Zope-DB mailing list