quick search:
 

Passing arguments to a query

Submitted by: alfons
Last Edited: 2003-08-04

Category: ZSQL and SQL DA

Average rating is: 0.0 out of 5 (0 ratings)

Description:
If that's the workflow: form -> script -> ZSQL Method for editing or adding a row, you might have to pass arguments. You can either type ALL the arguments by hand, ... or ... you could conveniently extract them from the request.form! The only problem is, that if you leave out any arguments, the ZSQL Method will try to aquire them (eg for a column called 'title'). Anyways, here's how to do it correctly:

Source (Text):
request = context.REQUEST

# get the arguments
query_args_src = container.edit_query.arguments_src.split()
query_args = {}

# build the dictionary
for arg in query_args_src:
  if arg in request.keys():
    query_args[arg] = request[arg]
  else:
    query_args[arg] = ''

# manipulate dictionary, if necessary
query_args['id'] = some_other_id

# pass the dictionary to the ZQL Method
container.edit_query(**query_args)

Explanation:
The ZSQL Method itself should be complete with ALL arguments defined. The **query_args will be passed like you would pass it to regular function and the ZSQL Method will assign it automagically to the arguments.

To read more about this functionality consult the offical Python Reference Manual Chapter 7.5 Function definitions on www.python.org


Comments:

No Comments