
 X                 @   s   d  d l  Z  d  d l m Z d  d l m Z d  d l m Z d  d l m Z m	 Z
 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 Gd d   d e
  Z	 d S)    N)find_library)settings)ImproperlyConfigured)DatabaseDatabaseWrapperSQLiteCursorWrapper)six   )SpatiaLiteClient)DatabaseFeatures)SpatiaLiteIntrospection)SpatiaLiteOperations)SpatialiteSchemaEditorc                   sL   e  Z d  Z e Z   f d d   Z   f d d   Z   f d d   Z   S)r   c                s   t  j d k  r t d   n  t t d t d   |  _ |  j sQ t d   n  t t |   j	 | |   t
 |   |  _ t |   |  _ t |   |  _ t |   |  _ d  S)	N      r   zLOnly versions of pysqlite 2.5+ are compatible with SpatiaLite and GeoDjango.ZSPATIALITE_LIBRARY_PATHZ
spatialitezUnable to locate the SpatiaLite library. Make sure it is in your library path, or set SPATIALITE_LIBRARY_PATH in your settings.)r   r   r   )r   version_infor   getattrr   r   spatialite_libsuperr   __init__r   featuresr   opsr
   clientr   introspection)selfargskwargs)	__class__ \/home/ubuntu/projects/ifolica/build/django/django/contrib/gis/db/backends/spatialite/base.pyr      s    		zDatabaseWrapper.__init__c                s   t  t |   j |  } y | j d  Wn t k
 rI t d   Yn X| j d t  } y | j d |  j	 f  Wn[ t
 k
 r } z; d |  j	 | f } t j t t |  t j   d  WYd  d  } ~ Xn X| j   | S)NTzThe pysqlite library does not support C extension loading. Both SQLite and pysqlite must be configured to allow the loading of extensions to use SpatiaLite.factoryzSELECT load_extension(%s)z@Unable to load the SpatiaLite library extension "%s" because: %sr   )r   r   get_new_connectionZenable_load_extensionAttributeErrorr   cursorr   executer   	Exceptionr   reraisesysexc_infoclose)r   Zconn_paramsconncurmsgZnew_msg)r   r   r   r!   -   s    6
z"DatabaseWrapper.get_new_connectionc          
      sw   t  t |   j   |  j   R } | j d  | j   g  k rm |  j j rS d n d } | j d |  n  Wd  QXd  S)Nz$PRAGMA table_info(geometry_columns);1 zSELECT InitSpatialMetaData(%s))r   r   prepare_databaser#   r$   Zfetchallr   Z/supports_initspatialmetadata_in_one_transaction)r   r#   arg)r   r   r   r/   D   s    z DatabaseWrapper.prepare_database)__name__
__module____qualname__r   ZSchemaEditorClassr   r!   r/   r   r   )r   r   r      s   r   )r'   ctypes.utilr   Zdjango.confr   Zdjango.core.exceptionsr   Zdjango.db.backends.sqlite3.baser   r   ZSQLiteDatabaseWrapperr   Zdjango.utilsr   r   r
   r   r   r   r   Z
operationsr   Zschemar   r   r   r   r   <module>   s   