Django

Code

Changeset 6218

Show
Ignore:
Timestamp:
09/14/07 16:32:25 (1 year ago)
Author:
ikelly
Message:

Fixed #4896: fixed #4765: Patch for cursor.executemany using oracle and
sqlite3. Thanks, jdetaeye@www.frepple.com

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/db/backends/oracle/base.py

    r6198 r6218  
    439439    charset = 'utf-8' 
    440440 
    441     def _rewrite_args(self, query, params=None): 
    442         if params is None: 
    443             params = [] 
    444         else: 
    445             params = self._format_params(params) 
    446         args = [(':arg%d' % i) for i in range(len(params))] 
    447         query = smart_str(query, self.charset) % tuple(args) 
    448         # cx_Oracle wants no trailing ';' for SQL statements.  For PL/SQL, it 
    449         # it does want a trailing ';' but not a trailing '/'.  However, these 
    450         # characters must be included in the original query in case the query 
    451         # is being passed to SQL*Plus. 
    452         if query.endswith(';') or query.endswith('/'): 
    453             query = query[:-1] 
    454         return query, params 
    455  
    456441    def _format_params(self, params): 
    457442        if isinstance(params, dict): 
     
    465450 
    466451    def execute(self, query, params=None): 
    467         query, params = self._rewrite_args(query, params) 
     452        if params is None: 
     453            params = [] 
     454        else: 
     455            params = self._format_params(params) 
     456        args = [(':arg%d' % i) for i in range(len(params))] 
     457        # cx_Oracle wants no trailing ';' for SQL statements.  For PL/SQL, it 
     458        # it does want a trailing ';' but not a trailing '/'.  However, these 
     459        # characters must be included in the original query in case the query 
     460        # is being passed to SQL*Plus. 
     461        if query.endswith(';') or query.endswith('/'): 
     462            query = query[:-1] 
     463        query = smart_str(query, self.charset) % tuple(args) 
    468464        return Database.Cursor.execute(self, query, params) 
    469465 
    470466    def executemany(self, query, params=None): 
    471         query, params = self._rewrite_args(query, params) 
    472         return Database.Cursor.executemany(self, query, params) 
     467        try: 
     468          args = [(':arg%d' % i) for i in range(len(params[0]))] 
     469        except (IndexError, TypeError): 
     470          # No params given, nothing to do 
     471          return None 
     472        # cx_Oracle wants no trailing ';' for SQL statements.  For PL/SQL, it 
     473        # it does want a trailing ';' but not a trailing '/'.  However, these 
     474        # characters must be included in the original query in case the query 
     475        # is being passed to SQL*Plus. 
     476        if query.endswith(';') or query.endswith('/'): 
     477            query = query[:-1] 
     478        query = smart_str(query, self.charset) % tuple(args) 
     479        new_param_list = [self._format_params(i) for i in params] 
     480        return Database.Cursor.executemany(self, query, new_param_list) 
    473481 
    474482    def fetchone(self): 
  • django/trunk/django/db/backends/sqlite3/base.py

    r6035 r6218  
    134134 
    135135    def executemany(self, query, param_list): 
    136         query = self.convert_query(query, len(param_list[0])) 
    137         return Database.Cursor.executemany(self, query, param_list) 
     136        try: 
     137          query = self.convert_query(query, len(param_list[0])) 
     138          return Database.Cursor.executemany(self, query, param_list) 
     139        except (IndexError,TypeError): 
     140          # No parameter list provided 
     141          return None 
    138142 
    139143    def convert_query(self, query, num_params):