Django

Code

Ticket #4765 (closed: fixed)

Opened 1 year ago

Last modified 1 year ago

sqlite3 executemany wrapper fails with empty parameter list

Reported by: jdetaeye@www.frepple.com Assigned to: nobody
Milestone: Component: Database layer (models, ORM)
Version: SVN Keywords: sqlite3
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation:
Needs tests: Patch needs improvement:

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

Change History

09/14/07 16:32:25 changed by ikelly

  • status changed from new to closed.
  • resolution set to fixed.

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


Add/Change #4765 (sqlite3 executemany wrapper fails with empty parameter list)




Change Properties
Action