For a given , returns the absolute . . This is useful when constructing queries with relations to other tables.
(table, field)
| 1017 | "strftime|date_format" |
| 1018 | |
| 1019 | def abs(table, field): |
| 1020 | """ For a given <fieldname>, returns the absolute <tablename>.<fieldname>. |
| 1021 | This is useful when constructing queries with relations to other tables. |
| 1022 | """ |
| 1023 | def _format(s): |
| 1024 | if not "." in s: |
| 1025 | # Field could be wrapped in a function: year(date) => year(table.date). |
| 1026 | p = s.endswith(")") and re.match(r"^("+sql_functions+r")\(", s, re.I) or None |
| 1027 | i = p and len(p.group(0)) or 0 |
| 1028 | return "%s%s.%s" % (s[:i], table, s[i:]) |
| 1029 | return s |
| 1030 | if isinstance(field, (list, tuple)): |
| 1031 | return [_format(f) for f in field] |
| 1032 | return _format(field) |
| 1033 | |
| 1034 | def cmp(field, value, comparison="=", escape=lambda v: _escape(v), table=""): |
| 1035 | """ Returns an SQL WHERE comparison string using =, i=, !=, >, <, >=, <= or BETWEEN. |