a
    5Xh                     @   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   s/var/www/viveiro_mudafortebrasil/venv/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  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                    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   