
    Vhq                     j    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	y)    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yt        |   |      S )NT)
isinstancer   $_supports_limited_data_type_defaultssuperskip_default)selffield	__class__s     [/home/dcms/DCMS/lib/python3.12/site-packages/django/contrib/gis/db/backends/mysql/schema.pyr   z!MySQLGISSchemaEditor.skip_default   s+     um,==w#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   sA    eT__008897&s5z22w"5))r   c                    t        |t              r|j                  r|j                  s| j                  j                         5 }| j                  j                  j                  ||j                  j                        }d d d        | j                  ||      }r|gS t        j                  d| d       g S t        | 9  ||      S # 1 sw Y   KxY w)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]+0C0CEJJ'') VOO11HH 4 4 ' 00>C%u23% 8$ % 	w)%77 s   ;C		Cc                    t        |t              r<|j                  r0|j                  s$| j	                  ||      }	 | j                  |       t        | )  ||       y # t        $ r t        j                  d|       Y 2w xY w)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/   su    e]+0C0CEJJ00>CS! 	UE* $ Ds   A B Bc	           
         t         |   ||||||||       t        |t              xr |j                  xr |j
                   }	t        |t              xr |j                  xr |j
                   }
|	s$|
r"| j                  | j                  ||             y |	r%|
s"| j                  | j                  ||             y y y )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 #''#NN" 	  y-0 #''#NN" 	 
 '+BLL77yIJ$-DLL77yIJ .E$r   c                 N    |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15<<@@r   c                     | j                  ||      }| 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   sf    44UEB
__  ++))
^,,-&-
 
 	
r   c                 J    | j                  ||      }| j                  ||      S r   )r;   _delete_index_sql)r   r&   r   rA   s       r   r)   z.MySQLGISSchemaEditor._delete_spatial_index_sqln   s'    44UEB
%%eZ88r   )F)__name__
__module____qualname__r@   r   r   r%   r+   r.   r;   r"   r)   __classcell__)r   s   @r   r   r   
   s9    U+*
8&+. #KJA
9r   r   )
loggingdjango.contrib.gis.db.modelsr   	django.dbr   django.db.backends.mysql.schemar   	getLoggerr#   r    r   r   <module>rO      s3     6 & @			/	0f9/ f9r   