
    ?
i@                    j   d Z ddlm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 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 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 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! ddl"m#Z# ddl"m$Z$ er<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* dd!l'm+Z+ dd"l'm,Z, dd#l'm-Z- dd$l.m/Z/ dd%l0m1Z1  G d& d'          Z2 G d( d)e2          Z3 G d* d+ee!          Z4 G d, d-e4          Z5 G d. d/e          Z6 G d0 d1e          Z7 G d2 d3e          Z8e8Z9dS )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                  l    e Zd ZdZdZddZddZdd	Z	 d d!dZd"dZ	d#dZ
d$dZd%dZd d&dZd'dZd
S )(AsyncAdapt_aiosqlite_cursor)_adapt_connection_connectiondescriptionawait__rows	arraysizerowcount	lastrowidFadapt_connectionAsyncAdapt_aiosqlite_connectionc                    || _         |j        | _        |j        | _        d| _        d| _        d | _        t                      | _        d S )Nr   )r(   r)   r+   r-   r.   r*   r   r,   )selfr0   s     C:\Users\Dell Inspiron 16\Desktop\tws\AgrotaPowerBi\back-agrota-powerbi\mcp-client-agrota\venv\Lib\site-packages\sqlalchemy/dialects/sqlite/aiosqlite.py__init__z$AsyncAdapt_aiosqlite_cursor.__init__   sD    !1+7&->B!&


    returnNonec                
   K   d S N r4   s    r5   _async_soft_closez-AsyncAdapt_aiosqlite_cursor._async_soft_close   s      r7   c                8    | j                                          d S r;   )r,   clearr=   s    r5   closez!AsyncAdapt_aiosqlite_cursor.close   s    
r7   N	operationr   
parameters#Optional[_DBAPISingleExecuteParams]c                   	 |                      | j                                                  }|)|                      |                    |                     n)|                      |                    ||                     |j        r[|j        | _        dx| _        | _        | j        s9t          |                      |	                                                    | _
        nd | _        |j        | _        |j        | _        | j        s)|                      |                                           d S || _        d S # t          $ r%}| j                            |           Y d }~d S d }~ww xY w)Nr3   )r+   r)   cursorexecuter*   r/   r.   server_sider   fetchallr,   rA   _cursor	Exceptionr(   _handle_exception)r4   rB   rC   rJ   errors        r5   rG   z#AsyncAdapt_aiosqlite_cursor.execute   s`   	<*.++d6F6M6M6O6O*P*PG!GOOI667777GOOIzBBCCC" 	1#*#6 133' H!&t{{73C3C3E3E'F'F!G!GDJ#' !(!2 ' 0# 'GMMOO,,,,,& 	< 	< 	<"44U;;;;;;;;;	<s   D/D< 3D< <
E+E&&E+seq_of_parametersr   c                   	 |                      | j                                                  }|                      |                    ||                     d | _        |j        | _        |j        | _        |                      |                                           d S # t          $ r%}| j	        
                    |           Y d }~d S d }~ww xY wr;   )r+   r)   rF   executemanyr*   r/   r.   rA   rK   r(   rL   )r4   rB   rN   rJ   rM   s        r5   rP   z'AsyncAdapt_aiosqlite_cursor.executemany   s    
	<*.++d6F6M6M6O6O*P*PGKK++I7HIIJJJ#D$.DN#,DMKK((((( 	< 	< 	<"44U;;;;;;;;;	<s   BB 
C)C		C
inputsizesc                    d S r;   r<   )r4   rQ   s     r5   setinputsizesz)AsyncAdapt_aiosqlite_cursor.setinputsizes   s    r7   Iterator[Any]c              #  `   K   | j         r$| j                                         V  | j         "d S d S r;   r,   popleftr=   s    r5   __iter__z$AsyncAdapt_aiosqlite_cursor.__iter__   sJ      j 	'*$$&&&&& j 	' 	' 	' 	' 	'r7   Optional[Any]c                F    | j         r| j                                         S d S r;   rV   r=   s    r5   fetchonez$AsyncAdapt_aiosqlite_cursor.fetchone   s%    : 	:%%'''4r7   sizeOptional[int]Sequence[Any]c           	         || j         }| j        fdt          t          |t	                                        D             S )Nc                8    g | ]}                                 S r<   )rW   ).0_rrs     r5   
<listcomp>z9AsyncAdapt_aiosqlite_cursor.fetchmany.<locals>.<listcomp>   s!    @@@

@@@r7   )r-   r,   rangeminlen)r4   r\   rc   s     @r5   	fetchmanyz%AsyncAdapt_aiosqlite_cursor.fetchmany   sH    <>DZ@@@@eCc"gg,>,>&?&?@@@@r7   c                `    t          | j                  }| j                                         |S r;   )listr,   r@   )r4   retvals     r5   rI   z$AsyncAdapt_aiosqlite_cursor.fetchall   s*    dj!!
r7   )r0   r1   r8   r9   r;   )rB   r   rC   rD   r8   r   )rB   r   rN   r   r8   r   )rQ   r   r8   r9   )r8   rT   r8   rY   r\   r]   r8   r^   r8   r^   )__name__
__module____qualname__	__slots__rH   r6   r>   rA   rG   rP   rS   rX   r[   rh   rI   r<   r7   r5   r'   r'   x   s        	I K) ) ) )       ;?< < < < <@< < < <   ' ' ' '   A A A A A     r7   r'   c                  J     e Zd ZdZdZd fdZdd	ZddZdddZddZ	 xZ
S )AsyncAdapt_aiosqlite_ss_cursorrJ   Targr   kwr8   r9   c                H     t                      j        |i | d | _        d S r;   )superr6   rJ   )r4   rv   rw   	__class__s      r5   r6   z'AsyncAdapt_aiosqlite_ss_cursor.__init__   s*    #$$$$59r7   c                ~    | j         5|                     | j                                                    d | _         d S d S r;   )rJ   r+   rA   r=   s    r5   rA   z$AsyncAdapt_aiosqlite_ss_cursor.close   s=    <#KK**,,---DLLL $#r7   rY   c                l    | j         J |                     | j                                                   S r;   )rJ   r+   r[   r=   s    r5   r[   z'AsyncAdapt_aiosqlite_ss_cursor.fetchone   0    |'''{{4<0022333r7   Nr\   r]   r^   c                    | j         J || j        }|                     | j                             |                    S )N)r\   )rJ   r-   r+   rh   )r4   r\   s     r5   rh   z(AsyncAdapt_aiosqlite_ss_cursor.fetchmany   sA    |'''<>D{{4<11t1<<===r7   c                l    | j         J |                     | j                                                   S r;   )rJ   r+   rI   r=   s    r5   rI   z'AsyncAdapt_aiosqlite_ss_cursor.fetchall   r}   r7   )rv   r   rw   r   r8   r9   rl   rm   r;   rn   ro   )rp   rq   rr   rs   rH   r6   rA   r[   rh   rI   __classcell__rz   s   @r5   ru   ru      s         IK: : : : : :       
4 4 4 4> > > > >4 4 4 4 4 4 4 4r7   ru   c                      e Zd Z ee          ZdZd dZed!d
            Z	e	j
        d"d            Z	d#dZd$d%dZd&dZd'dZd'dZd'dZd(dZd'dZd'dZdS ))r1   )dbapir   r   
connectionr   r8   r9   c                "    || _         || _        d S r;   )r   r)   )r4   r   r   s      r5   r6   z(AsyncAdapt_aiosqlite_connection.__init__  s    
%r7   Optional[str]c                @    t          t          | j        j                  S r;   )r	   strr)   isolation_levelr=   s    r5   r   z/AsyncAdapt_aiosqlite_connection.isolation_level  s    C)9:::r7   valuec                V   dd}t          || j        j        |          }t          j                                                    }| j        j                            ||f           	 |                     |           d S # t          $ r }| 
                    |           Y d }~d S d }~ww xY w)	Nr   r1   r   r   r8   r9   c                    || _         d S r;   )r   )r   r   s     r5   set_isoz@AsyncAdapt_aiosqlite_connection.isolation_level.<locals>.set_iso  s     */J&&&r7   )r   r1   r   r   r8   r9   )r   r)   _connasyncioget_event_loopcreate_future_tx
put_nowaitr+   rK   rL   )r4   r   r   functionfuturerM   s         r5   r   z/AsyncAdapt_aiosqlite_connection.isolation_level  s    	/ 	/ 	/ 	/
 7D$4$:EBB'))7799''(:;;;	*KK 	* 	* 	*""5)))))))))	*s   'A> >
B(B##B(argsrw   c                    	 |                       | j        j        |i |           d S # t          $ r }|                     |           Y d }~d S d }~ww xY wr;   )r+   r)   create_functionrK   rL   )r4   r   rw   rM   s       r5   r   z/AsyncAdapt_aiosqlite_connection.create_function"  sz    	*KK8(8$E"EEFFFFF 	* 	* 	*""5)))))))))	*s   %) 
AAAFrH   boolr'   c                B    |rt          |           S t          |           S r;   )ru   r'   )r4   rH   s     r5   rF   z&AsyncAdapt_aiosqlite_connection.cursor(  s&     	51$777.t444r7   c                L    |                       | j        j        |i |          S r;   )r+   r)   rG   )r4   r   rw   s      r5   rG   z'AsyncAdapt_aiosqlite_connection.execute.  s*    {{34+3T@R@@AAAr7   c                    	 |                      | j                                                   d S # t          $ r }|                     |           Y d }~d S d }~ww xY wr;   )r+   r)   rollbackrK   rL   r4   rM   s     r5   r   z(AsyncAdapt_aiosqlite_connection.rollback1  ss    	*KK(113344444 	* 	* 	*""5)))))))))	*   ,0 
AAAc                    	 |                      | j                                                   d S # t          $ r }|                     |           Y d }~d S d }~ww xY wr;   )r+   r)   commitrK   rL   r   s     r5   r   z&AsyncAdapt_aiosqlite_connection.commit7  ss    	*KK(//1122222 	* 	* 	*""5)))))))))	*r   c                    	 |                      | j                                                   d S # t          $ r Y d S t          $ r }|                     |           Y d }~d S d }~ww xY wr;   )r+   r)   rA   
ValueErrorrK   rL   r   s     r5   rA   z%AsyncAdapt_aiosqlite_connection.close=  s    	*KK(..0011111 		 		 		 DD 	* 	* 	*""5)))))))))	*s   ,0 
A&	A&A!!A&rM   rK   r   c                    t          |t                    r1|j        d         dk    r | j        j                            d          ||)Nr   no active connection)
isinstancer   r   r   sqliteOperationalErrorr   s     r5   rL   z1AsyncAdapt_aiosqlite_connection._handle_exceptionM  sP    uj))	
1!777*#44&  Kr7   c                H   K   | j                                          d{V  dS )z"Try to close connection gracefullyN)r)   rA   r=   s    r5   _terminate_graceful_closez9AsyncAdapt_aiosqlite_connection._terminate_graceful_closeX  s3      $$&&&&&&&&&&&r7   c                x    	 | j         j        } |             dS # t          $ r}t          d          |d}~ww xY w)zTerminate the connectionz:terminate_force_close() not implemented by this DBAPI shimN)r)   stopAttributeErrorNotImplementedError)r4   methaes      r5   _terminate_force_closez6AsyncAdapt_aiosqlite_connection._terminate_force_close\  s\    
	#(D DFFFFF  	 	 	%L 	s    
949N)r   r   r   r   r8   r9   )r8   r   )r   r   r8   r9   )r   r   rw   r   r8   r9   )F)rH   r   r8   r'   )r   r   rw   r   r8   r   rl   )rM   rK   r8   r   )rp   rq   rr   staticmethodr   r+   rs   r6   propertyr   setterr   rF   rG   r   r   rA   rL   r   r   r<   r7   r5   r1   r1      s=       \*%%FI& & & & ; ; ; X; * * * *** * * *5 5 5 5 5B B B B* * * ** * * ** * * * 	 	 	 	' ' ' '     r7   r1   c                  (    e Zd ZdZ ee          ZdS )'AsyncAdaptFallback_aiosqlite_connectionr<   N)rp   rq   rr   rs   r   r   r+   r<   r7   r5   r   r   k  s"        I\.))FFFr7   r   c                  &    e Zd ZddZddZddZdS )AsyncAdapt_aiosqlite_dbapi	aiosqliter   r   c                    || _         || _        d| _        t          |j        d          | _        |                                  d S )Nqmarkr   )r   r   
paramstylehasattr
Connectionhas_stop_init_dbapi_attributes)r4   r   r   s      r5   r6   z#AsyncAdapt_aiosqlite_dbapi.__init__r  sC    "!	 4f==##%%%%%r7   r8   r9   c           	         dD ]&}t          | |t          | j        |                     'dD ]&}t          | |t          | j        |                     'dD ]&}t          | |t          | j        |                     'd S )N)DatabaseErrorErrorIntegrityErrorNotSupportedErrorr   ProgrammingErrorsqlite_versionsqlite_version_info)PARSE_COLNAMESPARSE_DECLTYPES)Binary)setattrgetattrr   r   )r4   names     r5   r   z1AsyncAdapt_aiosqlite_dbapi._init_dbapi_attributesy  s    	
 
	? 
	?D D$ = =>>>>9 	< 	<DD$T : :;;;; 	< 	<DD$T : :;;;;	< 	<r7   rv   r   rw   r1   c                   |                     dd          }|                     dd           }|r	 ||i |}n; | j        j        |i |}t          |t                    rd|_        nd|j        _        t          j        |          rt          | t          |                    S t          | t          |                    S )Nasync_fallbackFasync_creator_fnT)popr   connectr   r   daemon_threadr   asboolr   r   r1   r   )r4   rv   rw   r   
creator_fnr   s         r5   r   z"AsyncAdapt_aiosqlite_dbapi.connect  s     0%88VV.55
 	1#S/B//JJ//;;;J *f-- 1$(
!! -1
");~&& 		:z**  
 3:&&  r7   N)r   r   r   r   rl   )rv   r   rw   r   r8   r1   )rp   rq   rr   r6   r   r   r<   r7   r5   r   r   q  sP        & & & &< < < <&     r7   r   c                      e Zd ZddZdS ) SQLiteExecutionContext_aiosqliter8   r"   c                8    | j                             d          S )NT)rH   )_dbapi_connectionrF   r=   s    r5   create_server_side_cursorz:SQLiteExecutionContext_aiosqlite.create_server_side_cursor  s    %,,,>>>r7   N)r8   r"   )rp   rq   rr   r   r<   r7   r5   r   r     s(        ? ? ? ? ? ?r7   r   c                       e Zd ZdZdZdZdZdZeZ	d fdZ
edd            Zedd            Zd fdZddZd dZ xZS )!SQLiteDialect_aiosqliter   Tkwargsr   c                v     t                      j        di | | j        r| j        j        sd| _        d S d S d S )NFr<   )ry   r6   r   r   has_terminate)r4   r   rz   s     r5   r6   z SQLiteDialect_aiosqlite.__init__  sX    ""6""": 	'dj1 	'!&D	' 	' 	' 	'r7   r8   r   c                V    t          t          d          t          d                    S )Nr   sqlite3)r   
__import__)clss    r5   import_dbapiz$SQLiteDialect_aiosqlite.import_dbapi  s)    ){##Z	%:%:
 
 	
r7   urlr$   type[pool.Pool]c                \    |                      |          rt          j        S t          j        S r;   )_is_url_file_dbr   AsyncAdaptedQueuePool
StaticPool)r   r   s     r5   get_pool_classz&SQLiteDialect_aiosqlite.get_pool_class  s)    s## 	#--?"r7   eDBAPIModule.Errorr   7Optional[Union[PoolProxiedConnection, DBAPIConnection]]rF   Optional[DBAPICursor]r   c                    t          d| j                  | _        t          || j        j                  rdt	          |          v rdS t                                          |||          S )Nr#   r   T)r	   r   r   r   r   ry   is_disconnect)r4   r   r   rF   rz   s       r5   r   z%SQLiteDialect_aiosqlite.is_disconnect  sf     -44
tz*
 
 	$A..4ww$$Q
F;;;r7   r!   r   c                    |j         S r;   )r)   )r4   r   s     r5   get_driver_connectionz-SQLiteDialect_aiosqlite.get_driver_connection  s     %%r7   dbapi_connectionr9   c                .    |                                  d S r;   )	terminate)r4   r   s     r5   do_terminatez$SQLiteDialect_aiosqlite.do_terminate  s    ""$$$$$r7   )r   r   )r8   r   )r   r$   r8   r   )r   r   r   r   rF   r   r8   r   )r   r!   r8   r   )r   r!   r8   r9   )rp   rq   rr   driversupports_statement_cacheis_asyncr   supports_server_side_cursorsr   execution_ctx_clsr6   classmethodr   r   r   r   r   r   r   s   @r5   r   r     s        F#HM#' 8' ' ' ' ' '
 
 
 
 [

 # # # [#< < < < < <& & & &
% % % % % % % %r7   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'   ru   r1   r   r   r   r   dialectr<   r7   r5   <module>r     s  F FN # " " " " "                                                                                      ( ( ( ( ( ( , , , , , ,             9 9 9 9 9 9 6 6 6 6 6 6 ' ' ' ' ' ' . . . . . . * * * * * * 
3<<<<<<888888<<<<<<======>>>>>>444444000000000000!!!!!!222222f f f f f f f fR4 4 4 4 4%@ 4 4 4>h h h h h&:<M h h hV* * * * *.M * * *5 5 5 5 5!8 5 5 5p? ? ? ? ?'= ? ? ?
1% 1% 1% 1% 1%4 1% 1% 1%h "r7   