From ebe27acd14c4353e5a3b94eb9d9c678ea142d794 Mon Sep 17 00:00:00 2001 From: Boulder Sprinters Date: Tue, 13 Mar 2007 15:33:37 +0000 Subject: [PATCH] boulder-oracle-sprint: Caught up with refactoring in test/utils.py, so now at least some of the tests are passing again. git-svn-id: http://code.djangoproject.com/svn/django/branches/boulder-oracle-sprint@4720 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/backends/oracle/base.py | 46 ++++++++++++++++++++++----- django/db/backends/oracle/creation.py | 3 ++ 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py index 759a0a3590..1353406e66 100644 --- a/django/db/backends/oracle/base.py +++ b/django/db/backends/oracle/base.py @@ -45,7 +45,7 @@ class DatabaseWrapper(local): cursor.arraysize = 256 # set oracle date to ansi date format cursor.execute("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD'") - cursor.execute("ALTER SESSION SET NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS'") + cursor.execute("ALTER SESSION SET NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS.FF'") return cursor def _commit(self): @@ -181,13 +181,43 @@ def get_sql_flush(style, tables, sequences): all tables in the database (without actually removing the tables themselves) and put the database in an empty 'initial' state """ - # Return a list of 'TRUNCATE x;', 'TRUNCATE y;', 'TRUNCATE z;'... style SQL statements - # TODO - SQL not actually tested against Oracle yet! - # TODO - autoincrement indices reset required? See other get_sql_flush() implementations - sql = ['%s %s;' % \ - (style.SQL_KEYWORD('TRUNCATE'), - style.SQL_FIELD(quote_name(table)) - ) for table in tables] + # Return a list of 'TRUNCATE x;', 'TRUNCATE y;', + # 'TRUNCATE z;'... style SQL statements + if tables: + sql = ['%s %s %s;' % \ + (style.SQL_KEYWORD('TRUNCATE'), style.SQL_KEYWORD('TABLE'), + 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 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 __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') + ) + ) + else: + # sequence name in this case will be
_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') + ) + ) + return sql + else: + return [] OPERATOR_MAPPING = { 'exact': '= %s', diff --git a/django/db/backends/oracle/creation.py b/django/db/backends/oracle/creation.py index 8d62dcb2a1..0b322bbfc7 100644 --- a/django/db/backends/oracle/creation.py +++ b/django/db/backends/oracle/creation.py @@ -1,4 +1,5 @@ import sys, time +from django.core import management # This dictionary maps Field objects to their associated Oracle column # types, as strings. Column-type strings can contain format strings; they'll @@ -108,6 +109,8 @@ def create_test_db(settings, connection, backend, verbosity=1, autoclobber=False settings.DATABASE_USER = TEST_DATABASE_USER settings.DATABASE_PASSWORD = TEST_DATABASE_PASSWD + management.syncdb(verbosity, interactive=False) + # Get a cursor (even though we don't need one yet). This has # the side effect of initializing the test database. cursor = connection.cursor()