257 |
257 |
value = self.value
|
258 |
258 |
return {'c%s' % id(self.value): value}
|
259 |
259 |
|
|
260 |
def has_multi_fts(self):
|
|
261 |
return False
|
|
262 |
|
|
263 |
def iter_all(self):
|
|
264 |
yield self
|
|
265 |
|
260 |
266 |
|
261 |
267 |
class Less(Criteria):
|
262 |
268 |
sql_op = '<'
|
... | ... | |
382 |
388 |
d.update(criteria.as_sql_param())
|
383 |
389 |
return d
|
384 |
390 |
|
|
391 |
def iter_all(self):
|
|
392 |
yield self
|
|
393 |
for criteria in self.criterias:
|
|
394 |
yield from criteria.iter_all()
|
|
395 |
|
385 |
396 |
|
386 |
397 |
class And(Criteria):
|
387 |
398 |
def __init__(self, criterias, **kwargs):
|
... | ... | |
400 |
411 |
d.update(criteria.as_sql_param())
|
401 |
412 |
return d
|
402 |
413 |
|
|
414 |
def iter_all(self):
|
|
415 |
yield self
|
|
416 |
for criteria in self.criterias:
|
|
417 |
yield from criteria.iter_all()
|
|
418 |
|
403 |
419 |
|
404 |
420 |
class Not(Criteria):
|
405 |
421 |
def __init__(self, criteria, **kwargs):
|
... | ... | |
413 |
429 |
def as_sql_param(self):
|
414 |
430 |
return self.criteria.as_sql_param()
|
415 |
431 |
|
|
432 |
def iter_all(self):
|
|
433 |
yield self
|
|
434 |
yield from self.criteria.iter_all()
|
|
435 |
|
416 |
436 |
|
417 |
437 |
class Intersects(Criteria):
|
418 |
438 |
def as_sql(self):
|
... | ... | |
473 |
493 |
else:
|
474 |
494 |
return {self.value_to_identifier(self.value): self.value}
|
475 |
495 |
|
|
496 |
def is_multiple_match(self):
|
|
497 |
return isinstance(self.value, list) and len(self.value) > 1
|
|
498 |
|
476 |
499 |
|
477 |
500 |
class ElementEqual(Criteria):
|
478 |
501 |
def __init__(self, attribute, key, value):
|
... | ... | |
2192 |
2215 |
return list(generator)
|
2193 |
2216 |
|
2194 |
2217 |
@classmethod
|
2195 |
|
def get_order_by_clause(cls, order_by):
|
|
2218 |
def get_order_by_clause(cls, order_by, select_clause=None):
|
2196 |
2219 |
if not order_by:
|
2197 |
2220 |
return ''
|
2198 |
2221 |
# [SEC_ORDER] security note: it is not possible to use
|
... | ... | |
2216 |
2239 |
# for a sort on field of block field, just check the existence of the block field
|
2217 |
2240 |
return ''
|
2218 |
2241 |
|
|
2242 |
if select_clause and any(isinstance(criteria, FtsMatch) and criteria.is_multiple_match() for criteria in select_clause.iter_all()):
|
|
2243 |
if order_by.lstrip('-') == 'receipt_time':
|
|
2244 |
order_by = '(receip_time + interval \'0 second\''
|
|
2245 |
|
2219 |
2246 |
return ' ORDER BY %s %s' % (order_by, direction)
|
2220 |
2247 |
|
2221 |
2248 |
@classmethod
|
... | ... | |
2267 |
2294 |
if where_clauses:
|
2268 |
2295 |
sql_statement += ' WHERE ' + ' AND '.join(where_clauses)
|
2269 |
2296 |
|
2270 |
|
sql_statement += cls.get_order_by_clause(order_by)
|
|
2297 |
sql_statement += cls.get_order_by_clause(order_by, select_clause=clause)
|
2271 |
2298 |
|
2272 |
2299 |
if not func_clause:
|
2273 |
2300 |
if limit:
|
... | ... | |
3002 |
3029 |
return all_ids
|
3003 |
3030 |
|
3004 |
3031 |
@classmethod
|
3005 |
|
def get_order_by_clause(cls, order_by):
|
|
3032 |
def get_order_by_clause(cls, order_by, **kwargs):
|
3006 |
3033 |
if hasattr(order_by, 'id'):
|
3007 |
3034 |
# form field, convert to its column name
|
3008 |
3035 |
attribute = order_by
|
3009 |
3036 |
order_by = get_field_id(attribute)
|
3010 |
3037 |
if attribute.store_display_value:
|
3011 |
3038 |
order_by = order_by + '_display'
|
3012 |
|
return super().get_order_by_clause(order_by)
|
|
3039 |
return super().get_order_by_clause(order_by, **kwargs)
|
3013 |
3040 |
|
3014 |
3041 |
@classmethod
|
3015 |
3042 |
@guard_postgres
|