
    Ki>                    H   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!  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%K0J1r1   " S& S'5      r2 " S( S)\25      r3 " S* S+\\!5      r4 " S, S-\45      r5 " S. S/\5      r6 " S0 S1\5      r7 " S2 S3\5      r8\8r9g)4a	  

.. 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)Thread)
ModuleType)Any)cast)Deque)Iterator)NoReturn)Optional)Sequence)TYPE_CHECKING)Union   )SQLiteExecutionContext)SQLiteDialect_pysqlite   )pool)util)AsyncAdapt_dbapi_module)AsyncAdapt_terminate)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 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_cursorx   )_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     f/var/www/html/dynamic-report/venv/lib/python3.13/site-packages/sqlalchemy/dialects/sqlite/aiosqlite.py__init__$AsyncAdapt_aiosqlite_cursor.__init__   sB    !1+77&-->B!&
    c                   #    g 7fN r3   s    r5   _async_soft_close-AsyncAdapt_aiosqlite_cursor._async_soft_close   s     s   c                8    U R                   R                  5         g r:   )r-   clearr<   s    r5   close!AsyncAdapt_aiosqlite_cursor.close   s    

r8   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)Nr2   )r,   r*   cursorexecuter+   r0   r/   server_sider   fetchallr-   rA   _cursor	Exceptionr)   _handle_exception)r3   	operation
parametersrH   errors        r5   rE   #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r:   )r,   r*   rD   executemanyr+   r0   r/   rA   rI   r)   rJ   )r3   rK   seq_of_parametersrH   rM   s        r5   rP   '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 r:   r;   )r3   
inputsizess     r5   setinputsizes)AsyncAdapt_aiosqlite_cursor.setinputsizes   s    r8   c              #     #    U R                   (       a0  U R                   R                  5       v   U R                   (       a  M/  g g 7fr:   r-   popleftr<   s    r5   __iter__$AsyncAdapt_aiosqlite_cursor.__iter__   s*     jj**$$&& jjjs   ?AAc                Z    U R                   (       a  U R                   R                  5       $ g r:   rX   r<   s    r5   fetchone$AsyncAdapt_aiosqlite_cursor.fetchone   s    ::::%%''r8   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 r:   )r.   r-   rangeminlenrY   )r3   sizerr_s       r5   	fetchmany%AsyncAdapt_aiosqlite_cursor.fetchmany   sG    <>>DZZ&+Cc"g,>&?@&?

&?@@@s   Ac                d    [        U R                  5      nU R                  R                  5         U$ r:   )listr-   r@   )r3   retvals     r5   rG   $AsyncAdapt_aiosqlite_cursor.fetchall   s%    djj!

r8   )	r)   r*   rH   r-   r.   r,   r+   r0   r/   )r4   AsyncAdapt_aiosqlite_connectionreturnNoner:   )rK   r   rL   z#Optional[_DBAPISingleExecuteParams]rn   r   )rK   r   rQ   r   rn   r   )rT   r   rn   ro   )rn   zIterator[Any]rn   zOptional[Any]rc   zOptional[int]rn   Sequence[Any]rn   rr   )__name__
__module____qualname____firstlineno__	__slots__rF   r6   r=   rA   rE   rP   rU   rZ   r]   rf   rG   __static_attributes__r;   r8   r5   r'   r'   x   s    	I K) ;?<< 8< 
	<@<< 4< 
	<'Ar8   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   rH   Tc                4   > [         TU ]  " U0 UD6  S U l        g r:   )superr6   rH   )r3   argkw	__class__s      r5   r6   'AsyncAdapt_aiosqlite_ss_cursor.__init__   s    #$$59r8   c                    U R                   b1  U R                  U R                   R                  5       5        S U l         g g r:   )rH   r,   rA   r<   s    r5   rA   $AsyncAdapt_aiosqlite_ss_cursor.close   s1    <<#KK**,-DL $r8   c                r    U R                   c   eU R                  U R                   R                  5       5      $ r:   )rH   r,   r]   r<   s    r5   r]   'AsyncAdapt_aiosqlite_ss_cursor.fetchone   .    ||'''{{4<<00233r8   c                    U R                   c   eUc  U R                  nU R                  U R                   R                  US95      $ )N)rc   )rH   r.   r,   rf   )r3   rc   s     r5   rf   (AsyncAdapt_aiosqlite_ss_cursor.fetchmany   sA    ||'''<>>D{{4<<11t1<==r8   c                r    U R                   c   eU R                  U R                   R                  5       5      $ r:   )rH   r,   rG   r<   s    r5   rG   'AsyncAdapt_aiosqlite_ss_cursor.fetchall   r   r8   )rH   )r   r   r   r   rn   ro   rm   rp   r:   rq   rs   )rt   ru   rv   rw   rx   rF   r6   rA   r]   rf   rG   ry   __classcell__r   s   @r5   r{   r{      s-     IK: 
4>4 4r8   r{   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S jrSS jrSrg)rl      )dbapic                    Xl         X l        g r:   )r   r*   )r3   r   
connections      r5   r6   (AsyncAdapt_aiosqlite_connection.__init__  s    
%r8   c                J    [        [        U R                  R                  5      $ r:   )r	   strr*   isolation_levelr<   s    r5   r   /AsyncAdapt_aiosqlite_connection.isolation_level  s    C))99::r8   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 r:   )r   )r   values     r5   set_iso@AsyncAdapt_aiosqlite_connection.isolation_level.<locals>.set_iso  s
     */&r8   )r   rl   r   Optional[str]rn   ro   )r   r*   _connasyncioget_event_loopcreate_future_tx
put_nowaitr,   rI   rJ   )r3   r   r   functionfuturerM   s         r5   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r:   )r,   r*   create_functionrI   rJ   )r3   argsr   rM   s       r5   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      $ r:   )r{   r'   )r3   rF   s     r5   rD   &AsyncAdapt_aiosqlite_connection.cursor(  s    1$77.t44r8   c                X    U R                  U R                  R                  " U0 UD65      $ r:   )r,   r*   rE   )r3   r   r   s      r5   rE   'AsyncAdapt_aiosqlite_connection.execute.  s'    {{4++33T@R@AAr8   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r:   )r,   r*   rollbackrI   rJ   r3   rM   s     r5   r   (AsyncAdapt_aiosqlite_connection.rollback1  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r:   )r,   r*   commitrI   rJ   r   s     r5   r   &AsyncAdapt_aiosqlite_connection.commit7  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r:   )r,   r*   rA   
ValueErrorrI   rJ   r   s     r5   rA   %AsyncAdapt_aiosqlite_connection.close=  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     r5   rJ   1AsyncAdapt_aiosqlite_connection._handle_exceptionM  sJ    uj))

1!77**##44& Kr8   c                T   #    U R                   R                  5       I Sh  vN   g N7f)z"Try to close connection gracefullyN)r*   rA   r<   s    r5   _terminate_graceful_close9AsyncAdapt_aiosqlite_connection._terminate_graceful_closeX  s     $$&&&s   (&(c                |     U R                   R                  nU" 5         g! [         a  n[        S5      UeSnAff = f)zTerminate the connectionz:terminate_force_close() not implemented by this DBAPI shimN)r*   stopAttributeErrorNotImplementedError)r3   methaes      r5   _terminate_force_close6AsyncAdapt_aiosqlite_connection._terminate_force_close\  sD    
	##((D F  	%L	s     
;6;)r*   r   N)r   r   r   r   rn   ro   )rn   r   )r   r   rn   ro   )r   r   r   r   rn   ro   )F)rF   boolrn   r'   )r   r   r   r   rn   r   rm   )rM   rI   rn   r   )rt   ru   rv   rw   staticmethodr   r,   rx   r6   propertyr   setterr   rD   rE   r   r   rA   rJ   r   r   ry   r;   r8   r5   rl   rl      sr    *%FI& ; ; * ***5B*** 	'r8   rl   c                  (    \ rS rSrSr\" \5      rSrg)'AsyncAdaptFallback_aiosqlite_connectionik  r;   N)	rt   ru   rv   rw   rx   r   r   r,   ry   r;   r8   r5   r   r   k  s    I.)Fr8   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_dbapiiq  c                    Xl         X l        SU l        [        UR                  S5      U l        U R                  5         g )Nqmarkr   )	aiosqliter   
paramstylehasattr
Connectionhas_stop_init_dbapi_attributes)r3   r   r   s      r5   r6   #AsyncAdapt_aiosqlite_dbapi.__init__r  s3    "!	 4 4f=##%r8   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   )r3   names     r5   r   1AsyncAdapt_aiosqlite_dbapi._init_dbapi_attributesy  sg    	
D D =>	
 :DDT :; :  DDT :;  r8   c                   UR                  SS5      nUR                  SS 5      nU(       a	  U" U0 UD6nOJU R                  R                  " U0 UD6n[        U[        5      (       a  SUl        OSUR                  l        [        R                  " U5      (       a  [        U [        U5      5      $ [        U [        U5      5      $ )Nasync_fallbackFasync_creator_fnT)popr   connectr   r   daemon_threadr   asboolr   r   rl   r   )r3   r   r   r   
creator_fnr   s         r5   r   "AsyncAdapt_aiosqlite_dbapi.connect  s     0%8VV.5
#S/B/J//;;J *f--$(
! -1
"");;~&&:z* 
 3:& r8   )r   r   r   r   N)r   r   r   r   rm   )r   r   r   r   rn   rl   )rt   ru   rv   rw   r6   r   r   ry   r;   r8   r5   r   r   q  s    &<&r8   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)rF   )_dbapi_connectionrD   r<   s    r5   create_server_side_cursor:SQLiteExecutionContext_aiosqlite.create_server_side_cursor  s    %%,,,>>r8   r;   N)rn   r"   )rt   ru   rv   rw   r   ry   r;   r8   r5   r   r     s    ?r8   r   c                     ^  \ rS rSrSrSrSrSrSr\	r
SU 4S jjr\SS j5       r\SS j5       r        SU 4S jjr    SS jrSS	 jrS
rU =r$ )SQLiteDialect_aiosqlitei  r   Tc                   > [         TU ]  " S0 UD6  U R                  (       a$  U R                  R                  (       d  SU l        g g g )NFr;   )r~   r6   r   r   has_terminate)r3   kwargsr   s     r5   r6    SQLiteDialect_aiosqlite.__init__  s5    "6"::djj11!&D 2:r8   c                >    [        [        S5      [        S5      5      $ )Nr   sqlite3)r   
__import__)clss    r5   import_dbapi$SQLiteDialect_aiosqlite.import_dbapi  s    ){#Z	%:
 	
r8   c                n    U R                  U5      (       a  [        R                  $ [        R                  $ r:   )_is_url_file_dbr   AsyncAdaptedQueuePool
StaticPool)r  urls     r5   get_pool_class&SQLiteDialect_aiosqlite.get_pool_class  s)    s##---??"r8   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   r~   is_disconnect)r3   er   rD   r   s       r5   r  %SQLiteDialect_aiosqlite.is_disconnect  sR     -4
zz**
 
$A.w$QF;;r8   c                    UR                   $ r:   )r*   )r3   r   s     r5   get_driver_connection-SQLiteDialect_aiosqlite.get_driver_connection  s     %%%r8   c                $    UR                  5         g r:   )	terminate)r3   dbapi_connections     r5   do_terminate$SQLiteDialect_aiosqlite.do_terminate  s    ""$r8   )r   r   )r   r   )rn   r   )r
  r$   rn   ztype[pool.Pool])r  zDBAPIModule.Errorr   z7Optional[Union[PoolProxiedConnection, DBAPIConnection]]rD   zOptional[DBAPICursor]rn   r   )r   r!   rn   r   )r  r!   rn   ro   )rt   ru   rv   rw   driversupports_statement_cacheis_asyncr   supports_server_side_cursorsr   execution_ctx_clsr6   classmethodr  r  r  r  r  ry   r   r   s   @r5   r   r     s    F#HM#' 8'
 
 

 # #<< L< &	<
 
<&)&	&
% %r8   r   ):__doc__
__future__r   r   collectionsr   	functoolsr   	threadingr   typesr   typingr   r	   r
   r   r   r   r   r   r   baser   pysqliter    r   r   connectors.asyncior   r   enginer   util.concurrencyr   r   r   r   engine.interfacesr   r   r    r!   r"   r#   
engine.urlr$   	pool.baser%   r'   r{   rl   r   r   r   r   dialectr;   r8   r5   <module>r0     s   FN #                ( ,   9 6 ' . *<8<=>400!2f fR4%@ 4>h&:<M hV*.M *5!8 5p?'= ?
1%4 1%h "r8   