
    7 f                         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 d dlmZ d Zee	ed                      Zee	ed	                      Zee	ed
                      Zy)    )HttpResponseBadRequestJsonResponse)render_to_string)csrf_exempt)render_with_toolbar_languagerequire_show_toolbar)SignedDataForm)SQLSelectFormc                     | j                   dk(  r| j                  n| j                  }t        |      }|j	                         r|j                         S y)z2Unpack a signed data form, if invalid returns NoneGETN)methodr   POSTr	   is_validverified_data)requestdatasigned_forms      T/var/www/equiseq/venv/lib/python3.11/site-packages/debug_toolbar/panels/sql/views.pyget_signed_datar   
   sD    !..E17;;w||D &K((**    c                    t        |       }|st        d      S 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Invalid signatureraw_sqlparamsr   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$   dr    r   contextr!   s              r   
sql_selectr,      s   
 $G,M%&9::'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>?C9C>9C>>Dc                    t        |       }|st        d      S t        |      }|j                         r	|j                  d   }|j                  d   }|j
                  j                  }|j                  5 }|dk(  r|j                  d| |       n0|dk(  r|j                  d| |       n|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 # 1 sw Y   bxY w)z8Returns the output of the SQL EXPLAIN on the given queryr   r   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
   r   r#   
connectionvendorr$   r%   r&   r'   r(   r   r   )r   r   r)   r   r   r1   r$   r*   r    r   r+   r!   s               r   sql_explainr2   1   s_   
 $G,M%&9::'D}}	*""8,''[[ 	'F! !4SE:FC<'!1#7@#/8%+%7%78qt8G8__&F	' $$&))*5&&w/
 ##JGTY011!-00 9	' 	's   5AEE	E	EEc                    t        |       }|st        d      S 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   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%   r&   r'   	Exceptionr(   r   r   )r   r   r)   r   r   r   r    r4   r$   r*   r+   r!   s               r   sql_profiler6   X   sj   
 $G,M%&9::'D}}	*""8,[[ 	F01sF+01 	 *0););<A1Q4<<*)	8 ($$&))*5&&w/
 ##JGTY011!-00% =   +	 	s=   $E
&AD99D4D94D99EE
EE

EN)django.httpr   r   django.template.loaderr   django.views.decorators.csrfr   debug_toolbar.decoratorsr   r   debug_toolbar.formsr	   debug_toolbar.panels.sql.formsr
   r   r,   r2   r6    r   r   <module>r>      s    < 3 4 W . 8 1   16 !1   !1H 21   21r   