comparison salut.py @ 2:77b77f48c975

don't expect queries to specify all the fields
author souliane <souliane@mailoo.org>
date Thu, 23 Jul 2015 21:05:51 +0200
parents 92549e4336a6
children 593345584d21
comparison
equal deleted inserted replaced
1:92549e4336a6 2:77b77f48c975
92 query = ["SELECT jid, description FROM directory"] 92 query = ["SELECT jid, description FROM directory"]
93 args = OrderedDict() 93 args = OrderedDict()
94 try: 94 try:
95 query_elt = request.elements(NS_SEARCH, 'query').next() 95 query_elt = request.elements(NS_SEARCH, 'query').next()
96 form_elt = query_elt.elements(data_form.NS_X_DATA, 'x').next() 96 form_elt = query_elt.elements(data_form.NS_X_DATA, 'x').next()
97 except StopIteration:
98 raise ValueError # TODO: proper error handling
99 else:
97 parsed_form = data_form.Form.fromElement(form_elt) 100 parsed_form = data_form.Form.fromElement(form_elt)
98 for col in ('jid', 'description'): 101 for col in ('jid', 'description'):
99 value = parsed_form[col].strip() 102 try:
100 if value: 103 value = parsed_form[col].strip()
101 args[col] = value 104 except KeyError:
102 except (StopIteration, KeyError): 105 pass
103 raise ValueError # TODO: proper error handling 106 else:
107 if value:
108 args[col] = value
104 109
105 if args: 110 if args:
106 query.append("WHERE") 111 query.append("WHERE")
107 query.append(" AND ".join(("%s LIKE ?" % col for col in args))) 112 query.append(" AND ".join(("%s LIKE ?" % col for col in args)))
108 113