o
    3g-                     @  sp  d dl mZ ddlmZ ee d dl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	lmZmZmZmZmZ dd
lmZ ddlmZ dBddZdCddZeejejgef Zdd Zeeed f Ze
ddddDd!d"Z dBd#d$Z!edEd*d+Z"edFd.d+Z"edGd1d+Z"edHd4d+Z"edId7d+Z"edJd:d+Z"edKd=d+Z"edLd@d+Z"dAd+ Z"dS )M    )annotations   )assert_subpackageN)Iterator)contextmanager)Path)TemporaryDirectory)AnyCallableLiteralUnionoverload)PathIsh)assert_neverdbr   returnsqlite3.Connectionc                 C  s   t jd|  dddS )Nfile:?immutable=1Turi)sqlite3connect)r    r   (/home/garg/my-data/HPI/my/core/sqlite.pysqlite_connect_immutable   s   r   tmp_pathr   Nonec              	   C  s   t | d }t|}|d W d    n1 sw   Y  dd l}|jtjdd! t|}|d W d    n1 sAw   Y  W d    n1 sPw   Y  t|}|d W d    d S 1 skw   Y  d S )Nz	db.sqlitezCREATE TABLE testtable (col)r   zreadonly database)matchzDROP TABLE testtable)strr   r   executepytestraisesOperationalErrorr   )r   r   connr!   r   r   r   test_sqlite_connect_immutable   s   
"r%   c                 C  s   dd | j D }tt||S )Nc                 S  s   g | ]}|d  qS )r   r   ).0columnr   r   r   
<listcomp>+   s    z dict_factory.<locals>.<listcomp>)descriptiondictzip)cursorrowfieldsr   r   r   dict_factory*   s   r/   )r-   r*   F)	immutablerow_factoryr0   boolr1   Factory | NoneIterator[sqlite3.Connection]c                c  s    d|  }|rt |  sJ | | d}d }|d ur6t|r$|}n|dkr,tj}n
|dkr3t}nt  tj|dd}z&||_| |V  W d    n1 sQw   Y  W |	  d S W |	  d S |	  w )Nr   r   r-   r*   Tr   )
r   existscallabler   Rowr/   r   r   r1   close)r   r0   r1   dbprow_factory_r$   r   r   r   sqlite_connection2   s.   

r;   c              	   C  s   t | }td}t P}t |}|gdd |j|jd D  }|D ]}t|||j  q$tt	||j }|j
|d W d   n1 sKw   Y  |  W d   |S 1 s_w   Y  |S )z`
    'Snapshots' database and opens by making a deep copy of it including journal/WAL files
    z:memory:c                 S  s   g | ]
}|j d s|qS )z-shm)nameendswith)r&   pr   r   r   r(   [   s    z(sqlite_copy_and_open.<locals>.<listcomp>z-*)targetN)r   r   r   r   parentglobr<   shutilcopyr   backupr8   )r   dpdesttdtdirtocopyr>   r$   r   r   r   sqlite_copy_and_openQ   s   
"

		rJ   cols
tuple[str]restr   Iterator[tuple[Any]]c                C     d S Nr   rK   rM   r   r   r   r   selectl      rR   tuple[str, str]Iterator[tuple[Any, Any]]c                C  rO   rP   r   rQ   r   r   r   rR   o   rS   tuple[str, str, str]Iterator[tuple[Any, Any, Any]]c                C  rO   rP   r   rQ   r   r   r   rR   r   rS   tuple[str, str, str, str]#Iterator[tuple[Any, Any, Any, Any]]c                C  rO   rP   r   rQ   r   r   r   rR   u   rS   tuple[str, str, str, str, str](Iterator[tuple[Any, Any, Any, Any, Any]]c                C  rO   rP   r   rQ   r   r   r   rR   x   rS   #tuple[str, str, str, str, str, str]-Iterator[tuple[Any, Any, Any, Any, Any, Any]]c                C  rO   rP   r   rQ   r   r   r   rR   {   rS   (tuple[str, str, str, str, str, str, str]2Iterator[tuple[Any, Any, Any, Any, Any, Any, Any]]c                C  rO   rP   r   rQ   r   r   r   rR   ~   rS   -tuple[str, str, str, str, str, str, str, str]7Iterator[tuple[Any, Any, Any, Any, Any, Any, Any, Any]]c                C  rO   rP   r   rQ   r   r   r   rR      rS   c                C  s   | dd|  d | S )NzSELECT , )r    joinrQ   r   r   r   rR      s   )r   r   r   r   )r   r   r   r   )r   r   r0   r2   r1   r3   r   r4   )rK   rL   rM   r   r   r   r   rN   )rK   rT   rM   r   r   r   r   rU   )rK   rV   rM   r   r   r   r   rW   )rK   rX   rM   r   r   r   r   rY   )rK   rZ   rM   r   r   r   r   r[   )rK   r\   rM   r   r   r   r   r]   )rK   r^   rM   r   r   r   r   r_   )rK   r`   rM   r   r   r   r   ra   )#
__future__r   internalr   __name__rB   r   collections.abcr   
contextlibr   pathlibr   tempfiler   typingr	   r
   r   r   r   commonr   compatr   r   r%   Cursorr7   SqliteRowFactoryr/   Factoryr;   rJ   rR   r   r   r   r   <module>   sJ    


