diff options
| author | Florian Hahn <flo@fhahn.com> | 2013-02-21 23:02:18 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2013-10-22 10:29:57 -0400 |
| commit | 5240b83462ba4887b67da8d493dfdc23fec5df97 (patch) | |
| tree | 7bae13c499bc84b5f4bcf79c592aa2a9b8008033 /django/db/backends/sqlite3 | |
| parent | 1597503a017a9ced422a81d314cb4097d53c3dfd (diff) | |
Fixed #17027 -- Added support for the power operator in F expressions.
Thanks dan at dlo.me for the initial patch.
- Added __pow__ and __rpow__ to ExpressionNode
- Added oracle and mysql specific power expressions
- Added used-defined power function for sqlite
Diffstat (limited to 'django/db/backends/sqlite3')
| -rw-r--r-- | django/db/backends/sqlite3/base.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py index ef214234e9..5d07f68f73 100644 --- a/django/db/backends/sqlite3/base.py +++ b/django/db/backends/sqlite3/base.py @@ -304,6 +304,13 @@ class DatabaseOperations(BaseDatabaseOperations): res.extend(["UNION ALL SELECT %s" % ", ".join(["%s"] * len(fields))] * (num_values - 1)) return " ".join(res) + def combine_expression(self, connector, sub_expressions): + # SQLite doesn't have a power function, so we fake it with a + # user-defined function django_power that's registered in connect(). + if connector == '^': + return 'django_power(%s)' % ','.join(sub_expressions) + return super(DatabaseOperations, self).combine_expression(connector, sub_expressions) + class DatabaseWrapper(BaseDatabaseWrapper): vendor = 'sqlite' @@ -376,6 +383,7 @@ class DatabaseWrapper(BaseDatabaseWrapper): conn.create_function("django_datetime_trunc", 3, _sqlite_datetime_trunc) conn.create_function("regexp", 2, _sqlite_regexp) conn.create_function("django_format_dtdelta", 5, _sqlite_format_dtdelta) + conn.create_function("django_power", 2, _sqlite_power) return conn def init_connection_state(self): @@ -567,3 +575,7 @@ def _sqlite_format_dtdelta(dt, conn, days, secs, usecs): def _sqlite_regexp(re_pattern, re_string): return bool(re.search(re_pattern, force_text(re_string))) if re_string is not None else False + + +def _sqlite_power(x, y): + return x ** y |
