Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #4896: fixed #4765: Patch for cursor.executemany using oracle and

sqlite3. Thanks, jdetaeye@www.frepple.com


git-svn-id: http://code.djangoproject.com/svn/django/trunk@6218 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit f180d95903d298e7fed54d777e781a9271e469d7 1 parent aff47aa
Ian Kelly authored September 14, 2007
44  django/db/backends/oracle/base.py
@@ -438,21 +438,6 @@ class FormatStylePlaceholderCursor(Database.Cursor):
438 438
     """
439 439
     charset = 'utf-8'
440 440
 
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  
-
456 441
     def _format_params(self, params):
457 442
         if isinstance(params, dict):
458 443
             result = {}
@@ -464,12 +449,35 @@ def _format_params(self, params):
464 449
             return tuple([smart_str(p, self.charset, True) for p in params])
465 450
 
466 451
     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)
468 464
         return Database.Cursor.execute(self, query, params)
469 465
 
470 466
     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)
473 481
 
474 482
     def fetchone(self):
475 483
         return to_unicode(Database.Cursor.fetchone(self))
8  django/db/backends/sqlite3/base.py
@@ -133,8 +133,12 @@ def execute(self, query, params=()):
133 133
         return Database.Cursor.execute(self, query, params)
134 134
 
135 135
     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
138 142
 
139 143
     def convert_query(self, query, num_params):
140 144
         return query % tuple("?" * num_params)

0 notes on commit f180d95

Please sign in to comment.
Something went wrong with that request. Please try again.