
    L-Ph%                        d Z ddlmZ ddlZddlZddlZddlmZmZ ddl	m
Z
mZ ddlmZmZmZ ddlmZ ddlmZ  G d	 d
          ZdS )z"SQLite abstraction for coverage.py    )annotationsN)castAny)IterableIterator)	auto_reprclipped_reprexc_one_line)	DataError)	TDebugCtlc                      e Zd ZdZd%dZeZd&d	Zd&d
Zd'dZ	d&dZ
d(dZej        	 d)d*d            Zd+d,dZd)d-dZd)d.dZd/dZd0d Zd1d"Zd2d#Zd$S )3SqliteDbaU  A simple abstraction over a SQLite database.

    Use as a context manager, then you can use it like a
    :class:`python:sqlite3.Connection` object::

        with SqliteDb(filename, debug_control) as db:
            with db.execute("select a, b from some_table") as cur:
                for a, b in cur:
                    etc(a, b)

    filenamestrdebugr   returnNonec                >    || _         || _        d| _        d | _        d S )Nr   )r   r   nestcon)selfr   r   s      Q/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/coverage/sqlitedb.py__init__zSqliteDb.__init__    s"    
 	.2    c                   | j         dS | j                            d          r"| j                            d| j                   	 t          j        | j        d          | _         n2# t
          j        $ r }t          d| j        d|           |d}~ww xY w| j                            d          r*| j                            d| j        d	| j                    | j         	                    d
dd            t          t
          d          r%| j                             t
          j        d           |                     d           |                     dd           dS )z2Connect to the db and do universal initialization.NsqlzConnecting to F)check_same_threadCouldn't use data file : zConnected to z as REGEXP   c                0    t          j        | |          d uS )N)research)txtpats     r   <lambda>z#SqliteDb._connect.<locals>.<lambda><   s    ryc?R?RZ^?^ r   SQLITE_DBCONFIG_DEFENSIVEzpragma journal_mode=offzpragma synchronous=offT)fail_ok)r   r   shouldwriter   sqlite3connectErrorr   create_functionhasattr	setconfigr(   execute_void)r   excs     r   _connectzSqliteDb._connect(   s   8F :U## 	AJ?dm??@@@	Yt}NNNDHH} 	Y 	Y 	YNdmNNNNOOUXX	Y :U## 	PJNT]NN$(NNOOO  1.^.^___
 7788 	H15  
 	3444
 	2DAAAAAs    A( (B7BBc                    | j         q| j        dk    rh| j                            d          r*| j                            d| j         d| j                   | j                                          d| _         dS dS dS )z If needed, close the connection.N:memory:r   zClosing z on )r   r   r   r*   r+   closer   s    r   r7   zSqliteDb.closeO   s    8DMZ$?$?z  '' O
  !MDH!M!MDM!M!MNNNHNNDHHH	  $?$?r   c                    | j         dk    r6|                                  | j        J | j                                         | xj         dz  c_         | S )Nr      )r   r4   r   	__enter__r8   s    r   r;   zSqliteDb.__enter__W   sP    9>>MMOOO8'''H   		Q		r   c                   | xj         dz  c_         | j         dk    r	 | j        J | j                            |||           |                                  d S # t          $ rd}| j                            d          r*| j                            dt          |                      t          d| j
        d|           |d }~ww xY wd S )Nr:   r   r   zEXCEPTION from __exit__: zCouldn't end data file r   )r   r   __exit__r7   	Exceptionr   r*   r+   r
   r   r   )r   exc_type	exc_value	tracebackr3   s        r   r=   zSqliteDb.__exit___   s    		Q		9>>]x+++!!(IyAAA

 ] ] ]:$$U++ VJ$$%TcARAR%T%TUUU R$- R RS R RSSY\\] >s   9A 
C"ACCr   
parametersIterable[Any]sqlite3.Cursorc                   | j                             d          r(|rd|nd}| j                             d||            	 | j        J 	 | j                            ||          S # t
          $ r | j                            ||          cY S w xY w# t          j        $ r}t          |          }| j	        dk    ri	 t          | j	        d          5 }d}|                    t          |                    |k    rd	}ddd           n# 1 swxY w Y   n# t
          $ r Y nw xY w| j                             d          r*| j                             d
t          |                      t          d| j	        d|           |d}~ww xY w)z2Same as :meth:`python:sqlite3.Connection.execute`.r    with  z
Executing Nr6   rbs&   !coverage.py: This is a private formatzILooks like a coverage 4.x data file. Are you mixing versions of coverage?zEXCEPTION from execute: r   r   )r   r*   r+   r   executer>   r,   r.   r   r   openreadlenr
   r   )r   r   rB   tailr3   msgbad_filecov4_sigs           r   _executezSqliteDb._executek   s    :U## 	9.8@*J***bDJ7#777888	Y8'''9x''Z888 9 9 9 x''Z88888	9
 } 	Y 	Y 	Yc((C}
** dmT22 h#L#==X778CC!G                 !   Dz  '' Q
  !OL<M<M!O!OPPPNdmNNNNOOUXX#	Ys   	B A) )%BB BB F
#F>D+D
>D
D	DD	DF
D# F"D##A"FF
 Iterator[sqlite3.Cursor]c              #     K   |                      ||          }	 |V  |                                 dS # |                                 w xY w)zContext managed :meth:`python:sqlite3.Connection.execute`.

        Use with a ``with`` statement to auto-close the returned cursor.
        N)rQ   r7   )r   r   rB   curs       r   rI   zSqliteDb.execute   sL       mmC,,	IIIIIKKKKKCIIKKKKs	   4 A
Fr)   boolc                    	 |                      ||                                           dS # t          $ r |s Y dS w xY w)zSame as :meth:`python:sqlite3.Connection.execute` when you don't need the cursor.

        If `fail_ok` is True, then SQLite errors are ignored.
        N)rQ   r7   r   )r   r   rB   r)   s       r   r2   zSqliteDb.execute_void   sd    
	 MM#z**0022222 	 	 	   	s   (, ==intc                    |                      ||          5 }|j        J |j        }ddd           n# 1 swxY w Y   | j                            d          r| j                            d|           |S )z(Like execute, but returns the lastrowid.NsqldatazRow id result: )rI   	lastrowidr   r*   r+   )r   r   rB   rU   rowids        r   execute_for_rowidzSqliteDb.execute_for_rowid   s    \\#z** 	'c=,,,E	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' :Y'' 	:J8u88999s   488tuple[Any, ...] | Nonec                b   |                      ||          5 }t          |          }ddd           n# 1 swxY w Y   t          |          dk    rdS t          |          dk    r(t          t          t
          df         |d                   S t          d|dt          |           d          )a6  Execute a statement and return the one row that results.

        This is like execute(sql, parameters).fetchone(), except it is
        correct in reading the entire result set.  This will raise an
        exception if more than one row results.

        Returns a row, or None if there were no rows.
        Nr   r:   .zSQL z shouldn't return  rows)rI   listrL   r   tupler   AssertionError)r   r   rB   rU   rowss        r   execute_onezSqliteDb.execute_one   s     \\#z** 	c99D	 	 	 	 	 	 	 	 	 	 	 	 	 	 	t99>>4YY!^^c3ha111 !Q!Q!QT!Q!Q!QRRRs   377data	list[Any]c                   | j                             d          r| j                             d          rdnd}| j                             d|dt          |           d|            | j                             d          r5t	          |          D ]%\  }}| j                             |dd	|           &| j        J 	 | j                            ||          S # t          $ r | j                            ||          cY S w xY w)
z6Same as :meth:`python:sqlite3.Connection.executemany`.r   rZ   :rG   zExecuting many rF   r`   4dr   )r   r*   r+   rL   	enumerater   executemanyr>   )r   r   rf   finalirows         r   _executemanyzSqliteDb._executemany   s.   :U## 	9:,,Y77?CCREJSsSSCIISSESSTTTz  ++ 9'oo 9 9FAsJ$$%7%7%7%7%78888x###	38''T222 	3 	3 	3 8''T22222		3s   C %DDc                |    t          |          }|r*|                     ||                                           dS dS )zUSame as :meth:`python:sqlite3.Connection.executemany` when you don't need the cursor.N)ra   rp   r7   )r   r   rf   s      r   executemany_voidzSqliteDb.executemany_void   sG    Dzz 	1c4((..00000	1 	1r   scriptc           	     6   | j                             d          rI| j                             d                    t	          |          t          |d                               | j        J | j                            |                                           dS )z8Same as :meth:`python:sqlite3.Connection.executescript`.r   z"Executing script with {} chars: {}d   N)	r   r*   r+   formatrL   r	   r   executescriptr7   )r   rs   s     r   rw   zSqliteDb.executescript   s    :U## 	JAHHF\&#66     x###v&&,,.....r   c                l    | j         J d                    | j                                                   S )z9Return a multi-line string, the SQL dump of the database.N
)r   joiniterdumpr8   s    r   dumpzSqliteDb.dump   s0    x###yy**,,---r   N)r   r   r   r   r   r   )r   r   )r   r   )r   r   rB   rC   r   rD   )rR   )r   r   rB   rC   r   rS   )rR   F)r   r   rB   rC   r)   rV   r   r   )r   r   rB   rC   r   rX   )r   r   rB   rC   r   r^   )r   r   rf   rg   r   rD   )r   r   rf   rC   r   r   )rs   r   r   r   )r   r   )__name__
__module____qualname____doc__r   r   __repr__r4   r7   r;   r=   rQ   
contextlibcontextmanagerrI   r2   r]   re   rp   rr   rw   r|   rR   r   r   r   r      sy       
 
3 3 3 3 H%B %B %B %BN      
] 
] 
] 
]Y Y Y YB  %'            S S S S S$3 3 3 3"1 1 1 1/ / / /. . . . . .r   r   )r   
__future__r   r   r#   r,   typingr   r   collections.abcr   r   coverage.debugr   r	   r
   coverage.exceptionsr   coverage.typesr   r   rR   r   r   <module>r      s    ) ( " " " " " "     				          . . . . . . . . @ @ @ @ @ @ @ @ @ @ ) ) ) ) ) ) $ $ $ $ $ $S. S. S. S. S. S. S. S. S. S.r   