Exemplo n.º 1
0
 def _post_delete_sql(self, style, db_table):
     "Drops the geometry column."
     sql = style.SQL_KEYWORD('SELECT ') + \
         style.SQL_KEYWORD('DropGeometryColumn') + '(' + \
         style.SQL_TABLE(gqn(db_table)) + ', ' + \
         style.SQL_FIELD(gqn(self.column)) +  ');'
     return sql
Exemplo n.º 2
0
    def _add_geom(self, style, db_table):
        """
        Adds this geometry column into the Oracle USER_SDO_GEOM_METADATA
        table.
        """
        # Checking the dimensions.
        # TODO: Add support for 3D geometries.
        if self.dim != 2:
            raise Exception('3D geometries not yet supported on Oracle Spatial backend.')

        # Constructing the SQL that will be used to insert information about
        # the geometry column into the USER_GSDO_GEOM_METADATA table.
        meta_sql = (style.SQL_KEYWORD('INSERT INTO ') +
                    style.SQL_TABLE('USER_SDO_GEOM_METADATA') +
                    ' (%s, %s, %s, %s)\n  ' % tuple(map(qn, ['TABLE_NAME', 'COLUMN_NAME', 'DIMINFO', 'SRID'])) +
                    style.SQL_KEYWORD(' VALUES ') + '(\n    ' +
                    style.SQL_TABLE(gqn(db_table)) + ',\n    ' +
                    style.SQL_FIELD(gqn(self.column)) + ',\n    ' +
                    style.SQL_KEYWORD("MDSYS.SDO_DIM_ARRAY") + '(\n      ' +
                    style.SQL_KEYWORD("MDSYS.SDO_DIM_ELEMENT") +
                    ("('LONG', %s, %s, %s),\n      " % (self._extent[0], self._extent[2], self._tolerance)) +
                    style.SQL_KEYWORD("MDSYS.SDO_DIM_ELEMENT") +
                    ("('LAT', %s, %s, %s)\n    ),\n" % (self._extent[1], self._extent[3], self._tolerance)) +
                    '    %s\n  );' % self.srid)
        return meta_sql
Exemplo n.º 3
0
    def _add_geom(self, style, db_table):
        """
        Constructs the addition of the geometry to the table using the
        AddGeometryColumn(...) PostGIS (and OGC standard) stored procedure.

        Takes the style object (provides syntax highlighting) and the
        database table as parameters.
        """
        sql = style.SQL_KEYWORD('SELECT ') + \
              style.SQL_TABLE('AddGeometryColumn') + '(' + \
              style.SQL_TABLE(gqn(db_table)) + ', ' + \
              style.SQL_FIELD(gqn(self.column)) + ', ' + \
              style.SQL_FIELD(str(self._srid)) + ', ' + \
              style.SQL_COLTYPE(gqn(self._geom)) + ', ' + \
              style.SQL_KEYWORD(str(self._dim)) + ');'

        if not self.null:
            # Add a NOT NULL constraint to the field
            sql += '\n' + \
                   style.SQL_KEYWORD('ALTER TABLE ') + \
                   style.SQL_TABLE(qn(db_table)) + \
                   style.SQL_KEYWORD(' ALTER ') + \
                   style.SQL_FIELD(qn(self.column)) + \
                   style.SQL_KEYWORD(' SET NOT NULL') + ';'
        return sql
Exemplo n.º 4
0
    def _add_geom(self, style, db_table):
        """
        Adds this geometry column into the Oracle USER_SDO_GEOM_METADATA
        table.
        """

        # Checking the dimensions.
        # TODO: Add support for 3D geometries.
        if self._dim != 2:
            raise Exception('3D geometries not yet supported on Oracle Spatial backend.')

        # Constructing the SQL that will be used to insert information about
        # the geometry column into the USER_GSDO_GEOM_METADATA table.
        meta_sql = style.SQL_KEYWORD('INSERT INTO ') + \
                   style.SQL_TABLE('USER_SDO_GEOM_METADATA') + \
                   ' (%s, %s, %s, %s)\n  ' % tuple(map(qn, ['TABLE_NAME', 'COLUMN_NAME', 'DIMINFO', 'SRID'])) + \
                   style.SQL_KEYWORD(' VALUES ') + '(\n    ' + \
                   style.SQL_TABLE(gqn(db_table)) + ',\n    ' + \
                   style.SQL_FIELD(gqn(self.column)) + ',\n    ' + \
                   style.SQL_KEYWORD("MDSYS.SDO_DIM_ARRAY") + '(\n      ' + \
                   style.SQL_KEYWORD("MDSYS.SDO_DIM_ELEMENT") + \
                   ("('LONG', %s, %s, %s),\n      " % (self._extent[0], self._extent[2], self._tolerance)) + \
                   style.SQL_KEYWORD("MDSYS.SDO_DIM_ELEMENT") + \
                   ("('LAT', %s, %s, %s)\n    ),\n" % (self._extent[1], self._extent[3], self._tolerance)) + \
                   '    %s\n  );' % self._srid
        return meta_sql
Exemplo n.º 5
0
 def _geom_index(self, style, db_table):
     "Creates a spatial index for this geometry field."
     sql = (style.SQL_KEYWORD('SELECT ') +
           style.SQL_TABLE('CreateSpatialIndex') + '(' +
           style.SQL_TABLE(gqn(db_table)) + ', ' +
           style.SQL_FIELD(gqn(self.column)) + ');')
     return sql
Exemplo n.º 6
0
 def _geom_index(self, style, db_table):
     "Creates a spatial index for this geometry field."
     sql = (style.SQL_KEYWORD('SELECT ') +
            style.SQL_TABLE('CreateSpatialIndex') + '(' +
            style.SQL_TABLE(gqn(db_table)) + ', ' +
            style.SQL_FIELD(gqn(self.column)) + ');')
     return sql
Exemplo n.º 7
0
    def _add_geom(self, style, db_table):
        """
        Constructs the addition of the geometry to the table using the
        AddGeometryColumn(...) OpenGIS stored procedure.

        Takes the style object (provides syntax highlighting) and the
        database table as parameters.
        """
        sql = (style.SQL_KEYWORD('SELECT ') +
               style.SQL_TABLE('AddGeometryColumn') + '(' +
               style.SQL_TABLE(gqn(db_table)) + ', ' +
               style.SQL_FIELD(gqn(self.column)) + ', ' +
               style.SQL_FIELD(str(self.srid)) + ', ' +
               style.SQL_COLTYPE(gqn(self.geom_type)) + ', ' +
               style.SQL_KEYWORD(str(self.dim)) + ', ' +
               style.SQL_KEYWORD(str(int(not self.null))) + ');')
        return sql
Exemplo n.º 8
0
    def _add_geom(self, style, db_table):
        """
        Constructs the addition of the geometry to the table using the
        AddGeometryColumn(...) OpenGIS stored procedure.

        Takes the style object (provides syntax highlighting) and the
        database table as parameters.
        """
        sql = (style.SQL_KEYWORD('SELECT ') +
               style.SQL_TABLE('AddGeometryColumn') + '(' +
               style.SQL_TABLE(gqn(db_table)) + ', ' +
               style.SQL_FIELD(gqn(self.column)) + ', ' +
               style.SQL_FIELD(str(self.srid)) + ', ' +
               style.SQL_COLTYPE(gqn(self.geom_type)) + ', ' +
               style.SQL_KEYWORD(str(self.dim)) + ', ' +
               style.SQL_KEYWORD(str(int(not self.null))) +
               ');')
        return sql