o
    >h?                     @   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	 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)SQLSelectFormc                 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   ~/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/debug_toolbar/panels/sql/views.pyget_signed_data   s
   r   c           
      C   s   t | }|s
tdS t|}| r\|jd }|jd }|j}||| dd |jD }| }W d   n1 s<w   Y  ||	 |jd ||jd d	}t
d
|}	td|	iS tdS )z.Returns the output of the SQL SELECT statementInvalid signatureraw_sqlparamsc                 S      g | ]}|d  qS r   r   .0dr   r   r   
<listcomp>$       zsql_select.<locals>.<listcomp>Ndurationaliasresultsqlr    headersr!   z$debug_toolbar/panels/sql_select.htmlcontentForm errors)r   r   r
   r   cleaned_datacursorexecutedescriptionfetchallreformat_sqlr   r   )
r   r   formr$   r   r)   r%   r#   contextr&   r   r   r   
sql_select   s*   



r0   c                 C   s  t | }|s
tdS t|}| r|jd }|jd }|jj}|j9}|dkr2|d| | n|dkr@|d| | n	|d| | d	d
 |j	D }|
 }W d   n1 s_w   Y  || |jd ||jd d}	td|	}
td|
iS tdS )z8Returns the output of the SQL EXPLAIN on the given queryr   r   r   sqlitezEXPLAIN QUERY PLAN 
postgresqlzEXPLAIN ANALYZE zEXPLAIN c                 S   r   r   r   r   r   r   r   r   L   r   zsql_explain.<locals>.<listcomp>Nr    r!   r"   z%debug_toolbar/panels/sql_explain.htmlr&   r'   )r   r   r
   r   r(   
connectionvendorr)   r*   r+   r,   r-   r   r   )r   r   r.   r$   r   r4   r)   r%   r#   r/   r&   r   r   r   sql_explain3   s4   



r5   c              	   C   s  t | }|s
tdS t|}| r|jd }|jd }d}d}d}|j7}z#|d ||| |d |d dd	 |jD }| }W n t	yT   d
}Y nw W d   n1 s_w   Y  |||
 |jd ||jd d}	td|	}
td|
iS tdS )zJReturns the output of running the SQL and getting the profiling statisticsr   r   r   NzSET PROFILING=1zSET PROFILING=0aV  
                    SELECT *
                    FROM information_schema.profiling
                    WHERE query_id = (
                        SELECT query_id
                        FROM information_schema.profiling
                        ORDER BY query_id DESC
                        LIMIT 1
                    )
                    c                 S   r   r   r   r   r   r   r   r      r   zsql_profile.<locals>.<listcomp>zDProfiling 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(   r)   r*   r+   r,   	Exceptionr-   r   r   )r   r   r.   r$   r   r#   r%   r6   r)   r/   r&   r   r   r   sql_profile[   sH   




r8   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
   r   r0   r5   r8   r   r   r   r   <module>   s.    	$