Commit 9dc4ba87 authored by Russell Keith-Magee's avatar Russell Keith-Magee
Browse files

Fixed #5461 -- Refactored the database backend code to use classes for the...

Fixed #5461 -- Refactored the database backend code to use classes for the creation and introspection modules. Introduces a new validation module for DB-specific validation. This is a backwards incompatible change; see the wiki for details.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8296 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent cec69eb7
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
from django.test.utils import create_test_db

def create_spatial_db(test=True, verbosity=1, autoclobber=False):
    if not test: raise NotImplementedError('This uses `create_test_db` from test/utils.py')
    create_test_db(verbosity, autoclobber)
    from django.db import connection
    connection.creation.create_test_db(verbosity, autoclobber)
+1 −3
Original line number Diff line number Diff line
from django.db.backends.oracle.creation import create_test_db

def create_spatial_db(test=True, verbosity=1, autoclobber=False):
    "A wrapper over the Oracle `create_test_db` routine."
    if not test: raise NotImplementedError('This uses `create_test_db` from db/backends/oracle/creation.py')
    from django.conf import settings
    from django.db import connection
    create_test_db(settings, connection, verbosity, autoclobber)
    connection.creation.create_test_db(verbosity, autoclobber)
+16 −16
Original line number Diff line number Diff line
from django.conf import settings
from django.core.management import call_command
from django.db import connection
from django.test.utils import _set_autocommit, TEST_DATABASE_PREFIX
from django.db.backends.creation import TEST_DATABASE_PREFIX
import os, re, sys

def getstatusoutput(cmd):
@@ -40,7 +40,7 @@ def _create_with_cursor(db_name, verbosity=1, autoclobber=False):
        create_sql += ' OWNER %s' % settings.DATABASE_USER

    cursor = connection.cursor()
    _set_autocommit(connection)
    connection.creation.set_autocommit(connection)

    try:
        # Trying to create the database first.
+12 −14
Original line number Diff line number Diff line
@@ -67,11 +67,9 @@ class Command(InspectCommand):

    def handle_inspection(self):
        "Overloaded from Django's version to handle geographic database tables."
        from django.db import connection, get_introspection_module
        from django.db import connection
        import keyword

        introspection_module = get_introspection_module()

        geo_cols = self.geometry_columns()

        table2model = lambda table_name: table_name.title().replace('_', '')
@@ -88,20 +86,20 @@ class Command(InspectCommand):
        yield ''
        yield 'from django.contrib.gis.db import models'
        yield ''
        for table_name in introspection_module.get_table_list(cursor):
        for table_name in connection.introspection.get_table_list(cursor):
            # Getting the geographic table dictionary.
            geo_table = geo_cols.get(table_name, {})

            yield 'class %s(models.Model):' % table2model(table_name)
            try:
                relations = introspection_module.get_relations(cursor, table_name)
                relations = connection.introspection.get_relations(cursor, table_name)
            except NotImplementedError:
                relations = {}
            try:
                indexes = introspection_module.get_indexes(cursor, table_name)
                indexes = connection.introspection.get_indexes(cursor, table_name)
            except NotImplementedError:
                indexes = {}
            for i, row in enumerate(introspection_module.get_table_description(cursor, table_name)):
            for i, row in enumerate(connection.introspection.get_table_description(cursor, table_name)):
                att_name, iatt_name = row[0].lower(), row[0]
                comment_notes = [] # Holds Field notes, to be displayed in a Python comment.
                extra_params = {}  # Holds Field parameters such as 'db_column'.
@@ -133,12 +131,12 @@ class Command(InspectCommand):
                        if srid != 4326: extra_params['srid'] = srid
                    else:
                        try:
                            field_type = introspection_module.DATA_TYPES_REVERSE[row[1]]
                            field_type = connection.introspection.data_types_reverse[row[1]]
                        except KeyError:
                            field_type = 'TextField'
                            comment_notes.append('This field type is a guess.')

                    # This is a hook for DATA_TYPES_REVERSE to return a tuple of
                    # This is a hook for data_types_reverse to return a tuple of
                    # (field_type, extra_params_dict).
                    if type(field_type) is tuple:
                        field_type, new_params = field_type
+2 −2
Original line number Diff line number Diff line
@@ -6,5 +6,5 @@ class Command(NoArgsCommand):
    requires_model_validation = False

    def handle_noargs(self, **options):
        from django.db import runshell
        runshell()
        from django.db import connection
        connection.client.runshell()
Loading