
    Bh9                    .   S r SSKJr  SSKrSSKJr  SSKJr  SSKJ	r	  SSK
Jr  SSK
Jr  SS	K
Jr  SS
K
Jr  SSK
Jr  SSK
Jr  SSK
Jr  SSK
Jr  SSK
Jr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJ r   SSKJ!r!  \(       a<  SSKJ"r"  SSKJ#r#  SSK$J%r%  SSK$J&r&  SSK$J'r'  SSK$J(r(  SS K$J)r)  SS!K$J*r*  SS"K+J,r,  SS#K-J.r.   " S$ S%5      r/ " S& S'\/5      r0 " S( S)\5      r1 " S* S+\15      r2 " S, S-\5      r3 " S. S/\5      r4 " S0 S1\5      r5\5r6g)2a	  

.. dialect:: sqlite+aiosqlite
    :name: aiosqlite
    :dbapi: aiosqlite
    :connectstring: sqlite+aiosqlite:///file_path
    :url: https://pypi.org/project/aiosqlite/

The aiosqlite dialect provides support for the SQLAlchemy asyncio interface
running on top of pysqlite.

aiosqlite is a wrapper around pysqlite that uses a background thread for
each connection.   It does not actually use non-blocking IO, as SQLite
databases are not socket-based.  However it does provide a working asyncio
interface that's useful for testing and prototyping purposes.

Using a special asyncio mediation layer, the aiosqlite dialect is usable
as the backend for the :ref:`SQLAlchemy asyncio <asyncio_toplevel>`
extension package.

This dialect should normally be used only with the
:func:`_asyncio.create_async_engine` engine creation function::

    from sqlalchemy.ext.asyncio import create_async_engine

    engine = create_async_engine("sqlite+aiosqlite:///filename")

The URL passes through all arguments to the ``pysqlite`` driver, so all
connection arguments are the same as they are for that of :ref:`pysqlite`.

.. _aiosqlite_udfs:

User-Defined Functions
----------------------

aiosqlite extends pysqlite to support async, so we can create our own user-defined functions (UDFs)
in Python and use them directly in SQLite queries as described here: :ref:`pysqlite_udfs`.

.. _aiosqlite_serializable:

Serializable isolation / Savepoints / Transactional DDL (asyncio version)
-------------------------------------------------------------------------

A newly revised version of this important section is now available
at the top level of the SQLAlchemy SQLite documentation, in the section
:ref:`sqlite_transactions`.


.. _aiosqlite_pooling:

Pooling Behavior
----------------

The SQLAlchemy ``aiosqlite`` DBAPI establishes the connection pool differently
based on the kind of SQLite database that's requested:

* When a ``:memory:`` SQLite database is specified, the dialect by default
  will use :class:`.StaticPool`. This pool maintains a single
  connection, so that all access to the engine
  use the same ``:memory:`` database.
* When a file-based database is specified, the dialect will use
  :class:`.AsyncAdaptedQueuePool` as the source of connections.

  .. versionchanged:: 2.0.38

    SQLite file database engines now use :class:`.AsyncAdaptedQueuePool` by default.
    Previously, :class:`.NullPool` were used.  The :class:`.NullPool` class
    may be used by specifying it via the
    :paramref:`_sa.create_engine.poolclass` parameter.

    )annotationsN)deque)partial)
ModuleType)Any)cast)Deque)Iterator)NoReturn)Optional)Sequence)TYPE_CHECKING)Union   )SQLiteExecutionContext)SQLiteDialect_pysqlite   )pool)util)AsyncAdapt_dbapi_module)AdaptedConnection)await_fallback)
await_only)AsyncIODBAPIConnection)AsyncIODBAPICursor)_DBAPICursorDescription)_DBAPIMultiExecuteParams)_DBAPISingleExecuteParams)DBAPIConnection)DBAPICursor)DBAPIModule)URL)PoolProxiedConnectionc                      \ rS rSrSrSrSS jrSS jr S     SS jjr      SS jr	SS	 jr
SS
 jrSS jrSSS jjrSS jrSrg)AsyncAdapt_aiosqlite_cursorv   )_adapt_connection_connectiondescriptionawait__rows	arraysizerowcount	lastrowidFc                    Xl         UR                  U l        UR                  U l        SU l        SU l        S U l        [        5       U l        g )Nr   )r'   r(   r*   r,   r-   r)   r   r+   )selfadapt_connections     g/home/kali/devsecops-assessor/venv/lib/python3.13/site-packages/sqlalchemy/dialects/sqlite/aiosqlite.py__init__$AsyncAdapt_aiosqlite_cursor.__init__   sB    !1+77&-->B!&
    c                8    U R                   R                  5         g N)r+   clearr1   s    r3   close!AsyncAdapt_aiosqlite_cursor.close   s    

r6   Nc                    U R                  U R                  R                  5       5      nUc!  U R                  UR                  U5      5        O U R                  UR                  X5      5        UR                  (       a^  UR                  U l        S=U l        U l        U R                  (       d-  [        U R                  UR                  5       5      5      U l
        O)S U l        UR
                  U l        UR                  U l        U R                  (       d   U R                  UR                  5       5        g X0l        g ! [         a%  nU R                  R                  U5         S nAg S nAff = f)Nr0   )r*   r(   cursorexecuter)   r.   r-   server_sider   fetchallr+   r;   _cursor	Exceptionr'   _handle_exception)r1   	operation
parametersrB   errors        r3   r?   #AsyncAdapt_aiosqlite_cursor.execute   s
   	<*.++d6F6F6M6M6O*PG!GOOI67GOOIBC""#*#6#6 133''!&t{{73C3C3E'F!GDJ#' !(!2!2 ' 0 0##GMMO,& 	<""44U;;	<s   D5D? 8D? ?
E.	E))E.c                    U R                  U R                  R                  5       5      nU R                  UR                  X5      5        S U l        UR
                  U l        UR                  U l        U R                  UR                  5       5        g ! [         a%  nU R                  R                  U5         S nAg S nAff = fr8   )r*   r(   r>   executemanyr)   r.   r-   r;   rC   r'   rD   )r1   rE   seq_of_parametersrB   rG   s        r3   rJ   'AsyncAdapt_aiosqlite_cursor.executemany   s    
	<*.++d6F6F6M6M6O*PGKK++IIJ#D$..DN#,,DMKK( 	<""44U;;	<s   BB 
CB>>Cc                    g r8    )r1   
inputsizess     r3   setinputsizes)AsyncAdapt_aiosqlite_cursor.setinputsizes   s    r6   c              #     #    U R                   (       a0  U R                   R                  5       v   U R                   (       a  M/  g g 7fr8   r+   popleftr:   s    r3   __iter__$AsyncAdapt_aiosqlite_cursor.__iter__   s*     jj**$$&& jjjs   ?AAc                Z    U R                   (       a  U R                   R                  5       $ g r8   rS   r:   s    r3   fetchone$AsyncAdapt_aiosqlite_cursor.fetchone   s    ::::%%''r6   c                    Uc  U R                   nU R                  n[        [        U[	        U5      5      5       Vs/ s H  o2R                  5       PM     sn$ s  snf r8   )r,   r+   rangeminlenrT   )r1   sizerr_s       r3   	fetchmany%AsyncAdapt_aiosqlite_cursor.fetchmany   sG    <>>DZZ&+Cc"g,>&?@&?

&?@@@s   Ac                d    [        U R                  5      nU R                  R                  5         U$ r8   )listr+   r9   )r1   retvals     r3   rA   $AsyncAdapt_aiosqlite_cursor.fetchall   s%    djj!

r6   )	r'   r(   rB   r+   r,   r*   r)   r.   r-   )r2   AsyncAdapt_aiosqlite_connectionreturnNoner8   )rE   r   rF   z#Optional[_DBAPISingleExecuteParams]ri   r   )rE   r   rK   r   ri   r   )rO   r   ri   rj   )ri   zIterator[Any]ri   zOptional[Any]r^   zOptional[int]ri   Sequence[Any]ri   rm   )__name__
__module____qualname____firstlineno__	__slots__r@   r4   r;   r?   rJ   rP   rU   rX   ra   rA   __static_attributes__rN   r6   r3   r%   r%   v   s|    	I K) ;?<< 8< 
	<@<< 4< 
	<'Ar6   r%   c                  `   ^  \ rS rSrSrSrS
U 4S jjrSS jrSS jrSSS jjr	SS jr
S	rU =r$ )AsyncAdapt_aiosqlite_ss_cursor   rB   Tc                4   > [         TU ]  " U0 UD6  S U l        g r8   )superr4   rB   )r1   argkw	__class__s      r3   r4   'AsyncAdapt_aiosqlite_ss_cursor.__init__   s    #$$59r6   c                    U R                   b1  U R                  U R                   R                  5       5        S U l         g g r8   )rB   r*   r;   r:   s    r3   r;   $AsyncAdapt_aiosqlite_ss_cursor.close   s1    <<#KK**,-DL $r6   c                r    U R                   c   eU R                  U R                   R                  5       5      $ r8   )rB   r*   rX   r:   s    r3   rX   'AsyncAdapt_aiosqlite_ss_cursor.fetchone   .    ||'''{{4<<00233r6   c                    U R                   c   eUc  U R                  nU R                  U R                   R                  US95      $ )N)r^   )rB   r,   r*   ra   )r1   r^   s     r3   ra   (AsyncAdapt_aiosqlite_ss_cursor.fetchmany   sA    ||'''<>>D{{4<<11t1<==r6   c                r    U R                   c   eU R                  U R                   R                  5       5      $ r8   )rB   r*   rA   r:   s    r3   rA   'AsyncAdapt_aiosqlite_ss_cursor.fetchall   r   r6   )rB   )rz   r   r{   r   ri   rj   rh   rk   r8   rl   rn   )ro   rp   rq   rr   rs   r@   r4   r;   rX   ra   rA   rt   __classcell__r|   s   @r3   rv   rv      s-     IK: 
4>4 4r6   rv   c                      \ rS rSr\" \5      rSrSS jr\	SS j5       r
\
R                  SS j5       r
SS jrSSS jjrSS jrSS	 jrSS
 jrSS jrSS jrSrg)rg      dbapic                    Xl         X l        g r8   )r   r(   )r1   r   
connections      r3   r4   (AsyncAdapt_aiosqlite_connection.__init__   s    
%r6   c                J    [        [        U R                  R                  5      $ r8   )r   strr(   isolation_levelr:   s    r3   r   /AsyncAdapt_aiosqlite_connection.isolation_level  s    C))99::r6   c                `         SS jn[        X R                  R                  U5      n[        R                  " 5       R                  5       nU R                  R                  R                  XC45         U R                  U5        g ! [         a  nU R                  U5         S nAg S nAff = f)Nc                    Xl         g r8   )r   )r   values     r3   set_iso@AsyncAdapt_aiosqlite_connection.isolation_level.<locals>.set_iso  s
     */&r6   )r   rg   r   Optional[str]ri   rj   )r   r(   _connasyncioget_event_loopcreate_future_tx
put_nowaitr*   rC   rD   )r1   r   r   functionfuturerG   s         r3   r   r     s    	/7	/@M	/	/
 7$4$4$:$:EB'')779''(:;	*KK 	*""5))	*s   6B 
B-B((B-c                     U R                  U R                  R                  " U0 UD65        g ! [         a  nU R	                  U5         S nAg S nAff = fr8   )r*   r(   create_functionrC   rD   )r1   argsr{   rG   s       r3   r   /AsyncAdapt_aiosqlite_connection.create_function  sJ    	*KK((88$E"EF 	*""5))	*s   +. 
AAAc                <    U(       a  [        U 5      $ [        U 5      $ r8   )rv   r%   )r1   r@   s     r3   r>   &AsyncAdapt_aiosqlite_connection.cursor#  s    1$77.t44r6   c                X    U R                  U R                  R                  " U0 UD65      $ r8   )r*   r(   r?   )r1   r   r{   s      r3   r?   'AsyncAdapt_aiosqlite_connection.execute)  s'    {{4++33T@R@AAr6   c                     U R                  U R                  R                  5       5        g ! [         a  nU R	                  U5         S nAg S nAff = fr8   )r*   r(   rollbackrC   rD   r1   rG   s     r3   r   (AsyncAdapt_aiosqlite_connection.rollback,  sC    	*KK((1134 	*""5))	*   ), 
AAAc                     U R                  U R                  R                  5       5        g ! [         a  nU R	                  U5         S nAg S nAff = fr8   )r*   r(   commitrC   rD   r   s     r3   r   &AsyncAdapt_aiosqlite_connection.commit2  sC    	*KK((//12 	*""5))	*r   c                     U R                  U R                  R                  5       5        g ! [         a     g [         a  nU R                  U5         S nAg S nAff = fr8   )r*   r(   r;   
ValueErrorrC   rD   r   s     r3   r;   %AsyncAdapt_aiosqlite_connection.close8  sP    	*KK((..01 		  	*""5))	*s   ), 
A	AAAc                    [        U[        5      (       a9  UR                  S   S:X  a&  U R                  R                  R                  S5      UeUe)Nr   no active connection)
isinstancer   r   r   sqliteOperationalErrorr   s     r3   rD   1AsyncAdapt_aiosqlite_connection._handle_exceptionH  sJ    uj))

1!77**##44& Kr6   )r(   r   N)r   r   r   r   ri   rj   )ri   r   )r   r   ri   rj   )r   r   r{   r   ri   rj   )F)r@   boolri   r%   )r   r   r{   r   ri   r   rh   )rG   rC   ri   r   )ro   rp   rq   rr   staticmethodr   r*   rs   r4   propertyr   setterr   r>   r?   r   r   r;   rD   rt   rN   r6   r3   rg   rg      sh    *%FI& ; ; * ***5B*** 	r6   rg   c                  (    \ rS rSrSr\" \5      rSrg)'AsyncAdaptFallback_aiosqlite_connectioniT  rN   N)	ro   rp   rq   rr   rs   r   r   r*   rt   rN   r6   r3   r   r   T  s    I.)Fr6   r   c                  2    \ rS rSrSS jrSS jrS	S jrSrg)
AsyncAdapt_aiosqlite_dbapiiZ  c                J    Xl         X l        SU l        U R                  5         g )Nqmark)	aiosqliter   
paramstyle_init_dbapi_attributes)r1   r   r   s      r3   r4   #AsyncAdapt_aiosqlite_dbapi.__init__[  s    "!##%r6   c           	         S H#  n[        X[        U R                  U5      5        M%     S H#  n[        X[        U R                  U5      5        M%     S H#  n[        X[        U R                  U5      5        M%     g )N)DatabaseErrorErrorIntegrityErrorNotSupportedErrorr   ProgrammingErrorsqlite_versionsqlite_version_info)PARSE_COLNAMESPARSE_DECLTYPES)Binary)setattrgetattrr   r   )r1   names     r3   r   1AsyncAdapt_aiosqlite_dbapi._init_dbapi_attributesa  sg    	
D D =>	
 :DDT :; :  DDT :;  r6   c                :   UR                  SS5      nUR                  SS 5      nU(       a	  U" U0 UD6nO#U R                  R                  " U0 UD6nSUl        [        R
                  " U5      (       a  [        U [        U5      5      $ [        U [        U5      5      $ )Nasync_fallbackFasync_creator_fnT)
popr   connectdaemonr   asboolr   r   rg   r   )r1   rz   r{   r   
creator_fnr   s         r3   r   "AsyncAdapt_aiosqlite_dbapi.connectt  s     0%8VV.5
#S/B/J//;;J $J;;~&&:z* 
 3:& r6   )r   r   r   N)r   r   r   r   rh   )rz   r   r{   r   ri   rg   )ro   rp   rq   rr   r4   r   r   rt   rN   r6   r3   r   r   Z  s    &<&r6   r   c                      \ rS rSrSS jrSrg) SQLiteExecutionContext_aiosqlitei  c                4    U R                   R                  SS9$ )NT)r@   )_dbapi_connectionr>   r:   s    r3   create_server_side_cursor:SQLiteExecutionContext_aiosqlite.create_server_side_cursor  s    %%,,,>>r6   rN   N)ri   r    )ro   rp   rq   rr   r   rt   rN   r6   r3   r   r     s    ?r6   r   c                     ^  \ rS rSrSrSrSrSr\r	\
S	S j5       r\
S
S j5       r        SU 4S jjr    SS jrSrU =r$ )SQLiteDialect_aiosqlitei  r   Tc                >    [        [        S5      [        S5      5      $ )Nr   sqlite3)r   
__import__)clss    r3   import_dbapi$SQLiteDialect_aiosqlite.import_dbapi  s    ){#Z	%:
 	
r6   c                n    U R                  U5      (       a  [        R                  $ [        R                  $ r8   )_is_url_file_dbr   AsyncAdaptedQueuePool
StaticPool)r   urls     r3   get_pool_class&SQLiteDialect_aiosqlite.get_pool_class  s)    s##---??"r6   c                   > [        SU R                  5      U l        [        XR                  R                  5      (       a  S[	        U5      ;   a  g[
        TU ]  XU5      $ )Nr!   r   T)r   r   r   r   r   ry   is_disconnect)r1   er   r>   r|   s       r3   r   %SQLiteDialect_aiosqlite.is_disconnect  sR     -4
zz**
 
$A.w$QF;;r6   c                    UR                   $ r8   )r(   )r1   r   s     r3   get_driver_connection-SQLiteDialect_aiosqlite.get_driver_connection  s     %%%r6   r   )ri   r   )r   r"   ri   ztype[pool.Pool])r   zDBAPIModule.Errorr   z7Optional[Union[PoolProxiedConnection, DBAPIConnection]]r>   zOptional[DBAPICursor]ri   r   )r   r   ri   r   )ro   rp   rq   rr   driversupports_statement_cacheis_asyncsupports_server_side_cursorsr   execution_ctx_clsclassmethodr   r   r   r   rt   r   r   s   @r3   r   r     s    F#H#' 8
 

 # #<< L< &	<
 
<&)&	& &r6   r   )7__doc__
__future__r   r   collectionsr   	functoolsr   typesr   typingr   r   r	   r
   r   r   r   r   r   baser   pysqliter    r   r   connectors.asyncior   enginer   util.concurrencyr   r   r   r   engine.interfacesr   r   r   r   r    r!   
engine.urlr"   	pool.baser#   r%   rv   rg   r   r   r   r   dialectrN   r6   r3   <module>r     s   FN #               ( ,   9 ' . *<8<=>400!2c cL4%@ 4>V&7 Vr*.M *.!8 .b?'= ?
(&4 (&V "r6   