mirror of
https://github.com/django/django.git
synced 2025-07-04 09:49:12 +00:00
boulder-oracle-sprint: Made negligible coding style changes
git-svn-id: http://code.djangoproject.com/svn/django/branches/boulder-oracle-sprint@4019 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
20a30ff32c
commit
afcb877128
@ -16,7 +16,6 @@ class LogEntry(models.Model):
|
|||||||
action_time = models.DateTimeField(_('action time'), auto_now=True)
|
action_time = models.DateTimeField(_('action time'), auto_now=True)
|
||||||
user = models.ForeignKey(User)
|
user = models.ForeignKey(User)
|
||||||
content_type = models.ForeignKey(ContentType, blank=True, null=True)
|
content_type = models.ForeignKey(ContentType, blank=True, null=True)
|
||||||
#changed for Oracle support
|
|
||||||
object_id = models.CharField(_('object id'), maxlength=200, blank=True, null=True)
|
object_id = models.CharField(_('object id'), maxlength=200, blank=True, null=True)
|
||||||
object_repr = models.CharField(_('object repr'), maxlength=200)
|
object_repr = models.CharField(_('object repr'), maxlength=200)
|
||||||
action_flag = models.PositiveSmallIntegerField(_('action flag'))
|
action_flag = models.PositiveSmallIntegerField(_('action flag'))
|
||||||
|
@ -89,7 +89,7 @@ def get_version():
|
|||||||
|
|
||||||
def get_sql_create(app):
|
def get_sql_create(app):
|
||||||
"Returns a list of the CREATE TABLE SQL statements for the given app."
|
"Returns a list of the CREATE TABLE SQL statements for the given app."
|
||||||
from django.db import models,get_creation_module, backend
|
from django.db import models, get_creation_module, backend
|
||||||
data_types = get_creation_module().DATA_TYPES
|
data_types = get_creation_module().DATA_TYPES
|
||||||
|
|
||||||
if not data_types:
|
if not data_types:
|
||||||
@ -169,7 +169,7 @@ def _get_sql_model_create(model, known_models=set()):
|
|||||||
field_output.append(style.SQL_KEYWORD('UNIQUE'))
|
field_output.append(style.SQL_KEYWORD('UNIQUE'))
|
||||||
if f.primary_key:
|
if f.primary_key:
|
||||||
field_output.append(style.SQL_KEYWORD('PRIMARY KEY'))
|
field_output.append(style.SQL_KEYWORD('PRIMARY KEY'))
|
||||||
if (settings.DATABASE_ENGINE == 'oracle') and f.unique and f.primary_key:
|
if settings.DATABASE_ENGINE == 'oracle' and f.unique and f.primary_key:
|
||||||
# Suppress UNIQUE/PRIMARY KEY for Oracle (ORA-02259)
|
# Suppress UNIQUE/PRIMARY KEY for Oracle (ORA-02259)
|
||||||
field_output.remove(style.SQL_KEYWORD('UNIQUE'))
|
field_output.remove(style.SQL_KEYWORD('UNIQUE'))
|
||||||
if f.rel:
|
if f.rel:
|
||||||
@ -198,7 +198,7 @@ def _get_sql_model_create(model, known_models=set()):
|
|||||||
final_output.append('\n'.join(full_statement))
|
final_output.append('\n'.join(full_statement))
|
||||||
|
|
||||||
# To simulate auto-incrementing primary keys in Oracle -- creating primary tables
|
# To simulate auto-incrementing primary keys in Oracle -- creating primary tables
|
||||||
if (settings.DATABASE_ENGINE == 'oracle') & (opts.has_auto_field):
|
if settings.DATABASE_ENGINE == 'oracle' and opts.has_auto_field:
|
||||||
sequence_name = truncate_name('%s_sq' % opts.db_table, backend.get_max_name_length())
|
sequence_name = truncate_name('%s_sq' % opts.db_table, backend.get_max_name_length())
|
||||||
sequence_statement = 'CREATE SEQUENCE %s;' % sequence_name
|
sequence_statement = 'CREATE SEQUENCE %s;' % sequence_name
|
||||||
final_output.append(sequence_statement)
|
final_output.append(sequence_statement)
|
||||||
@ -277,7 +277,7 @@ def _get_many_to_many_sql_for_model(model):
|
|||||||
final_output.append('\n'.join(table_output))
|
final_output.append('\n'.join(table_output))
|
||||||
|
|
||||||
# To simulate auto-incrementing primary keys in Oracle -- creating m2m tables
|
# To simulate auto-incrementing primary keys in Oracle -- creating m2m tables
|
||||||
if (settings.DATABASE_ENGINE == 'oracle'):
|
if settings.DATABASE_ENGINE == 'oracle':
|
||||||
m_table = f.m2m_db_table()
|
m_table = f.m2m_db_table()
|
||||||
sequence_name = truncate_name('%s_sq' % m_table, backend.get_max_name_length())
|
sequence_name = truncate_name('%s_sq' % m_table, backend.get_max_name_length())
|
||||||
sequence_statement = 'CREATE SEQUENCE %s;' % sequence_name
|
sequence_statement = 'CREATE SEQUENCE %s;' % sequence_name
|
||||||
|
@ -161,7 +161,7 @@ class Field(object):
|
|||||||
"Returns field's value prepared for saving into a database."
|
"Returns field's value prepared for saving into a database."
|
||||||
# Oracle treats empty strings ('') the same as NULLs.
|
# Oracle treats empty strings ('') the same as NULLs.
|
||||||
# To get around this wart, we need to change it to something else...
|
# To get around this wart, we need to change it to something else...
|
||||||
if settings.DATABASE_ENGINE == 'oracle' and value == '':
|
if settings.DATABASE_ENGINE == 'oracle' and value == '':
|
||||||
value = ' '
|
value = ' '
|
||||||
return value
|
return value
|
||||||
|
|
||||||
@ -463,11 +463,11 @@ class DateField(Field):
|
|||||||
# Casts dates into string format for entry into database.
|
# Casts dates into string format for entry into database.
|
||||||
if isinstance(value, datetime.datetime):
|
if isinstance(value, datetime.datetime):
|
||||||
if settings.DATABASE_ENGINE != 'oracle':
|
if settings.DATABASE_ENGINE != 'oracle':
|
||||||
#Oracle does not need a string conversion
|
# Oracle does not need a string conversion
|
||||||
value = value.date().strftime('%Y-%m-%d')
|
value = value.date().strftime('%Y-%m-%d')
|
||||||
elif isinstance(value, datetime.date):
|
elif isinstance(value, datetime.date):
|
||||||
if settings.DATABASE_ENGINE != 'oracle':
|
if settings.DATABASE_ENGINE != 'oracle':
|
||||||
#Oracle does not need a string conversion
|
# Oracle does not need a string conversion
|
||||||
value = value.strftime('%Y-%m-%d')
|
value = value.strftime('%Y-%m-%d')
|
||||||
return Field.get_db_prep_save(self, value)
|
return Field.get_db_prep_save(self, value)
|
||||||
|
|
||||||
@ -498,19 +498,19 @@ class DateTimeField(DateField):
|
|||||||
def get_db_prep_save(self, value):
|
def get_db_prep_save(self, value):
|
||||||
# Casts dates into string format for entry into database.
|
# Casts dates into string format for entry into database.
|
||||||
if isinstance(value, datetime.datetime):
|
if isinstance(value, datetime.datetime):
|
||||||
# MySQL/Oracle will throw a warning if microseconds are given, because it
|
# MySQL/Oracle will throw a warning if microseconds are given, because
|
||||||
# doesn't support microseconds.
|
# neither database supports microseconds.
|
||||||
if (settings.DATABASE_ENGINE == 'mysql' or settings.DATABASE_ENGINE=='oracle') and hasattr(value, 'microsecond'):
|
if settings.DATABASE_ENGINE in ('mysql', 'oracle') and hasattr(value, 'microsecond'):
|
||||||
value = value.replace(microsecond=0)
|
value = value.replace(microsecond=0)
|
||||||
# cx_Oracle wants the raw datetime instead of a string
|
# cx_Oracle wants the raw datetime instead of a string.
|
||||||
if settings.DATABASE_ENGINE != 'oracle':
|
if settings.DATABASE_ENGINE != 'oracle':
|
||||||
value = str(value)
|
value = str(value)
|
||||||
elif isinstance(value, datetime.date):
|
elif isinstance(value, datetime.date):
|
||||||
# MySQL/Oracle will throw a warning if microseconds are given, because it
|
# MySQL/Oracle will throw a warning if microseconds are given, because
|
||||||
# doesn't support microseconds.
|
# neither database supports microseconds.
|
||||||
if (settings.DATABASE_ENGINE == 'mysql' or settings.DATABASE_ENGINE=='oracle') and hasattr(value, 'microsecond'):
|
if settings.DATABASE_ENGINE in ('mysql', 'oracle') and hasattr(value, 'microsecond'):
|
||||||
value = datetime.datetime(value.year, value.month, value.day, microsecond=0)
|
value = datetime.datetime(value.year, value.month, value.day, microsecond=0)
|
||||||
# cx_Oracle wants the raw datetime instead of a string
|
# cx_Oracle wants the raw datetime instead of a string.
|
||||||
if settings.DATABASE_ENGINE != 'oracle':
|
if settings.DATABASE_ENGINE != 'oracle':
|
||||||
value = str(value)
|
value = str(value)
|
||||||
return Field.get_db_prep_save(self, value)
|
return Field.get_db_prep_save(self, value)
|
||||||
@ -518,7 +518,7 @@ class DateTimeField(DateField):
|
|||||||
def get_db_prep_lookup(self, lookup_type, value):
|
def get_db_prep_lookup(self, lookup_type, value):
|
||||||
# Oracle will throw an error if microseconds are given, because it
|
# Oracle will throw an error if microseconds are given, because it
|
||||||
# doesn't support microseconds.
|
# doesn't support microseconds.
|
||||||
if (settings.DATABASE_ENGINE=='oracle') and hasattr(value, 'microsecond'):
|
if settings.DATABASE_ENGINE == 'oracle' and hasattr(value, 'microsecond'):
|
||||||
value = value.replace(microsecond=0)
|
value = value.replace(microsecond=0)
|
||||||
if lookup_type == 'range':
|
if lookup_type == 'range':
|
||||||
value = [str(v) for v in value]
|
value = [str(v) for v in value]
|
||||||
@ -547,8 +547,8 @@ class DateTimeField(DateField):
|
|||||||
def flatten_data(self,follow, obj = None):
|
def flatten_data(self,follow, obj = None):
|
||||||
val = self._get_val_from_obj(obj)
|
val = self._get_val_from_obj(obj)
|
||||||
date_field, time_field = self.get_manipulator_field_names('')
|
date_field, time_field = self.get_manipulator_field_names('')
|
||||||
#cx_Oracle does not support strftime
|
# cx_Oracle does not support strftime
|
||||||
if (settings.DATABASE_ENGINE=='oracle'):
|
if settings.DATABASE_ENGINE == 'oracle':
|
||||||
return {date_field: (val is not None or ''),
|
return {date_field: (val is not None or ''),
|
||||||
time_field: (val is not None or '')}
|
time_field: (val is not None or '')}
|
||||||
else:
|
else:
|
||||||
|
@ -172,7 +172,7 @@ class _QuerySet(object):
|
|||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
|
|
||||||
full_query = None
|
full_query = None
|
||||||
if (settings.DATABASE_ENGINE == 'oracle'):
|
if settings.DATABASE_ENGINE == 'oracle':
|
||||||
select, sql, params, full_query = self._get_sql_clause()
|
select, sql, params, full_query = self._get_sql_clause()
|
||||||
else:
|
else:
|
||||||
select, sql, params = self._get_sql_clause()
|
select, sql, params = self._get_sql_clause()
|
||||||
@ -203,7 +203,7 @@ class _QuerySet(object):
|
|||||||
counter._offset = None
|
counter._offset = None
|
||||||
counter._limit = None
|
counter._limit = None
|
||||||
counter._select_related = False
|
counter._select_related = False
|
||||||
if (settings.DATABASE_ENGINE == 'oracle'):
|
if settings.DATABASE_ENGINE == 'oracle':
|
||||||
select, sql, params, full_query = counter._get_sql_clause()
|
select, sql, params, full_query = counter._get_sql_clause()
|
||||||
else:
|
else:
|
||||||
select, sql, params = counter._get_sql_clause()
|
select, sql, params = counter._get_sql_clause()
|
||||||
@ -515,7 +515,7 @@ class _QuerySet(object):
|
|||||||
sql.append("ORDER BY " + ", ".join(order_by))
|
sql.append("ORDER BY " + ", ".join(order_by))
|
||||||
|
|
||||||
# LIMIT and OFFSET clauses
|
# LIMIT and OFFSET clauses
|
||||||
if (settings.DATABASE_ENGINE != 'oracle'):
|
if settings.DATABASE_ENGINE != 'oracle':
|
||||||
if self._limit is not None:
|
if self._limit is not None:
|
||||||
sql.append("%s " % backend.get_limit_offset_sql(self._limit, self._offset))
|
sql.append("%s " % backend.get_limit_offset_sql(self._limit, self._offset))
|
||||||
else:
|
else:
|
||||||
@ -581,7 +581,7 @@ class ValuesQuerySet(QuerySet):
|
|||||||
field_names = [f.attname for f in self.model._meta.fields]
|
field_names = [f.attname for f in self.model._meta.fields]
|
||||||
|
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
if (settings.DATABASE_ENGINE == 'oracle'):
|
if settings.DATABASE_ENGINE == 'oracle':
|
||||||
select, sql, params, full_query = self._get_sql_clause()
|
select, sql, params, full_query = self._get_sql_clause()
|
||||||
else:
|
else:
|
||||||
select, sql, params = self._get_sql_clause()
|
select, sql, params = self._get_sql_clause()
|
||||||
@ -697,7 +697,7 @@ def get_where_clause(lookup_type, table_prefix, field_name, value):
|
|||||||
if table_prefix.endswith('.'):
|
if table_prefix.endswith('.'):
|
||||||
table_prefix = backend.quote_name(table_prefix[:-1])+'.'
|
table_prefix = backend.quote_name(table_prefix[:-1])+'.'
|
||||||
field_name = backend.quote_name(field_name)
|
field_name = backend.quote_name(field_name)
|
||||||
#put some oracle exceptions here
|
# Put some oracle exceptions here
|
||||||
if lookup_type == "icontains" and settings.DATABASE_ENGINE == 'oracle':
|
if lookup_type == "icontains" and settings.DATABASE_ENGINE == 'oracle':
|
||||||
return 'lower(%s%s) %s' % (table_prefix, field_name, (backend.OPERATOR_MAPPING[lookup_type] % '%s'))
|
return 'lower(%s%s) %s' % (table_prefix, field_name, (backend.OPERATOR_MAPPING[lookup_type] % '%s'))
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user