
v^                 @   sV   d  d l  m Z d  d l m Z m Z Gd d   d e  Z Gd d   d e  Z d S)    )OGRGeomType)DatabaseIntrospectionFlexibleFieldLookupDictc               @   sO   e  Z d  Z d Z e j d d d d d d d d d d d d d	 d i  Z d
 S)GeoFlexibleFieldLookupDictzi
    Subclass that includes updates the `base_data_types_reverse` dict
    for geometry field types.
    ZpointZGeometryFieldZ
linestringZpolygonZ
multipointZmultilinestringZmultipolygonZgeometrycollectionN)__name__
__module____qualname____doc__r   Zbase_data_types_reverse r
   r
   Y/tmp/pip-build-8lau8j11/django/django/contrib/gis/db/backends/spatialite/introspection.pyr      s   r   c                   s7   e  Z d  Z e   Z d d   Z   f d d   Z   S)SpatiaLiteIntrospectionc       
      C   s  |  j  j    } | j d | | j f  | j   } | sV t d | | j f   | d } t | t  r | d k r | d t j	 } t |  j
 } | d } | d } i  }	 | d k r | |	 d <t | t  r d	 | k s | d
 k r d
 |	 d <Wd  QRX| |	 f S)NzpSELECT coord_dimension, srid, geometry_type FROM geometry_columns WHERE f_table_name=%s AND f_geometry_column=%sz.Could not find a geometry column for "%s"."%s"   i  r      i  sridZ   dim)
connectioncursorexecutenameZfetchone	Exception
isinstanceintr   Zwkb25bitZdjangostr)
self
table_namedescriptionr   rowZogr_typeZ
field_typer   r   Zfield_paramsr
   r
   r   get_geometry_type   s&    	



'z)SpatiaLiteIntrospection.get_geometry_typec                s   t    j | |  } | j d | f  xQ | j   D]C } d | d g d d d d d d  d d d	 d
 i | d | d <q5 W| S)Nz`SELECT f_geometry_column FROM geometry_columns WHERE f_table_name=%s AND spatial_index_enabled=1columnsr   Zprimary_keyFuniqueZforeign_keycheckindexTz%s__spatial__index)superget_constraintsr   Zfetchall)r   r   r   constraintsr   )	__class__r
   r   r%   ;   s    	
z'SpatiaLiteIntrospection.get_constraints)r   r   r   r   Zdata_types_reverser   r%   r
   r
   )r'   r   r      s   	 r   N)Zdjango.contrib.gis.gdalr   Z(django.db.backends.sqlite3.introspectionr   r   r   r   r
   r
   r
   r   <module>   s   