[Zope] How can you generalize SQL methods ?

Rob Page rob.page@digicool.com
Wed, 14 Jul 1999 07:10:17 -0400


Hi Marco:

> INSERT INTO <!--#var table_name-->
>   (<!--#var field_name-->) values
>     (<!--#sqlvar field_value type=<!--#var field_type--> -->)
> 
>   where field table_name, field_name, field_value and field_type are 
> arguments
>   for the methon. Naturally this doesn't work. Is there any way to do 
> something
>   like this ?

"Unfortunately" you can't use DTML tags inside DTML tags.  Your type=
setting shown above is already inside a sqlvar DTML tag.
 
> 2- creating a general SELECT query.
> 
>    I'd like to parametrize the name and the number of the fields shown
>    by a SELECT mysql query. Something like
> 
>    SELECT <variable_number_of_fields_of_variable_names> from
>      <!--#var table_name-->
> 
>    where table_name is an argument for the method.
>    I've no ideas about how to implement the
>    variable_number_of_fields_of_variable_names.

Try this:

Put the list of field names in a multiple SELECT box.  Make the name of
the field something:list

e.g., 

<SELECT NAME="fields_to_select:list" MULTIPLE>

Then you can say:

SELECT 

<!--#in fields_to_select-->

  <!--#var sequence-item-->

    <!--#if sequence-end-->
    <!--#else-->
      ,
    <!--#/if-->

<!--#/in -->

FROM 

<!--#var table_name-->

The <!--#in --> is relatively straightforward.  The <!--#if--> is
necessary to not produce a trailing comma after the LAST field name.
sequence-end is true if there are no more items in the sequence.  If
there are, then a comma is inserted.

Of course all of this is untested!  Hope this helps!

--Rob