o
    y¬´\)—  ã                   @   s*  d Z ddlmZ ddlZddl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 G dd„ dejƒZG dd„ dejƒZG dd„ deƒZG dd„ dee	jƒZG dd„ dee	jƒZG dd„ deƒZG dd„ dejƒZ G dd„ dej!ƒZ"G dd „ d ej#ƒZ$G d!d"„ d"ej%ƒZ&G d#d$„ d$e	j'ƒZ(G d%d&„ d&ej)ƒZ*G d'd(„ d(ej+ƒZ,G d)d*„ d*ej-ƒZ.G d+d,„ d,ej/ƒZ0G d-d.„ d.e	j1ƒZ2G d/d0„ d0e	j3ƒZ4G d1d2„ d2e	j5ƒZ6G d3d4„ d4e
ƒZ7G d5d6„ d6eƒZ8G d7d8„ d8ej9ƒZ:G d9d:„ d:eƒZ;e;Z<dS );aQ0  
.. dialect:: oracle+cx_oracle
    :name: cx-Oracle
    :dbapi: cx_oracle
    :connectstring: oracle+cx_oracle://user:pass@host:port/dbname[?key=value&key=value...]
    :url: https://oracle.github.io/python-cx_Oracle/

Additional Connect Arguments
----------------------------

When connecting with the ``dbname`` URL token present, the ``hostname``,
``port``, and ``dbname`` tokens are converted to a TNS name using the
``cx_Oracle.makedsn()`` function. The URL below::

    e = create_engine("oracle+cx_oracle://user:pass@hostname/dbname")

Will be used to create the DSN as follows::

    >>> import cx_Oracle
    >>> cx_Oracle.makedsn("hostname", 1521, sid="dbname")
    '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=hostname)(PORT=1521))(CONNECT_DATA=(SID=dbname)))'

The ``service_name`` parameter, also consumed by ``cx_Oracle.makedsn()``, may
be specified in the URL query string, e.g. ``?service_name=my_service``.

If ``dbname`` is not present, then the value of ``hostname`` in the
URL is used directly as the DSN passed to ``cx_Oracle.connect()``.

Additional connection arguments may be sent to the ``cx_Oracle.connect()``
function using the :paramref:`.create_engine.connect_args` dictionary.
Any cx_Oracle parameter value and/or constant may be passed, such as::

    import cx_Oracle
    e = create_engine(
        "oracle+cx_oracle://user:pass@dsn",
        connect_args={
            "mode": cx_Oracle.SYSDBA,
            "events": True
        }
    )

There are also options that are consumed by the SQLAlchemy cx_oracle dialect
itself.  These options are always passed directly to :func:`.create_engine`,
such as::

    e = create_engine(
        "oracle+cx_oracle://user:pass@dsn", coerce_to_unicode=False)

The parameters accepted by the cx_oracle dialect are as follows:

* ``arraysize`` - set the cx_oracle.arraysize value on cursors, defaulted
  to 50.  This setting is significant with cx_Oracle as the contents of LOB
  objects are only readable within a "live" row (e.g. within a batch of
  50 rows).

* ``auto_convert_lobs`` - defaults to True; See :ref:`cx_oracle_lob`.

* ``coerce_to_unicode`` - see :ref:`cx_oracle_unicode` for detail.

* ``coerce_to_decimal`` - see :ref:`cx_oracle_numeric` for detail.

* ``threaded`` - this parameter is passed as the value of "threaded" to
  ``cx_Oracle.connect()`` and defaults to True, which is the opposite of
  cx_Oracle's default.   This parameter is deprecated and will default to
  ``False`` in version 1.3 of SQLAlchemy.

.. _cx_oracle_unicode:

Unicode
-------

The cx_Oracle DBAPI as of version 5 fully supports unicode, and has the
ability to return string results as Python unicode objects natively.

When used in Python 3, cx_Oracle returns all strings as Python unicode objects
(that is, plain ``str`` in Python 3).  In Python 2, it will return as Python
unicode those column values that are of type ``NVARCHAR`` or ``NCLOB``.  For
column values that are of type ``VARCHAR`` or other non-unicode string types,
it will return values as Python strings (e.g. bytestrings).

The cx_Oracle SQLAlchemy dialect presents several different options for the use
case of receiving ``VARCHAR`` column values as Python unicode objects under
Python 2:

* When using Core expression objects as well as the ORM, SQLAlchemy's
  unicode-decoding services are available, which are established by
  using either the :class:`.Unicode` datatype or by using the
  :class:`.String` datatype with :paramref:`.String.convert_unicode` set
  to True.

* When using raw SQL strings, typing behavior can be added for unicode
  conversion using the :func:`.text` construct::

    from sqlalchemy import text, Unicode
    result = conn.execute(
        text("select username from user").columns(username=Unicode))

* Otherwise, when using raw SQL strings sent directly to an ``.execute()``
  method without any Core typing behavior added, the flag
  ``coerce_to_unicode=True`` flag can be passed to :func:`.create_engine`
  which will add an unconditional unicode processor to cx_Oracle for all
  string values::

    engine = create_engine("oracle+cx_oracle://dsn", coerce_to_unicode=True)

  The above approach will add significant latency to result-set fetches
  of plain string values.

Sending String Values as Unicode or Non-Unicode
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

As of SQLAlchemy 1.2.2, the cx_Oracle dialect unconditionally calls
``setinputsizes()`` for bound values that are passed as Python unicode objects.
In Python 3, all string values are Unicode; for cx_Oracle, this corresponds to
``cx_Oracle.NCHAR`` being passed to ``setinputsizes()`` for that parameter.
In some edge cases, such as passing format specifiers for
the ``trunc()`` function, Oracle does not accept these as NCHAR::

    from sqlalchemy import func

    conn.execute(
        func.trunc(func.sysdate(), 'dd')
    )

In these cases, an error as follows may be raised::

    ORA-01899: bad precision specifier

When this error is encountered, it may be necessary to pass the string value
with an explicit non-unicode type::

    from sqlalchemy import func
    from sqlalchemy import literal
    from sqlalchemy import String

    conn.execute(
        func.trunc(func.sysdate(), literal('dd', String))
    )

For full control over this ``setinputsizes()`` behavior, see the section
:ref:`cx_oracle_setinputsizes`

.. _cx_oracle_setinputsizes:

Fine grained control over cx_Oracle data binding performance with setinputsizes
-------------------------------------------------------------------------------

The cx_Oracle DBAPI has a deep and fundamental reliance upon the usage of the
DBAPI ``setinputsizes()`` call.   The purpose of this call is to establish the
datatypes that are bound to a SQL statement for Python values being passed as
parameters.  While virtually no other DBAPI assigns any use to the
``setinputsizes()`` call, the cx_Oracle DBAPI relies upon it heavily in its
interactions with the Oracle client interface, and in some scenarios it is  not
possible for SQLAlchemy to know exactly how data should be bound, as some
settings can cause profoundly different performance characteristics, while
altering the type coercion behavior at the same time.

Users of the cx_Oracle dialect are **strongly encouraged** to read through
cx_Oracle's list of built-in datatype symbols at
http://cx-oracle.readthedocs.io/en/latest/module.html#types.
Note that in some cases, significant performance degradation can occur when
using these types vs. not, in particular when specifying ``cx_Oracle.CLOB``.

On the SQLAlchemy side, the :meth:`.DialectEvents.do_setinputsizes` event can
be used both for runtime visibility (e.g. logging) of the setinputsizes step as
well as to fully control how ``setinputsizes()`` is used on a per-statement
basis.

.. versionadded:: 1.2.9 Added :meth:`.DialectEvents.setinputsizes`


Example 1 - logging all setinputsizes calls
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The following example illustrates how to log the intermediary values from a
SQLAlchemy perspective before they are converted to the raw ``setinputsizes()``
parameter dictionary.  The keys of the dictionary are :class:`.BindParameter`
objects which have a ``.key`` and a ``.type`` attribute::

    from sqlalchemy import create_engine, event

    engine = create_engine("oracle+cx_oracle://scott:tiger@host/xe")

    @event.listens_for(engine, "do_setinputsizes")
    def _log_setinputsizes(inputsizes, cursor, statement, parameters, context):
        for bindparam, dbapitype in inputsizes.items():
                log.info(
                    "Bound parameter name: %s  SQLAlchemy type: %r  "
                    "DBAPI object: %s",
                    bindparam.key, bindparam.type, dbapitype)

Example 2 - remove all bindings to CLOB
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The ``CLOB`` datatype in cx_Oracle incurs a significant performance overhead,
however is set by default for the ``Text`` type within the SQLAlchemy 1.2
series.   This setting can be modified as follows::

    from sqlalchemy import create_engine, event
    from cx_Oracle import CLOB

    engine = create_engine("oracle+cx_oracle://scott:tiger@host/xe")

    @event.listens_for(engine, "do_setinputsizes")
    def _remove_clob(inputsizes, cursor, statement, parameters, context):
        for bindparam, dbapitype in list(inputsizes.items()):
            if dbapitype is CLOB:
                del inputsizes[bindparam]


.. _cx_oracle_returning:

RETURNING Support
-----------------

The cx_Oracle dialect implements RETURNING using OUT parameters.
The dialect supports RETURNING fully, however cx_Oracle 6 is recommended
for complete support.

.. _cx_oracle_lob:

LOB Objects
-----------

cx_oracle returns oracle LOBs using the cx_oracle.LOB object.  SQLAlchemy
converts these to strings so that the interface of the Binary type is
consistent with that of other backends, which takes place within a cx_Oracle
outputtypehandler.

cx_Oracle prior to version 6 would require that LOB objects be read before
a new batch of rows would be read, as determined by the ``cursor.arraysize``.
As of the 6 series, this limitation has been lifted.  Nevertheless, because
SQLAlchemy pre-reads these LOBs up front, this issue is avoided in any case.

To disable the auto "read()" feature of the dialect, the flag
``auto_convert_lobs=False`` may be passed to :func:`.create_engine`.  Under
the cx_Oracle 5 series, having this flag turned off means there is the chance
of reading from a stale LOB object if not read as it is fetched.   With
cx_Oracle 6, this issue is resolved.

.. versionchanged:: 1.2  the LOB handling system has been greatly simplified
   internally to make use of outputtypehandlers, and no longer makes use
   of alternate "buffered" result set objects.

Two Phase Transactions Not Supported
-------------------------------------

Two phase transactions are **not supported** under cx_Oracle due to poor
driver support.   As of cx_Oracle 6.0b1, the interface for
two phase transactions has been changed to be more of a direct pass-through
to the underlying OCI layer with less automation.  The additional logic
to support this system is not implemented in SQLAlchemy.

.. _cx_oracle_numeric:

Precision Numerics
------------------

SQLAlchemy's numeric types can handle receiving and returning values as Python
``Decimal`` objects or float objects.  When a :class:`.Numeric` object, or a
subclass such as :class:`.Float`, :class:`.oracle.DOUBLE_PRECISION` etc. is in
use, the :paramref:`.Numeric.asdecimal` flag determines if values should be
coerced to ``Decimal`` upon return, or returned as float objects.   To make
matters more complicated under Oracle, Oracle's ``NUMBER`` type can also
represent integer values if the "scale" is zero, so the Oracle-specific
:class:`.oracle.NUMBER` type takes this into account as well.

The cx_Oracle dialect makes extensive use of connection- and cursor-level
"outputtypehandler" callables in order to coerce numeric values as requested.
These callables are specific to the specific flavor of :class:`.Numeric` in
use, as well as if no SQLAlchemy typing objects are present.   There are
observed scenarios where Oracle may sends incomplete or ambiguous information
about the numeric types being returned, such as a query where the numeric types
are buried under multiple levels of subquery.  The type handlers do their best
to make the right decision in all cases, deferring to the underlying cx_Oracle
DBAPI for all those cases where the driver can make the best decision.

When no typing objects are present, as when executing plain SQL strings, a
default "outputtypehandler" is present which will generally return numeric
values which specify precision and scale as Python ``Decimal`` objects.  To
disable this coercion to decimal for performance reasons, pass the flag
``coerce_to_decimal=False`` to :func:`.create_engine`::

    engine = create_engine("oracle+cx_oracle://dsn", coerce_to_decimal=False)

The ``coerce_to_decimal`` flag only impacts the results of plain string
SQL staements that are not otherwise associated with a :class:`.Numeric`
SQLAlchemy type (or a subclass of such).

.. versionchanged:: 1.2  The numeric handling system for cx_Oracle has been
   reworked to take advantage of newer cx_Oracle features as well
   as better integration of outputtypehandlers.

é    )Úabsolute_importNé   )Úbase)ÚOracleCompiler)ÚOracleDialect)ÚOracleExecutionContexté   )Úexc)Ú
processors)Útypes)Úutil)Úresultc                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )Ú_OracleIntegerc                 C   s   t S ©N©Úint©ÚselfÚdbapi© r   úV/var/www/html/env/lib/python3.10/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyÚget_dbapi_typeA  s   z_OracleInteger.get_dbapi_typec                 C   s   |j }|j|jd|jtd�S )Néÿ   ©Ú	arraysizeÚoutconverter)r   ÚvarÚSTRINGr   r   )r   ÚdialectÚcursorÚ	cx_Oracler   r   r   Ú_cx_oracle_varF  s   ÿz_OracleInteger._cx_oracle_varc                    s   ‡ ‡fdd„}|S )Nc                    s   ˆ  ˆ | ¡S r   )r!   ©r   ÚnameÚdefault_typeÚsizeÚ	precisionÚscale©r   r   r   r   ÚhandlerM  s   z<_OracleInteger._cx_oracle_outputtypehandler.<locals>.handlerr   ©r   r   r)   r   r(   r   Ú_cx_oracle_outputtypehandlerL  s   z+_OracleInteger._cx_oracle_outputtypehandlerN)Ú__name__Ú
__module__Ú__qualname__r   r!   r+   r   r   r   r   r   @  s    r   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	Ú_OracleNumericFc                    s:   | j dkrd S | jrt tj| j¡‰ ‡ fdd„}|S tjS )Nr   c                    s2   t | ttfƒrˆ | ƒS | d ur|  ¡ rt| ƒS | S r   )Ú
isinstancer   ÚfloatÚis_infinite©Úvalue©Ú	processorr   r   Úprocess^  s
   z._OracleNumeric.bind_processor.<locals>.process)r'   Ú	asdecimalr
   Úto_decimal_processor_factoryÚdecimalÚDecimalÚ_effective_decimal_return_scaleÚto_float©r   r   r7   r   r5   r   Úbind_processorV  s   
ÿz_OracleNumeric.bind_processorc                 C   ó   d S r   r   ©r   r   Úcoltyper   r   r   Úresult_processorj  ó   z_OracleNumeric.result_processorc                    s"   ˆj ‰ ˆj‰‡ ‡‡‡fdd„}|S )Nc                    sº   d }|r,ˆj r|ˆ jkr|}tj}nAˆrtj}n;ˆ j}ˆj}n4ˆjr(|dkr(d S ˆ j}n'ˆj rG|ˆ jkr:|}tj}nˆr@tj}nˆ j}ˆj}nˆjrP|dkrPd S ˆ j}| j|d| j|d�S )Nr   r   r   )	r8   ÚNATIVE_FLOATr:   r;   r   Ú_to_decimalÚ	is_numberr   r   )r   r#   r$   r%   r&   r'   r   Útype_©r    r   Úis_cx_oracle_6r   r   r   r)   r  s<   

üz<_OracleNumeric._cx_oracle_outputtypehandler.<locals>.handler)r   Ú_is_cx_oracle_6r*   r   rI   r   r+   m  s   2z+_OracleNumeric._cx_oracle_outputtypehandlerN)r,   r-   r.   rG   r?   rC   r+   r   r   r   r   r/   S  s
    r/   c                   @   ó   e Zd Zdd„ ZdS )Ú_OracleBinaryFloatc                 C   ó   |j S r   )rE   r   r   r   r   r   ¨  ó   z!_OracleBinaryFloat.get_dbapi_typeN©r,   r-   r.   r   r   r   r   r   rM   §  ó    rM   c                   @   ó   e Zd ZdS )Ú_OracleBINARY_FLOATN©r,   r-   r.   r   r   r   r   rS   ¬  ó    rS   c                   @   rR   )Ú_OracleBINARY_DOUBLENrT   r   r   r   r   rV   °  rU   rV   c                   @   s   e Zd ZdZdS )Ú_OracleNUMBERTN)r,   r-   r.   rG   r   r   r   r   rW   ´  s    rW   c                   @   s   e Zd Zdd„ Zdd„ ZdS )Ú_OracleDatec                 C   r@   r   r   ©r   r   r   r   r   r?   ¹  rD   z_OracleDate.bind_processorc                 C   s   dd„ }|S )Nc                 S   s   | d ur|   ¡ S | S r   )Údater3   r   r   r   r7   ½  s   z-_OracleDate.result_processor.<locals>.processr   )r   r   rB   r7   r   r   r   rC   ¼  s   z_OracleDate.result_processorN)r,   r-   r.   r?   rC   r   r   r   r   rX   ¸  s    rX   c                   @   rL   )Ú_OracleCharc                 C   rN   r   )Ú
FIXED_CHARr   r   r   r   r   Ç  rO   z_OracleChar.get_dbapi_typeNrP   r   r   r   r   r[   Æ  rQ   r[   c                   @   rL   )Ú_OracleNVarCharc                 C   rN   r   )ÚNCHARr   r   r   r   r   Ì  rO   z_OracleNVarChar.get_dbapi_typeNrP   r   r   r   r   r]   Ë  rQ   r]   c                   @   rL   )Ú_OracleTextc                 C   rN   r   )ÚCLOBr   r   r   r   r   Ñ  rO   z_OracleText.get_dbapi_typeNrP   r   r   r   r   r_   Ð  rQ   r_   c                   @   rL   )Ú_OracleLongc                 C   rN   r   )ÚLONG_STRINGr   r   r   r   r   Ö  rO   z_OracleLong.get_dbapi_typeNrP   r   r   r   r   ra   Õ  rQ   ra   c                   @   rR   )Ú_OracleStringNrT   r   r   r   r   rc   Ú  rU   rc   c                   @   rL   )Ú_OracleEnumc                    s   t j | |¡‰ ‡ fdd„}|S )Nc                    s   ˆ | ƒ}|S r   r   )r4   Úraw_str©Ú	enum_procr   r   r7   â  s   z+_OracleEnum.bind_processor.<locals>.process)ÚsqltypesÚEnumr?   r>   r   rf   r   r?   ß  s   z_OracleEnum.bind_processorN)r,   r-   r.   r?   r   r   r   r   rd   Þ  rQ   rd   c                   @   rL   )Ú_OracleUnicodeTextc                 C   rN   r   )ÚNCLOBr   r   r   r   r   ê  rO   z!_OracleUnicodeText.get_dbapi_typeNrP   r   r   r   r   rj   é  rQ   rj   c                       s,   e Zd Zdd„ Zdd„ Z‡ fdd„Z‡  ZS )Ú_OracleBinaryc                 C   rN   r   )ÚBLOBr   r   r   r   r   ï  rO   z_OracleBinary.get_dbapi_typec                 C   r@   r   r   rY   r   r   r   r?   ò  rD   z_OracleBinary.bind_processorc                    s   |j sd S tt| ƒ ||¡S r   )Úauto_convert_lobsÚsuperrl   rC   rA   ©Ú	__class__r   r   rC   õ  s
   
ÿz_OracleBinary.result_processor)r,   r-   r.   r   r?   rC   Ú__classcell__r   r   rp   r   rl   î  s    rl   c                   @   rL   )Ú_OracleIntervalc                 C   rN   r   )ÚINTERVALr   r   r   r   r   ÿ  rO   z_OracleInterval.get_dbapi_typeNrP   r   r   r   r   rs   þ  rQ   rs   c                   @   rR   )Ú
_OracleRawNrT   r   r   r   r   ru     rU   ru   c                   @   rL   )Ú_OracleRowidc                 C   rN   r   )ÚROWIDr   r   r   r   r     rO   z_OracleRowid.get_dbapi_typeNrP   r   r   r   r   rv     rQ   rv   c                   @   s   e Zd ZdZdd„ ZdS )ÚOracleCompiler_cx_oracleTc                 K   s|   t |dd ƒ}|du s|dur4| j |¡r4| dd¡r!t d| ¡‚d| }|| j|< tj| |fi |¤ŽS tj| |fi |¤ŽS )NÚquoteTFÚ	expandingzyCan't use expanding feature with parameter name %r on Oracle; it requires quoting which is not supported in this context.z"%s")	ÚgetattrÚpreparerÚ_bindparam_requires_quotesÚgetr	   ÚCompileErrorÚ_quoted_bind_namesr   Úbindparam_string)r   r#   Úkwry   Úquoted_namer   r   r   r�     s   
ÿþÿ
z)OracleCompiler_cx_oracle.bindparam_stringN)r,   r-   r.   Ú_oracle_cx_sql_compilerr�   r   r   r   r   rx     s    rx   c                   @   sH   e Zd Z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 )Ú OracleExecutionContext_cx_oracleNc                 C   sD   | j j}|r| jD ]}| ¡ D ]\}}|| ||< ||= qq	d S d S r   )Úcompiledr€   Ú
parametersÚitems)r   Úquoted_bind_namesÚparamÚfromnameÚtonamer   r   r   Ú_setup_quoted_bind_names&  s   
þþz9OracleExecutionContext_cx_oracle._setup_quoted_bind_namesc                 C   sÌ   t | jƒdkrb| jj}| jj ¡ D ]R}|jra| jj| }|j 	| j
¡}t|dƒr4| | j
| j¡| j|< n| | j
j¡}|d u rJt d|j|jf ¡‚| j |¡| j|< | j| | jd | ||¡< qd S d S )Nr   r!   zXCannot create out parameter for parameter %r - its type %r is not supported by cx_oracler   )ÚlenÚcompiled_parametersr†   r€   ÚbindsÚvaluesÚ
isoutparamÚ
bind_namesÚtypeÚdialect_implr   Úhasattrr!   r   Úout_parametersr   r   r	   ÚInvalidRequestErrorÚkeyr   r‡   r~   )r   r‰   Ú	bindparamr#   Ú	type_implÚdbtyper   r   r   Ú_handle_out_parameters.  s2   
ÿ
þÿþ
ÿ€íz7OracleExecutionContext_cx_oracle._handle_out_parametersc                    sn   i ‰| j jD ]\}}}}| | jd| j¡}|r!| j |¡}|ˆ|< qˆr5| jj‰ ‡ ‡fdd„}|| j_d S d S )NÚcx_oracle_outputtypehandlerc                    s0   |ˆv rˆ| | |||||ƒS ˆ | |||||ƒS r   r   r"   ©Údefault_handlerÚoutput_handlersr   r   Úoutput_type_handlerX  s   ÿÿzaOracleExecutionContext_cx_oracle._generate_cursor_outputtype_handler.<locals>.output_type_handler)	r†   Ú_result_columnsÚ_cached_custom_processorr   Ú_get_cx_oracle_type_handlerÚdenormalize_nameÚ_dbapi_connectionÚoutputtypehandlerr   )r   Úkeynamer#   ÚobjectsrH   r)   Údenormalized_namer¢   r   rŸ   r   Ú#_generate_cursor_outputtype_handlerG  s    ý€ñzDOracleExecutionContext_cx_oracle._generate_cursor_outputtype_handlerc                 C   s   t |dƒr| | j¡S d S )Nr+   )r–   r+   r   )r   Úimplr   r   r   r¥   f  s   
z<OracleExecutionContext_cx_oracle._get_cx_oracle_type_handlerc                 C   sR   t | jddƒs	d S i | _| jjr|  ¡  | j| jj| jjd� |  ¡  |  	¡  d S )Nr„   F)Úinclude_types)
r{   r†   r—   r€   r�   Úset_input_sizesr   Ú_include_setinputsizesr�   r¬   ©r   r   r   r   Úpre_execl  s   þz)OracleExecutionContext_cx_oracle.pre_execc                 C   s    | j  ¡ }| jjr| jj|_|S r   )r§   r   r   r   )r   Úcr   r   r   Úcreate_cursor~  s   

z.OracleExecutionContext_cx_oracle.create_cursorc           
         s  ˆ j rˆ jjr‡ fdd„ttˆ j ƒƒD ƒ}tˆ |ƒS t ˆ ¡}ˆ j rˆˆ jd urytˆ jƒdkryi  |_ }ˆ jj	 
¡ D ]=\}}|ˆ j v rv|j}| ˆ j¡}| ˆ jj¡}| ˆ j|¡}	|	d urk|	ˆ j ˆ j | ¡ƒ||< q9ˆ j ˆ j | ¡||< q9|S t‡ fdd„ˆ j  
¡ D ƒƒ|_ |S )Nc                    s"   g | ]}ˆ j  ˆ jd |  ¡‘qS )zret_%d)r   Ú_returningvalr—   )Ú.0Úir±   r   r   Ú
<listcomp>‡  s    ÿÿzEOracleExecutionContext_cx_oracle.get_result_proxy.<locals>.<listcomp>r   c                 3   s$   � | ]\}}|ˆ j  |¡fV  qd S r   )Ú_dialectÚ	_paramval)r¶   ÚkÚvr±   r   r   Ú	<genexpr>«  s
   € ÿ
ÿzDOracleExecutionContext_cx_oracle.get_result_proxy.<locals>.<genexpr>)r—   r†   Ú	returningÚrangerŽ   ÚReturningResultProxyÚ_resultÚResultProxyr�   r“   rˆ   r”   r•   r   r   r   rC   rº   Údict)
r   Úreturning_paramsr   r—   Úbindr#   rH   Ú	impl_typeÚ
dbapi_typerC   r   r±   r   Úget_result_proxy…  sF   
þ




ÿÿÿ
ÿÿ€	û
þz1OracleExecutionContext_cx_oracle.get_result_proxy)r,   r-   r.   r—   r�   r�   r¬   r¥   r²   r´   rÈ   r   r   r   r   r…   #  s    r…   c                       s0   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Z‡  ZS )rÀ   zOResult proxy which stuffs the _returning clause + outparams
    into the fetch.c                    s   || _ tt| ƒ |¡ d S r   )Ú_returning_paramsro   rÀ   Ú__init__)r   ÚcontextrÄ   rp   r   r   rÊ   ·  s   zReturningResultProxy.__init__c                 C   s   | j jj}dd„ |D ƒS )Nc                 S   s   g | ]}t |d |jƒdf‘qS )r#   N)r{   Ú
anon_label)r¶   Úcolr   r   r   r¸   ½  s    ÿz<ReturningResultProxy._cursor_description.<locals>.<listcomp>)rË   r†   r¾   )r   r¾   r   r   r   Ú_cursor_description»  s   
ÿz(ReturningResultProxy._cursor_descriptionc                 C   s   t  t| jƒg¡S r   )ÚcollectionsÚdequeÚtuplerÉ   r±   r   r   r   Ú_buffer_rowsÁ  ó   z!ReturningResultProxy._buffer_rows)r,   r-   r.   Ú__doc__rÊ   rÎ   rÒ   rr   r   r   rp   r   rÀ   ³  s
    rÀ   c                	       s–  e Zd ZeZeZdZdZdZ	dZ
dZi eje“eje“eje“eje“eje“eje“eje“eje“ejej“eje “ej!e “ej"e#“ej$e%“ej&e'“ej(e)“ej*e+“ej,e-“ej.e/ej0e1ej2e1ej3e4i¥Z5e6Z7					d,dd„Z8dd„ Z9d	d
„ Z:e;dd„ ƒZ<‡ fdd„Z=dd„ Z>dd„ Z?e@jAZBdd„ ZCdd„ ZDdd„ ZEdd„ ZFdd„ ZGdd„ ZHd-d d!„ZId"d#„ ZJd$d%„ ZK	d.d&d'„ZL	d.d(d)„ZMd*d+„ ZN‡  ZOS )/ÚOracleDialect_cx_oracleTÚ	cx_oracleFé2   c           	      K   sú   |   |¡ tj| fi |¤Ž || _|| _|| _|| _|| _| j}|d u r+i | _	d| _
nJ|  |j¡| _
| j
dk rA| j
dkrAt d¡‚|j|j|j|j|j|j|j|jttth| _	dd„ | _| j
dk| _| jrqd|j_dd	„ }|| _n| j| _| j
d
k| _d S )N©r   r   r   )é   é   z-cx_Oracle version 5.2 and above are supportedc                 S   ó   |   ¡ S r   )Úgetvaluer3   r   r   r   Ú<lambda>  ó    z2OracleDialect_cx_oracle.__init__.<locals>.<lambda>)é   r   Tc                 S   s&   z| j d d W S  ty   Y d S w ©Nr   )r‘   Ú
IndexErrorr3   r   r   r   rµ      s
   ÿz7OracleDialect_cx_oracle.__init__.<locals>._returningval)rß   ) Ú_pop_deprecated_kwargsr   rÊ   Úthreadedr   rn   Úcoerce_to_unicodeÚcoerce_to_decimalr   r°   Úcx_oracle_verÚ_parse_cx_oracle_verÚversionr	   r˜   rk   r`   ÚLOBr^   ÚFIXED_NCHARrm   r\   Ú	TIMESTAMPr   rS   rV   rº   Ú_values_are_listsÚ
__future__Údml_ret_array_valrµ   rK   )	r   rn   rã   rä   rå   r   Úkwargsr    rµ   r   r   r   rÊ   ë  sH   

ÿõ
z OracleDialect_cx_oracle.__init__c                 C   sR   |  dd ¡}|  dd ¡}|s|rt d¡ |  dd ¡}|d ur'tj d¡ d S d S )NÚauto_setinputsizesÚexclude_setinputsizeszµauto_setinputsizes and exclude_setinputsizes are deprecated. Modern cx_Oracle only requires that LOB types are part of this behavior, and these parameters no longer have any effect.Úallow_twophasezcallow_twophase is deprecated.  The cx_Oracle dialect no longer supports two-phase transaction mode.)Úpopr   Úwarn_deprecatedÚwarnÚ
deprecated)r   rï   rð   rñ   rò   r   r   r   râ   ,  s   ÿÿÿz.OracleDialect_cx_oracle._pop_deprecated_kwargsc                 C   s0   t  d|¡}|rtdd„ | ddd¡D ƒƒS dS )Nz(\d+)\.(\d+)(?:\.(\d+))?c                 s   s    � | ]}|d urt |ƒV  qd S r   r   ©r¶   Úxr   r   r   r½   @  s   € z?OracleDialect_cx_oracle._parse_cx_oracle_ver.<locals>.<genexpr>r   rÚ   r   rØ   )ÚreÚmatchrÑ   Úgroup)r   rè   Úmr   r   r   rç   =  s   z,OracleDialect_cx_oracle._parse_cx_oracle_verc                 C   s   dd l }|S rà   )r    )Úclsr    r   r   r   r   D  s   zOracleDialect_cx_oracle.dbapic                    s*   t t| ƒ |¡ | jrd| _|  |¡ d S )NF)ro   rÕ   Ú
initializeÚ_is_oracle_8Úsupports_unicode_bindsÚ_detect_decimal_char©r   Ú
connectionrp   r   r   rþ   J  s   z"OracleDialect_cx_oracle.initializec                    sN   |  d¡d ˆ_ˆjdkr%ˆj‰ ˆj‰‡ ‡fdd„ˆ_‡‡fdd„ˆ_d S d S )NzSselect value from nls_session_parameters where parameter = 'NLS_NUMERIC_CHARACTERS'r   Ú.c                    ó   ˆ |   ˆjd¡ƒS ©Nr  ©ÚreplaceÚ_decimal_charr3   )Ú_detect_decimalr   r   r   rÝ   `  ó    ÿz>OracleDialect_cx_oracle._detect_decimal_char.<locals>.<lambda>c                    r  r  r  r3   )rF   r   r   r   rÝ   c  r  )Úscalarr	  r
  rF   r  r   )r
  rF   r   r   r  Q  s   ÿý
ùz,OracleDialect_cx_oracle._detect_decimal_charc                 C   s   d|v r	|   |¡S t|ƒS r  )rF   r   )r   r4   r   r   r   r
  g  s   
z'OracleDialect_cx_oracle._detect_decimalc                    s@   | ‰ˆj ‰ tdd� ˆ¡‰tdd� ˆ¡‰‡ ‡‡‡fdd„}|S )z^establish the default outputtypehandler established at the
        connection level.

        T)r8   Fc                    sÎ   |ˆ j kr6ˆjs
d S |dkr|dv r| jˆ jdˆj| jd�S |r-|dkr-ˆ| |||||ƒS ˆ| |||||ƒS ˆjrJ|ˆ jˆ jfv rJ|  tj	|| j¡S ˆj
rc|ˆ jˆ jˆ jfv re| j||| jdd„ d�S d S d S )Nr   )r   i�ÿÿÿr   )r   r   c                 S   rÛ   r   )Úreadr3   r   r   r   rÝ   ¦  rÞ   znOracleDialect_cx_oracle._generate_connection_outputtype_handler.<locals>.output_type_handler.<locals>.<lambda>)r   )ÚNUMBERrå   r   r   r
  r   rä   r\   r   Ú	text_typern   r`   rk   rm   r"   ©r    r   Úfloat_handlerÚnumber_handlerr   r   r¢     sD   
üÿÿþýüûz\OracleDialect_cx_oracle._generate_connection_outputtype_handler.<locals>.output_type_handler)r   rW   r+   )r   r¢   r   r  r   Ú'_generate_connection_outputtype_handlero  s   ÿþÿþ*z?OracleDialect_cx_oracle._generate_connection_outputtype_handlerc                    s   |   ¡ ‰ ‡ fdd„}|S )Nc                    s
   ˆ | _ d S r   )r¨   )Úconn©r¢   r   r   Ú
on_connect¯  s   
z6OracleDialect_cx_oracle.on_connect.<locals>.on_connect)r  )r   r  r   r  r   r  «  s   z"OracleDialect_cx_oracle.on_connectc                 C   s|  t |jƒ}dD ]}||v rt ||t¡ t| ||| ƒ q|j}| dd ¡}|s*|rX|j}|r4t	|ƒ}nd}|r?|r?t
 d¡‚|rEd|i}|rKd|i}| jj|j|fi |¤Ž}n|j}t | jd�}	|d uri||	d< |jd urs|j|	d< |jd ur}|j|	d	< d
|jv rº|jd
 |	d
< t|	d
 tjƒrº|	d
  ¡ }
|
dkr¥| jj|	d
< g |	fS |
dkr³| jj|	d
< g |	fS t |	d
t	¡ g |	fS )N)Úuse_ansirð   rn   rã   rò   Úservice_nameiñ  zI"service_name" option shouldn't be used with a "database" part of the urlÚsid)rã   ÚdsnÚpasswordÚuserÚmodeÚSYSDBAÚSYSOPER)rÃ   Úqueryr   Úcoerce_kw_typeÚboolÚsetattrÚdatabaser~   Úportr   r	   r˜   r   ÚmakedsnÚhostrã   r  Úusernamer0   Ústring_typesÚupperr  r  )r   ÚurlÚdialect_optsÚoptr$  r  r%  Úmakedsn_kwargsr  Úoptsr  r   r   r   Úcreate_connect_args´  sT   
€
ÿ




üÿz+OracleDialect_cx_oracle.create_connect_argsc                 C   s   t dd„ |jj d¡D ƒƒS )Nc                 s   s   � | ]}t |ƒV  qd S r   r   r÷   r   r   r   r½   ñ  s   € zCOracleDialect_cx_oracle._get_server_version_info.<locals>.<genexpr>r  )rÑ   r  rè   Úsplitr  r   r   r   Ú_get_server_version_infoð  s   z0OracleDialect_cx_oracle._get_server_version_infoc                 C   sF   |j \}t|| jj| jjfƒrdt|ƒv rdS t|dƒr!|jdv S dS )Nznot connectedTÚcode)é   i*  i)  i?  i	  i\	  F)Úargsr0   r   ÚInterfaceErrorÚDatabaseErrorÚstrr–   r3  )r   Úer  r   Úerrorr   r   r   Úis_disconnectó  s   ÿ

z%OracleDialect_cx_oracle.is_disconnectc                 C   s"   t  ddd ¡}dd| dd fS )aH  create a two-phase transaction ID.

        this id will be passed to do_begin_twophase(), do_rollback_twophase(),
        do_commit_twophase().  its format is unspecified.

        .. deprecated:: two-phase transaction support is no longer functional
           in SQLAlchemy's cx_Oracle dialect as of cx_Oracle 6.0b1

        r   rÚ   é€   i4  z%032xé	   )ÚrandomÚrandint)r   Úid_r   r   r   Ú
create_xid  s   z"OracleDialect_cx_oracle.create_xidNc                 C   s"   t |tƒr	t|ƒ}| ||¡ d S r   )r0   rÑ   ÚlistÚexecutemany)r   r   Ú	statementr‡   rË   r   r   r   Údo_executemany  s   
z&OracleDialect_cx_oracle.do_executemanyc                 C   s   |j j|Ž  d S r   )r  Úbegin)r   r  Úxidr   r   r   Údo_begin_twophase  s   z)OracleDialect_cx_oracle.do_begin_twophasec                 C   s   |j  ¡ }||jd< d S ©NÚcx_oracle_prepared)r  ÚprepareÚinfo)r   r  rG  r   r   r   r   Údo_prepare_twophase  s   
z+OracleDialect_cx_oracle.do_prepare_twophasec                 C   s   |   |j¡ d S r   )Údo_rollbackr  )r   r  rG  Úis_preparedÚrecoverr   r   r   Údo_rollback_twophase   s   z,OracleDialect_cx_oracle.do_rollback_twophasec                 C   s6   |s
|   |j¡ d S |jd }|r|   |j¡ d S d S rI  )Ú	do_commitr  rL  )r   r  rG  rO  rP  Úoci_preparedr   r   r   Údo_commit_twophase%  s   
ÿz*OracleDialect_cx_oracle.do_commit_twophasec                 C   s   |j  dd ¡ d S rI  )rL  ró   r  r   r   r   Údo_recover_twophase/  rÓ   z+OracleDialect_cx_oracle.do_recover_twophase)TTFTr×   r   )TF)Pr,   r-   r.   r…   Úexecution_ctx_clsrx   Ústatement_compilerÚsupports_sane_rowcountÚsupports_sane_multi_rowcountÚsupports_unicode_statementsr   Údriverrh   ÚNumericr/   ÚFloatÚoracleÚBINARY_FLOATrS   ÚBINARY_DOUBLErV   ÚIntegerr   r  rW   ÚDaterX   ÚLargeBinaryrl   ÚBooleanÚ_OracleBooleanÚIntervalrs   rt   ÚTextr_   ÚStringrc   ÚUnicodeTextrj   ÚCHARr[   ri   rd   ÚLONGra   ÚRAWru   ÚUnicoder]   ÚNVARCHARrw   rv   ÚcolspecsrB  Úexecute_sequence_formatrÊ   râ   rç   Úclassmethodr   rþ   r  r
  r:   r;   rF   r  r  r0  r2  r;  rA  rE  rH  rM  rQ  rT  rU  rr   r   r   rp   r   rÕ   Å  sš    ÿþýüûúùø	÷
öõôóòñðïë
úA
<	<

ÿ
ÿ
rÕ   )=rÔ   rí   r   rÏ   r:   r>  rù   Ú r   r^  r   r   r   r	   r
   r   rh   r   Úenginer   rÁ   ra  r   r\  r/   rM   r_  rS   r`  rV   rW   rb  rX   rj  r[   rn  r]   rg  r_   rk  ra   rh  rc   ri   rd   ri  rj   rc  rl   rt   rs   rl  ru   rw   rv   rx   r…   ÚFullyBufferedResultProxyrÀ   rÕ   r   r   r   r   r   Ú<module>   sV     )T   p