diff --git a/django/db/backends/utils.py b/django/db/backends/utils.py
index 597e6b3a9d..a2271831d5 100644
a
|
b
|
class CursorWrapper:
|
45 | 45 | # The following methods cannot be implemented in __getattr__, because the |
46 | 46 | # code must run when the method is invoked, not just when it is accessed. |
47 | 47 | |
48 | | def callproc(self, procname, params=None, kparams=None): |
| 48 | def callproc(self, procname, params=(), kparams=None): |
49 | 49 | # Keyword parameters for callproc aren't supported in PEP 249, but the |
50 | 50 | # database driver may support them (e.g. cx_Oracle). |
51 | 51 | if kparams is not None and not self.db.features.supports_callproc_kwargs: |
… |
… |
class CursorWrapper:
|
60 | 60 | elif kparams is None: |
61 | 61 | return self.cursor.callproc(procname, params) |
62 | 62 | else: |
63 | | params = params or () |
64 | 63 | return self.cursor.callproc(procname, params, kparams) |
65 | 64 | |
66 | 65 | def execute(self, sql, params=None): |
diff --git a/django/db/models/query.py b/django/db/models/query.py
index ffd8626f4b..2469edf81e 100644
a
|
b
|
class QuerySet:
|
778 | 778 | # PUBLIC METHODS THAT RETURN A QUERYSET SUBCLASS # |
779 | 779 | ################################################## |
780 | 780 | |
781 | | def raw(self, raw_query, params=None, translations=None, using=None): |
| 781 | def raw(self, raw_query, params=(), translations=None, using=None): |
782 | 782 | if using is None: |
783 | 783 | using = self.db |
784 | 784 | qs = RawQuerySet(raw_query, model=self.model, params=params, translations=translations, using=using) |
… |
… |
class RawQuerySet:
|
1332 | 1332 | Provide an iterator which converts the results of raw SQL queries into |
1333 | 1333 | annotated model instances. |
1334 | 1334 | """ |
1335 | | def __init__(self, raw_query, model=None, query=None, params=None, |
| 1335 | def __init__(self, raw_query, model=None, query=None, params=(), |
1336 | 1336 | translations=None, using=None, hints=None): |
1337 | 1337 | self.raw_query = raw_query |
1338 | 1338 | self.model = model |
1339 | 1339 | self._db = using |
1340 | 1340 | self._hints = hints or {} |
1341 | 1341 | self.query = query or sql.RawQuery(sql=raw_query, using=self.db, params=params) |
1342 | | self.params = params or () |
| 1342 | self.params = params |
1343 | 1343 | self.translations = translations or {} |
1344 | 1344 | self._result_cache = None |
1345 | 1345 | self._prefetch_related_lookups = () |
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index b99f0e90ef..0a4cddbf83 100644
a
|
b
|
def _get_col(target, field, alias, simple_col):
|
71 | 71 | class RawQuery: |
72 | 72 | """A single raw SQL query.""" |
73 | 73 | |
74 | | def __init__(self, sql, using, params=None): |
75 | | self.params = params or () |
| 74 | def __init__(self, sql, using, params=()): |
| 75 | self.params = params |
76 | 76 | self.sql = sql |
77 | 77 | self.using = using |
78 | 78 | self.cursor = None |
… |
… |
class RawQuery:
|
113 | 113 | |
114 | 114 | @property |
115 | 115 | def params_type(self): |
| 116 | if self.params is None: |
| 117 | return None |
116 | 118 | return dict if isinstance(self.params, Mapping) else tuple |
117 | 119 | |
118 | 120 | def __str__(self): |
| 121 | if self.params_type is None: |
| 122 | return self.sql |
119 | 123 | return self.sql % self.params_type(self.params) |
120 | 124 | |
121 | 125 | def _execute_query(self): |
… |
… |
class RawQuery:
|
129 | 133 | params = tuple(adapter(val) for val in self.params) |
130 | 134 | elif params_type is dict: |
131 | 135 | params = {key: adapter(val) for key, val in self.params.items()} |
| 136 | elif params_type is None: |
| 137 | params = None |
132 | 138 | else: |
133 | 139 | raise RuntimeError("Unexpected params type: %s" % params_type) |
134 | 140 | |
diff --git a/tests/raw_query/tests.py b/tests/raw_query/tests.py
index 703a6b311e..e62d752fe5 100644
a
|
b
|
class RawQueryTests(TestCase):
|
180 | 180 | self.assertEqual(len(results), 1) |
181 | 181 | self.assertIsInstance(repr(qset), str) |
182 | 182 | |
| 183 | def test_like_param(self): |
| 184 | query = "SELECT * FROM raw_query_author WHERE first_name like 'J%'" |
| 185 | qset = Author.objects.raw(query, params=None) |
| 186 | results = list(qset) |
| 187 | self.assertEqual(len(results), 2) |
| 188 | |
183 | 189 | @skipUnlessDBFeature('supports_paramstyle_pyformat') |
184 | 190 | def test_pyformat_params(self): |
185 | 191 | """ |