Commit d1ca7011 authored by Claude Paroz's avatar Claude Paroz
Browse files

Factorized schema_editor() at BaseDatabaseWrapper level

parent a8f07530
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -20,13 +20,11 @@ class DatabaseFeatures(BaseSpatialFeatures, MySQLDatabaseFeatures):


class DatabaseWrapper(MySQLDatabaseWrapper):
    SchemaEditorClass = MySQLGISSchemaEditor

    def __init__(self, *args, **kwargs):
        super(DatabaseWrapper, self).__init__(*args, **kwargs)
        self.features = DatabaseFeatures(self)
        self.creation = MySQLCreation(self)
        self.ops = MySQLOperations(self)
        self.introspection = MySQLIntrospection(self)

    def schema_editor(self, *args, **kwargs):
        "Returns a new instance of this backend's SchemaEditor"
        return MySQLGISSchemaEditor(self, *args, **kwargs)
+2 −3
Original line number Diff line number Diff line
@@ -15,12 +15,11 @@ class DatabaseFeatures(BaseSpatialFeatures, OracleDatabaseFeatures):


class DatabaseWrapper(OracleDatabaseWrapper):
    SchemaEditorClass = OracleGISSchemaEditor

    def __init__(self, *args, **kwargs):
        super(DatabaseWrapper, self).__init__(*args, **kwargs)
        self.features = DatabaseFeatures(self)
        self.ops = OracleOperations(self)
        self.creation = OracleCreation(self)
        self.introspection = OracleIntrospection(self)

    def schema_editor(self, *args, **kwargs):
        return OracleGISSchemaEditor(self, *args, **kwargs)
+2 −4
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@ class DatabaseFeatures(BaseSpatialFeatures, Psycopg2DatabaseFeatures):


class DatabaseWrapper(Psycopg2DatabaseWrapper):
    SchemaEditorClass = PostGISSchemaEditor

    def __init__(self, *args, **kwargs):
        super(DatabaseWrapper, self).__init__(*args, **kwargs)
        if kwargs.get('alias', '') != NO_DB_ALIAS:
@@ -23,7 +25,3 @@ class DatabaseWrapper(Psycopg2DatabaseWrapper):
            self.creation = PostGISCreation(self)
            self.ops = PostGISOperations(self)
            self.introspection = PostGISIntrospection(self)

    def schema_editor(self, *args, **kwargs):
        "Returns a new instance of this backend's SchemaEditor"
        return PostGISSchemaEditor(self, *args, **kwargs)
+2 −4
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ class DatabaseFeatures(BaseSpatialFeatures, SQLiteDatabaseFeatures):


class DatabaseWrapper(SQLiteDatabaseWrapper):
    SchemaEditorClass = SpatialiteSchemaEditor

    def __init__(self, *args, **kwargs):
        # Before we get too far, make sure pysqlite 2.5+ is installed.
        if Database.version_info < (2, 5, 0):
@@ -47,10 +49,6 @@ class DatabaseWrapper(SQLiteDatabaseWrapper):
        self.creation = SpatiaLiteCreation(self)
        self.introspection = SpatiaLiteIntrospection(self)

    def schema_editor(self, *args, **kwargs):
        "Returns a new instance of this backend's SchemaEditor"
        return SpatialiteSchemaEditor(self, *args, **kwargs)

    def get_new_connection(self, conn_params):
        conn = super(DatabaseWrapper, self).get_new_connection(conn_params)
        # Enabling extension loading on the SQLite connection.
+8 −2
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ class BaseDatabaseWrapper(object):
    """
    ops = None
    vendor = 'unknown'
    SchemaEditorClass = None

    queries_limit = 9000

@@ -479,8 +480,13 @@ class BaseDatabaseWrapper(object):
        )

    def schema_editor(self, *args, **kwargs):
        "Returns a new instance of this backend's SchemaEditor"
        raise NotImplementedError('subclasses of BaseDatabaseWrapper may require a schema_editor() method')
        """
        Returns a new instance of this backend's SchemaEditor.
        """
        if self.SchemaEditorClass is None:
            raise NotImplementedError(
                'The SchemaEditorClass attribute of this database wrapper is still None')
        return self.SchemaEditorClass(self, *args, **kwargs)


class BaseDatabaseFeatures(object):
Loading