diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2018-03-19 17:35:16 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-03-19 17:35:16 +0100 |
| commit | cede5111bbeea1f02a7d35941a4264c7ff95df0a (patch) | |
| tree | 959f0785f3102ba84db7d4fcd96c17ae1baab479 /django/db/backends/sqlite3 | |
| parent | 8d67c7cffdcd5fd0c5cb0b87cd699a05b461e58d (diff) | |
Refs #28643 -- Added LPad and RPad database functions.
Thanks Tim Graham for the review.
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 996ec1e09b..3989028930 100644 --- a/django/db/backends/sqlite3/base.py +++ b/django/db/backends/sqlite3/base.py @@ -169,6 +169,8 @@ class DatabaseWrapper(BaseDatabaseWrapper): conn.create_function("regexp", 2, _sqlite_regexp) conn.create_function("django_format_dtdelta", 3, _sqlite_format_dtdelta) conn.create_function("django_power", 2, _sqlite_power) + conn.create_function('LPAD', 3, _sqlite_lpad) + conn.create_function('RPAD', 3, _sqlite_rpad) conn.execute('PRAGMA foreign_keys = ON') return conn @@ -467,5 +469,15 @@ def _sqlite_regexp(re_pattern, re_string): return bool(re.search(re_pattern, str(re_string))) if re_string is not None else False +def _sqlite_lpad(text, length, fill_text): + if len(text) >= length: + return text[:length] + return (fill_text * length)[:length - len(text)] + text + + +def _sqlite_rpad(text, length, fill_text): + return (text + fill_text * length)[:length] + + def _sqlite_power(x, y): return x ** y |
