diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2017-08-12 21:06:49 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-08-12 21:06:49 +0200 |
| commit | 489421b01562494ab506de5d30ea97d7b6b5df30 (patch) | |
| tree | 3ccf4b471f71c44e48e17dd028bcdb7e2262cc8b /django | |
| parent | 47ccefeada926ffbccaa354dec7a987a7e7ca701 (diff) | |
Fixed #23546 -- Added kwargs support for CursorWrapper.callproc() on Oracle.
Thanks Shai Berger, Tim Graham and Aymeric Augustin for reviews and
Renbi Yu for the initial patch.
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/backends/base/features.py | 3 | ||||
| -rw-r--r-- | django/db/backends/oracle/features.py | 1 | ||||
| -rw-r--r-- | django/db/backends/utils.py | 17 |
3 files changed, 18 insertions, 3 deletions
diff --git a/django/db/backends/base/features.py b/django/db/backends/base/features.py index 84f391ad79..7626595741 100644 --- a/django/db/backends/base/features.py +++ b/django/db/backends/base/features.py @@ -240,6 +240,9 @@ class BaseDatabaseFeatures: create_test_procedure_without_params_sql = None create_test_procedure_with_int_param_sql = None + # Does the backend support keyword parameters for cursor.callproc()? + supports_callproc_kwargs = False + def __init__(self, connection): self.connection = connection diff --git a/django/db/backends/oracle/features.py b/django/db/backends/oracle/features.py index 47e186af06..5cb012659c 100644 --- a/django/db/backends/oracle/features.py +++ b/django/db/backends/oracle/features.py @@ -54,3 +54,4 @@ class DatabaseFeatures(BaseDatabaseFeatures): V_I := P_I; END; """ + supports_callproc_kwargs = True diff --git a/django/db/backends/utils.py b/django/db/backends/utils.py index 8d3a8ab4b3..9634807a87 100644 --- a/django/db/backends/utils.py +++ b/django/db/backends/utils.py @@ -6,6 +6,7 @@ import re from time import time from django.conf import settings +from django.db.utils import NotSupportedError from django.utils.encoding import force_bytes from django.utils.timezone import utc @@ -45,13 +46,23 @@ class CursorWrapper: # The following methods cannot be implemented in __getattr__, because the # code must run when the method is invoked, not just when it is accessed. - def callproc(self, procname, params=None): + def callproc(self, procname, params=None, kparams=None): + # Keyword parameters for callproc aren't supported in PEP 249, but the + # database driver may support them (e.g. cx_Oracle). + if kparams is not None and not self.db.features.supports_callproc_kwargs: + raise NotSupportedError( + 'Keyword parameters for callproc are not supported on this ' + 'database backend.' + ) self.db.validate_no_broken_transaction() with self.db.wrap_database_errors: - if params is None: + if params is None and kparams is None: return self.cursor.callproc(procname) - else: + elif kparams is None: return self.cursor.callproc(procname, params) + else: + params = params or () + return self.cursor.callproc(procname, params, kparams) def execute(self, sql, params=None): self.db.validate_no_broken_transaction() |
