
    3h                        d dl mZ d dlZd dlZd dlZd dlmZ d dlZ	d dl
mZ d dlmZ d dlmZ d dlmZ ddZej$                   G d d	             Zdd
ZddZddZy)    )annotationsN)perf_counter)current_app)g)has_app_contextc                 .    t        j                  dg       S )a  Get the list of recorded query information for the current session. Queries are
    recorded if the config :data:`.SQLALCHEMY_RECORD_QUERIES` is enabled.

    Each query info object has the following attributes:

    ``statement``
        The string of SQL generated by SQLAlchemy with parameter placeholders.
    ``parameters``
        The parameters sent with the SQL statement.
    ``start_time`` / ``end_time``
        Timing info about when the query started execution and when the results where
        returned. Accuracy and value depends on the operating system.
    ``duration``
        The time the query took in seconds.
    ``location``
        A string description of where in your application code the query was executed.
        This may not be possible to calculate, and the format is not stable.

    .. versionchanged:: 3.0
        Renamed from ``get_debug_queries``.

    .. versionchanged:: 3.0
        The info object is a dataclass instead of a tuple.

    .. versionchanged:: 3.0
        The info object attribute ``context`` is renamed to ``location``.

    .. versionchanged:: 3.0
        Not enabled automatically in debug or testing mode.
    _sqlalchemy_queries)r   get     R/var/www/html/venv/lib/python3.12/site-packages/flask_sqlalchemy/record_queries.pyget_recorded_queriesr      s    > 55&++r   c                  p    e Zd ZU dZded<   ded<   ded<   ded<   d	ed
<   edd       Zedd       ZddZy)
_QueryInfoa8  Information about an executed query. Returned by :func:`get_recorded_queries`.

    .. versionchanged:: 3.0
        Renamed from ``_DebugQueryTuple``.

    .. versionchanged:: 3.0
        Changed to a dataclass instead of a tuple.

    .. versionchanged:: 3.0
        ``context`` is renamed to ``location``.
    z
str | None	statementt.Any
parametersfloat
start_timeend_timestrlocationc                4    | j                   | j                  z
  S N)r   r   )selfs    r   durationz_QueryInfo.durationE   s    }}t..r   c                R    dd l }|j                  dt        d       | j                  S )Nr   zk'context' is renamed to 'location'. The old name is deprecated and will be removed in Flask-SQLAlchemy 3.1.   
stacklevel)warningswarnDeprecationWarningr   )r   r!   s     r   contextz_QueryInfo.contextI   s-    0	 	 	
 }}r   c                d    dd l }d|   }|j                  d| dt        d       t        | |      S )Nr   r   r   r   r   r   z}Query info is a dataclass, not a tuple. Lookup by index is deprecated and will be removed in Flask-SQLAlchemy 3.1. Use 'info.z
' instead.r   r   )r!   r"   r#   getattr)r   keyr!   names       r   __getitem__z_QueryInfo.__getitem__U   sI    PQTUCCG&
T	 	 	
 tT""r   N)returnr   )r+   r   )r(   intr+   object)	__name__
__module____qualname____doc____annotations__propertyr   r$   r*   r   r   r   r   r   1   sP    
 OM/ / 	 	
#r   r   c                x    t        j                  | dt        d       t        j                  | dt        d       y )Nbefore_cursor_executeT)namedafter_cursor_execute)sa_eventlisten_record_start_record_end)engines    r   _listenr=   b   s(    OOF3]$OOOF2KtLr   c                8    t               sy t               | _        y r   )r   r   _fsa_start_time)r$   kwargss     r   r:   r:   g   s    *nGr   c           	     T   t               sy dt        vrg t        _        t        j                  j                  d      d   }| d}t        j                         }|rx|j                  j                  d      }|rL||k(  s|j                  |      r6|j                  }|j                   d|j                   d|j                   d}n|j                  }|rxd}t        j                  j!                  t#        | j$                  | j&                  | j(                  t+               |	             y )
Nr	   .r   r.   :z ()z	<unknown>r&   )r   r   r	   r   import_name	partitioninspectcurrentframe	f_globalsr
   
startswithf_codeco_filenamef_linenoco_namef_backappendr   r   r   r?   r   )r$   r@   
import_top
import_dotframer)   coder   s           r   r;   r;   n   s   A% "((2237:J<q!J  "E
"":.TZ'4??:+F<<D**+1U^^,<Bt||nANH    ''))..!^	
r   )r+   zlist[_QueryInfo])r<   zsa.engine.Enginer+   None)r$   zsa.engine.ExecutionContextr@   r   r+   rU   )
__future__r   dataclassesrG   typingttimer   
sqlalchemysasqlalchemy.eventeventr8   flaskr   r   r   r   	dataclassr   r=   r:   r;   r   r   r   <module>ra      sY    "      #   !,D -# -# -#`M
-r   