433 | | def _rewrite_args(self, query, params=None): |
| 433 | def _format_params(self, params): |
| 434 | if isinstance(params, dict): |
| 435 | result = {} |
| 436 | charset = self.charset |
| 437 | for key, value in params.items(): |
| 438 | result[smart_str(key, charset)] = smart_str(value, charset) |
| 439 | return result |
| 440 | else: |
| 441 | return tuple([smart_str(p, self.charset, True) for p in params]) |
| 442 | |
| 443 | def execute(self, query, params=None): |
446 | | return query, params |
447 | | |
448 | | def _format_params(self, params): |
449 | | if isinstance(params, dict): |
450 | | result = {} |
451 | | charset = self.charset |
452 | | for key, value in params.items(): |
453 | | result[smart_str(key, charset)] = smart_str(value, charset) |
454 | | return result |
455 | | else: |
456 | | return tuple([smart_str(p, self.charset, True) for p in params]) |
457 | | |
458 | | def execute(self, query, params=None): |
459 | | query, params = self._rewrite_args(query, params) |
| 455 | query = smart_str(query, self.charset) % tuple(args) |
463 | | query, params = self._rewrite_args(query, params) |
464 | | return Database.Cursor.executemany(self, query, params) |
| 459 | try: |
| 460 | args = [(':arg%d' % i) for i in range(len(params[0]))] |
| 461 | except (IndexError, TypeError): |
| 462 | # No params given, nothing to do |
| 463 | return None |
| 464 | # cx_Oracle wants no trailing ';' for SQL statements. For PL/SQL, it |
| 465 | # it does want a trailing ';' but not a trailing '/'. However, these |
| 466 | # characters must be included in the original query in case the query |
| 467 | # is being passed to SQL*Plus. |
| 468 | if query.endswith(';') or query.endswith('/'): |
| 469 | query = query[:-1] |
| 470 | query = smart_str(query, self.charset) % tuple(args) |
| 471 | new_param_list = [self._format_params(i) for i in params] |
| 472 | return Database.Cursor.executemany(self, query, new_param_list) |