Ticket #16455: django-trunk-rev16722-postgis2-version3.0.patch

File django-trunk-rev16722-postgis2-version3.0.patch, 3.3 KB (added by ckarrie, 4 years ago)
  • django/contrib/gis/db/backends/postgis/operations.py

    ### Eclipse Workspace Patch 1.0
    #P django-trunk
     
    399399
    400400        return placeholder
    401401
    402     def _get_postgis_func(self, func):
     402    def _get_postgis_func(self, func, close=True):
    403403        """
    404404        Helper routine for calling PostGIS functions and returning their result.
    405405        """
     
    413413                raise
    414414        finally:
    415415            # Close out the connection.  See #9437.
    416             self.connection.close()
     416            if close:
     417                self.connection.close()
    417418        return row[0]
    418419
    419420    def postgis_geos_version(self):
    420421        "Returns the version of the GEOS library used with PostGIS."
    421422        return self._get_postgis_func('postgis_geos_version')
    422423
    423     def postgis_lib_version(self):
     424    def postgis_lib_version(self, close=True):
    424425        "Returns the version number of the PostGIS library used with PostgreSQL."
    425         return self._get_postgis_func('postgis_lib_version')
     426        return self._get_postgis_func('postgis_lib_version', close)
    426427
    427428    def postgis_proj_version(self):
    428429        "Returns the version of the PROJ.4 library used with PostGIS."
     
    436437        "Returns PostGIS version number and compile-time options."
    437438        return self._get_postgis_func('postgis_full_version')
    438439
    439     def postgis_version_tuple(self):
     440    def postgis_version_tuple(self, close=True):
    440441        """
    441442        Returns the PostGIS version as a tuple (version string, major,
    442443        minor, subminor).
    443444        """
    444445        # Getting the PostGIS version
    445         version = self.postgis_lib_version()
     446        version = self.postgis_lib_version(close)
    446447        m = self.version_regex.match(version)
    447448
    448449        if m:
  • django/contrib/gis/db/backends/postgis/creation.py

     
    1010        from django.contrib.gis.db.models.fields import GeometryField
    1111
    1212        output = super(PostGISCreation, self).sql_indexes_for_field(model, f, style)
    13 
     13        postgis_version = self.connection.ops.postgis_version_tuple(close=False)[1:]
     14       
     15       
    1416        if isinstance(f, GeometryField):
    1517            gqn = self.connection.ops.geo_quote_name
    1618            qn = self.connection.ops.quote_name
     
    4547                if f.geography:
    4648                    index_opts = ''
    4749                else:
    48                     index_opts = ' ' + style.SQL_KEYWORD(self.geom_index_opts)
     50                    # Check for PostGIS Version
     51                    # PostGIS 2.0 does not support GIST_GEOMETRY_OPS
     52                    if postgis_version >= (2, 0):
     53                        index_opts = ''
     54                    else:
     55                        index_opts = ' ' + style.SQL_KEYWORD(self.geom_index_opts)
    4956                output.append(style.SQL_KEYWORD('CREATE INDEX ') +
    5057                              style.SQL_TABLE(qn('%s_%s_id' % (db_table, f.column))) +
    5158                              style.SQL_KEYWORD(' ON ') +
Back to Top