o
    "7hq                     @   sJ   d dl Z d dlmZ d dlmZ d dlmZ e dZG dd deZ	dS )    N)GeometryField)OperationalError)DatabaseSchemaEditorzdjango.contrib.gisc                       sl   e Zd ZdZ fddZ fddZ fddZ fdd	Z	
d fdd	Zdd Z	dd Z
dd Z  ZS )MySQLGISSchemaEditorz7CREATE SPATIAL INDEX %(index)s ON %(table)s(%(column)s)c                    s    t |tr
| js
dS t |S )NT)
isinstancer   $_supports_limited_data_type_defaultssuperskip_default)selffield	__class__ /var/www/epreuve.sigeris.cm/public_html/epreuve/venv/lib/python3.10/site-packages/django/contrib/gis/db/backends/mysql/schema.pyr	      s   z!MySQLGISSchemaEditor.skip_defaultc                    s,   t || jjjrt t|S t |S N)r   
connectionopsAdapterr   quote_valuestr)r
   valuer   r   r   r      s   z MySQLGISSchemaEditor.quote_valuec                    s   t |tr@|jr@|js@| j }| jj||jj	}W d    n1 s%w   Y  | 
||}|r5|gS td| d g S t ||S )NzCannot create SPATIAL INDEX z-. Only MyISAM, Aria, and InnoDB support them.)r   r   spatial_indexnullr   cursorintrospectionsupports_spatial_index_metadb_table_create_spatial_index_sqlloggererrorr   _field_indexes_sql)r
   modelr   r   r   sqlr   r   r   r!      s   
z'MySQLGISSchemaEditor._field_indexes_sqlc                    sb   t |tr(|jr(|js(| ||}z| | W n ty'   td| Y nw t	 
|| d S )Nz`Couldn't remove spatial index: %s (may be expected if your storage engine doesn't support them).)r   r   r   r   _delete_spatial_index_sqlexecuter   r   r    r   remove_field)r
   r"   r   r#   r   r   r   r&   /   s   z!MySQLGISSchemaEditor.remove_fieldFc	              
      s   t  j||||||||d t|to|jo|j }	t|to%|jo%|j }
|	s5|
r5| | || d S |	rD|
sF| | || d S d S d S )N)strict)	r   _alter_fieldr   r   r   r   r%   r   r$   )r
   r"   	old_field	new_fieldold_typenew_typeold_db_paramsnew_db_paramsr'   old_field_spatial_indexnew_field_spatial_indexr   r   r   r(   =   s2   

z!MySQLGISSchemaEditor._alter_fieldc                 C   s   d|j j|jf S )Nz%s_%s_id)r   r   column)r
   r"   r   r   r   r   _create_spatial_index_nameb   s   z/MySQLGISSchemaEditor._create_spatial_index_namec                 C   s:   |  ||}| jjj}| j||||jj||jd S )N)indextabler1   )r2   r   r   
quote_namesql_add_spatial_indexr   r   r1   )r
   r"   r   
index_nameqnr   r   r   r   e   s   

z.MySQLGISSchemaEditor._create_spatial_index_sqlc                 C   s   |  ||}| ||S r   )r2   _delete_index_sql)r
   r"   r   r7   r   r   r   r$   n   s   z.MySQLGISSchemaEditor._delete_spatial_index_sql)F)__name__
__module____qualname__r6   r	   r   r!   r&   r(   r2   r   r$   __classcell__r   r   r   r   r   
   s    
%	r   )
loggingdjango.contrib.gis.db.modelsr   	django.dbr   django.db.backends.mysql.schemar   	getLoggerr   r   r   r   r   r   <module>   s    
