
    +hU                       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dj?                               Z  edj?                               Z! G d dejD                        Z#e#Z$ G d dejJ                        Z& G d  d!e      Z'eZ( G d" d#ejR                  ejT                        Z+ G d$ d%ejX                        Z- G d& d'ejX                        Z. G d( d)ejX                        Z/ G d* d+ej`                        Z1 G d, d-ejJ                        Z2 G d. d/ejf                        Z4 G d0 d1ejj                  ejl                        Z7 G d2 d3ejp                        Z9 G d4 d5ejt                        Z;ejt                  e;ejx                  e7ejf                  e4iZ=i d!ed6ed7ed8ed/e4d#e+d9ed+e1d:ede&d;ed<ed=e7de#d>ed?e-d-e2e.e/e9d@Z> G dA dBej~                        Z@ G dC dDej                        ZB G dE dFej                        ZD G dG dHej                        ZF G dI dJej                        ZH G dK dLej                        ZJ G dM dNe	j                        ZLy)OaTU  
.. dialect:: oracle
    :name: Oracle
    :full_support: 11.2, 18c
    :normal_support: 11+
    :best_effort: 8+


Auto Increment Behavior
-----------------------

SQLAlchemy Table objects which include integer primary keys are usually
assumed to have "autoincrementing" behavior, meaning they can generate their
own primary key values upon INSERT. For use within Oracle, two options are
available, which are the use of IDENTITY columns (Oracle 12 and above only)
or the association of a SEQUENCE with the column.

Specifying GENERATED AS IDENTITY (Oracle 12 and above)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Starting from version 12 Oracle can make use of identity columns using
the :class:`_sql.Identity` to specify the autoincrementing behavior::

    t = Table('mytable', metadata,
        Column('id', Integer, Identity(start=3), primary_key=True),
        Column(...), ...
    )

The CREATE TABLE for the above :class:`_schema.Table` object would be:

.. sourcecode:: sql

    CREATE TABLE mytable (
        id INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 3),
        ...,
        PRIMARY KEY (id)
    )

The :class:`_schema.Identity` object support many options to control the
"autoincrementing" behavior of the column, like the starting value, the
incrementing value, etc.
In addition to the standard options, Oracle supports setting
:paramref:`_schema.Identity.always` to ``None`` to use the default
generated mode, rendering GENERATED AS IDENTITY in the DDL. It also supports
setting :paramref:`_schema.Identity.on_null` to ``True`` to specify ON NULL
in conjunction with a 'BY DEFAULT' identity column.

Using a SEQUENCE (all Oracle versions)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Older version of Oracle had no "autoincrement"
feature, SQLAlchemy relies upon sequences to produce these values.   With the
older Oracle versions, *a sequence must always be explicitly specified to
enable autoincrement*.  This is divergent with the majority of documentation
examples which assume the usage of an autoincrement-capable database.   To
specify sequences, use the sqlalchemy.schema.Sequence object which is passed
to a Column construct::

  t = Table('mytable', metadata,
        Column('id', Integer, Sequence('id_seq'), primary_key=True),
        Column(...), ...
  )

This step is also required when using table reflection, i.e. autoload_with=engine::

  t = Table('mytable', metadata,
        Column('id', Integer, Sequence('id_seq'), primary_key=True),
        autoload_with=engine
  )

.. versionchanged::  1.4   Added :class:`_schema.Identity` construct
   in a :class:`_schema.Column` to specify the option of an autoincrementing
   column.

.. _oracle_isolation_level:

Transaction Isolation Level / Autocommit
----------------------------------------

The Oracle database supports "READ COMMITTED" and "SERIALIZABLE" modes of
isolation. The AUTOCOMMIT isolation level is also supported by the cx_Oracle
dialect.

To set using per-connection execution options::

    connection = engine.connect()
    connection = connection.execution_options(
        isolation_level="AUTOCOMMIT"
    )

For ``READ COMMITTED`` and ``SERIALIZABLE``, the Oracle dialect sets the
level at the session level using ``ALTER SESSION``, which is reverted back
to its default setting when the connection is returned to the connection
pool.

Valid values for ``isolation_level`` include:

* ``READ COMMITTED``
* ``AUTOCOMMIT``
* ``SERIALIZABLE``

.. note:: The implementation for the
   :meth:`_engine.Connection.get_isolation_level` method as implemented by the
   Oracle dialect necessarily forces the start of a transaction using the
   Oracle LOCAL_TRANSACTION_ID function; otherwise no level is normally
   readable.

   Additionally, the :meth:`_engine.Connection.get_isolation_level` method will
   raise an exception if the ``v$transaction`` view is not available due to
   permissions or other reasons, which is a common occurrence in Oracle
   installations.

   The cx_Oracle dialect attempts to call the
   :meth:`_engine.Connection.get_isolation_level` method when the dialect makes
   its first connection to the database in order to acquire the
   "default"isolation level.  This default level is necessary so that the level
   can be reset on a connection after it has been temporarily modified using
   :meth:`_engine.Connection.execution_options` method.   In the common event
   that the :meth:`_engine.Connection.get_isolation_level` method raises an
   exception due to ``v$transaction`` not being readable as well as any other
   database-related failure, the level is assumed to be "READ COMMITTED".  No
   warning is emitted for this initial first-connect condition as it is
   expected to be a common restriction on Oracle databases.

.. versionadded:: 1.3.16 added support for AUTOCOMMIT to the cx_oracle dialect
   as well as the notion of a default isolation level

.. versionadded:: 1.3.21 Added support for SERIALIZABLE as well as live
   reading of the isolation level.

.. versionchanged:: 1.3.22 In the event that the default isolation
   level cannot be read due to permissions on the v$transaction view as
   is common in Oracle installations, the default isolation level is hardcoded
   to "READ COMMITTED" which was the behavior prior to 1.3.21.

.. seealso::

    :ref:`dbapi_autocommit`

Identifier Casing
-----------------

In Oracle, the data dictionary represents all case insensitive identifier
names using UPPERCASE text.   SQLAlchemy on the other hand considers an
all-lower case identifier name to be case insensitive.   The Oracle dialect
converts all case insensitive identifiers to and from those two formats during
schema level communication, such as reflection of tables and indexes.   Using
an UPPERCASE name on the SQLAlchemy side indicates a case sensitive
identifier, and SQLAlchemy will quote the name - this will cause mismatches
against data dictionary data received from Oracle, so unless identifier names
have been truly created as case sensitive (i.e. using quoted names), all
lowercase names should be used on the SQLAlchemy side.

.. _oracle_max_identifier_lengths:

Max Identifier Lengths
----------------------

Oracle has changed the default max identifier length as of Oracle Server
version 12.2.   Prior to this version, the length was 30, and for 12.2 and
greater it is now 128.   This change impacts SQLAlchemy in the area of
generated SQL label names as well as the generation of constraint names,
particularly in the case where the constraint naming convention feature
described at :ref:`constraint_naming_conventions` is being used.

To assist with this change and others, Oracle includes the concept of a
"compatibility" version, which is a version number that is independent of the
actual server version in order to assist with migration of Oracle databases,
and may be configured within the Oracle server itself. This compatibility
version is retrieved using the query  ``SELECT value FROM v$parameter WHERE
name = 'compatible';``.   The SQLAlchemy Oracle dialect, when tasked with
determining the default max identifier length, will attempt to use this query
upon first connect in order to determine the effective compatibility version of
the server, which determines what the maximum allowed identifier length is for
the server.  If the table is not available, the  server version information is
used instead.

As of SQLAlchemy 1.4, the default max identifier length for the Oracle dialect
is 128 characters.  Upon first connect, the compatibility version is detected
and if it is less than Oracle version 12.2, the max identifier length is
changed to be 30 characters.  In all cases, setting the
:paramref:`_sa.create_engine.max_identifier_length` parameter will bypass this
change and the value given will be used as is::

    engine = create_engine(
        "oracle+cx_oracle://scott:tiger@oracle122",
        max_identifier_length=30)

The maximum identifier length comes into play both when generating anonymized
SQL labels in SELECT statements, but more crucially when generating constraint
names from a naming convention.  It is this area that has created the need for
SQLAlchemy to change this default conservatively.   For example, the following
naming convention produces two very different constraint names based on the
identifier length::

    from sqlalchemy import Column
    from sqlalchemy import Index
    from sqlalchemy import Integer
    from sqlalchemy import MetaData
    from sqlalchemy import Table
    from sqlalchemy.dialects import oracle
    from sqlalchemy.schema import CreateIndex

    m = MetaData(naming_convention={"ix": "ix_%(column_0N_name)s"})

    t = Table(
        "t",
        m,
        Column("some_column_name_1", Integer),
        Column("some_column_name_2", Integer),
        Column("some_column_name_3", Integer),
    )

    ix = Index(
        None,
        t.c.some_column_name_1,
        t.c.some_column_name_2,
        t.c.some_column_name_3,
    )

    oracle_dialect = oracle.dialect(max_identifier_length=30)
    print(CreateIndex(ix).compile(dialect=oracle_dialect))

With an identifier length of 30, the above CREATE INDEX looks like::

    CREATE INDEX ix_some_column_name_1s_70cd ON t
    (some_column_name_1, some_column_name_2, some_column_name_3)

However with length=128, it becomes::

    CREATE INDEX ix_some_column_name_1some_column_name_2some_column_name_3 ON t
    (some_column_name_1, some_column_name_2, some_column_name_3)

Applications which have run versions of SQLAlchemy prior to 1.4 on an  Oracle
server version 12.2 or greater are therefore subject to the scenario of a
database migration that wishes to "DROP CONSTRAINT" on a name that was
previously generated with the shorter length.  This migration will fail when
the identifier length is changed without the name of the index or constraint
first being adjusted.  Such applications are strongly advised to make use of
:paramref:`_sa.create_engine.max_identifier_length`
in order to maintain control
of the generation of truncated names, and to fully review and test all database
migrations in a staging environment when changing this value to ensure that the
impact of this change has been mitigated.

.. versionchanged:: 1.4 the default max_identifier_length for Oracle is 128
   characters, which is adjusted down to 30 upon first connect if an older
   version of Oracle server (compatibility version < 12.2) is detected.


LIMIT/OFFSET/FETCH Support
--------------------------

Methods like :meth:`_sql.Select.limit` and :meth:`_sql.Select.offset` currently
use an emulated approach for LIMIT / OFFSET based on window functions, which
involves creation of a subquery using ``ROW_NUMBER`` that is prone to
performance issues as well as SQL construction issues for complex statements.
However, this approach is supported by all Oracle versions.  See notes below.

When using Oracle 12c and above, use the :meth:`_sql.Select.fetch` method
instead; this will render the more modern
``FETCH FIRST N ROW / OFFSET N ROWS`` syntax.

Notes on LIMIT / OFFSET emulation (when fetch() method cannot be used)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If using :meth:`_sql.Select.limit` and :meth:`_sql.Select.offset`,
or with the ORM the :meth:`_orm.Query.limit` and :meth:`_orm.Query.offset` methods,
and the :meth:`_sql.Select.fetch` method **cannot** be used instead, the following
notes apply:

* SQLAlchemy currently makes use of ROWNUM to achieve
  LIMIT/OFFSET; the exact methodology is taken from
  https://blogs.oracle.com/oraclemagazine/on-rownum-and-limiting-results .

* the "FIRST_ROWS()" optimization keyword is not used by default.  To enable
  the usage of this optimization directive, specify ``optimize_limits=True``
  to :func:`_sa.create_engine`.

  .. versionchanged:: 1.4
      The Oracle dialect renders limit/offset integer values using a "post
      compile" scheme which renders the integer directly before passing the
      statement to the cursor for execution.   The ``use_binds_for_limits`` flag
      no longer has an effect.

      .. seealso::

          :ref:`change_4808`.

* A future release may use ``FETCH FIRST N ROW / OFFSET N ROWS`` automatically
  when :meth:`_sql.Select.limit`, :meth:`_sql.Select.offset`, :meth:`_orm.Query.limit`,
  :meth:`_orm.Query.offset` are used.

.. _oracle_returning:

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

The Oracle database supports a limited form of RETURNING, in order to retrieve
result sets of matched rows from INSERT, UPDATE and DELETE statements.
Oracle's RETURNING..INTO syntax only supports one row being returned, as it
relies upon OUT parameters in order to function.  In addition, supported
DBAPIs have further limitations (see :ref:`cx_oracle_returning`).

SQLAlchemy's "implicit returning" feature, which employs RETURNING within an
INSERT and sometimes an UPDATE statement in order to fetch newly generated
primary key values and other SQL defaults and expressions, is normally enabled
on the Oracle backend.  By default, "implicit returning" typically only
fetches the value of a single ``nextval(some_seq)`` expression embedded into
an INSERT in order to increment a sequence within an INSERT statement and get
the value back at the same time. To disable this feature across the board,
specify ``implicit_returning=False`` to :func:`_sa.create_engine`::

    engine = create_engine("oracle://scott:tiger@dsn",
                           implicit_returning=False)

Implicit returning can also be disabled on a table-by-table basis as a table
option::

    # Core Table
    my_table = Table("my_table", metadata, ..., implicit_returning=False)


    # declarative
    class MyClass(Base):
        __tablename__ = 'my_table'
        __table_args__ = {"implicit_returning": False}

.. seealso::

    :ref:`cx_oracle_returning` - additional cx_oracle-specific restrictions on
    implicit returning.

ON UPDATE CASCADE
-----------------

Oracle doesn't have native ON UPDATE CASCADE functionality.  A trigger based
solution is available at
https://asktom.oracle.com/tkyte/update_cascade/index.html .

When using the SQLAlchemy ORM, the ORM has limited ability to manually issue
cascading updates - specify ForeignKey objects using the
"deferrable=True, initially='deferred'" keyword arguments,
and specify "passive_updates=False" on each relationship().

Oracle 8 Compatibility
----------------------

When Oracle 8 is detected, the dialect internally configures itself to the
following behaviors:

* the use_ansi flag is set to False.  This has the effect of converting all
  JOIN phrases into the WHERE clause, and in the case of LEFT OUTER JOIN
  makes use of Oracle's (+) operator.

* the NVARCHAR2 and NCLOB datatypes are no longer generated as DDL when
  the :class:`~sqlalchemy.types.Unicode` is used - VARCHAR2 and CLOB are
  issued instead.   This because these types don't seem to work correctly on
  Oracle 8 even though they are available.  The
  :class:`~sqlalchemy.types.NVARCHAR` and
  :class:`~sqlalchemy.dialects.oracle.NCLOB` types will always generate
  NVARCHAR2 and NCLOB.

* the "native unicode" mode is disabled when using cx_oracle, i.e. SQLAlchemy
  encodes all Python unicode objects to "string" before passing in as bind
  parameters.

Synonym/DBLINK Reflection
-------------------------

When using reflection with Table objects, the dialect can optionally search
for tables indicated by synonyms, either in local or remote schemas or
accessed over DBLINK, by passing the flag ``oracle_resolve_synonyms=True`` as
a keyword argument to the :class:`_schema.Table` construct::

    some_table = Table('some_table', autoload_with=some_engine,
                                oracle_resolve_synonyms=True)

When this flag is set, the given name (such as ``some_table`` above) will
be searched not just in the ``ALL_TABLES`` view, but also within the
``ALL_SYNONYMS`` view to see if this name is actually a synonym to another
name.  If the synonym is located and refers to a DBLINK, the oracle dialect
knows how to locate the table's information using DBLINK syntax(e.g.
``@dblink``).

``oracle_resolve_synonyms`` is accepted wherever reflection arguments are
accepted, including methods such as :meth:`_schema.MetaData.reflect` and
:meth:`_reflection.Inspector.get_columns`.

If synonyms are not in use, this flag should be left disabled.

.. _oracle_constraint_reflection:

Constraint Reflection
---------------------

The Oracle dialect can return information about foreign key, unique, and
CHECK constraints, as well as indexes on tables.

Raw information regarding these constraints can be acquired using
:meth:`_reflection.Inspector.get_foreign_keys`,
:meth:`_reflection.Inspector.get_unique_constraints`,
:meth:`_reflection.Inspector.get_check_constraints`, and
:meth:`_reflection.Inspector.get_indexes`.

.. versionchanged:: 1.2  The Oracle dialect can now reflect UNIQUE and
   CHECK constraints.

When using reflection at the :class:`_schema.Table` level, the
:class:`_schema.Table`
will also include these constraints.

Note the following caveats:

* When using the :meth:`_reflection.Inspector.get_check_constraints` method,
  Oracle
  builds a special "IS NOT NULL" constraint for columns that specify
  "NOT NULL".  This constraint is **not** returned by default; to include
  the "IS NOT NULL" constraints, pass the flag ``include_all=True``::

      from sqlalchemy import create_engine, inspect

      engine = create_engine("oracle+cx_oracle://s:t@dsn")
      inspector = inspect(engine)
      all_check_constraints = inspector.get_check_constraints(
          "some_table", include_all=True)

* in most cases, when reflecting a :class:`_schema.Table`,
  a UNIQUE constraint will
  **not** be available as a :class:`.UniqueConstraint` object, as Oracle
  mirrors unique constraints with a UNIQUE index in most cases (the exception
  seems to be when two or more unique constraints represent the same columns);
  the :class:`_schema.Table` will instead represent these using
  :class:`.Index`
  with the ``unique=True`` flag set.

* Oracle creates an implicit index for the primary key of a table; this index
  is **excluded** from all index results.

* the list of columns reflected for an index will not include column names
  that start with SYS_NC.

Table names with SYSTEM/SYSAUX tablespaces
-------------------------------------------

The :meth:`_reflection.Inspector.get_table_names` and
:meth:`_reflection.Inspector.get_temp_table_names`
methods each return a list of table names for the current engine. These methods
are also part of the reflection which occurs within an operation such as
:meth:`_schema.MetaData.reflect`.  By default,
these operations exclude the ``SYSTEM``
and ``SYSAUX`` tablespaces from the operation.   In order to change this, the
default list of tablespaces excluded can be changed at the engine level using
the ``exclude_tablespaces`` parameter::

    # exclude SYSAUX and SOME_TABLESPACE, but not SYSTEM
    e = create_engine(
      "oracle://scott:tiger@xe",
      exclude_tablespaces=["SYSAUX", "SOME_TABLESPACE"])

.. versionadded:: 1.1

DateTime Compatibility
----------------------

Oracle has no datatype known as ``DATETIME``, it instead has only ``DATE``,
which can actually store a date and time value.  For this reason, the Oracle
dialect provides a type :class:`_oracle.DATE` which is a subclass of
:class:`.DateTime`.   This type has no special behavior, and is only
present as a "marker" for this type; additionally, when a database column
is reflected and the type is reported as ``DATE``, the time-supporting
:class:`_oracle.DATE` type is used.

.. versionchanged:: 0.9.4 Added :class:`_oracle.DATE` to subclass
   :class:`.DateTime`.  This is a change as previous versions
   would reflect a ``DATE`` column as :class:`_types.DATE`, which subclasses
   :class:`.Date`.   The only significance here is for schemes that are
   examining the type of column for use in special Python translations or
   for migrating schemas to other database backends.

.. _oracle_table_options:

Oracle Table Options
-------------------------

The CREATE TABLE phrase supports the following options with Oracle
in conjunction with the :class:`_schema.Table` construct:


* ``ON COMMIT``::

    Table(
        "some_table", metadata, ...,
        prefixes=['GLOBAL TEMPORARY'], oracle_on_commit='PRESERVE ROWS')

.. versionadded:: 1.0.0

* ``COMPRESS``::

    Table('mytable', metadata, Column('data', String(32)),
        oracle_compress=True)

    Table('mytable', metadata, Column('data', String(32)),
        oracle_compress=6)

   The ``oracle_compress`` parameter accepts either an integer compression
   level, or ``True`` to use the default compression level.

.. versionadded:: 1.0.0

.. _oracle_index_options:

Oracle Specific Index Options
-----------------------------

Bitmap Indexes
~~~~~~~~~~~~~~

You can specify the ``oracle_bitmap`` parameter to create a bitmap index
instead of a B-tree index::

    Index('my_index', my_table.c.data, oracle_bitmap=True)

Bitmap indexes cannot be unique and cannot be compressed. SQLAlchemy will not
check for such limitations, only the database will.

.. versionadded:: 1.0.0

Index compression
~~~~~~~~~~~~~~~~~

Oracle has a more efficient storage mode for indexes containing lots of
repeated values. Use the ``oracle_compress`` parameter to turn on key
compression::

    Index('my_index', my_table.c.data, oracle_compress=True)

    Index('my_index', my_table.c.data1, my_table.c.data2, unique=True,
           oracle_compress=1)

The ``oracle_compress`` parameter accepts either an integer specifying the
number of prefix columns to compress, or ``True`` to use the default (all
columns for non-unique indexes, all but the last column for unique indexes).

.. versionadded:: 1.0.0

    )groupbyN   )Computed)excschema)sql)util)default)
reflection)compiler)
expression)sqltypes)visitors)BLOB)CHAR)CLOB)FLOAT)INTEGER)NCHAR)NVARCHAR)	TIMESTAMP)VARCHAR)compata
  SHARE RAW DROP BETWEEN FROM DESC OPTION PRIOR LONG THEN DEFAULT ALTER IS INTO MINUS INTEGER NUMBER GRANT IDENTIFIED ALL TO ORDER ON FLOAT DATE HAVING CLUSTER NOWAIT RESOURCE ANY TABLE INDEX FOR UPDATE WHERE CHECK SMALLINT WITH DELETE BY ASC REVOKE LIKE SIZE RENAME NOCOMPRESS NULL GROUP VALUES AS IN VIEW EXCLUSIVE COMPRESS SYNONYM SELECT INSERT EXISTS NOT TRIGGER ELSE CREATE INTERSECT PCTFREE DISTINCT USER CONNECT SET MODE OF UNIQUE VARCHAR2 VARCHAR LOCK OR CHAR DECIMAL UNION PUBLIC AND START UID COMMENT CURRENT LEVELz<UID CURRENT_DATE SYSDATE USER CURRENT_TIME CURRENT_TIMESTAMPc                       e Zd Zd Zy)RAWN__name__
__module____qualname____visit_name__     R/var/www/html/venv/lib/python3.12/site-packages/sqlalchemy/dialects/oracle/base.pyr   r   W  s    Nr#   r   c                       e Zd Zd Zy)NCLOBNr   r"   r#   r$   r&   r&   ^      Nr#   r&   c                       e Zd Zd Zy)VARCHAR2Nr   r"   r#   r$   r)   r)   b  s    Nr#   r)   c                   >     e Zd Zd Zd fd	Z fdZed        Z xZS )NUMBERc                 Z    |t        |xr |dkD        }t        t        |   |||       y )Nr   )	precisionscale	asdecimal)boolsuperr+   __init__)selfr-   r.   r/   	__class__s       r$   r2   zNUMBER.__init__l  s7    U0uqy1Ifd$u	 	% 	
r#   c                 <    t         t        |   |      }d|_        |S )NT)r1   r+   adapt_is_oracle_number)r3   impltyperetr4   s      r$   r6   zNUMBER.adaptt  s!    FD'1 $
r#   c                     t        | j                  xr | j                  dkD        rt        j                  S t        j                  S Nr   )r0   r.   r   NumericIntegerr3   s    r$   _type_affinityzNUMBER._type_affinityz  s3    

-tzzA~.######r#   NNN)	r   r   r    r!   r2   r6   propertyr?   __classcell__r4   s   @r$   r+   r+   i  s&    N
 $ $r#   r+   c                       e Zd Zd Zy)DOUBLE_PRECISIONNr   r"   r#   r$   rE   rE     s    'Nr#   rE   c                       e Zd Zd Zy)BINARY_DOUBLENr   r"   r#   r$   rG   rG     s    $Nr#   rG   c                       e Zd Zd Zy)BINARY_FLOATNr   r"   r#   r$   rI   rI     s    #Nr#   rI   c                       e Zd Zd Zy)BFILENr   r"   r#   r$   rK   rK     r'   r#   rK   c                       e Zd Zd Zy)LONGNr   r"   r#   r$   rM   rM     s    Nr#   rM   c                       e Zd ZdZd Zd Zy)DATEzProvide the oracle DATE type.

    This type has no special Python behavior, except that it subclasses
    :class:`_types.DateTime`; this is to suit the fact that the Oracle
    ``DATE`` type supports a time value.

    .. versionadded:: 0.9.4

    c                 Z    |j                   t        j                  t        j                  fv S N)r?   r   DateTimeDate)r3   others     r$   _compare_type_affinityzDATE._compare_type_affinity  s"    ##(9(98=='IIIr#   N)r   r   r    __doc__r!   rU   r"   r#   r$   rO   rO     s     NJr#   rO   c                   F    e Zd Zd ZddZed        Zed        ZddZ	d Z
y)	INTERVALNc                      || _         || _        y)a  Construct an INTERVAL.

        Note that only DAY TO SECOND intervals are currently supported.
        This is due to a lack of support for YEAR TO MONTH intervals
        within available DBAPIs.

        :param day_precision: the day precision value.  this is the number of
          digits to store for the day field.  Defaults to "2"
        :param second_precision: the second precision value.  this is the
          number of digits to store for the fractional seconds field.
          Defaults to "6".

        Nday_precisionsecond_precision)r3   r[   r\   s      r$   r2   zINTERVAL.__init__  s     + 0r#   c                 D    t        |j                  |j                        S )NrZ   )rX   r[   r\   )clsintervals     r$   _adapt_from_generic_intervalz%INTERVAL._adapt_from_generic_interval  s!    "00%66
 	
r#   c                 "    t         j                  S rQ   )r   Intervalr>   s    r$   r?   zINTERVAL._type_affinity  s       r#   c                 Z    t        j                  d| j                  | j                        S )NT)nativer\   r[   )r   rb   r\   r[   )r3   allow_nulltypes     r$   
as_genericzINTERVAL.as_generic  s*      !22,,
 	
r#   c                     | S rQ   r"   )r3   opvalues      r$   coerce_compared_valuezINTERVAL.coerce_compared_value  s    r#   )NN)F)r   r   r    r!   r2   classmethodr`   rA   r?   rf   rj   r"   r#   r$   rX   rX     s>    N1" 
 
 ! !
r#   rX   c                       e Zd ZdZd Zy)ROWIDzPOracle ROWID type.

    When used in a cast() or similar, generates ROWID.

    N)r   r   r    rV   r!   r"   r#   r$   rm   rm     s     Nr#   rm   c                       e Zd Zd Zy)_OracleBooleanc                     |j                   S rQ   )r+   )r3   dbapis     r$   get_dbapi_typez_OracleBoolean.get_dbapi_type  s    ||r#   N)r   r   r    rr   r"   r#   r$   ro   ro     s    r#   ro   	NVARCHAR2r   r   r   r   r   TIMESTAMP WITH TIME ZONEzINTERVAL DAY TO SECONDr   DOUBLE PRECISION)rG   rI   rm   c                       e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Z	 ddZd Zd Zd ZeZd Zd Zd Zd Zd Zd Zd Zd Zd Zy)OracleTypeCompilerc                 (     | j                   |fi |S rQ   )
visit_DATEr3   type_kws      r$   visit_datetimez!OracleTypeCompiler.visit_datetime      tu+++r#   c                 (     | j                   |fi |S rQ   )visit_FLOATrz   s      r$   visit_floatzOracleTypeCompiler.visit_float  s    t,,,r#   c                 z    | j                   j                  r | j                  |fi |S  | j                  |fi |S rQ   )dialect_use_nchar_for_unicodevisit_NVARCHAR2visit_VARCHAR2rz   s      r$   visit_unicodez OracleTypeCompiler.visit_unicode
  s?    <<..'4''444&4&&u333r#   c                     d|j                   d uxr d|j                   z  xs dd|j                  d uxr d|j                  z  xs dS )NzINTERVAL DAYz(%d) z
 TO SECONDrZ   rz   s      r$   visit_INTERVALz!OracleTypeCompiler.visit_INTERVAL  sj    t+ -,,, ""$. 0///	
 	
r#   c                      y)NrM   r"   rz   s      r$   
visit_LONGzOracleTypeCompiler.visit_LONG      r#   c                     |j                   ryy)Nrt   r   timezonerz   s      r$   visit_TIMESTAMPz"OracleTypeCompiler.visit_TIMESTAMP  s    >>-r#   c                 *     | j                   |dfi |S )Nru   _generate_numericrz   s      r$   visit_DOUBLE_PRECISIONz)OracleTypeCompiler.visit_DOUBLE_PRECISION#  s    %t%%e-?F2FFr#   c                 *     | j                   |dfi |S )NrG   r   rz   s      r$   visit_BINARY_DOUBLEz&OracleTypeCompiler.visit_BINARY_DOUBLE&  s    %t%%e_CCCr#   c                 *     | j                   |dfi |S )NrI   r   rz   s      r$   visit_BINARY_FLOATz%OracleTypeCompiler.visit_BINARY_FLOAT)  s    %t%%e^BrBBr#   c                 4    d|d<    | j                   |dfi |S )NTno_precisionr   r   rz   s      r$   r   zOracleTypeCompiler.visit_FLOAT,  s(     ">%t%%eW;;;r#   c                 *     | j                   |dfi |S )Nr+   r   rz   s      r$   visit_NUMBERzOracleTypeCompiler.visit_NUMBER2  s    %t%%eX<<<r#   Nc                 v    ||j                   }|t        |dd       }|s||S |
d}|||dz  S d}||||dz  S )Nr.   z%(name)s(%(precision)s))namer-   z"%(name)s(%(precision)s, %(scale)s))r   r-   r.   )r-   getattr)r3   r{   r   r-   r.   r   r|   ns           r$   r   z$OracleTypeCompiler._generate_numeric5  sd     I=E7D1E9,K])A9===4A9uMMMr#   c                 (     | j                   |fi |S rQ   )r   rz   s      r$   visit_stringzOracleTypeCompiler.visit_stringG      "t""5/B//r#   c                 (    | j                  |dd      S )Nr   2_visit_varcharrz   s      r$   r   z!OracleTypeCompiler.visit_VARCHAR2J  s    ""5"c22r#   c                 (    | j                  |dd      S )NNr   r   rz   s      r$   r   z"OracleTypeCompiler.visit_NVARCHAR2M  s    ""5#s33r#   c                 (    | j                  |dd      S Nr   r   rz   s      r$   visit_VARCHARz OracleTypeCompiler.visit_VARCHARR  s    ""5"b11r#   c                     |j                   sd||dz  S |s*| j                  j                  rd}||j                   |dz  S d}||j                   ||dz  S )Nz%(n)sVARCHAR%(two)s)twor   zVARCHAR%(two)s(%(length)s CHAR))lengthr   z%(n)sVARCHAR%(two)s(%(length)s))r   r   r   )r   r   _supports_char_length)r3   r{   r   numvarchars        r$   r   z!OracleTypeCompiler._visit_varcharU  s\    ||(3Q+???t||997GSAAA7GSqIIIr#   c                 (     | j                   |fi |S rQ   )
visit_CLOBrz   s      r$   
visit_textzOracleTypeCompiler.visit_text_  r~   r#   c                 z    | j                   j                  r | j                  |fi |S  | j                  |fi |S rQ   )r   r   visit_NCLOBr   rz   s      r$   visit_unicode_textz%OracleTypeCompiler.visit_unicode_textb  s=    <<..#4##E0R00"4??5/B//r#   c                 (     | j                   |fi |S rQ   )
visit_BLOBrz   s      r$   visit_large_binaryz%OracleTypeCompiler.visit_large_binaryh  r~   r#   c                 ,     | j                   |fddi|S )Nr-      )r   rz   s      r$   visit_big_integerz$OracleTypeCompiler.visit_big_integerk  s     t  ;";;;r#   c                 (     | j                   |fi |S rQ   )visit_SMALLINTrz   s      r$   visit_booleanz OracleTypeCompiler.visit_booleann  r   r#   c                 >    |j                   rdd|j                   iz  S y)NzRAW(%(length)s)r   r   )r   rz   s      r$   	visit_RAWzOracleTypeCompiler.visit_RAWq  s     <<$%,,'???r#   c                      y)Nrm   r"   rz   s      r$   visit_ROWIDzOracleTypeCompiler.visit_ROWIDw  s    r#   )NNF)r   r   r    r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   visit_NVARCHARr   r   r   r   r   r   r   r   r   r"   r#   r$   rw   rw     s    ,-4
GDC<= EJN$034 %N2J,0,<0r#   rw   c                   H    e Zd ZdZ ej
                  ej                  j                  e	j                  j                  di      Z fdZd Zd Zd Zd Zd Zd	 Zd
 Zd Zd Z fdZ fdZd ZddZd Zd Zd Zd Zd Zd Zd Z d Z!d Z"d Z#d Z$d Z%d Z&d Z' xZ(S ) OracleCompilerzOracle compiler modifies the lexical structure of Select
    statements to work under non-ANSI configured Oracle databases, if
    the use_ansi flag is False.
    MINUSc                 :    i | _         t        t        |   |i | y rQ   )_OracleCompiler__wheresr1   r   r2   )r3   argskwargsr4   s      r$   r2   zOracleCompiler.__init__  s    nd,d=f=r#   c                     d | j                   |j                  fi |d | j                   |j                  fi |dS )Nzmod(, )processleftrightr3   binaryoperatorr|   s       r$   visit_mod_binaryzOracleCompiler.visit_mod_binary  s:    DLL++DLL,,
 	
r#   c                      y)NCURRENT_TIMESTAMPr"   r3   fnr|   s      r$   visit_now_funczOracleCompiler.visit_now_func  s    "r#   c                 .    d | j                   |fi |z   S )NLENGTH)function_argspecr   s      r$   visit_char_length_funcz%OracleCompiler.visit_char_length_func  s     /$//9b999r#   c                 x    d| j                  |j                        d| j                  |j                        dS )Nz
CONTAINS (r   r   r   r   s       r$   visit_match_op_binaryz$OracleCompiler.visit_match_op_binary  ,    LL%LL&
 	
r#   c                      y)N1r"   r3   exprr|   s      r$   
visit_truezOracleCompiler.visit_true      r#   c                      y)N0r"   r   s      r$   visit_falsezOracleCompiler.visit_false  r   r#   c                      y)NWITHr"   )r3   	recursives     r$   get_cte_preamblezOracleCompiler.get_cte_preamble  r   r#   c                 N    dj                  d |j                         D              S )N c              3   ,   K   | ]  \  }}d |z    yw)z	/*+ %s */Nr"   ).0tabletexts      r$   	<genexpr>z6OracleCompiler.get_select_hint_text.<locals>.<genexpr>  s     N{udd*Ns   )joinitems)r3   byfromss     r$   get_select_hint_textz#OracleCompiler.get_select_hint_text  s    xxNgmmoNNNr#   c                     t        |j                        dkD  s |j                  j                         t        vr!t        j                  j                  | |fi |S y)Nr   r   )lenclausesr   upper
NO_ARG_FNSr   SQLCompilerr   r   s      r$   r   zOracleCompiler.function_argspec  sD    rzz?Q"''--/"C''88rHRHHr#   c                 ^    t        t        | 
  |fi |}|j                  dd      rd|z  }|S )NasfromFz
TABLE (%s))r1   r   visit_functionget)r3   funcr|   r   r4   s       r$   r  zOracleCompiler.visit_function  s6    ^T9$E"E66(E"$&Dr#   c                 :    t        t        | 
  |fi |}|dz   }|S )Nz.COLUMN_VALUE)r1   r   visit_table_valued_column)r3   elementr|   r   r4   s       r$   r
  z(OracleCompiler.visit_table_valued_column  s0    ^TD

 o%r#   c                      y)zCalled when a ``SELECT`` statement has no froms,
        and no ``FROM`` clause is to be appended.

        The Oracle compiler tacks a "FROM DUAL" to the statement.
        z
 FROM DUALr"   r>   s    r$   default_fromzOracleCompiler.default_from  s     r#   c                    | j                   j                  r#t        j                  j                  | |fd|i|S |r1|j
                  j                  |j                  |j                  f       d|d<   t        |j                  t        j                        r|j                  j                  }n|j                  } | j                  |j                  fd|i|dz    | j                  |fd|i|z   S )Nfrom_linterTr  r   )r   use_ansir   r  
visit_joinedgesaddr   r   
isinstancer   FromGroupingr  r   )r3   r   r  r   r   s        r$   r  zOracleCompiler.visit_join  s    <<  ''22d(37=  !!%%tyy$**&=>#F8$**j&=&=>

**

TYYJKJ6J$,,uH+HHIr#   c                     g fd|D ]%  }t        |t        j                        s |       ' sy t        j                   S )Nc                      j                   r8 fd}j                  t        j                   j                  i d|i             nj                   j                          j
                   j                  fD ]R  }t        |t        j                        r	 |       &t        |t        j                        sA |j                         T y )Nc                    t        | j                  t        j                        rJj                  j                  | j                  j                        rt        | j                        | _        y t        | j                  t        j                        rKj                  j                  | j                  j                        rt        | j                        | _        y y y rQ   )r  r   r   ColumnClauser   is_derived_fromr   _OuterJoinColumn)r   r   s    r$   visit_binaryzVOracleCompiler._get_nonansi_join_whereclause.<locals>.visit_join.<locals>.visit_binary  s    !Z%<%<**44V[[5F5FG&6v{{&C#j&=&=**44V\\5G5GH'7'E Ir#   r   )isouterappendr   cloned_traverseonclauser   r   r  r   Joinr  r  )r   r  jr   r  s   `  r$   r  z@OracleCompiler._get_nonansi_join_whereclause.<locals>.visit_join  s    ||
F ,,rHl+C t}}-YY

* *a1qM:#:#:;qyy)	*r#   )r  r   r!  r	   and_)r3   fromsfr   r  s      @@r$   _get_nonansi_join_whereclausez,OracleCompiler._get_nonansi_join_whereclause  sJ    	*<  	A!Z__-1	 88W%%r#   c                 B     | j                   |j                  fi |dz   S )Nz(+))r   column)r3   vcr|   s      r$   visit_outer_join_columnz&OracleCompiler.visit_outer_join_column  s!    t||BII,,u44r#   c                 >    | j                   j                  |      dz   S )Nz.nextval)preparerformat_sequence)r3   seqr|   s      r$   visit_sequencezOracleCompiler.visit_sequence  s    }},,S1J>>r#   c                     d|z   S )z+Oracle doesn't like ``FROM table AS alias``r   r"   )r3   alias_name_texts     r$   get_render_as_alias_suffixz)OracleCompiler.get_render_as_alias_suffix  s     _$$r#   c                    g }g }t        t        j                  |            D ]  \  }}| j                  r_t	        |t
        j                        rEt	        |j                  t              r+| j                  j                  st        j                  d       |j                  j                  r|j                  j                  |      }n|}t!        j"                  d|z  |j                        }|| j$                  |j&                  <   |j)                  | j+                  | j-                  |                   d| _        |j)                  | j1                  |d             | j3                  t5        |d|j6                        t5        |d|j6                        |t5        |dd       t5        |dd       f|j                          dd	j9                  |      z   d
z   d	j9                  |      z   S )Nak  Computed columns don't work with Oracle UPDATE statements that use RETURNING; the value of the column *before* the UPDATE takes place is returned.   It is advised to not use RETURNING with an Oracle computed column.  Consider setting implicit_returning to False on the Table object in order to avoid implicit RETURNING clauses from being generated for this Table.zret_%d)r{   F)within_columns_clauser   keyz
RETURNING r   z INTO )	enumerater   _select_iterablesisupdater  	sa_schemaColumnserver_defaultr   r   (_supports_update_returning_computed_colsr
   warntype_has_column_expressioncolumn_expressionr	   outparambindsr5  r  bindparam_string_truncate_bindparamhas_out_parametersr   _add_to_result_mapr   _anon_name_labelr   )	r3   stmtreturning_colscolumnsrB  ir(  col_exprrA  s	            r$   returning_clausezOracleCompiler.returning_clause  s   "((8
 -	IAv vy'7'78v44h?MM		C {{11!;;88@!||HqLDH'/DJJx||$LL%%d&>&>x&HI ',D#NN4<<<NO##&(*C*CD&(*C*CDFFD1FE40
 	I-	^ dii008;dii>NNNr#   c           
      	   |}t        |dd       sb| j                  j                  sM| j                  ||j	                  dd            }| j                  |      }||j                  |      }d|_        |j                  r|j                  |j                  }|j                  }|j                  |      r|j                         }|j                  |      r|j                         }|}|j                         }d|_        |j                  }	|	j|	j                   r^|	j#                         }	|	j%                          |	j                   D ]/  }
|j&                  j)                  |
      r|j+                  |
      }1 |j-                         }t/        j0                  |j2                  D cg c]   }|j&                  j5                  |      	 |" c} }|_| j                  j6                  rI|j                  |      r8|j9                  t;        j<                  d | j>                  |fi |z              }d|_        d|_         |	O|	j                   rCtC        jD                  |      }|	j                   D 
cg c]  }
|jG                  |
       c}
|	_        |^|j                  |      r||j                  |      r
|}|||z   }n	|}|||z   }|j                  t/        jH                  d      |k        }||	|_        |}|S |j+                  t/        jH                  d      jK                  d            }d|_        d|_         |	M|	j                   rA|j&                  }|	j                   D ]&  }
|j5                  |
      	 |j+                  |
      }( |j-                         }|j&                  }t/        j0                  |j2                  D cg c]  }|j5                  |      	 | c} }d|_        d|_         |	O|	j                   rCtC        jD                  |      }|	j                   D 
cg c]  }
|jG                  |
       c}
|	_        |j                  t/        jH                  d      |kD        }|	|_        |}|S c c}w c c}
w c c}w c c}
w )N_oracle_visitr  FTz/*+ FIRST_ROWS(%s) */ROWNUMora_rn)&r   r   r  _display_froms_for_selectr  r&  whererO  _has_row_limiting_clause_fetch_clause_limit_clause_offset_clause_simple_int_clauserender_literal_execute	_generate_for_update_argof_clone_copy_internalsselected_columnscontains_columnadd_columnsaliasr	   selectccorresponding_columnoptimize_limitsprefix_withr   r   r   _is_wrappersql_utilClauseAdaptertraverseliteral_columnlabel)r3   select_stmtr   rc  r$  whereclauselimit_clauseoffset_clauseorig_select
for_updateeleminner_subqueryrd  limitselectadaptermax_rowlimitselect_colslimit_subqueryorigselect_colsoffsetselects                       r$   translate_select_structurez)OracleCompiler.translate_select_structureB  s   v5<<((66FJJx7 #@@G*#\\+6F+/F( //((0%33 & 5 5,,\:#/#F#F#HL,,];$1$H$H$JM %))+'+$ $33
)jmm!+!2!2!4J..0 * >%66FFtL%+%7%7%=F>
 "(!jj "0!1!1&77LLQO#$  !,4411,?"-"9"9"3*dll<B6BC#K -1)*.' )jmm&44^DG;E==%37((.%JM
  +00>%-!44]C".(4&-&=G #/(4&-&=G"-"3"3**84?#K
 !(2<K/(FX U #."9"9**84::8D#K 15K-.2K+!-*--+6+G+G($.MM LD 0 E Ed K#'!( /:.E.Ed.KL &1%6%6%8N&1&B&BO#&:: &4%5%5 !.CCAF#' ( $L 26L./3L,!-*--"*"8"8"H?I}})7;G,,T2)
 $0#5#5**84}D$L 4>L0)FE6%^)s   &%Q5/Q:Q?#Rc                      yr   r"   )r3   rc  r|   s      r$   rp  zOracleCompiler.limit_clause  s    r#   c                      y)NzSELECT 1 FROM DUAL WHERE 1!=1r"   )r3   r{   s     r$   visit_empty_set_exprz#OracleCompiler.visit_empty_set_expr  s    .r#   c                 2     j                         ryd}|j                  j                  r5|ddj                   fd|j                  j                  D              z   z  }|j                  j                  r|dz  }|j                  j
                  r|dz  }|S )Nr   z FOR UPDATEz OF r   c              3   D   K   | ]  } j                   |fi   y wrQ   )r   )r   rt  r|   r3   s     r$   r   z3OracleCompiler.for_update_clause.<locals>.<genexpr>  s&      &-1T(R(&s    z NOWAITz SKIP LOCKED)is_subqueryr[  r\  r   nowaitskip_locked)r3   rc  r|   tmps   ` ` r$   for_update_clausez OracleCompiler.for_update_clause  s    !!$$6DII &5;5K5K5N5N&   C !!((9C!!-->!C
r#   c                 x    d| j                  |j                        d| j                  |j                        dS )NDECODE(r   z, 0, 1) = 1r   r   s       r$   visit_is_distinct_from_binaryz,OracleCompiler.visit_is_distinct_from_binary  r   r#   c                 x    d| j                  |j                        d| j                  |j                        dS )Nr  r   z, 0, 1) = 0r   r   s       r$   !visit_is_not_distinct_from_binaryz0OracleCompiler.visit_is_not_distinct_from_binary  r   r#   c           	           | j                   |j                  fi |} | j                   |j                  fi |}|j                  d   }|	d|d|dS d|d|d| j	                  |t
        j                        dS )NflagszREGEXP_LIKE(r   r   r   r   r   	modifiersrender_literal_valuer   
STRINGTYPE)r3   r   r   r|   stringpatternr  s          r$   visit_regexp_match_op_binaryz+OracleCompiler.visit_regexp_match_op_binary  s    fkk0R0$,,v||2r2  )=,2G<<  ))%1D1DE r#   c                 0    d | j                   ||fi |z  S )NzNOT %s)r  r   s       r$    visit_not_regexp_match_op_binaryz/OracleCompiler.visit_not_regexp_match_op_binary  s,    ;$;;H
 "
 
 	
r#   c           	           | j                   |j                  fi |} | j                   |j                  fi |}|j                  d   }|	d|d|dS d|d|d| j	                  |t
        j                        dS )Nr  zREGEXP_REPLACE(r   r   r  )r3   r   r   r|   r  pattern_replacer  s          r$   visit_regexp_replace_op_binaryz-OracleCompiler.visit_regexp_replace_op_binary  s    fkk0R0&$,,v||:r:  )=   ))%1D1DE r#   rQ   ))r   r   r    rV   r
   update_copyr   r  compound_keywordsr   CompoundSelectEXCEPTr2   r   r   r   r   r   r   r   r   r   r  r
  r  r  r&  r*  r/  r2  rM  r}  rp  r  r  r  r  r  r  r  rB   rC   s   @r$   r   r   {  s    
 )((..		"	"	)	)73
>
#:
O((&T5?%
3OjRh/$



r#   r   c                   B     e Zd Zd Zd Zd Zd Z fdZd Zd Z	 xZ
S )OracleDDLCompilerc                     d}|j                   |d|j                   z  z  }|j                  t        j                  d       |S )Nr   z ON DELETE %szOracle does not contain native UPDATE CASCADE functionality - onupdates will not be rendered for foreign keys.  Consider using deferrable=True, initially='deferred' or triggers.)ondeleteonupdater
   r=  )r3   
constraintr   s      r$   define_constraint_cascadesz,OracleDDLCompiler.define_constraint_cascades  sN    *Oj&9&999D
 *II r#   c                 R    d| j                   j                  |j                        z  S )NzCOMMENT ON TABLE %s IS '')r,  format_tabler  )r3   drops     r$   visit_drop_table_commentz*OracleDDLCompiler.visit_drop_table_comment0  s'    *T]]-G-GLL.
 
 	
r#   c           
          |j                   } j                  |        j                  }d}|j                  r|dz  }|j                  d   d   r|dz  }|d j                  |d      d	|j                  |j                  d
      ddj                   fd|j                  D              dz  }|j                  d   d   dur3|j                  d   d   du r|dz  }|S |d|j                  d   d   z  z  }|S )NzCREATE zUNIQUE oraclebitmapzBITMAP zINDEX T)include_schemaz ON )
use_schemaz (r   c              3   Z   K   | ]"  }j                   j                  |d d       $ yw)FTinclude_tableliteral_bindsN)sql_compilerr   )r   r   r3   s     r$   r   z7OracleDDLCompiler.visit_create_index.<locals>.<genexpr>A  s8        !!))T * s   (+r   compressFz	 COMPRESSz COMPRESS %d)
r  _verify_index_tabler,  uniquedialect_options_prepared_index_namer  r   r   expressions)r3   createindexr,  r   s   `    r$   visit_create_indexz$OracleDDLCompiler.visit_create_index5  s      '==<<ID  *84ID%%eD%A!!%++$!?II  "--	 	
 		
   *:6eC$$X.z:dB#
  ))(3J?  r#   c                 (   g }|j                   d   }|d   r7|d   j                  dd      j                         }|j                  d|z         |d   r0|d   du r|j                  d       n|j                  d	|d   z         d
j	                  |      S )Nr  	on_commit_r   z
 ON COMMIT %sr  Tz

 COMPRESSz
 COMPRESS FOR %sr   )r  replacer  r  r   )r3   r   
table_optsoptson_commit_optionss        r$   post_create_tablez#OracleDDLCompiler.post_create_tableQ  s    
$$X. $[ 1 9 9#s C I I K/2CCD
J4'!!-0!!"6$z:J"KLwwz""r#   c                     t         t        |   |      }|j                  dd      }|j                  dd      }|j                  dd      }|j                  dd      }|S )	NzNO MINVALUE
NOMINVALUEzNO MAXVALUE
NOMAXVALUEzNO CYCLENOCYCLEzNO ORDERNOORDER)r1   r  get_identity_optionsr  )r3   identity_optionsr   r4   s      r$   r  z&OracleDDLCompiler.get_identity_optionsa  s_    &B
 ||M<8||M<8||J	2||J	2r#   c                     d| j                   j                  |j                  dd      z  }|j                  du rt	        j
                  d      |j                  du r|dz  }|S )NzGENERATED ALWAYS AS (%s)FTr  zzOracle computed columns do not support 'stored' persistence; set the 'persisted' flag to None or False for Oracle support.z VIRTUAL)r  r   sqltext	persistedr   CompileError)r3   	generatedr   s      r$   visit_computed_columnz'OracleDDLCompiler.visit_computed_columnk  sz    )D,=,=,E,EU$ -F -
 
 $&""P    E)JDr#   c                     |j                   d}n|j                   rdnd}d|z  }|j                  r|dz  }|dz  }| j                  |      }|r|d|z  z  }|S )Nr   ALWAYSz
BY DEFAULTzGENERATED %sz ON NULLz AS IDENTITYz (%s))alwayson_nullr  )r3   identityr|   kindr   optionss         r$   visit_identity_columnz'OracleDDLCompiler.visit_identity_columnx  sl    ??"D'8LD$JD++H5Gg%%Dr#   )r   r   r    r  r  r  r  r  r  r  rB   rC   s   @r$   r  r    s&    $

8# r#   r  c                       e Zd ZeD  ch c]  }|j	                          c}} Z edd      D  ch c]  }t        |       c}}} j                  ddg      Z	d Z
fdZxZS c c}} w c c}}} w )OracleIdentifierPreparerr   
   r  $c                     |j                         }|| j                  v xsB |d   | j                  v xs/ | j                  j	                  t        j                  |             S )z5Return True if the given identifier requires quoting.r   )lowerreserved_wordsillegal_initial_characterslegal_charactersmatchr
   	text_type)r3   ri   lc_values      r$   _bindparam_requires_quotesz3OracleIdentifierPreparer._bindparam_requires_quotes  s^    ;;=+++ FQx4:::F((..t~~e/DEE	
r#   c                 b    |j                   j                  d      }t        t        |   ||      S )Nr  )identlstripr1   r  format_savepoint)r3   	savepointr   r4   s      r$   r  z)OracleIdentifierPreparer.format_savepoint  s1    %%c*-tEt
 	
r#   )r   r   r    RESERVED_WORDSr  r  rangestrunionr  r  r  rB   )r   xdigr  r4   s   0000@r$   r  r    s`    )78Aaggi8N6;Arl!C!Cs#c(!C!I!I	c
"

 
 9!Cs
   A'A-r  c                       e Zd Zd Zy)OracleExecutionContextc                 d    | j                  d| j                  j                  |      z   dz   |      S )NzSELECT z.nextval FROM DUAL)_execute_scalaridentifier_preparerr-  )r3   r.  r{   s      r$   fire_sequencez$OracleExecutionContext.fire_sequence  s>    ##&&66s;<"# 	
 	
r#   N)r   r   r    r  r"   r#   r$   r  r    s    
r#   r  c                   8    e Zd ZdZdZdZdZdZdZdZ	dZ
dZdZdZdZeZeZdZdZdZdZdZdZeZeZeZeZeZ dZ!dZ"e#jH                  ddddfe#jJ                  ddd	fgZ& e'jP                  d
      	 	 	 	 	 d1d       Z) fdZ*d Z+e,d        Z-e,d        Z.e,d        Z/e,d        Z0e,d        Z1d Z2d Z3 fdZ4ddgZ5d Z6d Z7d Z8d2dZ9d2dZ:d Z;	 	 	 d3dZ<e=j|                  	 	 	 d4d        Z?e=j|                  d!        Z@e=j|                  d2d"       ZAe=j|                  d#        ZBe=j|                  d2d$       ZCe=j|                  d2d%       ZDe=j|                  d2d&       ZEe=j|                  d2d'       ZFd( ZGe=j|                  	 	 	 d4d)       ZHe=j|                  	 	 	 d4d*       ZIe=j|                  	 d5d+       ZJe=j|                  d2d,       ZKe=j|                  d2d-       ZLe=j|                  	 d2d.       ZMe=j|                  	 	 	 d4d/       ZNe=j|                  	 d6d0       ZO xZPS )7OracleDialectr  TF   named)oracle_resolve_synonymsN)resolve_synonymsr  r  )r  r  )z1.4a  The ``use_binds_for_limits`` Oracle dialect parameter is deprecated. The dialect now renders LIMIT /OFFSET integers inline in all cases using a post-compilation hook, so that the value is still represented by a 'bound parameter' on the Core Expression side.)use_binds_for_limitsc                 |    t        j                  j                  | fi | || _        || _        || _        || _        y rQ   )r   DefaultDialectr2   r   r  rf  exclude_tablespaces)r3   r  rf  r  use_nchar_for_unicoder  r   s          r$   r2   zOracleDialect.__init__  s<    & 	''77&;# .#6 r#   c                 f   t         t        |   |       | j                  j	                  d| j
                  dkD        | _        | j                  rO| j                  j                         | _        | j                  j                  t        j                         d| _        | j
                  dk\  | _        y )Nimplicit_returning)r  F   )r1   r  
initialize__dict__r  server_version_infor  _is_oracle_8colspecscopypopr   rb   r  supports_identity_columns)r3   
connectionr4   s     r$   r  zOracleDialect.initialize  s    mT-j9"&--"3"3 $":":U"B#
  MM..0DMMMh//0!DM)-)A)AU)J&r#   c                 6   | j                   dk  r| j                   S 	 |j                  d      j                         }|r#	 t        d  |j                  d      D              S | j                   S # t        j                  $ r d }Y Hw xY w#  | j                   cY S xY w)Nr     z7SELECT value FROM v$parameter WHERE name = 'compatible'c              3   2   K   | ]  }t        |        y wrQ   )int)r   r  s     r$   r   zJOracleDialect._get_effective_compat_server_version_info.<locals>.<genexpr>  s     ?SV?s   .)r	  exec_driver_sqlscalarr   
DBAPIErrortuplesplit)r3   r  r   s      r$   )_get_effective_compat_server_version_infoz7OracleDialect._get_effective_compat_server_version_info  s     ##g-+++	//Ifh  0?\V\\#->??? +++ ~~ 	F	0///s   A- !B -BBBc                 <    | j                   xr | j                   dk  S )N)	   r	  r>   s    r$   r
  zOracleDialect._is_oracle_8  s    ''KD,D,Dt,KKr#   c                 <    | j                   xr | j                   dk\  S )N)r     r  r>   s    r$   _supports_table_compressionz)OracleDialect._supports_table_compression  s    ''OD,D,D,OOr#   c                 <    | j                   xr | j                   dk\  S )N)   r  r>   s    r$   _supports_table_compress_forz*OracleDialect._supports_table_compress_for  s    ''MD,D,D,MMr#   c                     | j                    S rQ   )r
  r>   s    r$   r   z#OracleDialect._supports_char_length  s    $$$$r#   c                 <    | j                   xr | j                   dk\  S )N)   r  r>   s    r$   r<  z6OracleDialect._supports_update_returning_computed_cols!  s      ''MD,D,D,MMr#   c                      y rQ   r"   )r3   r  r   s      r$   do_release_savepointz"OracleDialect.do_release_savepoint'  s    r#   c                 .    | j                  |      dk  ryy )Nr     )r  r3   r  s     r$   _check_max_identifier_lengthz*OracleDialect._check_max_identifier_length+  s%    99*E I
 
  r#   c                     t        j                  t        j                  d      t        j                  d            g}t
        t        |   ||      S )Nz'test nvarchar2 returns'<   )r   castrl  r   r   r1   r  _check_unicode_returns)r3   r  additional_testsr4   s      r$   r1  z$OracleDialect._check_unicode_returns5  sP    OO))*DE!!"%
 ]D@(
 	
r#   READ COMMITTEDSERIALIZABLEc                     t        d      Nz implemented by cx_Oracle dialectNotImplementedErrorr,  s     r$   get_isolation_levelz!OracleDialect.get_isolation_levelB      !"DEEr#   c                 F    	 | j                  |      S # t        $ r   Y yxY w)Nr3  )r9  r8  )r3   
dbapi_conns     r$   get_default_isolation_levelz)OracleDialect.get_default_isolation_levelE  s-    	$++J77" 		$#s     c                     t        d      r6  r7  )r3   r  levels      r$   set_isolation_levelz!OracleDialect.set_isolation_levelM  r:  r#   c           	          | j                  |       |s| j                  }|j                  t        j                  d      t        | j                  |      | j                  |                  }|j                         d uS )NzSELECT table_name FROM all_tables WHERE table_name = CAST(:name AS VARCHAR2(128)) AND owner = CAST(:schema_name AS VARCHAR2(128))r   schema_name)_ensure_has_table_connectiondefault_schema_nameexecuter	   r   dictdenormalize_namefirst)r3   r  
table_namer   cursors        r$   	has_tablezOracleDialect.has_tableP  sy    ))*5--F##HHB
 **:6 11&9

 ||~T))r#   c           	          |s| j                   }|j                  t        j                  d      t	        | j                  |      | j                  |                  }|j                         d uS )NzeSELECT sequence_name FROM all_sequences WHERE sequence_name = :name AND sequence_owner = :schema_namerB  )rE  rF  r	   r   rG  rH  rI  )r3   r  sequence_namer   rK  s        r$   has_sequencezOracleDialect.has_sequencec  sj    --F##HH0
 **=9 11&9

 ||~T))r#   c                 ^    | j                  |j                  d      j                               S )Nz;select sys_context( 'userenv', 'current_schema' ) from dual)normalize_namer  r  r,  s     r$   _get_default_schema_namez&OracleDialect._get_default_schema_names  s-    ""&&Mfh
 	
r#   c                 T   d}g }i }|r|j                  d       ||d<   |r|j                  d       ||d<   |r|j                  d       ||d<   |dj                  |      z  }|j                  d	
      j                  t	        j
                  |      |      }|r3|j                         j                         }	|	r|	d   |	d   |	d   |	d   fS y|j                         j                         }
t        |
      dkD  rt        d      t        |
      dk(  r|
d   }	|	d   |	d   |	d   |	d   fS y)zsearch for a local synonym matching the given desired owner/name.

        if desired_owner is None, attempts to locate a distinct owner.

        returns the actual name, owner, dblink name, and synonym name if
        found.
        zUSELECT owner, table_owner, table_name, db_link, synonym_name FROM all_synonyms WHERE z3synonym_name = CAST(:synonym_name AS VARCHAR2(128))synonym_namez-owner = CAST(:desired_owner AS VARCHAR2(128))desired_ownerz*table_name = CAST(:tname AS VARCHAR2(128))tnamez AND T)future_resultrJ  table_ownerdb_linkNNNNr   zGThere are multiple tables visible to the schema, you must specify ownerr   )r  r   execution_optionsrF  r	   r   mappingsrI  allr   AssertionError)r3   r  rU  desired_synonymdesired_tableqr   paramsresultrowrowss              r$   _resolve_synonymzOracleDialect._resolve_synonymz  sh    4 	
 NNE &5F>"NNJK&3F?#NNGH+F7O	W\\'""--D-AIIHHQK
 //#))+C%&	N'	  .??$((*D4y1}$)  Ta1g%&	N'	  .r#   c                 n   |r8| j                  || j                  |      | j                  |            \  }}}}	nd\  }}}}	|s| j                  |      }|r5|j                  t        j                  d      t        |            }d|z   }n!|s| j                  |xs | j                        }|||xs d|	fS )N)rU  r_  rZ  z6SELECT username FROM user_db_links WHERE db_link=:link)link@r   )rf  rH  r  r	   r   rG  rE  )
r3   r  rJ  r   r  dblinkr|   actual_nameownersynonyms
             r$   _prepare_reflection_argsz&OracleDialect._prepare_reflection_args  s     262G2G"33F; $ 5 5j A 3H 3/K 3I/K//
;K %%O &!	E 6\F))&*LD4L4LMEUFLb'::r#   c                 v    d}|j                  |      }|D cg c]  }| j                  |d          c}S c c}w )Nz0SELECT username FROM all_users ORDER BY usernamer   )r  rQ  )r3   r  r|   srK  rd  s         r$   get_schema_nameszOracleDialect.get_schema_names  s:    >++A.7=>##CF+>>>s   6c           	         | j                  |xs | j                        }|| j                  }d}| j                  r2|ddj                  | j                  D cg c]  }d|z  	 c}      z  z  }|dz  }|j	                  t        j                  |      t        |            }|D cg c]  }| j                  |d          c}S c c}w c c}w )N(SELECT table_name FROM all_tables WHERE 6nvl(tablespace_name, 'no tablespace') NOT IN (%s) AND r   '%s'z8OWNER = :owner AND IOT_NAME IS NULL AND DURATION IS NULLrl  r   	rH  rE  r  r   rF  r	   r   rG  rQ  )r3   r  r   r|   sql_strtsrK  rd  s           r$   get_table_nameszOracleDialect.get_table_names  s    &&v'I1I1IJ >--F<###99D4L4LMbfrkMNPG
 	L	
 ##CHHW$5t&7IJ7=>##CF+>> N ?s   C&C	c           	      x   | j                  | j                        }d}| j                  r2|ddj                  | j                  D cg c]  }d|z  	 c}      z  z  }|dz  }|j	                  t        j                  |      t        |            }|D cg c]  }| j                  |d          c}S c c}w c c}w )Nrs  rt  r   ru  z<OWNER = :owner AND IOT_NAME IS NULL AND DURATION IS NOT NULLrv  r   rw  )r3   r  r|   r   rx  ry  rK  rd  s           r$   get_temp_table_namesz"OracleDialect.get_temp_table_names  s    &&t'?'?@<###99D4L4LMbfrkMNPG
 	'	
 ##CHHW$5t&7IJ7=>##CF+>> N ?s   B2B7c                    | j                  |xs | j                        }t        j                  d      }|j	                  |t        | j                  |                  }|D cg c]  }| j                  |d          c}S c c}w )Nz4SELECT view_name FROM all_views WHERE owner = :ownerrv  r   )rH  rE  r	   r   rF  rG  rQ  )r3   r  r   r|   rp  rK  rd  s          r$   get_view_nameszOracleDialect.get_view_names  sv    &&v'I1I1IJHHKL##t$//78
 8>>##CF+>>>s   $Bc                     |s| j                   }|j                  t        j                  d      t	        | j                  |                  }|D cg c]  }| j                  |d          c}S c c}w )NzKSELECT sequence_name FROM all_sequences WHERE sequence_owner = :schema_name)rC  r   )rE  rF  r	   r   rG  rH  rQ  )r3   r  r   r|   rK  rd  s         r$   get_sequence_namesz OracleDialect.get_sequence_names  sk    --F##HH6 T226:;
 8>>##CF+>>>s   A/c                    i }|j                  dd      }|j                  dd      }|j                  d      }| j                  ||||||      \  }}}}	d|i}
dg}| j                  r|j                  d       | j                  r|j                  d	       d
}|
||
d<   |dz  }||dj                  |      dz  }|j                  t        j                  |      |
      }t        dd      }|j                         }|rNd|j                  v r@|j                  |j                  d      r$d	|j                  v r|j                  |d<   |S d|d<   |S )Nr  Frj  r   
info_cacher  rJ  compressioncompress_forzaSELECT %(columns)s FROM ALL_TABLES%(dblink)s WHERE table_name = CAST(:table_name AS VARCHAR(128))rl  z* AND owner = CAST(:owner AS VARCHAR(128)) r   )rj  rJ  TDISABLEDENABLEDoracle_compress)r  rn  r!  r  r$  r   rF  r	   r   rG  rI  _fieldsr  r  )r3   r  rJ  r   r|   r  r  rj  r  rm  rb  rJ  r   rc  enabledrd  s                   r$   get_table_optionszOracleDialect.get_table_options+  sp   66";UC"%VVL)
040M0M! 1N 1
-VVW 
+.++NN=),,NN>*C 	 $F7O@@DDIIg4FGG##CHHTNF;t4lln+1 "S[[0141A1AG-.  26G-.r#   c           	         |j                  dd      }|j                  dd      }|j                  d      }| j                  ||||||      \  }}}}g }	| j                  rd}
nd}
| j                  d	k\  rd
d|iz  }nd}d|i}d}|
||d<   |dz  }|dz  }|||
|dz  }|j	                  t        j                  |      |      }|D ]R  }| j                  |d         }|d   }|d   }|d   }|d   }|d   }|d   dk(  }|d   }|d   }|d   }|d   }|d   }|dk(  r||dk(  rt               }n{t        ||      }nn|d k(  rt               }n^|d!v r" | j                  j                  |      |      }n8d"|v rt        d#$      }n't        j                  d%d|      }	 | j                  |   }|d)k(  rt)        |*      }d}nd}|| j+                  ||      }d}nd}||||d+|d,}|j-                         |k(  rd#|d-<   |||d.<   |||d/<   |	j/                  |       U |	S # t        $ r/ t!        j"                  d&|d'|d(       t$        j&                  }Y w xY w)0a

        kw arguments can be:

            oracle_resolve_synonyms

            dblink

        r  Frj  r   r  r  char_lengthdata_lengthr  a                  col.default_on_null,
                (
                    SELECT id.generation_type || ',' || id.IDENTITY_OPTIONS
                    FROM ALL_TAB_IDENTITY_COLS%(dblink)s id
                    WHERE col.table_name = id.table_name
                    AND col.column_name = id.column_name
                    AND col.owner = id.owner
                ) AS identity_optionsz1NULL as default_on_null, NULL as identity_optionsrJ  a  
            SELECT
                col.column_name,
                col.data_type,
                col.%(char_length_col)s,
                col.data_precision,
                col.data_scale,
                col.nullable,
                col.data_default,
                com.comments,
                col.virtual_column,
                %(identity_cols)s
            FROM all_tab_cols%(dblink)s col
            LEFT JOIN all_col_comments%(dblink)s com
            ON col.table_name = com.table_name
            AND col.column_name = com.column_name
            AND col.owner = com.owner
            WHERE col.table_name = CAST(:table_name AS VARCHAR2(128))
            AND col.hidden_column = 'NO'
        Nrl  z AND col.owner = :owner z ORDER BY col.column_id)rj  char_length_colidentity_colsr   r   r  r         Y         r  r  r+   r   )r)   rs   r   r   zWITH TIME ZONETr   z\(\d+\)zDid not recognize type 'z' of column ''YES)r  auto)r   r>  nullabler   autoincrementcommentquotecomputedr  )r  rn  r   r	  rF  r	   r   rQ  r   r+   r   ischema_namesr   resubKeyErrorr
   r=  r   NULLTYPErG  _parse_identity_optionsr  r  )r3   r  rJ  r   r|   r  rj  r  rm  rJ  r  r  rb  r   rd  rd  colnameorig_colnamecoltyper   r-   r.   r  r   r  r  default_on_nulr  r  r  cdicts                                  r$   get_columnszOracleDialect.get_columns_  s!    66";UC"%VVL)
040M0M! 1N 1
-VVW %%+O+O##u,) &,
M PM
+( $F7O..D)).*
 
 sxx~v6 B	"C))#a&1Gq6L!fGVFAIFE1v}H!fG!fGAI VN"2w("$!%iG$Y6GG#'FF9$,,009&A!W,#T2&&R90"009G E!0+77$n   $"!'"E !!#|3!%g#$,j!#$,j!NN5!EB	"F K   0II"G- '//G0s   H5IIc                 6   |j                  d      D cg c]  }|j                          }}|d   dk(  |dk(  d}|dd  D ]  }|j                  d      \  }}|j                         }d|v rt        j                  |      |d	<   Dd
|v rt        j                  |      |d<   ad|v rt        j                  |      |d<   ~d|v rt        j                  |      |d<   d|v r	|dk(  |d<   d|v rt        j                  |      |d<   d|v s|dk(  |d<    |S c c}w )N,r   r  r  )r  r  r   :z
START WITHstartzINCREMENT BY	increment	MAX_VALUEmaxvalue	MIN_VALUEminvalue
CYCLE_FLAGr  cycle
CACHE_SIZEcache
ORDER_FLAGorder)r  stripr   	long_type)	r3   r  r  ppartsr  partoptionri   s	            r$   r  z%OracleDialect._parse_identity_options  s@    %5$:$:3$?@q@@Ah(*%.

 !"I 	1D JJsOMFEKKMEv%$*$4$4U$;!6)(.(8(8(?%&'-'7'7'>$&'-'7'7'>$'$)SL!'$*$4$4U$;!'$)SL!#	1$ 1 As   Dc                     |j                  d      }| j                  ||||||      \  }}}}|s| j                  }d}	|j                  t	        j
                  |	      t        ||            }
d|
j                         iS )Nr  r  z
            SELECT comments
            FROM all_tab_comments
            WHERE table_name = CAST(:table_name AS VARCHAR(128))
            AND owner = CAST(:schema_name AS VARCHAR(128))
        )rJ  rC  r   )r  rn  rE  rF  r	   r   rG  r  )r3   r  rJ  r   r  rj  r|   r  rm  COMMENT_SQLrd  s              r$   get_table_commentzOracleDialect.get_table_comment  s     VVL)
040M0M! 1N 1
-VVW --F HH[!JF;
 
##r#   c           
         |j                  d      }| j                  ||||||      \  }}}}g }	d|i}
d}|
||
d<   |dz  }|dz  }|d|iz  }t        j                  |      }|j	                  ||
      }g }	d }| j                  ||||||j                  d      	      }t        d
d      }t        d
d      }t        j                  dt        j                        }d }|D ]  }| j                  |j                        }|r	||d   k(  r*|j                  |k7  rt        |g i       }|	j                  |       |j                  |j                  d
      |d<   |j                  dv rd|d   d<   |j                  |j                  d
      r|j                   |d   d<   |j#                  |j$                        s-|d   j                  | j                  |j$                               |j                  } |	S )Nr  r  rJ  a9  SELECT a.index_name, a.column_name, 
b.index_type, b.uniqueness, b.compression, b.prefix_length 
FROM ALL_IND_COLUMNS%(dblink)s a, 
ALL_INDEXES%(dblink)s b 
WHERE 
a.index_name = b.index_name 
AND a.table_owner = b.table_owner 
AND a.table_name = b.table_name 
AND a.table_name = CAST(:table_name AS VARCHAR(128))r   zAND a.table_owner = :schema z(ORDER BY a.index_name, a.column_positionrj  )r  rj  r  FT)	NONUNIQUEUNIQUEr  zSYS_NC\d+\$r   )r   column_namesr  r  )BITMAPzFUNCTION-BASED BITMAPr  oracle_bitmapr  r  )r  rn  r	   r   rF  get_pk_constraintrG  r  compile
IGNORECASErQ  
index_namer  
uniqueness
index_typer  prefix_lengthr  column_name)r3   r  rJ  r   r  rj  r|   r  rm  indexesrb  r   ra  rplast_index_namepk_constraintr  r  oracle_sys_colr  rsetindex_name_normalizeds                         r$   get_indexeszOracleDialect.get_indexes8  s@    VVL)
040M0M! 1N 1
-VVW 
+E 	 %F822D::x((HHTN6*..-vvl+ / 
 E$7
t4NBMMB $	.D$($7$7$H! )]6-BB/1.!#$&
 u%(nnT__eDE(O"EE<@'(9{{4++U3 && '(% "''(8(89n%,,''(8(89 #ooOI$	.L r#   c                     d|i}d}|
||d<   |dz  }|dz  }|d|iz  }|j                  t        j                  |      |      }|j                         }	|	S )NrJ  a  SELECT
ac.constraint_name,
ac.constraint_type,
loc.column_name AS local_column,
rem.table_name AS remote_table,
rem.column_name AS remote_column,
rem.owner AS remote_owner,
loc.position as loc_pos,
rem.position as rem_pos,
ac.search_condition,
ac.delete_rule
FROM all_constraints%(dblink)s ac,
all_cons_columns%(dblink)s loc,
all_cons_columns%(dblink)s rem
WHERE ac.table_name = CAST(:table_name AS VARCHAR2(128))
AND ac.constraint_type IN ('R','P', 'U', 'C')rl  z-
AND ac.owner = CAST(:owner AS VARCHAR2(128))z
AND ac.owner = loc.owner
AND ac.constraint_name = loc.constraint_name
AND ac.r_owner = rem.owner(+)
AND ac.r_constraint_name = rem.constraint_name(+)
AND (rem.position IS NULL or loc.position=rem.position)
ORDER BY ac.constraint_name, loc.positionrj  )rF  r	   r   fetchall)
r3   r  rJ  r   rj  r|   rb  r   r  constraint_datas
             r$   _get_constraint_dataz"OracleDialect._get_constraint_data  s    
 
+> 	& $F7ODDD:	
 x((7++-r#   c           
         |j                  dd      }|j                  dd      }|j                  d      }| j                  ||||||      \  }}}}g }	d }
| j                  |||||j                  d            }|D ]d  }|dd t        |dd	 D cg c]  }| j	                  |       c}      z   \  }}}}}}|d
k(  sA|
| j	                  |      }
|	j                  |       f |	|
dS c c}w )Nr  Frj  r   r  r  r   r  r  P)constrained_columnsr   )r  rn  r  r  rQ  r  )r3   r  rJ  r   r|   r  rj  r  rm  pkeysconstraint_namer  rd  r  	cons_name	cons_typelocal_columnremote_tableremote_columnremote_owners                       r$   r  zOracleDialect.get_pk_constraint  s2   66";UC"%VVL)
040M0M! 1N 1
-VVW 33vvl+ 4 
 # 	+C Aa5#a(!KQ$"5"5a"8!KLLC"*&*&9&9)&DO\*	+ (-oFF "Ls   C)c           
         |}|j                  dd      }|j                  dd      }|j                  d      }| j                  ||||||      \  }}}}	| j                  |||||j                  d            }
d }t        j                  |      }|
D ]:  }|dd	 t        |d	d
 D cg c]  }| j                  |       c}      z   \  }}}}}}| j                  |      }|dk(  sS|t        j                  dd|iz         p||   }||d<   |d   |d   }}|d   s|r[| j                  || j                  |      | j                  |            \  }}}}|r"| j                  |      }| j                  |      }||d<   || j                  |      |k7  r||d<   |d   dk7  r|d   |d   d<   |j                  |       |j                  |       = t        |j                               S c c}w )r  r  Frj  r   r  r  c                      d g d d g i dS )N)r   r  referred_schemareferred_tablereferred_columnsr  r"   r"   r#   r$   fkey_recz0OracleDialect.get_foreign_keys.<locals>.fkey_rec	  s    ')#'"&$& r#   r   r  r  RzqGot 'None' querying 'table_name' from all_cons_columns%(dblink)s - does the user have proper rights to the table?r   r  r  r  )rU  r`  r  r  z	NO ACTIONr  r  )r  rn  r  r
   defaultdictr  rQ  r=  rf  rH  r  listvalues)r3   r  rJ  r   r|   requested_schemar  rj  r  rm  r  r  fkeysrd  r  r  r  r  r  r  r  rec
local_colsremote_colsref_remote_nameref_remote_owner
ref_dblinkref_synonyms                               r$   get_foreign_keyszOracleDialect.get_foreign_keys  s}    "66";UC"%VVL)
040M0M! 1N 1
-VVW 33vvl+ 4 
	   *" >	2C Aa5#a(!KQ$"5"5a"8!KLL ++I6IC'II: $V,- I&'F-.*+ (

 +,' !11&*.*?*?*M*.*?*?*M 2 +,&' '+/+>+>{+KL+/+>+> 0,L -9C() )400>&H1=-.1v,58VIz2!!,/""=1}>	2@ ELLN##q "Ls   'G*c                 b   |j                  dd      }|j                  dd      }|j                  d      }| j                  ||||||      \  }}}}| j                  |||||j                  d            }	t        d |	      }
t	        |
d       }| j                  |||	      D ch c]  }|d
   	 }}|D cg c];  }| j                  |d         |d   D cg c]  }| j                  |d          c}g= c}}D cg c]  \  }}||||v r|nd d c}}S c c}w c c}w c c}}w c c}}w )Nr  Frj  r   r  r  c                     | d   dk(  S )Nr   Ur"   r  s    r$   <lambda>z6OracleDialect.get_unique_constraints.<locals>.<lambda>y	  s    qts{ r#   c                     | d   S r;   r"   r  s    r$   r  z6OracleDialect.get_unique_constraints.<locals>.<lambda>z	  s
    qt r#   r   r   r   r   r  )r   r  duplicates_index)r  rn  r  filterr   r  rQ  )r3   r  rJ  r   r|   r  rj  r  rm  r  unique_keysuniques_groupixindex_namesrK  r  r   colss                     r$   get_unique_constraintsz$OracleDialect.get_unique_constraints`	  sy    66";UC"%VVL)
040M0M! 1N 1
-VVW 33vvl+ 4 
 2OD^< &&z:f&M
 vJ
 
 '
  ''!-89!=1T((1.=
 d	  $,0K,?DT
 	
	
 >
s$   'D:D%D 4D%D+ D%c                 F   |j                  d      }| j                  ||||||      \  }}}}d|i}	d}
|
|
dz  }
||	d<   |j                  t        j                  |
      |	      j                         }|r-t        j                  r|j                  | j                        }|S y )Nr  r  	view_namez5SELECT text FROM all_views WHERE view_name=:view_namez AND owner = :schemar   )
r  rn  rF  r	   r   r  r
   py2kdecodeencoding)r3   r  r  r   r  rj  r|   r  rm  rb  r   r  s               r$   get_view_definitionz!OracleDialect.get_view_definition	  s     VVL)
/3/L/L! 0M 0
,FFG y)F**D%F87>>@yyYYt}}-Ir#   c           	         |j                  dd      }|j                  dd      }|j                  d      }| j                  ||||||      \  }}}}	| j                  |||||j                  d            }
t        d |
      }|D cg c]7  }|st	        j
                  d|d	         s| j                  |d
         |d	   d9 c}S c c}w )Nr  Frj  r   r  r  c                     | d   dk(  S )Nr   Cr"   r  s    r$   r  z5OracleDialect.get_check_constraints.<locals>.<lambda>	  s    QqTS[ r#   z..+?. IS NOT NULL$r  r   )r   r  )r  rn  r  r  r  r  rQ  )r3   r  rJ  r   include_allr|   r  rj  r  rm  r  check_constraintsconss                r$   get_check_constraintsz#OracleDialect.get_check_constraints	  s     66";UC"%VVL)
040M0M! 1N 1
-VVW 33vvl+ 4 
 ##8/J *
"((+@$q'"J ((a1d1gF
 	
 
s   <C)TFNF)SYSTEMSYSAUXrQ   r@   )NFr   r   )NF)Qr   r   r    r   supports_statement_cachesupports_altersupports_unicode_statementssupports_unicode_bindsmax_identifier_lengthsupports_simple_order_by_labelcte_follows_insertsupports_sequencessequences_optionalpostfetch_lastrowiddefault_paramstyler  r  requires_name_normalizesupports_commentssupports_default_valuessupports_default_metavaluesupports_empty_insertr  r   statement_compilerr  ddl_compilerrw   type_compilerr  r,  r  execution_ctx_clsreflection_optionsr   r9  TableIndexconstruct_argumentsr
   deprecated_paramsr2   r  r  rA   r
  r!  r$  r   r<  r)  r-  r1  _isolation_lookupr9  r=  r@  rL  rO  rR  rf  r   r  rn  rq  rz  r|  r~  r  r  r  r  r  r  r  r  r  r  r  r  rB   rC   s   @r$   r  r    s   D#N"'"%*" H!M"#!%! $'$L&M'H.5" OO!&TuM	
 
U>? T
	 !#07	7K,* L L P P N N % % N N
	
 *>:F$F*&* 
 A.F 
 %; %;N ? ?
 ? ?* ? ?& ? ? 
? 
? 1 1f Q Qf@ 
 "$ "$H 
 c cJ :<) )V $G $GL l$ l$\ -1,
 ,
\ 
    D ?D
 
r#   r  c                       e Zd ZdZd Zy)r  outer_join_columnc                     || _         y rQ   )r(  )r3   r(  s     r$   r2   z_OuterJoinColumn.__init__	  s	    r#   N)r   r   r    r!   r2   r"   r#   r$   r  r  	  s    (Nr#   r  )MrV   	itertoolsr   r  r   r   r   r   r9  r	   r
   enginer   r   r   r   r   ri  r   typesr   r   r   r   r   r   r   r   r   r   setr  r  r  _Binaryr   	OracleRawTextr&   r)   rs   r<   r=   r+   FloatrE   rG   rI   LargeBinaryrK   rM   rR   rO   NativeForEmulated_AbstractIntervalrX   
TypeEnginerm   Booleanro   rb   r  r  GenericTypeCompilerrw   r  r   DDLCompilerr  IdentifierPreparerr  DefaultExecutionContextr  r   r  ClauseElementr  r"   r#   r$   <module>rJ     s  bH  	   #         #           ? @Euw
 EKKM

(

  	HMM  w   	$Xx// $2(x~~ (%HNN %$8>> $H   8== J8 J"'x))8+E+E 'TH X%%  nxt D U	
 D f D U D U  	 h 
3 U  (!" D#$ # )0z55 zz_X)) _Dg,, gT
x:: 
.
W<< 
i
G** i
X!s(( r#   