a
    Kcò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                    s:   dd„ t tdd ƒddtdƒfD ƒ| _tƒ j|i |¤Ž d S )Nc                 S   s   g | ]}|d ur|‘qS )N© )Ú.0Únamer   r   úk/home/httpd/docs/test/DocsMgr/lib/python3.9/site-packages/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y4   tdƒ‚Y n0 | jD ]B}z| |¡ W n* tyx   tt	dd ƒrptdƒ‚Y q<Y q<0  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                    sn   t ƒ  ¡  |  ¡ �H}| d¡ | ¡ g krL| jjdk rB| d¡ n
| d¡ W d   ƒ n1 s`0    Y  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   