Ticket #12612: 12612_patch.diff

File 12612_patch.diff, 2.4 KB (added by Gabriel Hurley, 15 years ago)

Removes error suppression from sqlite executemany parameter handling and adds tests.

  • django/db/backends/sqlite3/base.py

     
    201201            raise utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2]
    202202
    203203    def executemany(self, query, param_list):
     204        query = self.convert_query(query, len(param_list[0]))
    204205        try:
    205             query = self.convert_query(query, len(param_list[0]))
    206206            return Database.Cursor.executemany(self, query, param_list)
    207         except (IndexError,TypeError):
    208             # No parameter list provided
    209             return None
    210207        except Database.IntegrityError, e:
    211208            raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]
    212209        except Database.DatabaseError, e:
  • tests/modeltests/cursor/tests.py

     
     1from django.db import connection
     2from django.test import TestCase
     3
     4class CursorTests(TestCase):
     5    def setUp(self):
     6        cursor = connection.cursor()
     7        query = 'create table test (Field1 NUMBER(11),Field2 NUMBER(11))'
     8        cursor.execute(query)
     9   
     10    def testExecuteManyEmptyParams(self):
     11        """ Test for bug 12612, removing the error suppression of 4765 """
     12        cursor = connection.cursor()
     13        query = "insert into test (name) values(%s)"
     14        try:
     15            cursor.executemany(query, [])
     16            self.fail("Should have raised an IndexError here!")
     17        except IndexError:
     18            pass
     19   
     20    def testExecuteManyStringFormatting(self):
     21        """ Test for bug 4896 re: string formatting with executemany() """
     22        cursor = connection.cursor()
     23        query = 'insert into test values (%s, %s)'
     24        cursor.executemany(query, [(i,i+1) for i in range(1,100)])
     25   
     26    def tearDown(self):
     27        cursor = connection.cursor()
     28        query = 'drop table test'
     29        cursor.execute(query)
Back to Top