Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

boulder-oracle-sprint: Fixed #3053. Zoltan Arokszallasi contributed s…

…everal

important patches.  Thanks!

Also made Oracle test DB more generous, since we were 
hitting INTIAL EXTENT errors trying to run the whole test suite.


git-svn-id: http://code.djangoproject.com/svn/django/branches/boulder-oracle-sprint@4726 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit e1d2422cfd2dc36ab92db7c63342e856fc6b9e10 1 parent 0900528
Boulder Sprinters authored
View
9 django/core/management.py
@@ -296,6 +296,7 @@ def _get_many_to_many_sql_for_model(model):
def get_sql_delete(app):
"Returns a list of the DROP TABLE SQL statements for the given app."
from django.db import backend, connection, models, get_introspection_module
+ from django.db.backends.util import truncate_name
introspection = get_introspection_module()
# This should work even if a connecton isn't available
@@ -342,12 +343,15 @@ def get_sql_delete(app):
col = f.column
r_table = model._meta.db_table
r_col = model._meta.get_field(f.rel.field_name).column
+ r_name = '%s_refs_%s_%s_%s' % (col, r_col, table, r_table)
output.append('%s %s %s %s;' % \
(style.SQL_KEYWORD('ALTER TABLE'),
style.SQL_TABLE(backend.quote_name(table)),
style.SQL_KEYWORD(backend.get_drop_foreignkey_sql()),
- style.SQL_FIELD(backend.quote_name('%s_refs_%s_%x' % (col, r_col, abs(hash((table, r_table))))))))
+ style.SQL_FIELD(truncate_name(r_name, backend.get_max_name_length()))))
del references_to_delete[model]
+ if hasattr(backend, 'get_drop_sequence'):
+ output.append(backend.get_drop_sequence(model._meta.db_table))
# Output DROP TABLE statements for many-to-many tables.
for model in app_models:
@@ -356,6 +360,9 @@ def get_sql_delete(app):
if cursor and table_name_converter(f.m2m_db_table()) in table_names:
output.append("%s %s;" % (style.SQL_KEYWORD('DROP TABLE'),
style.SQL_TABLE(backend.quote_name(f.m2m_db_table()))))
+ if hasattr(backend, 'get_drop_sequence'):
+ output.append(backend.get_drop_sequence("%s_%s" % (model._meta.db_table, f.column)))
+
app_label = app_models[0]._meta.app_label
View
49 django/db/backends/oracle/base.py
@@ -152,7 +152,7 @@ def get_fulltext_search_sql(field_name):
raise NotImplementedError
def get_drop_foreignkey_sql():
- return "DROP FOREIGN KEY"
+ return "DROP CONSTRAINT"
def get_pk_default_value():
return "DEFAULT"
@@ -184,41 +184,46 @@ def get_sql_flush(style, tables, sequences):
# Return a list of 'TRUNCATE x;', 'TRUNCATE y;',
# 'TRUNCATE z;'... style SQL statements
if tables:
+ # Oracle does support TRUNCATE, but it seems to get us into
+ # FK referential trouble, whereas DELETE FROM table works.
sql = ['%s %s %s;' % \
- (style.SQL_KEYWORD('TRUNCATE'), style.SQL_KEYWORD('TABLE'),
+ (style.SQL_KEYWORD('DELETE'),
+ style.SQL_KEYWORD('FROM'),
style.SQL_FIELD(quote_name(table))
- ) for table in tables]
- # 'ALTER SEQUENCE sequence_name RESTART WITH 1;'... style SQL statements
- # to reset sequence indices
+ ) for table in tables]
+ # You can't ALTER SEQUENCE back to 1 in Oracle. You must DROP and
+ # CREATE the sequence.
+ # What? You got something better to do than marching up and
+ # down the square?
for sequence_info in sequences:
table_name = sequence_info['table']
column_name = sequence_info['column']
if column_name and len(column_name):
# sequence name in this case will be <table>_<column>_seq
- sql.append("%s %s %s %s %s %s;" % \
- (style.SQL_KEYWORD('ALTER'),
- style.SQL_KEYWORD('SEQUENCE'),
- style.SQL_FIELD('%s_%s_seq' % (table_name, column_name)),
- style.SQL_KEYWORD('RESTART'),
- style.SQL_KEYWORD('WITH'),
- style.SQL_FIELD('1')
- )
- )
+ seq_name = '%s_%s_seq' % (table_name, column_name)
else:
# sequence name in this case will be <table>_id_seq
- sql.append("%s %s %s %s %s %s;" % \
- (style.SQL_KEYWORD('ALTER'),
- style.SQL_KEYWORD('SEQUENCE'),
- style.SQL_FIELD('%s_id_seq' % table_name),
- style.SQL_KEYWORD('RESTART'),
- style.SQL_KEYWORD('WITH'),
- style.SQL_FIELD('1')
- )
+ seq_name = '%s_id_seq' % table_name
+ sql.append('%s %s %s;' % \
+ (style.SQL_KEYWORD('DROP'),
+ style.SQL_KEYWORD('SEQUENCE'),
+ style.SQL_FIELD(seq_name))
+ )
+ sql.append('%s %s %s;' % \
+ (style.SQL_KEYWORD('CREATE'),
+ style.SQL_KEYWORD('SEQUENCE'),
+ style.SQL_FIELD(seq_name))
)
return sql
else:
return []
+def get_drop_sequence(table):
+ name_length = get_max_name_length() - 3
+ sq_name = '%s_sq' % util.truncate_name(table, name_length)
+ drop_sequence_sql = 'DROP SEQUENCE %s;' % sq_name
+ return drop_sequence_sql
+
OPERATOR_MAPPING = {
'exact': '= %s',
'iexact': "LIKE %s ESCAPE '\\'",
View
6 django/db/backends/oracle/creation.py
@@ -158,10 +158,12 @@ def _create_test_db(cursor, parameters, verbosity):
print "_create_test_db(): dbname = %s" % parameters['dbname']
statements = [
"""CREATE TABLESPACE %(tblspace)s
- DATAFILE '%(tblspace)s.dbf' SIZE 10M AUTOEXTEND ON NEXT 10M MAXSIZE 20M
+ DATAFILE '%(tblspace)s.dbf' SIZE 20M
+ REUSE AUTOEXTEND ON NEXT 10M MAXSIZE 100M
""",
"""CREATE TEMPORARY TABLESPACE %(tblspace_temp)s
- TEMPFILE '%(tblspace_temp)s.dbf' SIZE 10M AUTOEXTEND ON NEXT 10M MAXSIZE 20M
+ TEMPFILE '%(tblspace_temp)s.dbf' SIZE 20M
+ REUSE AUTOEXTEND ON NEXT 10M MAXSIZE 100M
""",
]
_execute_statements(cursor, statements, parameters, verbosity)
View
6 django/db/models/query.py
@@ -742,7 +742,11 @@ def get_where_clause(lookup_type, table_prefix, field_name, value):
if lookup_type == 'in':
in_string = ','.join(['%s' for id in value])
if in_string:
- return '%s%s IN (%s)' % (table_prefix, field_name, in_string)
+ if value:
+ value_set = ','.join(['%s' for v in value])
+ else:
+ value_set = 'NULL'
+ return '%s%s IN (%s)' % (table_prefix, field_name, value_set)
else:
raise EmptyResultSet
elif lookup_type in ('range', 'year'):
View
2  django/utils/tzinfo.py
@@ -46,7 +46,7 @@ def tzname(self, dt):
return time.tzname[self._isdst(dt)]
def _isdst(self, dt):
- tt = (dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.weekday(), 0, -1)
+ tt = (dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, 0, 0, -1)
stamp = time.mktime(tt)
tt = time.localtime(stamp)
return tt.tm_isdst > 0
Please sign in to comment.
Something went wrong with that request. Please try again.