U
    5øiY  ã                   @   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-gcyiijx6/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  q˜q>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"   D   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   