Code

Opened 7 years ago

Closed 7 years ago

#4765 closed (fixed)

sqlite3 executemany wrapper fails with empty parameter list

Reported by: jdetaeye@… Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords: sqlite3
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation:
Needs tests: Patch needs improvement:
Easy pickings: UI/UX:

Description

The following statement fails with the sqlite wrapper:

  cursor = connection.cursor()
  cursor.executemany("insert into test (name) values(%s)",[])

It raises an IndexError exception when the code tries to pick up the first element in the parameter list.
The code is in the following statements in the file django\db\backends\sqlite3\base.py :

    def executemany(self, query, param_list):
        query = self.convert_query(query, len(param_list[0]))
        return Database.Cursor.executemany(self, query, param_list)

An obvious fix is as follows:

    def executemany(self, query, param_list):
        try:
          query = self.convert_query(query, len(param_list[0]))
          return Database.Cursor.executemany(self, query, param_list)
        except IndexError:
          # No parameter list provided
          return None

Attachments (0)

Change History (1)

comment:1 Changed 7 years ago by ikelly

  • Resolution set to fixed
  • Status changed from new to closed

(In [6218]) Fixed #4896: fixed #4765: Patch for cursor.executemany using oracle and
sqlite3. Thanks, jdetaeye@…

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.