Revision 5364
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/sql.py | ||
---|---|---|
1030 | 1030 |
op_re = ' '+op+' ' |
1031 | 1031 |
return '(?:'+expr_re+op_re+value_re+'|'+value_re+op_re+expr_re+')' |
1032 | 1032 |
|
1033 |
and_false_re = logic_op_re('AND', false_re, atom_re) |
|
1033 | 1034 |
or_re = logic_op_re('OR', bool_re) |
1034 | 1035 |
|
1035 | 1036 |
def simplify_parens(expr): |
... | ... | |
1043 | 1044 |
lambda s: sub_func(simplify_parens(s)), expr)) |
1044 | 1045 |
|
1045 | 1046 |
def simplify_expr(expr): |
1047 |
def simplify_logic_ops(expr): |
|
1048 |
total_n = 0 |
|
1049 |
expr, n = re.subn(and_false_re, 'false', expr) |
|
1050 |
total_n += n |
|
1051 |
expr, n = re.subn(or_re, r'', expr) |
|
1052 |
total_n += n |
|
1053 |
return expr, total_n |
|
1054 |
|
|
1046 | 1055 |
expr = expr.replace('(NULL IS NULL)', 'true') |
1047 | 1056 |
expr = expr.replace('(NULL IS NOT NULL)', 'false') |
1048 |
expr = simplify_recursive(lambda s: re.subn(or_re, r'', s), expr)
|
|
1057 |
expr = simplify_recursive(simplify_logic_ops, expr)
|
|
1049 | 1058 |
return expr |
1050 | 1059 |
|
1051 | 1060 |
name_re = r'(?:\w+|(?:"[^"]*")+)' |
Also available in: Unified diff
sql.py: simplify_expr(): Also simplify "AND false" expressions