o
    QDiU                     @   s   d dl mZmZ 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 d dlmZ d	d
 Zeeee
dd Zeeee
dd Zeeee
dd ZdS )    )HttpResponseBadRequestJsonResponse)render_to_string)csrf_exempt)login_not_required)render_with_toolbar_languagerequire_show_toolbar)SignedDataForm)SQLSelectForm)reformat_sqlc                 C   s2   | j dkr| jn| j}t|}| r| S dS )z2Unpack a signed data form, if invalid returns NoneGETN)methodr   POSTr	   is_validverified_data)requestdatasigned_form r   W/var/www/Datamplify/venv/lib/python3.10/site-packages/debug_toolbar/panels/sql/views.pyget_signed_data   s
   r   c                 C   |   t | }|s
tdS t|}| r:|jd }| \}}|t|d dd|d ||d d}td	|}td
|iS tdS )z.Returns the output of the SQL SELECT statementInvalid signaturequerysqlFwith_toggledurationaliasresultr   r   headersr   z$debug_toolbar/panels/sql_select.htmlcontentForm errors)	r   r   r
   r   cleaned_dataselectr   r   r   r   r   formr   r    r!   contextr"   r   r   r   
sql_select       

r)   c                 C   r   )z8Returns the output of the SQL EXPLAIN on the given queryr   r   r   Fr   r   r   r   z%debug_toolbar/panels/sql_explain.htmlr"   r#   )	r   r   r
   r   r$   explainr   r   r   r&   r   r   r   sql_explain/   r*   r,   c           	      C   s   t | }|s
tdS t|}| rK|jd }d}d}d}z| \}}W n ty0   d}Y nw ||| |d ||d d}td|}t	d	|iS td
S )zJReturns the output of running the SQL and getting the profiling statisticsr   r   NzDProfiling is either not available or not supported by your database.r   r   )r    result_errorr   r   r!   r   z%debug_toolbar/panels/sql_profile.htmlr"   r#   )
r   r   r
   r   r$   profile	Exceptionr   r   r   )	r   r   r'   r   r    r!   r-   r(   r"   r   r   r   sql_profileI   s2   

r0   N)django.httpr   r   django.template.loaderr   django.views.decorators.csrfr   debug_toolbar._compatr   debug_toolbar.decoratorsr   r   debug_toolbar.formsr	   debug_toolbar.panels.sql.formsr
   debug_toolbar.panels.sql.utilsr   r   r)   r,   r0   r   r   r   r   <module>   s0    	