Ticket #13648: all_patches.patch

File all_patches.patch, 2.4 KB (added by tzulberti, 13 years ago)

The patch of the #12268 and #13648, and a test

  • django/db/models/sql/query.py

     
    16261626                entry_params = []
    16271627                pos = entry.find("%s")
    16281628                while pos != -1:
    1629                     entry_params.append(param_iter.next())
     1629                    # allow %s to be sent to the database, example calling strftime
     1630                    # from sqlite
     1631                    if entry.find("%%s", pos-1) != pos-1:
     1632                        entry_params.append(param_iter.next())
    16301633                    pos = entry.find("%s", pos + 2)
    16311634                select_pairs[name] = (entry, entry_params)
    16321635            # This is order preserving, since self.extra_select is a SortedDict.
  • django/db/backends/sqlite3/base.py

     
    207207        if self.settings_dict['NAME'] != ":memory:":
    208208            BaseDatabaseWrapper.close(self)
    209209
    210 FORMAT_QMARK_REGEX = re.compile(r'(?![^%])%s')
     210FORMAT_QMARK_REGEX = re.compile(r'(?<![%])%s')
    211211
    212212class SQLiteCursorWrapper(Database.Cursor):
    213213    """
  • tests/regressiontests/backends/tests.py

     
    4747        self.assertEqual(long_str, row[0].read())
    4848        c.execute('DROP TABLE ltext')
    4949
     50
     51class SQLiteCheckTest(unittest.TestCase):
     52
     53    def setUp(self):
     54        # Creates the SchoolClass
     55        person = models.Person.objects.create(first_name='Django',
     56                                                   last_name='Sprint')
     57
     58
     59    def test_regression_13648(self):
     60        """
     61        Test %%s scapping for sqlite3 - see #12268__ and #13648__
     62
     63        __: http://code.djangoproject.com/ticket/12268
     64        __: http://code.djangoproject.com/ticket/13648
     65
     66        """
     67        self.assertTrue(len(models.Person.objects.all()), 1)
     68        qs = models.Person.objects.extra(
     69                select={'extra': "strftime(\"%%s\", '2010-11-13', 'utc')"},
     70                )
     71        p = qs.get()
     72        self.assertEquals(int(p.extra), 1289617200)
     73
    5074class DateQuotingTest(TestCase):
    5175
    5276    def test_django_date_trunc(self):
Back to Top