
    -h'                         S 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      r " S S\	5      r " S S\5      r " S S5      r " S S\5      r " S S\5      r\rg)aZ  

.. 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`.


   )SQLiteExecutionContext)SQLiteDialect_pysqlite   )pool)util)AdaptedConnection)await_fallback)
await_onlyc                   Z    \ rS rSrSrSrS rS rSS jrS r	S	 r
S
 rS rSS jrS rSrg)AsyncAdapt_aiosqlite_cursor9   )_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        / U l        g )Nr   )r   r   r   r   r   r   r   )selfadapt_connections     yC:\Users\ROHAN GUPTA\OneDrive\Desktop\mathbuddy-assessment\venv\Lib\site-packages\sqlalchemy/dialects/sqlite/aiosqlite.py__init__$AsyncAdapt_aiosqlite_cursor.__init__G   s@    !1+77&--
    c                 "    / U R                   S S & g Nr   r   s    r   close!AsyncAdapt_aiosqlite_cursor.closeP   s    

1r   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                  (       aU  UR                  U l        S=U l        U l        U R                  (       d$  U R                  UR                  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)Nr   )r   r   cursorexecuter   r   r   server_sidefetchallr   r"   _cursor	Exceptionr   _handle_exception)r   	operation
parametersr)   errors        r   r&   #AsyncAdapt_aiosqlite_cursor.executeS   s   	<kk$"2"2"9"9";<G!GOOI67GOOIBC""#*#6#6 133''!%W-=-=-?!@DJ#' !(!2!2 ' 0 0##GMMO,& 	<""44U;;	<s   D,D6 /D6 6
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   r%   executemanyr   r   r   r"   r*   r   r+   )r   r,   seq_of_parametersr)   r.   s        r   r1   'AsyncAdapt_aiosqlite_cursor.executemanyn   s    	<kk$"2"2"9"9";<GKK++IIJ#D$..DN#,,DMKK( 	<""44U;;	<s   BB 
CB>>Cc                     g r    )r   
inputsizess     r   setinputsizes)AsyncAdapt_aiosqlite_cursor.setinputsizesy   s    r   c              #      #    U R                   (       a1  U R                   R                  S5      v   U R                   (       a  M0  g g 7fN    r   popr!   s    r   __iter__$AsyncAdapt_aiosqlite_cursor.__iter__|   s*     jj**..## jjjs   A AAc                 \    U R                   (       a  U R                   R                  S5      $ g r:   r<   r!   s    r   fetchone$AsyncAdapt_aiosqlite_cursor.fetchone   s    ::::>>!$$r   c                 z    Uc  U R                   nU R                  SU nU R                  US  U R                  S S & U$ r:   )r   r   )r   sizeretvals      r   	fetchmany%AsyncAdapt_aiosqlite_cursor.fetchmany   s=    <>>DAd#

45)

1r   c                 B    U R                   S S  n/ U R                   S S & U$ r   r    )r   rE   s     r   r(   $AsyncAdapt_aiosqlite_cursor.fetchall   s!    A

1r   )	r   r   r)   r   r   r   r   r   r   r   )__name__
__module____qualname____firstlineno__	__slots__r'   r   r"   r&   r1   r7   r>   rA   rF   r(   __static_attributes__r5   r   r   r   r   9   s=    	I K<6	<$r   r   c                   L   ^  \ rS rSrSrSrU 4S jrS rS rS
S jr	S r
S	rU =r$ )AsyncAdapt_aiosqlite_ss_cursor   r)   Tc                 4   > [         TU ]  " U0 UD6  S U l        g r   )superr   r)   )r   argkw	__class__s      r   r   'AsyncAdapt_aiosqlite_ss_cursor.__init__   s    #$$r   c                     U R                   b1  U R                  U R                   R                  5       5        S U l         g g r   )r)   r   r"   r!   s    r   r"   $AsyncAdapt_aiosqlite_ss_cursor.close   s1    <<#KK**,-DL $r   c                 T    U R                  U R                  R                  5       5      $ r   )r   r)   rA   r!   s    r   rA   'AsyncAdapt_aiosqlite_ss_cursor.fetchone       {{4<<00233r   c                 p    Uc  U R                   nU R                  U R                  R                  US95      $ )N)rD   )r   r   r)   rF   )r   rD   s     r   rF   (AsyncAdapt_aiosqlite_ss_cursor.fetchmany   s1    <>>D{{4<<11t1<==r   c                 T    U R                  U R                  R                  5       5      $ r   )r   r)   r(   r!   s    r   r(   'AsyncAdapt_aiosqlite_ss_cursor.fetchall   r]   r   )r)   r   )rJ   rK   rL   rM   rN   r'   r   r"   rA   rF   r(   rO   __classcell__rW   s   @r   rQ   rQ      s+    IK 
4>
4 4r   rQ   c                       \ rS rSr\" \5      rSrS r\	S 5       r
\
R                  S 5       r
S rSS jrS rS	 rS
 rS rS rSrg)AsyncAdapt_aiosqlite_connection   dbapir   c                     Xl         X l        g r   rg   )r   rh   
connections      r   r   (AsyncAdapt_aiosqlite_connection.__init__   s    
%r   c                 .    U R                   R                  $ r   )r   isolation_levelr!   s    r   rm   /AsyncAdapt_aiosqlite_connection.isolation_level   s    ///r   c                 v     XR                   l        g ! [         a  nU R                  U5         S nAg S nAff = fr   )r   rm   r*   r+   )r   valuer.   s      r   rm   rn      s4    	*/4, 	*""5))	*s    
838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_functionr*   r+   )r   argsrV   r.   s       r   rr   /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   )rQ   r   )r   r'   s     r   r%   &AsyncAdapt_aiosqlite_connection.cursor   s    1$77.t44r   c                 X    U R                  U R                  R                  " U0 UD65      $ r   )r   r   r&   )r   rs   rV   s      r   r&   'AsyncAdapt_aiosqlite_connection.execute   s'    {{4++33T@R@AAr   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   rollbackr*   r+   r   r.   s     r   rz   (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r   )r   r   commitr*   r+   r{   s     r   r   &AsyncAdapt_aiosqlite_connection.commit   sC    	*KK((//12 	*""5))	*r}   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   r"   r*   r+   r{   s     r   r"   %AsyncAdapt_aiosqlite_connection.close   sC    	*KK((..01 	*""5))	*r}   c                     [        U[        5      (       aL  UR                  S   S:X  a9  [        R                  " U R
                  R                  R                  S5      US9  g Ue)Nr;   no active connection)from_)
isinstance
ValueErrorrs   r   raise_rh   sqliteOperationalErrorr{   s     r   r+   1AsyncAdapt_aiosqlite_connection._handle_exception   sO    uj))

1!77KK

!!223IJ
 Kr   )r   rh   N)F)rJ   rK   rL   rM   staticmethodr
   r   rN   r   propertyrm   setterrr   r%   r&   rz   r   r"   r+   rO   r5   r   r   re   re      sh    *%F(I& 0 0 * **5B***
r   re   c                   (    \ rS rSrSr\" \5      rSrg)'AsyncAdaptFallback_aiosqlite_connection   r5   N)	rJ   rK   rL   rM   rN   r   r	   r   rO   r5   r   r   r   r      s    I.)Fr   r   c                   &    \ rS rSrS rS rS rSrg)AsyncAdapt_aiosqlite_dbapi   c                 J    Xl         X l        SU l        U R                  5         g )Nqmark)	aiosqliter   
paramstyle_init_dbapi_attributes)r   r   r   s      r   r   #AsyncAdapt_aiosqlite_dbapi.__init__   s    "!##%r   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   )r   names     r   r   1AsyncAdapt_aiosqlite_dbapi._init_dbapi_attributes   sg    	
D D =>	
 :DDT :; :  DDT :;  r   c                     UR                  SS5      nSUS'   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check_same_threadT)
r=   r   connectdaemonr   asboolr   r	   re   r
   )r   rU   rV   r   rj   s        r   r   "AsyncAdapt_aiosqlite_dbapi.connect  s     0%8 #(^^++S7B7
 !
;;~&&:z* 
 3:& r   )r   r   r   N)rJ   rK   rL   rM   r   r   r   rO   r5   r   r   r   r      s    &<&r   r   c                       \ rS rSrS rSrg) SQLiteExecutionContext_aiosqlitei/  c                 4    U R                   R                  SS9$ )NT)r'   )_dbapi_connectionr%   r!   s    r   create_server_side_cursor:SQLiteExecutionContext_aiosqlite.create_server_side_cursor0  s    %%,,,>>r   r5   N)rJ   rK   rL   rM   r   rO   r5   r   r   r   r   /  s    ?r   r   c                   b   ^  \ rS rSrSrSrSrSr\r	\
S 5       r\
S 5       rU 4S jrS rSrU =r$ )	SQLiteDialect_aiosqlitei4  r   Tc                 >    [        [        S5      [        S5      5      $ )Nr   sqlite3)r   
__import__)clss    r   rh   SQLiteDialect_aiosqlite.dbapi>  s    ){#Z	%:
 	
r   c                 n    U R                  U5      (       a  [        R                  $ [        R                  $ r   )_is_url_file_dbr   NullPool
StaticPool)r   urls     r   get_pool_class&SQLiteDialect_aiosqlite.get_pool_classD  s'    s##== ??"r   c                    > [        XR                  R                  5      (       a  S[        U5      ;   a  g[        TU ]  XU5      $ )Nr   T)r   rh   r   strrT   is_disconnect)r   erj   r%   rW   s       r   r   %SQLiteDialect_aiosqlite.is_disconnectK  s>    zz**
 
$A.w$QF;;r   c                     UR                   $ r   )r   )r   rj   s     r   get_driver_connection-SQLiteDialect_aiosqlite.get_driver_connectionS  s    %%%r   r5   )rJ   rK   rL   rM   driversupports_statement_cacheis_asyncsupports_server_side_cursorsr   execution_ctx_clsclassmethodrh   r   r   r   rO   rb   rc   s   @r   r   r   4  sT    F#H#' 8
 

 # #<& &r   r   N)__doc__baser   pysqliter    r   r   enginer   util.concurrencyr	   r
   r   rQ   re   r   r   r   r   dialectr5   r   r   <module>r      s   &P ) ,   ' . *X Xv4%@ 44>&7 >B*.M *7 7t?'= ?
 &4  &F "r   