î
ªÍ X2  ã               @   sƒ   d  d l  m Z d  d l m Z d  d l m Z d  d l m Z m Z d  d l	 m
 Z
 d  d l m Z Gd d „  d e e
 ƒ Z d	 S)
é    )Ú
WKTAdapter)ÚBaseSpatialOperations)ÚSpatialOperator)ÚGeometryFieldÚ
aggregates)ÚDatabaseOperations)Úcached_propertyc                   s  e  Z d  Z d Z d Z e Z e d d „  ƒ Z e d d „  ƒ Z	 e d d „  ƒ Z
 e d	 d
 „  ƒ Z e d d „  ƒ Z e d d „  ƒ Z e d d „  ƒ Z e d d „  ƒ Z e j e j e j e j e j f Z e d d „  ƒ Z d d „  Z d d „  Z ‡  f d d †  Z d d „  Z ‡  S)ÚMySQLOperationsTÚmysqlc             C   s   |  j  j d k  S)Né   é   é   )r   r   r   )Ú
connectionÚmysql_version)Úself© r   ú]/home/ubuntu/projects/ifolica/build/django/django/contrib/gis/db/backends/mysql/operations.pyÚis_mysql_5_5   s    zMySQLOperations.is_mysql_5_5c             C   s   |  j  j d k  S)Nr   é   r   )r   r   r   )r   r   )r   r   r   r   Úis_mysql_5_6   s    zMySQLOperations.is_mysql_5_6c             C   s   |  j  j d k S)Nr   r   )r   r   r   )r   r   )r   r   r   r   Ú&uses_invalid_empty_geometry_collection   s    z6MySQLOperations.uses_invalid_empty_geometry_collectionc             C   s   |  j  r d Sd S)Nz
AsText(%s)zST_AsText(%s))r   )r   r   r   r   Úselect   s    	zMySQLOperations.selectc             C   s   |  j  r d Sd S)NZGeomFromWKBZST_GeomFromWKB)r   )r   r   r   r   Úfrom_wkb#   s    	zMySQLOperations.from_wkbc             C   s   |  j  r d Sd S)NZGeomFromTextZST_GeomFromText)r   )r   r   r   r   Ú	from_text)   s    	zMySQLOperations.from_textc             C   sÙ   |  j  r d n d } i t d d ƒ d 6t d d ƒ d 6t d d ƒ d	 6t d d ƒ d
 6t d d ƒ d 6t d | ƒ d 6t d | ƒ d 6t d d ƒ d 6t d d ƒ d 6t d | ƒ d 6t d d ƒ d 6t d d ƒ d 6S)NZMBREqualÚ	MBREqualsÚfuncZMBRContainsZ
bbcontainsZMBROverlapsZ
bboverlapsZ	MBRWithinZ	containedÚcontainsZMBRDisjointZdisjointÚequalsÚexactZMBRIntersectsZ
intersectsZoverlapsZsame_asZ
MBRTouchesZtouchesZwithin)r   r   )r   r   r   r   r   Úgis_operators/   s    zMySQLOperations.gis_operatorsc             C   s«   i |  j  r d n d d 6|  j  r( d n d d 6d d 6d d 6|  j  rL d	 n d
 d	 6d d 6|  j  ri d n d d 6|  j  r d n d d 6|  j  r• d n d d 6d d 6d d 6S)NZAreaZST_AreaZCentroidZST_CentroidZST_DifferenceÚ
DifferenceZST_DistanceÚDistanceZEnvelopeZST_EnvelopeZST_IntersectionÚIntersectionZGLengthZ	ST_LengthZLengthZNumGeometriesZST_NumGeometriesZ	NumPointsZST_NumPointsZST_SymDifferenceÚSymDifferenceZST_UnionÚUnion)r   )r   r   r   r   Úfunction_namesA   s    zMySQLOperations.function_namesc             C   se   d d d d d d d d d	 d
 d d d d d d d h } |  j  ra | j d d d d d h ƒ n  | S)NZ	AsGeoJSONZAsGMLZAsKMLZAsSVGZBoundingCircleZForceRHRZGeoHashZIsValidZ	MakeValidZMemSizeZ	PerimeterZPointOnSurfaceZReverseZScaleZ
SnapToGridZ	TransformZ	Translater    r!   r"   r#   r$   )r   Úupdate)r   Zunsupportedr   r   r   Úunsupported_functionsV   s    	z%MySQLOperations.unsupported_functionsc             C   s   | j  S)N)Z	geom_type)r   Úfr   r   r   Úgeo_db_typeb   s    zMySQLOperations.geo_db_typec             C   s8   t  | d ƒ r' | j | ƒ \ } } n d |  j } | S)zì
        The placeholder here has to include MySQL's WKT constructor.  Because
        MySQL does not support spatial transformations, there is no need to
        modify the placeholder based on the contents of the given value.
        Zas_sqlz%s(%%s))ÚhasattrÚcompiler   )r   r(   ÚvalueÚcompilerÚplaceholderÚ_r   r   r   Úget_geom_placeholdere   s    z$MySQLOperations.get_geom_placeholderc                sJ   t  t |  ƒ j | ƒ } t | j t ƒ rF |  j rF | j |  j ƒ n  | S)N)	Úsuperr	   Úget_db_convertersÚ
isinstanceZoutput_fieldr   r   ÚappendÚ)convert_invalid_empty_geometry_collection)r   Ú
expressionZ
converters)Ú	__class__r   r   r2   q   s    z!MySQLOperations.get_db_convertersc             C   s   | d k r d S| S)Ns   GEOMETRYCOLLECTION()s   GEOMETRYCOLLECTION EMPTYr   )r   r,   r6   r   Úcontextr   r   r   r5   y   s    z9MySQLOperations.convert_invalid_empty_geometry_collection)Ú__name__Ú
__module__Ú__qualname__r
   Únamer   ZAdapterr   r   r   r   r   r   r   r   r%   r   ZCollectZExtentZExtent3DZMakeLiner$   Zdisallowed_aggregatesr'   r)   r0   r2   r5   r   r   )r7   r   r	   
   s$   r	   N)Z+django.contrib.gis.db.backends.base.adapterr   Z.django.contrib.gis.db.backends.base.operationsr   Z$django.contrib.gis.db.backends.utilsr   Zdjango.contrib.gis.db.modelsr   r   Z#django.db.backends.mysql.operationsr   Zdjango.utils.functionalr   r	   r   r   r   r   Ú<module>   s   