U
    f                     @   s   d dl mZ d dlmZ d dlmZ d dlmZ ddl	m
Z
 ddlmZ ddlmZ dd	lmZ dd
lmZ G dd deZdS )    )find_library)settings)ImproperlyConfigured)DatabaseWrapper   )SpatiaLiteClient)DatabaseFeatures)SpatiaLiteIntrospection)SpatiaLiteOperations)SpatialiteSchemaEditorc                       sH   e Zd ZeZeZeZe	Z
eZ fddZ fddZ fddZ  ZS )r   c                    s6   dd t tdd ddtdfD | _t j|| d S )Nc                 S   s   g | ]}|d k	r|qS )N ).0namer   r   R/tmp/pip-unpacked-wheel-_jot26k8/django/contrib/gis/db/backends/spatialite/base.py
<listcomp>   s   z,DatabaseWrapper.__init__.<locals>.<listcomp>SPATIALITE_LIBRARY_PATHzmod_spatialite.soZmod_spatialiteZ
spatialite)getattrr   r   lib_spatialite_pathssuper__init__)selfargskwargs	__class__r   r   r      s    

zDatabaseWrapper.__init__c              	      s   t  |}z|d W n tk
r6   tdY nX | jD ]D}z|| W n, tk
r|   tt	dd rttdY q>Y q>X  qq>tdd
| j |S )NTzGSpatiaLite requires SQLite to be configured to allow extension loading.r   zeUnable to load the SpatiaLite library extension as specified in your SPATIALITE_LIBRARY_PATH setting.zHUnable to load the SpatiaLite library extension. Library names tried: %sz, )r   get_new_connectionZenable_load_extensionAttributeErrorr   r   Zload_extension	Exceptionr   r   join)r   Zconn_paramsconnpathr   r   r   r   (   s.    



z"DatabaseWrapper.get_new_connectionc              	      sZ   t    |  >}|d | g krL| jjdk rB|d n
|d W 5 Q R X d S )Nz$PRAGMA table_info(geometry_columns);)   zSELECT InitSpatialMetaData(1)z!SELECT InitSpatialMetaDataFull(1))r   prepare_databasecursorexecuteZfetchallopsZspatial_version)r   r#   r   r   r   r"   F   s    


z DatabaseWrapper.prepare_database)__name__
__module____qualname__r   ZSchemaEditorClassr   Zclient_classr   Zfeatures_classr	   Zintrospection_classr
   Z	ops_classr   r   r"   __classcell__r   r   r   r   r      s   r   N)Zctypes.utilr   Zdjango.confr   Zdjango.core.exceptionsr   Zdjango.db.backends.sqlite3.baser   ZSQLiteDatabaseWrapperclientr   featuresr   Zintrospectionr	   
operationsr
   Zschemar   r   r   r   r   <module>   s   