
    )f%                    P   d Z ddlmZ 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 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  G d de
      Z G d de      Z G d de      Z G d dee      Z G d d      Z G d de      ZeZeZ y)a
  
.. dialect:: oracle+oracledb
    :name: python-oracledb
    :dbapi: oracledb
    :connectstring: oracle+oracledb://user:pass@hostname:port[/dbname][?service_name=<service>[&key=value&key=value...]]
    :url: https://oracle.github.io/python-oracledb/

python-oracledb is released by Oracle to supersede the cx_Oracle driver.
It is fully compatible with cx_Oracle and features both a "thin" client
mode that requires no dependencies, as well as a "thick" mode that uses
the Oracle Client Interface in the same way as cx_Oracle.

.. seealso::

    :ref:`cx_oracle` - all of cx_Oracle's notes apply to the oracledb driver
    as well.

The SQLAlchemy ``oracledb`` dialect provides both a sync and an async
implementation under the same dialect name. The proper version is
selected depending on how the engine is created:

* calling :func:`_sa.create_engine` with ``oracle+oracledb://...`` will
  automatically select the sync version, e.g.::

    from sqlalchemy import create_engine
    sync_engine = create_engine("oracle+oracledb://scott:tiger@localhost/?service_name=XEPDB1")

* calling :func:`_asyncio.create_async_engine` with
  ``oracle+oracledb://...`` will automatically select the async version,
  e.g.::

    from sqlalchemy.ext.asyncio import create_async_engine
    asyncio_engine = create_async_engine("oracle+oracledb://scott:tiger@localhost/?service_name=XEPDB1")

The asyncio version of the dialect may also be specified explicitly using the
``oracledb_async`` suffix, as::

    from sqlalchemy.ext.asyncio import create_async_engine
    asyncio_engine = create_async_engine("oracle+oracledb_async://scott:tiger@localhost/?service_name=XEPDB1")

.. versionadded:: 2.0.25 added support for the async version of oracledb.

Thick mode support
------------------

By default the ``python-oracledb`` is started in thin mode, that does not
require oracle client libraries to be installed in the system. The
``python-oracledb`` driver also support a "thick" mode, that behaves
similarly to ``cx_oracle`` and requires that Oracle Client Interface (OCI)
is installed.

To enable this mode, the user may call ``oracledb.init_oracle_client``
manually, or by passing the parameter ``thick_mode=True`` to
:func:`_sa.create_engine`. To pass custom arguments to ``init_oracle_client``,
like the ``lib_dir`` path, a dict may be passed to this parameter, as in::

    engine = sa.create_engine("oracle+oracledb://...", thick_mode={
        "lib_dir": "/path/to/oracle/client/lib", "driver_name": "my-app"
    })

.. seealso::

    https://python-oracledb.readthedocs.io/en/latest/api_manual/module.html#oracledb.init_oracle_client


.. versionadded:: 2.0.0 added support for oracledb driver.

    )annotationsN)Any)TYPE_CHECKING   )OracleDialect_cx_oracle   )exc)pool)AsyncAdapt_dbapi_connection)AsyncAdapt_dbapi_cursor)#AsyncAdaptFallback_dbapi_connection)asbool)await_fallback)
await_only)AsyncConnection)AsyncCursorc                  l     e Zd ZdZdZdZ	 	 	 	 	 d	 fd	Zed        Zed        Z	ed        Z
d Z xZS )
OracleDialect_oracledbToracledb)r   c                    t        |   ||||fi | | j                  D|st        |t              r1t        |t              r|ni } | j                  j
                  di | y y y )N )super__init__dbapi
isinstancedictinit_oracle_client)	selfauto_convert_lobscoerce_to_decimal	arraysizeencoding_errors
thick_modekwargskw	__class__s	           `/var/www/html/flask-app/venv/lib/python3.12/site-packages/sqlalchemy/dialects/oracle/oracledb.pyr   zOracleDialect_oracledb.__init__h   sq     			

 	
 ::!*Z6)*d;B)DJJ))/B/ 7 "    c                    dd l }|S Nr   )r   clsr   s     r'   import_dbapiz#OracleDialect_oracledb.import_dbapi   s
    r(   c                B    |j                   j                  j                  S N)
connectiondbapi_connectionthin)r,   r0   s     r'   is_thin_modez#OracleDialect_oracledb.is_thin_mode   s    $$55:::r(   c                    t         S r/   )OracleDialectAsync_oracledb)r,   urls     r'   get_async_dialect_clsz,OracleDialect_oracledb.get_async_dialect_cls   s    **r(   c                <   d}|Et        j                  d|j                        }|r#t        d |j	                  ddd      D              }|| _        | j
                  dkD  r=| j
                  | j                  k  r#t        j                  d| j                   d      y y )	N)r   r   r   z(\d+)\.(\d+)(?:\.(\d+))?c              3  8   K   | ]  }|t        |        y wr/   )int).0xs     r'   	<genexpr>z7OracleDialect_oracledb._load_version.<locals>.<genexpr>   s        CF s   r      r   zoracledb version z and above are supported)	rematchversiontuplegrouporacledb_ver_min_versionr	   InvalidRequestError)r   dbapi_modulerA   ms       r'   _load_versionz$OracleDialect_oracledb._load_version   s    #4l6J6JKA  $%GGAq!$4   $	)!!D$5$55))#D$5$5#66NO  6 *r(   )TTNNN)__name__
__module____qualname__supports_statement_cachedriverrE   r   classmethodr-   r3   r7   rI   __classcell__)r&   s   @r'   r   r   c   sj    #FL 0.  
 ; ; + +r(   r   c                      e Zd ZU ded<   dZed        Zej                  d        Zd Zd Z	ddZ
dd	Zd
 Zd Zd ZddZy)AsyncAdapt_oracledb_cursorr   _cursorr   c                .    | j                   j                  S r/   rS   outputtypehandlerr   s    r'   rV   z,AsyncAdapt_oracledb_cursor.outputtypehandler   s    ||---r(   c                &    || j                   _        y r/   rU   r   values     r'   rV   z,AsyncAdapt_oracledb_cursor.outputtypehandler   s    ).&r(   c                :     | j                   j                  |i |S r/   )rS   varr   argsr$   s      r'   r\   zAsyncAdapt_oracledb_cursor.var   s    t||000r(   c                l    | j                   j                          | j                  j                          y r/   )_rowsclearrS   closerW   s    r'   rb   z AsyncAdapt_oracledb_cursor.close   s"    

r(   c                :     | j                   j                  |i |S r/   )rS   setinputsizesr]   s      r'   rd   z(AsyncAdapt_oracledb_cursor.setinputsizes   s    )t||))4:6::r(   c                    	 |j                         S # t        $ r%}| j                  j                  |       Y d }~y d }~ww xY wr/   )	__enter__	Exception_adapt_connection_handle_exception)r   cursorerrors      r'   _aenter_cursorz)AsyncAdapt_oracledb_cursor._aenter_cursor   s=    	<##%% 	<""44U;;	<s    	A ;A c                f  K   |$| j                   j                  |       d {   }n$| j                   j                  ||       d {   }| j                   j                  rF| j                  s:t	        j
                  | j                   j                          d {         | _        |S 7 7 d7 wr/   )rS   executedescriptionserver_sidecollectionsdequefetchallr`   )r   	operation
parametersresults       r'   _execute_asyncz)AsyncAdapt_oracledb_cursor._execute_async   s      <<//	::F<<//	:FFF<<##D,<,<$**1F1F1H+HIDJ ;F ,Is4   !B1B+$B1B-	AB1B/B1-B1/B1c                V   K   | j                   j                  ||       d {   S 7 wr/   )rS   executemany)r   rt   seq_of_parameterss      r'   _executemany_asyncz-AsyncAdapt_oracledb_cursor._executemany_async   s&      \\--i9JKKKKs    )')c                    | S r/   r   rW   s    r'   rf   z$AsyncAdapt_oracledb_cursor.__enter__   s    r(   c                $    | j                          y r/   )rb   )r   type_rZ   	tracebacks       r'   __exit__z#AsyncAdapt_oracledb_cursor.__exit__   s    

r(   N)r^   r   r$   r   returnr   )rj   r   r   r   )r~   r   rZ   r   r   r   r   None)rJ   rK   rL   __annotations__	__slots__propertyrV   setterr\   rb   rd   rl   rw   r{   rf   r   r   r(   r'   rR   rR      sb    I. . / /1;<
Lr(   rR   c                      e Zd ZU ded<   dZdZeZdZe	d        Z
e
j                  d        Z
e	d        Zej                  d	        Ze	d
        Ze	d        Zej                  d        Zd Zy)AsyncAdapt_oracledb_connectionr   _connectionr   TNc                .    | j                   j                  S r/   r   
autocommitrW   s    r'   r   z)AsyncAdapt_oracledb_connection.autocommit   s    ***r(   c                &    || j                   _        y r/   r   rY   s     r'   r   z)AsyncAdapt_oracledb_connection.autocommit   s    &+#r(   c                .    | j                   j                  S r/   r   rV   rW   s    r'   rV   z0AsyncAdapt_oracledb_connection.outputtypehandler   s    111r(   c                &    || j                   _        y r/   r   rY   s     r'   rV   z0AsyncAdapt_oracledb_connection.outputtypehandler   s    -2*r(   c                .    | j                   j                  S r/   )r   rA   rW   s    r'   rA   z&AsyncAdapt_oracledb_connection.version   s    '''r(   c                .    | j                   j                  S r/   r   stmtcachesizerW   s    r'   r   z,AsyncAdapt_oracledb_connection.stmtcachesize   s    ---r(   c                &    || j                   _        y r/   r   rY   s     r'   r   z,AsyncAdapt_oracledb_connection.stmtcachesize   s    ).&r(   c                    t        |       S r/   )rR   rW   s    r'   rj   z%AsyncAdapt_oracledb_connection.cursor   s    )$//r(   )rJ   rK   rL   r   r   r2   rR   _cursor_cls_ss_cursor_clsr   r   r   rV   rA   r   rj   r   r(   r'   r   r      s      ID,KN+ + , , 2 2 3 3 ( ( . . / /0r(   r   c                      e Zd ZdZy)&AsyncAdaptFallback_oracledb_connectionr   N)rJ   rK   rL   r   r   r(   r'   r   r      s	     Ir(   r   c                      e Zd ZddZd Zy)OracledbAdaptDBAPIc                    || _         | j                   j                  j                         D ]  \  }}|dk7  s|| j                  |<    y )Nconnect)r   __dict__items)r   r   kvs       r'   r   zOracledbAdaptDBAPI.__init__  sD     MM**002 	%DAqI~#$a 	%r(   c           
         |j                  dd      }|j                  d| j                  j                        }t        |      rt	        | t         ||i |            S t        | t         ||i |            S )Nasync_fallbackFasync_creator_fn)popr   connect_asyncr   r   r   r   r   )r   argr%   r   
creator_fns        r'   r   zOracledbAdaptDBAPI.connect  sz     0%8VV.0K0KL
.!9nZ%;%;< 
 2jS!7B!78 r(   N)r   r   )rJ   rK   rL   r   r   r   r(   r'   r   r     s    %r(   r   c                  >    e Zd ZdZdZdZed        Zed        Zd Z	y)r5   T)r>   c                     dd l }t        |      S r*   )r   r   r+   s     r'   r-   z(OracleDialectAsync_oracledb.import_dbapi#  s    !(++r(   c                    |j                   j                  dd      }t        |      rt        j                  S t        j
                  S )Nr   F)querygetr   r
   FallbackAsyncAdaptedQueuePoolAsyncAdaptedQueuePool)r,   r6   r   s      r'   get_pool_classz*OracleDialectAsync_oracledb.get_pool_class)  s7    '7?.!555---r(   c                    |j                   S r/   )r   )r   r0   s     r'   get_driver_connectionz1OracleDialectAsync_oracledb.get_driver_connection2  s    %%%r(   N)
rJ   rK   rL   is_asyncrM   rE   rO   r-   r   r   r   r(   r'   r5   r5     s?    H#L , ,
 . .&r(   r5   )!__doc__
__future__r   rq   r?   typingr   r   	cx_oracler   _OracleDialect_cx_oracle r	   r
   connectors.asyncior   r   r   utilr   r   r   r   r   r   r   rR   r   r   r   r5   dialectdialect_asyncr   r(   r'   <module>r      s   CH #  	    J   = 9 E  " ($95 9x4!8 4n&0%@ &0R')G .&"8 &4 !+r(   