ó
:ÏOc           @   sP   d  d l  m Z d  d l m Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   DatabaseIntrospection(   t   OGRGeomTypet   GeoIntrospectionErrorc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    sM   ../Django//lib/python/django/contrib/gis/db/backends/postgis/introspection.pyR      s   t   PostGISIntrospectionc           B   s)   e  Z i  Z d  „  Z d „  Z d „  Z RS(   c         C   s¡   |  j  j ƒ  } d } zz | j | d ƒ | j ƒ  d } i d | 6} |  j  j j rŽ | j | d ƒ | j ƒ  d } d i t d 6f | | <n  Wd | j ƒ  X| S(	   s·   
        Returns a dictionary with keys that are the PostgreSQL object
        identification integers for the PostGIS geometry and/or
        geography types (if supported).
        s0   SELECT "oid" FROM "pg_type" WHERE "typname" = %st   geometryi    t   GeometryFieldt	   geographyN(   R   (   s	   geography(   t
   connectiont   cursort   executet   fetchonet   opsR   t   Truet   close(   t   selfR
   t   oid_sqlt	   GEOM_TYPEt   postgis_typest	   GEOG_TYPE(    (    sM   ../Django//lib/python/django/contrib/gis/db/backends/postgis/introspection.pyt   get_postgis_types   s    c         C   sG   |  j  s. |  j ƒ  |  _  |  j j |  j  ƒ n  t t |  ƒ j | | ƒ S(   N(   t   postgis_types_reverseR   t   data_types_reverset   updatet   superR   t   get_field_type(   R   t	   data_typet   description(    (    sM   ../Django//lib/python/django/contrib/gis/db/backends/postgis/introspection.pyR   (   s    	c   	      C   s&  |  j  j ƒ  } zÿ y5 | j d | | f ƒ | j ƒ  } | sF t ‚ n  WnE t k
 rŽ |  j  j j r | j d | | f ƒ | j ƒ  } q n X| s® t d | | f ƒ ‚ n  t | d ƒ j	 } | d } | d } i  } | d k rô | | d <n  | d k r| | d	 <n  Wd
 | j
 ƒ  X| | f S(   s%  
        The geometry type OID used by PostGIS does not indicate the particular
        type of field that a geometry column is (e.g., whether it's a
        PointField or a PolygonField).  Thus, this routine queries the PostGIS
        metadata tables to determine the geometry type,
        ss   SELECT "coord_dimension", "srid", "type" FROM "geometry_columns" WHERE "f_table_name"=%s AND "f_geometry_column"=%ssu   SELECT "coord_dimension", "srid", "type" FROM "geography_columns" WHERE "f_table_name"=%s AND "f_geography_column"=%ss;   Could not find a geometry or geography column for "%s"."%s"i   i    i   iæ  t   sridt   dimN(   R	   R
   R   R   R   R   R   t	   ExceptionR   t   djangoR   (	   R   t
   table_namet   geo_colR
   t   rowt
   field_typeR   R   t   field_params(    (    sM   ../Django//lib/python/django/contrib/gis/db/backends/postgis/introspection.pyt   get_geometry_type3   s4    	 	

(   R   R   R   R   R   R&   (    (    (    sM   ../Django//lib/python/django/contrib/gis/db/backends/postgis/introspection.pyR      s   		N(   t4   django.db.backends.postgresql_psycopg2.introspectionR    t   django.contrib.gis.gdalR   R   R   R   (    (    (    sM   ../Django//lib/python/django/contrib/gis/db/backends/postgis/introspection.pyt   <module>   s   