Ticket #1261: django_firebird_rev3077.patch
File django_firebird_rev3077.patch, 10.9 KB (added by , 18 years ago) |
---|
-
db/models/base.py
157 157 record_exists = True 158 158 if pk_set: 159 159 # Determine whether a record with the primary key already exists. 160 cursor.execute("SELECT 1 FROM %s WHERE %s=%%s LIMIT 1" % \ 160 check_sql = "SELECT 1 FROM %s WHERE %s=%%s" 161 if settings.DATABASE_ENGINE == "firebird": 162 check_sql = backend.add_limit_offset_sql(check_sql, 1) 163 else: 164 check_sql += backend.get_limit_offset_sql(1) 165 cursor.execute(check_sql % \ 161 166 (backend.quote_name(self._meta.db_table), backend.quote_name(self._meta.pk.column)), [pk_val]) 162 167 # If it does already exist, do an UPDATE. 163 168 if cursor.fetchone(): … … 174 179 db_values = [f.get_db_prep_save(f.pre_save(self, True)) for f in self._meta.fields if not isinstance(f, AutoField)] 175 180 # If the PK has been manually set, respect that. 176 181 if pk_set: 177 field_names += [ f.columnfor f in self._meta.fields if isinstance(f, AutoField)]182 field_names += [backend.quote_name(f.column) for f in self._meta.fields if isinstance(f, AutoField)] 178 183 db_values += [f.get_db_prep_save(f.pre_save(self, True)) for f in self._meta.fields if isinstance(f, AutoField)] 179 184 placeholders = ['%s'] * len(field_names) 180 185 if self._meta.order_with_respect_to: -
db/models/fields/__init__.py
475 475 if value is not None: 476 476 # MySQL will throw a warning if microseconds are given, because it 477 477 # doesn't support microseconds. 478 if settings.DATABASE_ENGINE == 'mysql' :478 if settings.DATABASE_ENGINE == 'mysql' or settings.DATABASE_ENGINE == 'firebird': 479 479 value = value.replace(microsecond=0) 480 480 value = str(value) 481 481 return Field.get_db_prep_save(self, value) … … 484 484 if lookup_type == 'range': 485 485 value = [str(v) for v in value] 486 486 else: 487 value = str(value) 487 # kinterbasdb accepts datetime objects 488 # but not datetime string with microseconds 489 if settings.DATABASE_ENGINE != 'firebird': 490 value = str(value) 488 491 return Field.get_db_prep_lookup(self, lookup_type, value) 489 492 490 493 def get_manipulator_field_objs(self): … … 739 742 if value is not None: 740 743 # MySQL will throw a warning if microseconds are given, because it 741 744 # doesn't support microseconds. 742 if settings.DATABASE_ENGINE == 'mysql' :745 if settings.DATABASE_ENGINE == 'mysql' or settings.DATABASE_ENGINE == 'firebird': 743 746 value = value.replace(microsecond=0) 744 747 value = str(value) 745 748 return Field.get_db_prep_save(self, value) -
db/models/query.py
2 2 from django.db.models.fields import DateField, FieldDoesNotExist 3 3 from django.db.models import signals 4 4 from django.dispatch import dispatcher 5 from django.conf import settings 5 6 from django.utils.datastructures import SortedDict 6 7 import operator 7 8 import re … … 159 160 extra_select = self._select.items() 160 161 161 162 cursor = connection.cursor() 162 select, sql, params = self._get_sql_clause() 163 cursor.execute("SELECT " + (self._distinct and "DISTINCT " or "") + ",".join(select) + sql, params) 163 select, criteria, params = self._get_sql_clause() 164 sql = "SELECT " + (self._distinct and "DISTINCT " or "") + ",".join(select) + criteria 165 if settings.DATABASE_ENGINE == "firebird" and self._limit is not None: 166 sql = backend.add_limit_offset_sql(sql, self._limit, self._offset) 167 cursor.execute(sql, params) 164 168 fill_cache = self._select_related 165 169 index_end = len(self.model._meta.fields) 166 170 while 1: … … 418 422 419 423 # Add any additional SELECTs. 420 424 if self._select: 421 select.extend(['(%s) AS%s' % (quote_only_if_word(s[1]), backend.quote_name(s[0])) for s in self._select.items()])425 select.extend(['(%s) %s' % (quote_only_if_word(s[1]), backend.quote_name(s[0])) for s in self._select.items()]) 422 426 423 427 # Start composing the body of the SQL statement. 424 428 sql = [" FROM", backend.quote_name(opts.db_table)] 425 429 426 430 # Compose the join dictionary into SQL describing the joins. 427 431 if joins: 428 sql.append(" ".join(["%s %s AS%s ON %s" % (join_type, table, alias, condition)432 sql.append(" ".join(["%s %s %s ON %s" % (join_type, table, alias, condition) 429 433 for (alias, (table, join_type, condition)) in joins.items()])) 430 434 431 435 # Compose the tables clause into SQL. … … 468 472 469 473 # LIMIT and OFFSET clauses 470 474 if self._limit is not None: 471 sql.append("%s " % backend.get_limit_offset_sql(self._limit, self._offset)) 475 if settings.DATABASE_ENGINE != "firebird": 476 sql.append("%s " % backend.get_limit_offset_sql(self._limit, self._offset)) 472 477 else: 473 478 assert self._offset is None, "'offset' is not allowed without 'limit'" 474 479 -
core/management.py
6 6 import os, re, shutil, sys, textwrap 7 7 from optparse import OptionParser 8 8 from django.utils import termcolors 9 from django.conf import settings 9 10 10 11 # For Python 2.3 11 12 if not hasattr(__builtins__, 'set'): … … 110 111 final_output.extend(_get_sql_for_pending_references(klass, pending_references)) 111 112 # Keep track of the fact that we've created the table for this model. 112 113 models_output.add(klass) 114 115 if (settings.DATABASE_ENGINE == 'firebird') & (klass._meta.has_auto_field): 116 final_output.extend(get_creation_module().create_sequence_sql(klass._meta.db_table, klass._meta.pk.column)) 113 117 114 118 # Create the many-to-many join tables. 115 119 for klass in app_models: … … 153 157 # Make the definition (e.g. 'foo VARCHAR(30)') for this field. 154 158 field_output = [style.SQL_FIELD(backend.quote_name(f.column)), 155 159 style.SQL_COLTYPE(col_type % rel_field.__dict__)] 156 field_output.append(style.SQL_KEYWORD('%sNULL' % (not f.null and 'NOT ' or ' ')))160 field_output.append(style.SQL_KEYWORD('%sNULL' % (not f.null and 'NOT ' or 'DEFAULT '))) 157 161 if f.unique: 158 162 field_output.append(style.SQL_KEYWORD('UNIQUE')) 159 163 if f.primary_key: … … 204 208 col = opts.get_field(f.rel.field_name).column 205 209 final_output.append(style.SQL_KEYWORD('ALTER TABLE') + ' %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s);' % \ 206 210 (backend.quote_name(r_table), 207 backend.quote_name('%s_ referencing_%s_%s' % (r_col, table, col)),211 backend.quote_name('%s__%s' % (r_col, col)), 208 212 backend.quote_name(r_col), backend.quote_name(table), backend.quote_name(col))) 209 213 del pending_references[klass] 210 214 return final_output … … 240 244 style.SQL_FIELD(backend.quote_name(f.m2m_reverse_name())))) 241 245 table_output.append(');') 242 246 final_output.append('\n'.join(table_output)) 247 if (settings.DATABASE_ENGINE == 'firebird'): 248 final_output.extend(get_creation_module().create_sequence_sql(f.m2m_db_table(), "id")) 243 249 return final_output 244 250 245 251 def get_sql_delete(app): … … 291 297 (style.SQL_KEYWORD('ALTER TABLE'), 292 298 style.SQL_TABLE(backend.quote_name(table)), 293 299 style.SQL_KEYWORD(backend.get_drop_foreignkey_sql()), 294 style.SQL_FIELD(backend.quote_name("%s_ referencing_%s_%s" % (col, r_table, r_col)))))300 style.SQL_FIELD(backend.quote_name("%s__%s" % (col, r_col))))) 295 301 del references_to_delete[klass] 296 302 297 303 # Output DROP TABLE statements for many-to-many tables. … … 1026 1032 index_output = [] 1027 1033 for f in fields: 1028 1034 field_output = [backend.quote_name(f.name), data_types[f.get_internal_type()] % f.__dict__] 1029 field_output.append("%sNULL" % (not f.null and "NOT " or " "))1035 field_output.append("%sNULL" % (not f.null and "NOT " or "DEFAULT ")) 1030 1036 if f.unique: 1031 1037 field_output.append("UNIQUE") 1032 1038 if f.primary_key: -
contrib/auth/models.py
64 64 date_joined = models.DateTimeField(_('date joined'), default=models.LazyDate()) 65 65 groups = models.ManyToManyField(Group, verbose_name=_('groups'), blank=True, 66 66 help_text=_("In addition to the permissions manually assigned, this user will also get all permissions granted to each group he/she is in.")) 67 user_permissions = models.ManyToManyField(Permission, verbose_name=_('user permissions'), blank=True, filter_interface=models.HORIZONTAL)67 permissions = models.ManyToManyField(Permission, verbose_name=_('user permissions'), blank=True, filter_interface=models.HORIZONTAL) 68 68 objects = UserManager() 69 69 class Meta: 70 70 verbose_name = _('user') … … 74 74 fields = ( 75 75 (None, {'fields': ('username', 'password')}), 76 76 (_('Personal info'), {'fields': ('first_name', 'last_name', 'email')}), 77 (_('Permissions'), {'fields': ('is_staff', 'is_active', 'is_superuser', ' user_permissions')}),77 (_('Permissions'), {'fields': ('is_staff', 'is_active', 'is_superuser', 'permissions')}), 78 78 (_('Important dates'), {'fields': ('last_login', 'date_joined')}), 79 79 (_('Groups'), {'fields': ('groups',)}), 80 80 ) … … 160 160 def get_all_permissions(self): 161 161 if not hasattr(self, '_perm_cache'): 162 162 import sets 163 self._perm_cache = sets.Set(["%s.%s" % (p.content_type.app_label, p.codename) for p in self. user_permissions.all()])163 self._perm_cache = sets.Set(["%s.%s" % (p.content_type.app_label, p.codename) for p in self.permissions.all()]) 164 164 self._perm_cache.update(self.get_group_permissions()) 165 165 return self._perm_cache 166 166 … … 249 249 250 250 def _get_user_permissions(self): 251 251 raise NotImplementedError 252 user_permissions = property(_get_user_permissions)252 permissions = property(_get_user_permissions) 253 253 254 254 def has_perm(self, perm): 255 255 return False