Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
@ikelly ikelly authored
View
44 django/db/backends/oracle/base.py
@@ -438,21 +438,6 @@ class FormatStylePlaceholderCursor(Database.Cursor):
"""
charset = 'utf-8'
- def _rewrite_args(self, query, params=None):
- if params is None:
- params = []
- else:
- params = self._format_params(params)
- args = [(':arg%d' % i) for i in range(len(params))]
- query = smart_str(query, self.charset) % tuple(args)
- # cx_Oracle wants no trailing ';' for SQL statements. For PL/SQL, it
- # it does want a trailing ';' but not a trailing '/'. However, these
- # characters must be included in the original query in case the query
- # is being passed to SQL*Plus.
- if query.endswith(';') or query.endswith('/'):
- query = query[:-1]
- return query, params
-
def _format_params(self, params):
if isinstance(params, dict):
result = {}
@@ -464,12 +449,35 @@ def _format_params(self, params):
return tuple([smart_str(p, self.charset, True) for p in params])
def execute(self, query, params=None):
- query, params = self._rewrite_args(query, params)
+ if params is None:
+ params = []
+ else:
+ params = self._format_params(params)
+ args = [(':arg%d' % i) for i in range(len(params))]
+ # cx_Oracle wants no trailing ';' for SQL statements. For PL/SQL, it
+ # it does want a trailing ';' but not a trailing '/'. However, these
+ # characters must be included in the original query in case the query
+ # is being passed to SQL*Plus.
+ if query.endswith(';') or query.endswith('/'):
+ query = query[:-1]
+ query = smart_str(query, self.charset) % tuple(args)
return Database.Cursor.execute(self, query, params)
def executemany(self, query, params=None):
- query, params = self._rewrite_args(query, params)
- return Database.Cursor.executemany(self, query, params)
+ try:
+ args = [(':arg%d' % i) for i in range(len(params[0]))]
+ except (IndexError, TypeError):
+ # No params given, nothing to do
+ return None
+ # cx_Oracle wants no trailing ';' for SQL statements. For PL/SQL, it
+ # it does want a trailing ';' but not a trailing '/'. However, these
+ # characters must be included in the original query in case the query
+ # is being passed to SQL*Plus.
+ if query.endswith(';') or query.endswith('/'):
+ query = query[:-1]
+ query = smart_str(query, self.charset) % tuple(args)
+ new_param_list = [self._format_params(i) for i in params]
+ return Database.Cursor.executemany(self, query, new_param_list)
def fetchone(self):
return to_unicode(Database.Cursor.fetchone(self))
View
8 django/db/backends/sqlite3/base.py
@@ -133,8 +133,12 @@ def execute(self, query, params=()):
return Database.Cursor.execute(self, query, params)
def executemany(self, query, param_list):
- query = self.convert_query(query, len(param_list[0]))
- return Database.Cursor.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,TypeError):
+ # No parameter list provided
+ return None
def convert_query(self, query, num_params):
return query % tuple("?" * num_params)
Please sign in to comment.
Something went wrong with that request. Please try again.