
    ]j                         d dl mZmZ d dlmZ d dlmZ d dlmZm	Z	 d dl
mZ eee	d                      Zeee	d                      Zeee	d                      Zy	)
    )HttpResponseBadRequestJsonResponse)render_to_string)csrf_exempt)require_show_toolbarsigned_data_view)SQLSelectFormc                    t        |      }|j                         r|j                  d   }|j                  d   }|j                  5 }|j	                  ||       |j
                  D cg c]  }|d   	 }}|j                         }ddd       |j                         |j                  d   |j                  d   d}	t        d|	      }
t        d	|
i      S t        d
      S c c}w # 1 sw Y   bxY w)z.Returns the output of the SQL SELECT statementraw_sqlparamsr   Ndurationaliasresultsqlr   headersr   z$debug_toolbar/panels/sql_select.htmlcontentForm errors)r	   is_validcleaned_datacursorexecutedescriptionfetchallreformat_sqlr   r   r   )requestverified_dataformr   r   r   dr   r   contextr   s              H/root/env/lib/python3.12/site-packages/debug_toolbar/panels/sql/views.py
sql_selectr"   	   s    
 'D}}	*""8,[[ 	'FNN3'%+%7%78qt8G8__&F	' $$&))*5&&w/
 ##I7SY011!-00 9	' 	's   !C&'C!3C&!C&&C/c                    t        |      }|j                         r-|j                  d   }|j                  d   }|j                  j                  }|j
                  5 }|dk(  r"|j                  dj                  |      |       nH|dk(  r"|j                  dj                  |      |       n!|j                  dj                  |      |       |j                  D cg c]  }|d   	 }}|j                         }	d	d	d	       	|j                         |j                  d
   |j                  d   d}
t        d|
      }t        d|i      S t        d      S c c}w # 1 sw Y   bxY w)z8Returns the output of the SQL EXPLAIN on the given queryr   r   sqlitezEXPLAIN QUERY PLAN {}
postgresqlzEXPLAIN ANALYZE {}z
EXPLAIN {}r   Nr   r   r   z%debug_toolbar/panels/sql_explain.htmlr   r   )r	   r   r   
connectionvendorr   r   formatr   r   r   r   r   r   )r   r   r   r   r   r'   r   r   r   r   r    r   s               r!   sql_explainr)   $   sR   
 'D}}	*""8,''[[ 	'F! 6==cBFK<'3::3?H|2237@%+%7%78qt8G8__&F	' $$&))*5&&w/
 ##JGTY011!-00 9	' 	's   A>EE'EEE#c                 |   t        |      }|j                         r|j                  d   }|j                  d   }d}d}d}|j                  5 }	 |j	                  d       |j	                  ||       |j	                  d       |j	                  d       |j
                  D 	cg c]  }	|	d   	 }}	|j                         }ddd       |||j                         |j                  d	   ||j                  d
   d}
t        d|
      }t        d|i      S t        d      S c c}	w # t        $ r d}Y ow xY w# 1 sw Y   txY w)zJReturns the output of running the SQL and getting the profiling statisticsr   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
                    )
                    r   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   	Exceptionr   r   r   r   )r   r   r   r   r   r   r   r+   r   r   r    r   s               r!   sql_profiler-   H   sQ   
 'D}}	*""8,[[ 	F01sF+01 	 *0););<A1Q4<<*)	8 ($$&))*5&&w/
 ##JGTY011!-00% =   +	 	s=   D2AD!!D-D!D!!D/,D2.D//D22D;N)django.httpr   r   django.template.loaderr   django.views.decorators.csrfr   debug_toolbar.decoratorsr   r   debug_toolbar.panels.sql.formsr	   r"   r)   r-        r!   <module>r5      s    < 3 4 K 8 1   10 1   1B /1   /1r4   