
    zio$                        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)IterableIterator)Anycast)	auto_reprclipped_reprexc_one_line)	DataError)	TDebugCtlc                      e Zd ZdZd'd(dZeZd)dZd'd*dZd+dZ	d)dZ
d,dZej        	 d-d.d            Zd/d0dZd-d1dZd-d2dZd3d!Zd4d"Zd5d$Zd6d%Zd&S )7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)

    Ffilenamestrdebugr   no_diskboolreturnNonec                L    || _         || _        || _        d| _        d | _        d S )Nr   )r   r   r   nestcon)selfr   r   r   s       \/var/www/tmov.alphamb/tmov_inventario/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                   	 | j                            d          r"t          j        | j        dd          | _         n 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 zfile:FT)check_same_threaduri)r   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>A   s    ryc?R?RZ^?^ r   SQLITE_DBCONFIG_DEFENSIVEzpragma journal_mode=offzpragma synchronous=off)fail_ok)r   r   shouldwriter   
startswithsqlite3connectErrorr   create_functionhasattr	setconfigr+   execute_void)r   excs     r   _connectzSqliteDb._connect)   s   8F :U## 	AJ?dm??@@@	Y}''00 S"?4=EW[\\\"?4=ERRR} 	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1   	3444
 	2DAAAAAs   AB$ $C3CCforcec                    | j         o|s| j        sh| j                            d          r*| j                            d| j         d| j                   | j                                          d| _         dS dS dS )z If needed, close the connection.Nr   zClosing z on )r   r   r   r-   r.   r   close)r   r9   s     r   r;   zSqliteDb.closeU   s    8  DL  :$$U++ SJ$$%Q%Q%Q%Q%QRRR        r   c                    | j         dk    r6|                                  | j        J | j                                         | xj         dz  c_         | S )Nr      )r   r8   r   	__enter__r   s    r   r>   zSqliteDb.__enter__^   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__r;   	Exceptionr   r-   r.   r
   r   r   )r   exc_type	exc_value	tracebackr7   s        r   rA   zSqliteDb.__exit__f   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                2   | 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        $ rs}t          |          }| 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 NzEXCEPTION from execute: r!   r"   )r   r-   r.   r   executerB   r0   r2   r   r
   r   r   )r   r   rF   tailr7   msgs         r   _executezSqliteDb._executer   sX   :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z  '' Q
  !OL<M<M!O!OPPPNdmNNNNOOUXX		Ys7   	B A) )%BB BB D#A.DD 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)rO   r;   )r   r   rF   curs       r   rL   zSqliteDb.execute   sL       mmC,,	IIIIIKKKKKCIIKKKKs	   4 A
r,   c                    	 |                      ||                                           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)rO   r;   r   )r   r   rF   r,   s       r   r6   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: )rL   	lastrowidr   r-   r.   )r   r   rF   rS   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)rL   listlenr   tupler   AssertionError)r   r   rF   rS   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   rW   :rK   zExecuting many rJ   r]   4dr"   )r   r-   r.   r_   	enumerater   executemanyrB   )r   r   rd   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                V    |                      ||                                           dS )zUSame as :meth:`python:sqlite3.Connection.executemany` when you don't need the cursor.N)rn   r;   )r   r   rd   s      r   executemany_voidzSqliteDb.executemany_void   s*    #t$$**,,,,,r   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.   formatr_   r	   r   executescriptr;   )r   rq   s     r   ru   zSqliteDb.executescript   s    :U## 	J4;;KK --    x###v&&,,.....r   c                l    | j         J d                    | j                                                   S )z9Return a multi-line string, the SQL dump of the database.N
)r   joiniterdumpr?   s    r   dumpzSqliteDb.dump   s0    x###yy**,,---r   N)F)r   r   r   r   r   r   r   r   )r   r   )r9   r   r   r   )r   r   )r   r   rF   rG   r   rH   )rP   )r   r   rF   rG   r   rQ   )rP   F)r   r   rF   rG   r,   r   r   r   )r   r   rF   rG   r   rU   )r   r   rF   rG   r   r[   )r   r   rd   re   r   rH   )r   r   rd   re   r   r   )rq   r   r   r   )r   r   )__name__
__module____qualname____doc__r   r   __repr__r8   r;   r>   rA   rO   
contextlibcontextmanagerrL   r6   rZ   rc   rn   rp   ru   rz   rP   r   r   r   r      s       
 
3 3 3 3 3 H*B *B *B *BX            
] 
] 
] 
]Y Y Y Y(  %'            S S S S S$3 3 3 3"- - - -
/ 
/ 
/ 
/. . . . . .r   r   )r~   
__future__r   r   r&   r0   collections.abcr   r   typingr   r   coverage.debugr   r	   r
   coverage.exceptionsr   coverage.typesr   r   rP   r   r   <module>r      s    ) ( " " " " " "     				  . . . . . . . .         @ @ @ @ @ @ @ @ @ @ ) ) ) ) ) ) $ $ $ $ $ $O. O. O. O. O. O. O. O. O. O.r   