Ticket #14729: rev14757_raw_query_repr.diff
File rev14757_raw_query_repr.diff, 2.1 KB (added by , 14 years ago) |
---|
-
django/db/models/sql/query.py
80 80 return iter(result) 81 81 82 82 def __repr__(self): 83 return "<RawQuery: %r>" % (self.sql % self.params)83 return "<RawQuery: %r>" % (self.sql % tuple(self.params)) 84 84 85 85 def _execute_query(self): 86 86 self.cursor = connections[self.using].cursor() -
django/db/models/query.py
1363 1363 yield instance 1364 1364 1365 1365 def __repr__(self): 1366 return "<RawQuerySet: %r>" % (self.raw_query % self.params)1366 return "<RawQuerySet: %r>" % (self.raw_query % tuple(self.params)) 1367 1367 1368 1368 def __getitem__(self, k): 1369 1369 return list(self)[k] -
tests/regressiontests/queries/tests.py
1305 1305 self.assertIsNot(q1, q1.all()) 1306 1306 1307 1307 1308 class RawQueriesTests(TestCase): 1309 def setUp(self): 1310 n1 = Note.objects.create(note='n1', misc='foo', id=1) 1311 1312 def test_ticket14729(self): 1313 # Test representation of raw query with one or few parameters passed as list 1314 query = "SELECT * FROM queries_note WHERE note = %s" 1315 params = ['n1'] 1316 qs = Note.objects.raw(query, params=params) 1317 self.assertEqual(repr(qs), "<RawQuerySet: 'SELECT * FROM queries_note WHERE note = n1'>") 1318 1319 query = "SELECT * FROM queries_note WHERE note = %s and misc = %s" 1320 params = ['n1', 'foo'] 1321 qs = Note.objects.raw(query, params=params) 1322 self.assertEqual(repr(qs), "<RawQuerySet: 'SELECT * FROM queries_note WHERE note = n1 and misc = foo'>") 1323 1324 1308 1325 class GeneratorExpressionTests(TestCase): 1309 1326 def test_ticket10432(self): 1310 1327 # Using an empty generator expression as the rvalue for an "__in"