
    Dvg                     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                   l     e Zd ZdZ fdZ fdZ fdZd fd	Z fdZ fdZ	 fd	Z
d
 Zd Z xZS )MySQLGISSchemaEditorz7CREATE SPATIAL INDEX %(index)s ON %(table)s(%(column)s)c                 H     t                      j        |i | g | _        d S N)super__init__geometry_sql)selfargskwargs	__class__s      h/var/www/pixelcanvas.ch/venv/lib/python3.11/site-packages/django/contrib/gis/db/backends/mysql/schema.pyr   zMySQLGISSchemaEditor.__init__   s-    $)&)))    c                     t          |t                    r	| j        sdS t                                          |          S )NT)
isinstancer   $_supports_limited_data_type_defaultsr
   skip_default)r   fieldr   s     r   r   z!MySQLGISSchemaEditor.skip_default   sA     um,,	=	 4ww##E***r   c                     t          || j        j        j                  r.t	                                          t          |                    S t	                                          |          S r	   )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   Fc           	         t                                          |||          }t          |t                    r|j        r~|j        sw| j        j        j        }|j	        j
        }| j                            | j         ||                     ||                     ||           ||j                  dz             |S )N)indextablecolumn)r
   
column_sqlr   r   spatial_indexnullr   r   
quote_name_metadb_tabler   appendsql_add_spatial_index_create_spatial_index_namer"   )r   modelr   include_defaultr#   qnr(   r   s          r   r#   zMySQLGISSchemaEditor.column_sql    s    WW''uoFF
e]++ 
	0C 
	EJ 
	$/B{+H$$*R ? ?u M MNNR\\ b..    r   c                 r    t                                          |           |                                  d S r	   )r
   create_modelcreate_spatial_indexes)r   r,   r   s     r   r0   z!MySQLGISSchemaEditor.create_model0   s3    U#####%%%%%r   c                 t    t                                          ||           |                                  d S r	   )r
   	add_fieldr1   )r   r,   r   r   s      r   r3   zMySQLGISSchemaEditor.add_field4   s5    %'''##%%%%%r   c                 n   t          |t                    r||j        ru|j        sn|                     ||          }|                     ||          }	 |                     |           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%   r+   _delete_index_sqlexecuter   loggererrorr
   remove_field)r   r,   r   
index_namesqlr   s        r   r9   z!MySQLGISSchemaEditor.remove_field8   s    e]++ 
	0C 
	EJ 
	88FFJ((
;;CS!!!!#   D     	UE*****s   A( (%BBc                 0    |j         j        d|j        dS )N__id)r'   r(   r"   )r   r,   r   s      r   r+   z/MySQLGISSchemaEditor._create_spatial_index_nameG   s    "[1115<<<@@r   c                     | j         D ]F}	 |                     |           # t          $ r! t                              d| d           Y Cw xY wg | _         d S )NzCannot create SPATIAL INDEX z-. Only MyISAM, Aria, and InnoDB support them.)r   r6   r   r7   r8   )r   r;   s     r   r1   z+MySQLGISSchemaEditor.create_spatial_indexesJ   s    $ 	 	CS!!!!#   %3 % % %    
 s   !(AA)F)__name__
__module____qualname__r*   r   r   r   r#   r0   r3   r9   r+   r1   __classcell__)r   s   @r   r   r   
   s        U    + + + + +* * * * *
      & & & & && & & & &+ + + + +A A A	 	 	 	 	 	 	r   r   )
loggingdjango.contrib.gis.db.modelsr   	django.dbr   django.db.backends.mysql.schemar   	getLoggerr7   r    r   r   <module>rJ      s     6 6 6 6 6 6 & & & & & & @ @ @ @ @ @		/	0	0I I I I I/ I I I I Ir   