diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2007-09-15 21:42:51 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2007-09-15 21:42:51 +0000 |
| commit | 5ce2e6c2c827cf877f73bf0e42e6afb7e6a71ccf (patch) | |
| tree | 8c8c2fb8329e2db7dbfcf2c47026a11ff079e5c5 /django/db | |
| parent | ea9cd5421382c047e2cc140bd6736b54ba660793 (diff) | |
queryset-refactor: Merged to [6220]
git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@6337 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db')
| -rw-r--r-- | django/db/backends/oracle/base.py | 44 | ||||
| -rw-r--r-- | django/db/backends/sqlite3/base.py | 8 | ||||
| -rw-r--r-- | django/db/models/base.py | 4 | ||||
| -rw-r--r-- | django/db/models/fields/__init__.py | 3 | ||||
| -rw-r--r-- | django/db/models/options.py | 10 |
5 files changed, 46 insertions, 23 deletions
diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py index 76e5743539..dbb1d032eb 100644 --- a/django/db/backends/oracle/base.py +++ b/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 @@ class FormatStylePlaceholderCursor(Database.Cursor): 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)) diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py index a482a240cf..b4b445cd16 100644 --- a/django/db/backends/sqlite3/base.py +++ b/django/db/backends/sqlite3/base.py @@ -133,8 +133,12 @@ class SQLiteCursorWrapper(Database.Cursor): 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) diff --git a/django/db/models/base.py b/django/db/models/base.py index beb413fc4c..b728150a40 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -12,7 +12,7 @@ from django.db.models.loading import register_models, get_model from django.dispatch import dispatcher from django.utils.datastructures import SortedDict from django.utils.functional import curry -from django.utils.encoding import smart_str, force_unicode +from django.utils.encoding import smart_str, force_unicode, smart_unicode from django.conf import settings from itertools import izip import types @@ -213,7 +213,7 @@ class Model(object): pk_val = self._get_pk_val() # Note: the comparison with '' is required for compatibility with # oldforms-style model creation. - pk_set = pk_val is not None and pk_val != u'' + pk_set = pk_val is not None and smart_unicode(pk_val) != u'' record_exists = True if pk_set: # Determine whether a record with the primary key already exists. diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index 7e6a7cd258..8fa091dd76 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -693,7 +693,8 @@ class DecimalField(Field): class EmailField(CharField): def __init__(self, *args, **kwargs): - kwargs['max_length'] = 75 + if 'max_length' not in kwargs: + kwargs['max_length'] = 75 CharField.__init__(self, *args, **kwargs) def get_internal_type(self): diff --git a/django/db/models/options.py b/django/db/models/options.py index 502cbc4a65..788d1c80de 100644 --- a/django/db/models/options.py +++ b/django/db/models/options.py @@ -52,9 +52,19 @@ class Options(object): del meta_attrs['__doc__'] for attr_name in DEFAULT_NAMES: setattr(self, attr_name, meta_attrs.pop(attr_name, getattr(self, attr_name))) + + # unique_together can be either a tuple of tuples, or a single + # tuple of two strings. Normalize it to a tuple of tuples, so that + # calling code can uniformly expect that. + ut = meta_attrs.pop('unique_together', getattr(self, 'unique_together')) + if ut and not isinstance(ut[0], (tuple, list)): + ut = (ut,) + setattr(self, 'unique_together', ut) + # verbose_name_plural is a special case because it uses a 's' # by default. setattr(self, 'verbose_name_plural', meta_attrs.pop('verbose_name_plural', string_concat(self.verbose_name, 's'))) + # Any leftover attributes must be invalid. if meta_attrs != {}: raise TypeError, "'class Meta' got invalid attribute(s): %s" % ','.join(meta_attrs.keys()) |
