Hi, I have a database with 3 tables. I would like to create a ZSQL method for inserting data into the tables. I started by creating a separate method for each table, but that seems a bit of a waste. Ideally I would like to have one method, "addEntry". The template would look something like: <dtml-if "tname=='supplier'"> INSERT INTO <dtml-var tname> VALUES (NULL, <dtml-sqlvar sup_name type=string> etc...); <dtml-elif "tname='manufacturer'"> INSERT INTO <dtml-var tname> VALUES (NULL, <dtml-sqlvar man_name type=string> etc...); </dtml-if> The problem is that I have to specify the arguments in the argument list, and the arguments are different for each if clause in the above code. Is there a way around this? thanks Allen
(untested, and will need finishing off) Put ALL the arguments in the ZQSL method's arguments section, but give them all defaults (eg put myvar_name='' in the arguments section) Now, to make sure the right ones have been supplied, you need to put in an extra level of dtml-if in each branch of your current dtml-if, something like: <dtml-if "tname=='supplier'"> <dtml-if "_.has_key('var1') and _.has_key('var2')"> ... your insert here... <else> ... do something to warn of the error, such as a dtml-raise </dtml-if> <dtml-elif ...> ... HTH, Chris Allen Wallis wrote:
Hi, I have a database with 3 tables. I would like to create a ZSQL method for inserting data into the tables. I started by creating a separate method for each table, but that seems a bit of a waste. Ideally I would like to have one method, "addEntry". The template would look something like:
<dtml-if "tname=='supplier'"> INSERT INTO <dtml-var tname> VALUES (NULL, <dtml-sqlvar sup_name type=string> etc...); <dtml-elif "tname='manufacturer'"> INSERT INTO <dtml-var tname> VALUES (NULL, <dtml-sqlvar man_name type=string> etc...);
</dtml-if>
The problem is that I have to specify the arguments in the argument list, and the arguments are different for each if clause in the above code. Is there a way around this?
thanks Allen
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
participants (2)
-
Allen Wallis -
Chris Withers