
    	iq                     n    d dl Z d dlmZ d dlmZ d dlmZ  e j        d          Z G d de          Z	dS )    N)GeometryField)OperationalError)DatabaseSchemaEditorzdjango.contrib.gisc                   `     e Zd ZdZ fdZ fdZ fdZ fdZ	 d fd	Zd Z	d	 Z
d
 Z xZS )MySQLGISSchemaEditorz7CREATE SPATIAL INDEX %(index)s ON %(table)s(%(column)s)c                     t          |t                    r	| j        sdS t                                          |          S )NT)
isinstancer   $_supports_limited_data_type_defaultssuperskip_default)selffield	__class__s     c/srv/django_bis/venv311/lib/python3.11/site-packages/django/contrib/gis/db/backends/mysql/schema.pyr   z!MySQLGISSchemaEditor.skip_default   sA     um,,	=	 4ww##E***    c                     t          || j        j        j                  r.t	                                          t          |                    S t	                                          |          S N)r	   
connectionopsAdapterr   quote_valuestr)r   valuer   s     r   r   z MySQLGISSchemaEditor.quote_value   sS    eT_0899 	377&&s5zz222ww""5)))r   c                    t          |t                    r|j        r|j        s| j                                        5 }| j        j                            ||j        j	                  }d d d            n# 1 swxY w Y   | 
                    ||          }|r|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   s         r   r%   z'MySQLGISSchemaEditor._field_indexes_sql   s(   e]++ 	0C 	EJ 	'')) VO1HH 4  '               00>>C% u%3 % % %   	ww))%777s   +A55A9<A9c                 B   t          |t                    rf|j        r_|j        sX|                     ||          }	 |                     |           n+# t          $ r t                              d|           Y nw xY 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   s       r   r+   z!MySQLGISSchemaEditor.remove_field/   s    e]++ 		0C 		EJ 		00>>CS!!!!#   D     	UE*****s   A %A:9A:Fc	           
         t                                          ||||||||           t          |t                    o|j        o|j         }	t          |t                    o|j        o|j         }
|	s-|
r+|                     |                     ||                     d S |	r-|
s-|                     |                     ||                     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   s              r   r.   z!MySQLGISSchemaEditor._alter_field=   s$    	 	 		
 		
 		
 y-00 #'#N" 	  y-00 #'#N" 	 
 ' 	K+B 	KLL77yIIJJJJJ$ 	K-D 	KLL77yIIJJJJJ	K 	K 	K 	Kr   c                 0    |j         j        d|j        dS )N__id)r    r!   column)r   r&   r   s      r   _create_spatial_index_namez/MySQLGISSchemaEditor._create_spatial_index_nameb   s    "[1115<<<@@r   c                     |                      ||          }| j        j        j        }| j         ||           ||j        j                   ||j                  dz  S )N)indextabler:   )r;   r   r   
quote_namesql_add_spatial_indexr    r!   r:   )r   r&   r   
index_nameqns        r   r"   z.MySQLGISSchemaEditor._create_spatial_index_sqle   sj    44UEBB
_ +)R
^^R,--b&&-
 -
 
 	
r   c                 Z    |                      ||          }|                     ||          S r   )r;   _delete_index_sql)r   r&   r   rA   s       r   r)   z.MySQLGISSchemaEditor._delete_spatial_index_sqln   s-    44UEBB
%%eZ888r   )F)__name__
__module____qualname__r@   r   r   r%   r+   r.   r;   r"   r)   __classcell__)r   s   @r   r   r   
   s        U+ + + + +* * * * *
8 8 8 8 8&+ + + + +. #K #K #K #K #K #KJA A A
 
 
9 9 9 9 9 9 9r   r   )
loggingdjango.contrib.gis.db.modelsr   	django.dbr   django.db.backends.mysql.schemar   	getLoggerr#   r    r   r   <module>rO      s     6 6 6 6 6 6 & & & & & & @ @ @ @ @ @		/	0	0f9 f9 f9 f9 f9/ f9 f9 f9 f9 f9r   