
    hx                      d Z ddlmZ ddlmZ ddlm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! 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!m0Z0 dd,l!m1Z1 dd-l!m2Z2 ddl!m"Z3 dd.l!m4Z4 dd/l5m6Z6 dd0lm7Z7 dd1lm8Z8 dd2lm9Z9 dd3lm:Z: dd4lm;Z; dd5lm<Z< dd6lm=Z= dd7lm>Z> dd8lm?Z?  e@d9j                               ZB e@d:j                               ZCe2j                  ee2j                  ee2j                  ee2j                  eiZHi d;e?d<e=d=e8d>e<d?ed@edAe7dBedCe9dDedEedFedGedHedIedJedKe:e>eeeedLZI G dM dNe,j                        ZK G dO dPe,j                        ZM G dQ dRe,j                        ZO G dS dTe,j                        ZQ G dU dVe$j                        ZS G dW dXe$j                        ZU G dY dZe!j                        ZWy)[aq  
.. dialect:: oracle
    :name: Oracle Database
    :normal_support: 11+
    :best_effort: 9+


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 Database, two options are
available, which are the use of IDENTITY columns (Oracle Database 12 and above
only) or the association of a SEQUENCE with the column.

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

Starting from version 12, Oracle Database 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 Database
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 Database versions)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Older version of Oracle Database had no "autoincrement" feature: SQLAlchemy
relies upon sequences to produce these values.  With the older Oracle Database
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", start=1), 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", start=1), 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
----------------------------------------

Oracle Database supports "READ COMMITTED" and "SERIALIZABLE" modes of
isolation. The AUTOCOMMIT isolation level is also supported by the
python-oracledb and cx_Oracle dialects.

To set using per-connection execution options::

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

For ``READ COMMITTED`` and ``SERIALIZABLE``, the Oracle Database dialects 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 Database dialects necessarily force the start of a transaction using the
   Oracle Database DBMS_TRANSACTION.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 Database
   installations.

   The python-oracledb and cx_Oracle dialects attempt 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 Database, the data dictionary represents all case insensitive
identifier names using UPPERCASE text.  This is in contradiction to the
expectations of SQLAlchemy, which assume a case insensitive name is represented
as lowercase text.

As an example of case insensitive identifier names, consider the following table:

.. sourcecode:: sql

    CREATE TABLE MyTable (Identifier INTEGER PRIMARY KEY)

If you were to ask Oracle Database for information about this table, the
table name would be reported as ``MYTABLE`` and the column name would
be reported as ``IDENTIFIER``.    Compare to most other databases such as
PostgreSQL and MySQL which would report these names as ``mytable`` and
``identifier``.   The names are **not quoted, therefore are case insensitive**.
The special casing of ``MyTable`` and ``Identifier`` would only be maintained
if they were quoted in the table definition:

.. sourcecode:: sql

    CREATE TABLE "MyTable" ("Identifier" INTEGER PRIMARY KEY)

When constructing a SQLAlchemy :class:`.Table` object, **an all lowercase name
is considered to be case insensitive**.   So the following table assumes
case insensitive names::

    Table("mytable", metadata, Column("identifier", Integer, primary_key=True))

Whereas when mixed case or UPPERCASE names are used, case sensitivity is
assumed::

    Table("MyTable", metadata, Column("Identifier", Integer, primary_key=True))

A similar situation occurs at the database driver level when emitting a
textual SQL SELECT statement and looking at column names in the DBAPI
``cursor.description`` attribute.  A database like PostgreSQL will normalize
case insensitive names to be lowercase::

    >>> pg_engine = create_engine("postgresql://scott:tiger@localhost/test")
    >>> pg_connection = pg_engine.connect()
    >>> result = pg_connection.exec_driver_sql("SELECT 1 AS SomeName")
    >>> result.cursor.description
    (Column(name='somename', type_code=23),)

Whereas Oracle normalizes them to UPPERCASE::

    >>> oracle_engine = create_engine("oracle+oracledb://scott:tiger@oracle18c/xe")
    >>> oracle_connection = oracle_engine.connect()
    >>> result = oracle_connection.exec_driver_sql(
    ...     "SELECT 1 AS SomeName FROM DUAL"
    ... )
    >>> result.cursor.description
    [('SOMENAME', <DbType DB_TYPE_NUMBER>, 127, None, 0, -127, True)]

In order to achieve cross-database parity for the two cases of a. table
reflection and b. textual-only SQL statement round trips, SQLAlchemy performs a step
called **name normalization** when using the Oracle dialect.  This process may
also apply to other third party dialects that have similar UPPERCASE handling
of case insensitive names.

When using name normalization, SQLAlchemy attempts to detect if a name is
case insensitive by checking if all characters are UPPERCASE letters only;
if so, then it assumes this is a case insensitive name and is delivered as
a lowercase name.

For table reflection, a tablename that is seen represented as all UPPERCASE
in Oracle Database's catalog tables will be assumed to have a case insensitive
name.  This is what allows the ``Table`` definition to use lower case names
and be equally compatible from a reflection point of view on Oracle Database
and all other databases such as PostgreSQL and MySQL::

    # matches a table created with CREATE TABLE mytable
    Table("mytable", metadata, autoload_with=some_engine)

Above, the all lowercase name ``"mytable"`` is case insensitive; it will match
a table reported by PostgreSQL as ``"mytable"`` and a table reported by
Oracle as ``"MYTABLE"``.  If name normalization were not present, it would
not be possible for the above :class:`.Table` definition to be introspectable
in a cross-database way, since we are dealing with a case insensitive name
that is not reported by each database in the same way.

Case sensitivity can be forced on in this case, such as if we wanted to represent
the quoted tablename ``"MYTABLE"`` with that exact casing, most simply by using
that casing directly, which will be seen as a case sensitive name::

    # matches a table created with CREATE TABLE "MYTABLE"
    Table("MYTABLE", metadata, autoload_with=some_engine)

For the unusual case of a quoted all-lowercase name, the :class:`.quoted_name`
construct may be used::

    from sqlalchemy import quoted_name

    # matches a table created with CREATE TABLE "mytable"
    Table(
        quoted_name("mytable", quote=True), metadata, autoload_with=some_engine
    )

Name normalization also takes place when handling result sets from **purely
textual SQL strings**, that have no other :class:`.Table` or :class:`.Column`
metadata associated with them. This includes SQL strings executed using
:meth:`.Connection.exec_driver_sql` and SQL strings executed using the
:func:`.text` construct which do not include :class:`.Column` metadata.

Returning to the Oracle Database SELECT statement, we see that even though
``cursor.description`` reports the column name as ``SOMENAME``, SQLAlchemy
name normalizes this to ``somename``::

    >>> oracle_engine = create_engine("oracle+oracledb://scott:tiger@oracle18c/xe")
    >>> oracle_connection = oracle_engine.connect()
    >>> result = oracle_connection.exec_driver_sql(
    ...     "SELECT 1 AS SomeName FROM DUAL"
    ... )
    >>> result.cursor.description
    [('SOMENAME', <DbType DB_TYPE_NUMBER>, 127, None, 0, -127, True)]
    >>> result.keys()
    RMKeyView(['somename'])

The single scenario where the above behavior produces inaccurate results
is when using an all-uppercase, quoted name.  SQLAlchemy has no way to determine
that a particular name in ``cursor.description`` was quoted, and is therefore
case sensitive, or was not quoted, and should be name normalized::

    >>> result = oracle_connection.exec_driver_sql(
    ...     'SELECT 1 AS "SOMENAME" FROM DUAL'
    ... )
    >>> result.cursor.description
    [('SOMENAME', <DbType DB_TYPE_NUMBER>, 127, None, 0, -127, True)]
    >>> result.keys()
    RMKeyView(['somename'])

For this case, a new feature will be available in SQLAlchemy 2.1 to disable
the name normalization behavior in specific cases.


.. _oracle_max_identifier_lengths:

Maximum Identifier Lengths
--------------------------

SQLAlchemy is sensitive to the maximum identifier length supported by Oracle
Database. This affects 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.

Oracle Database 12.2 increased the default maximum identifier length from 30 to
128. As of SQLAlchemy 1.4, the default maximum identifier length for the Oracle
dialects is 128 characters.  Upon first connection, the maximum length actually
supported by the database is obtained. 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+oracledb://scott:tiger@localhost:1521?service_name=freepdb1",
        max_identifier_length=30,
    )

If :paramref:`_sa.create_engine.max_identifier_length` is not set, the oracledb
dialect internally uses the ``max_identifier_length`` attribute available on
driver connections since python-oracledb version 2.5. When using an older
driver version, or using the cx_Oracle dialect, SQLAlchemy will instead attempt
to use the query ``SELECT value FROM v$parameter WHERE name = 'compatible'``
upon first connect in order to determine the effective compatibility version of
the database. The "compatibility" version is a version number that is
independent of the actual database version. It is used to assist database
migration. It is configured by an Oracle Database initialization parameter. The
compatibility version then determines the maximum allowed identifier length for
the database. If the V$ view is not available, the database version information
is used instead.

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:

.. sourcecode:: sql

    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 of 128, it becomes::

.. sourcecode:: sql

    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 Oracle
Database 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 Database
   is 128 characters, which is adjusted down to 30 upon first connect if the
   Oracle Database, or its compatibility setting, are lower than version 12.2.


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

Methods like :meth:`_sql.Select.limit` and :meth:`_sql.Select.offset` make use
of ``FETCH FIRST N ROW / OFFSET N ROWS`` syntax assuming Oracle Database 12c or
above, and assuming the SELECT statement is not embedded within a compound
statement like UNION.  This syntax is also available directly by using the
:meth:`_sql.Select.fetch` method.

.. versionchanged:: 2.0 the Oracle Database dialects now use ``FETCH FIRST N
   ROW / OFFSET N ROWS`` for all :meth:`_sql.Select.limit` and
   :meth:`_sql.Select.offset` usage including within the ORM and legacy
   :class:`_orm.Query`.  To force the legacy behavior using window functions,
   specify the ``enable_offset_fetch=False`` dialect parameter to
   :func:`_sa.create_engine`.

The use of ``FETCH FIRST / OFFSET`` may be disabled on any Oracle Database
version by passing ``enable_offset_fetch=False`` to :func:`_sa.create_engine`,
which will force the use of "legacy" mode that makes use of window functions.
This mode is also selected automatically when using a version of Oracle
Database prior to 12c.

When using legacy mode, or when a :class:`.Select` statement with limit/offset
is embedded in a compound statement, an emulated approach for LIMIT / OFFSET
based on window functions is used, 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 Database versions. See notes below.

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 on an
Oracle Database version prior to 12c, 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 Database 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`.

.. _oracle_returning:

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

Oracle Database supports RETURNING fully for INSERT, UPDATE and DELETE
statements that are invoked with a single collection of bound parameters (that
is, a ``cursor.execute()`` style statement; SQLAlchemy does not generally
support RETURNING with :term:`executemany` statements).  Multiple rows may be
returned as well.

.. versionchanged:: 2.0 the Oracle Database backend has full support for
   RETURNING on parity with other backends.


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

Oracle Database doesn't have native ON UPDATE CASCADE functionality.  A trigger
based solution is available at
https://web.archive.org/web/20090317041251/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 Database 8 Compatibility
-------------------------------

.. warning:: The status of Oracle Database 8 compatibility is not known for
   SQLAlchemy 2.0.

When Oracle Database 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.


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 Database
dialects know 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 Database dialects 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 Database 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 Database 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+oracledb://scott:tiger@localhost:1521?service_name=freepdb1"
      )
      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
  Database 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 Database 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+oracledb://scott:tiger@localhost:1521/?service_name=freepdb1",
        exclude_tablespaces=["SYSAUX", "SOME_TABLESPACE"],
    )

.. _oracle_float_support:

FLOAT / DOUBLE Support and Behaviors
------------------------------------

The SQLAlchemy :class:`.Float` and :class:`.Double` datatypes are generic
datatypes that resolve to the "least surprising" datatype for a given backend.
For Oracle Database, this means they resolve to the ``FLOAT`` and ``DOUBLE``
types::

    >>> from sqlalchemy import cast, literal, Float
    >>> from sqlalchemy.dialects import oracle
    >>> float_datatype = Float()
    >>> print(cast(literal(5.0), float_datatype).compile(dialect=oracle.dialect()))
    CAST(:param_1 AS FLOAT)

Oracle's ``FLOAT`` / ``DOUBLE`` datatypes are aliases for ``NUMBER``.   Oracle
Database stores ``NUMBER`` values with full precision, not floating point
precision, which means that ``FLOAT`` / ``DOUBLE`` do not actually behave like
native FP values. Oracle Database instead offers special datatypes
``BINARY_FLOAT`` and ``BINARY_DOUBLE`` to deliver real 4- and 8- byte FP
values.

SQLAlchemy supports these datatypes directly using :class:`.BINARY_FLOAT` and
:class:`.BINARY_DOUBLE`.   To use the :class:`.Float` or :class:`.Double`
datatypes in a database agnostic way, while allowing Oracle backends to utilize
one of these types, use the :meth:`.TypeEngine.with_variant` method to set up a
variant::

    >>> from sqlalchemy import cast, literal, Float
    >>> from sqlalchemy.dialects import oracle
    >>> float_datatype = Float().with_variant(oracle.BINARY_FLOAT(), "oracle")
    >>> print(cast(literal(5.0), float_datatype).compile(dialect=oracle.dialect()))
    CAST(:param_1 AS BINARY_FLOAT)

E.g. to use this datatype in a :class:`.Table` definition::

    my_table = Table(
        "my_table",
        metadata,
        Column(
            "fp_data", Float().with_variant(oracle.BINARY_FLOAT(), "oracle")
        ),
    )

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

Oracle Database 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 Database dialects provide 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.

.. _oracle_table_options:

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

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


* ``ON COMMIT``::

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

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

*
  ``TABLESPACE``::

     Table("mytable", metadata, ..., oracle_tablespace="EXAMPLE_TABLESPACE")

  The ``oracle_tablespace`` parameter specifies the tablespace in which the
  table is to be created. This is useful when you want to create a table in a
  tablespace other than the default tablespace of the user.

  .. versionadded:: 2.0.37

.. _oracle_index_options:

Oracle Database 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.

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

Oracle Database 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).

    )annotations)defaultdict)	lru_cachewrapsN   )
dictionary)_OracleBoolean)_OracleDate)BFILE)BINARY_DOUBLE)BINARY_FLOAT)DATE)FLOAT)INTERVAL)LONG)NCLOB)NUMBER)	NVARCHAR2)	OracleRaw)RAW)ROWID)	TIMESTAMP)VARCHAR2   )Computed)exc)schema)sql)util)default)
ObjectKind)ObjectScope)
reflection)ReflectionDefaults)and_	bindparam)compiler)
expression)func)null)or_)select)sqltypes)visitors)InternalTraversal)BLOB)CHAR)CLOB)DOUBLE_PRECISION)INTEGER)NCHAR)NVARCHAR)REAL)VARCHARa
  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_TIMESTAMPr   r   r3   r7   r   r   r2   r   r4   r   r   TIMESTAMP WITH TIME ZONETIMESTAMP WITH LOCAL TIME ZONEzINTERVAL DAY TO SECONDr   r   DOUBLE PRECISION)r9   r   r   r   r   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 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 N)
visit_DATEselftype_kws      HD:\EasyAligner\venv\Lib\site-packages\sqlalchemy/dialects/oracle/base.pyvisit_datetimez!OracleTypeCompiler.visit_datetimeH      tu+++    c                (     | j                   |fi |S rA   )visit_FLOATrC   s      rG   visit_floatzOracleTypeCompiler.visit_floatK  s    t,,,rJ   c                (     | j                   |fi |S rA   )visit_DOUBLE_PRECISIONrC   s      rG   visit_doublezOracleTypeCompiler.visit_doubleN  s    *t**57B77rJ   c                z    | j                   j                  r | j                  |fi |S  | j                  |fi |S rA   )dialect_use_nchar_for_unicodevisit_NVARCHAR2visit_VARCHAR2rC   s      rG   visit_unicodez OracleTypeCompiler.visit_unicodeQ  s?    <<..'4''444&4&&u333rJ   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 SECOND)day_precisionsecond_precisionrC   s      rG   visit_INTERVALz!OracleTypeCompiler.visit_INTERVALW  sj    t+ -,,, ""$. 0///	
 	
rJ   c                     y)Nr    rC   s      rG   
visit_LONGzOracleTypeCompiler.visit_LONGa      rJ   c                :    t        |dd      ry|j                  ryy)Nlocal_timezoneFr<   r;   r   )getattrtimezonerC   s      rG   visit_TIMESTAMPz"OracleTypeCompiler.visit_TIMESTAMPd  s    5*E23^^-rJ   c                *     | j                   |dfi |S )Nr=   _generate_numericrC   s      rG   rO   z)OracleTypeCompiler.visit_DOUBLE_PRECISIONl  s    %t%%e-?F2FFrJ   c                *     | j                   |dfi |S )Nr   rf   rC   s      rG   visit_BINARY_DOUBLEz&OracleTypeCompiler.visit_BINARY_DOUBLEo  s    %t%%e_CCCrJ   c                *     | j                   |dfi |S )Nr   rf   rC   s      rG   visit_BINARY_FLOATz%OracleTypeCompiler.visit_BINARY_FLOATr  s    %t%%e^BrBBrJ   c                4    d|d<    | j                   |dfi |S )NT_requires_binary_precisionr   rf   rC   s      rG   rL   zOracleTypeCompiler.visit_FLOATu  s'    +/'(%t%%eW;;;rJ   c                *     | j                   |dfi |S )Nr   rf   rC   s      rG   visit_NUMBERzOracleTypeCompiler.visit_NUMBERy  s    %t%%eX<<<rJ   Nc           	         |t        |dd       }|rTt        |dd       }|rC|At        |dz        }t        j                  d|j                  j
                   d| d| d      |}|t        |dd       }||S |
d	}	|	||d
z  S d}	|	|||dz  S )N	precisionbinary_precisiong2ZGUD?zOracle Database FLOAT types use 'binary precision', which does not convert cleanly from decimal 'precision'.  Please specify this type with a separate Oracle Database variant, such as z(precision=z-).with_variant(oracle.FLOAT(binary_precision=zb), 'oracle'), so that the Oracle Database specific 'binary_precision' may be specified accurately.scalez%(name)s(%(precision)s))namerq   z"%(name)s(%(precision)s, %(scale)s))rt   rq   rs   )rb   intr   ArgumentError	__class____name__)
rD   rE   rt   rq   rs   rm   rF   rr   estimated_binary_precisionns
             rG   rg   z$OracleTypeCompiler._generate_numeric|  s     {D9I%&u.@$G-5-0W1D-E*''  //223;yk J) 22 3,	,  -	=E7D1EK])A9===4A9uMMMrJ   c                (     | j                   |fi |S rA   )rU   rC   s      rG   visit_stringzOracleTypeCompiler.visit_string      "t""5/B//rJ   c                (    | j                  |dd      S )NrX   2_visit_varcharrC   s      rG   rU   z!OracleTypeCompiler.visit_VARCHAR2  s    ""5"c22rJ   c                (    | j                  |dd      S )NNr   r   rC   s      rG   rT   z"OracleTypeCompiler.visit_NVARCHAR2  s    ""5#s33rJ   c                (    | j                  |dd      S NrX   r   rC   s      rG   visit_VARCHARz OracleTypeCompiler.visit_VARCHAR  s    ""5"b11rJ   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)tworz   zVARCHAR%(two)s(%(length)s CHAR))lengthr   z%(n)sVARCHAR%(two)s(%(length)s))r   r   rz   )r   rR   _supports_char_length)rD   rE   rz   numvarchars        rG   r   z!OracleTypeCompiler._visit_varchar  s\    ||(3Q+???t||997GSAAA7GSqIIIrJ   c                (     | j                   |fi |S rA   )
visit_CLOBrC   s      rG   
visit_textzOracleTypeCompiler.visit_text  rI   rJ   c                z    | j                   j                  r | j                  |fi |S  | j                  |fi |S rA   )rR   rS   visit_NCLOBr   rC   s      rG   visit_unicode_textz%OracleTypeCompiler.visit_unicode_text  s=    <<..#4##E0R00"4??5/B//rJ   c                (     | j                   |fi |S rA   )
visit_BLOBrC   s      rG   visit_large_binaryz%OracleTypeCompiler.visit_large_binary  rI   rJ   c                ,     | j                   |fddi|S )Nrq      )ro   rC   s      rG   visit_big_integerz$OracleTypeCompiler.visit_big_integer  s     t  ;";;;rJ   c                (     | j                   |fi |S rA   )visit_SMALLINTrC   s      rG   visit_booleanz OracleTypeCompiler.visit_boolean  r}   rJ   c                >    |j                   rdd|j                   iz  S y)NzRAW(%(length)s)r   r   )r   rC   s      rG   	visit_RAWzOracleTypeCompiler.visit_RAW  s     <<$%,,'???rJ   c                     y)Nr   r]   rC   s      rG   visit_ROWIDzOracleTypeCompiler.visit_ROWID  s    rJ   )NNF)rx   
__module____qualname__rH   rM   rP   rV   r[   r^   rd   rO   ri   rk   rL   ro   rg   r|   rU   rT   visit_NVARCHARr   r   r   r   r   r   r   r   r   r]   rJ   rG   r?   r?   B  s    ,-84
GDC<= #(+NZ034 %N2J,0,<0rJ   r?   c                      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 f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.d& Z/d' Z0d( Z1 xZ2S )*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                2    i | _         t        |   |i | y rA   )_OracleCompiler__wheressuper__init__)rD   argskwargsrw   s      rG   r   zOracleCompiler.__init__  s    $)&)rJ   c                    d | j                   |j                  fi |d | j                   |j                  fi |dS )Nzmod(, )processleftrightrD   binaryoperatorrF   s       rG   visit_mod_binaryzOracleCompiler.visit_mod_binary  s:    DLL++DLL,,
 	
rJ   c                     y)NCURRENT_TIMESTAMPr]   rD   fnrF   s      rG   visit_now_funczOracleCompiler.visit_now_func  s    "rJ   c                .    d | j                   |fi |z   S )NLENGTHfunction_argspecr   s      rG   visit_char_length_funcz%OracleCompiler.visit_char_length_func  s     /$//9b999rJ   c                x    d| j                  |j                        d| j                  |j                        dS )Nz
CONTAINS (r   r   r   r   s       rG   visit_match_op_binaryz$OracleCompiler.visit_match_op_binary  ,    LL%LL&
 	
rJ   c                     y)N1r]   rD   exprrF   s      rG   
visit_truezOracleCompiler.visit_true      rJ   c                     y)N0r]   r   s      rG   visit_falsezOracleCompiler.visit_false  r   rJ   c                     y)NWITHr]   )rD   	recursives     rG   get_cte_preamblezOracleCompiler.get_cte_preamble  r_   rJ   c                N    dj                  d |j                         D              S )N c              3  ,   K   | ]  \  }}d |z    yw)z	/*+ %s */Nr]   ).0tabletexts      rG   	<genexpr>z6OracleCompiler.get_select_hint_text.<locals>.<genexpr>  s     No{udd*os   )joinitems)rD   byfromss     rG   get_select_hint_textz#OracleCompiler.get_select_hint_text  s    xxNgmmoNNNrJ   c                    t        |j                        dkD  s |j                  j                         t        vr!t        j                  j                  | |fi |S y)Nr   rX   )lenclausesrt   upper
NO_ARG_FNSr)   SQLCompilerr   r   s      rG   r   zOracleCompiler.function_argspec
  sD    rzz?Q"''--/"C''88rHRHHrJ   c                    t        |   |fi |}|j                  dd      r"|j                  j	                         dk7  rd|z  }|S )NasfromFr   z
TABLE (%s))r   visit_functiongetrt   lower)rD   r+   rF   r   rw   s       rG   r   zOracleCompiler.visit_function  sF    w%d1b166(E"tyy'8G'C$&DrJ   c                2    t        |   |fi |}|dz   }|S )Nz.COLUMN_VALUE)r   visit_table_valued_column)rD   elementrF   r   rw   s       rG   r   z(OracleCompiler.visit_table_valued_column  s&    w0?B?o%rJ   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]   rD   s    rG   default_fromzOracleCompiler.default_from  s     rJ   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   )rR   use_ansir)   r   
visit_joinedgesaddr   r   
isinstancer*   FromGroupingr   r   )rD   r   r   r   r   s        rG   r   zOracleCompiler.visit_join$  s    <<  ''22d(37=  !!%%tyy$**&=>#F8$**j&=&=>

**

TYYJKJ6J$,,uH+HHIrJ   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 rA   )r   r   r*   ColumnClauser   is_derived_fromr   _OuterJoinColumn)r   r   s    rG   visit_binaryzVOracleCompiler._get_nonansi_join_whereclause.<locals>.visit_join.<locals>.visit_binaryA  s    !Z%<%<**44V[[5F5FG&6v{{&C#j&=&=**44V\\5G5GH'7'E IrJ   r   )isouterappendr0   cloned_traverseonclauser   r   r   r*   Joinr   r   )r   r   jr   r   s   `  rG   r   z@OracleCompiler._get_nonansi_join_whereclause.<locals>.visit_join;  s    ||
F ,,rHl+C t}}-YY

*a1qM:#:#:;qyy)	 +rJ   )r   r*   r   r   r&   )rD   fromsfr   r   s      @@rG   _get_nonansi_join_whereclausez,OracleCompiler._get_nonansi_join_whereclause8  sE    	*< A!Z__-1  88W%%rJ   c                B     | j                   |j                  fi |dz   S )Nz(+))r   column)rD   vcrF   s      rG   visit_outer_join_columnz&OracleCompiler.visit_outer_join_columnb  s!    t||BII,,u44rJ   c                >    | j                   j                  |      dz   S )Nz.nextval)preparerformat_sequence)rD   seqrF   s      rG   visit_sequencezOracleCompiler.visit_sequencee  s    }},,S1J>>rJ   c                    d|z   S )z+Oracle doesn't like ``FROM table AS alias``r   r]   )rD   alias_name_texts     rG   get_render_as_alias_suffixz)OracleCompiler.get_render_as_alias_suffixh  s     _$$rJ   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-                  |
                   | j.                  rt1        j2                  d      d| _        |j)                  | j7                  |	d             |s`| j9                  t;        |	d|	j<                        t;        |	d|	j<                        |t;        |dd       t;        |d	d       f|j                          d
dj?                  |      z   dz   dj?                  |      z   S )Na}  Computed columns don't work with Oracle Database 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 Database 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)rE   zUsing explicit outparam() objects with UpdateBase.returning() in the same Core DML statement is not supported in the Oracle Database dialects.TF)within_columns_clausert   keyz
RETURNING r   z INTO ) 	enumerater*   _select_iterablesisupdater   	sa_schemaColumnserver_defaultr   rR   (_supports_update_returning_computed_colsr    warntype_has_column_expressioncolumn_expressionr   outparambindsr  r   bindparam_string_truncate_bindparamhas_out_parametersr   InvalidRequestError_oracle_returningr   _add_to_result_maprb   _anon_name_labelr   )rD   stmtreturning_colspopulate_result_maprF   columnsr   ir  col_exprr  s              rG   returning_clausezOracleCompiler.returning_clausem  s    "((8
IAv vy'7'78v44h?MM		M {{11!;;88@!||HqLDH'/DJJx||$LL%%d&>&>x&HI &&--H  &*D"NN4<<<NO"''Hfh.G.GHHfh.G.GH5t4
 KK	_
t dii008;dii>NNNrJ   c                    |j                   | j                  j                  st        |   |fddi|S  | j
                  |f| j                  |      dd|S )zmOracle Database 12c supports OFFSET/FETCH operators
        Use it instead subquery with row_number

        "use_literal_execute_for_simple_intT)fetch_clauser0  )_fetch_clauserR   _supports_offset_fetchr   _row_limit_clauser1  _get_limit_or_fetch)rD   r.   rF   rw   s      rG   r4  z OracleCompiler._row_limit_clause  s}       ,<<667,;?CE  %4$$!55f=37 	 rJ   c                J    |j                   |j                  S |j                   S rA   )r2  _limit_clause)rD   r.   s     rG   r5  z"OracleCompiler._get_limit_or_fetch  s&    '''''''rJ   c           
     R	   |}t        |dd       s| j                  j                  sN| j                  ||j	                  dd            }| j                  |      }| |j                  |      }d|_        |j                  r| j                  j                  s|j                  |j                  }|j                  } |j                  |      r|j                         } |j                  |      r|j                         }|} |j                         }d|_        |j                   }	|	k|	j"                  r_|	j%                         }	|	j'                          |	j"                  D ]0  }
|j(                  j+                  |
      r |j,                  |
      }2  |j.                         }t1        j2                  |j4                  D cg c]   }|j(                  j7                  |      	 |" c} }|`| j                  j8                  rJ |j                  |      r8|j;                  t=        j>                  d | j@                  |fi |z              }d|_        d|_!        |	O|	j"                  rCtE        jF                  |      }|	j"                  D 
cg c]  }
|jI                  |
       c}
|	_        |` |j                  |      r| |j                  |      r
|}|||z   }n	|}|||z   }|j                  t1        jJ                  d      |k        }||	|_        |}|S |j-                  t1        jJ                  d      jM                  d            }d|_        d|_!        |	M|	j"                  rA|j(                  }|	j"                  D ]&  }
|j7                  |
      	 |j-                  |
      }( |j/                         }|j(                  }t1        j2                  |j4                  D cg c]  }|j7                  |      	 | c} }d|_        d|_!        |	O|	j"                  rCtE        jF                  |      }|	j"                  D 
cg c]  }
|jI                  |
       c}
|	_        |j                  t1        jJ                  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)'rb   rR   r   _display_froms_for_selectr   r  wherer9  _has_row_limiting_clauser3  r2  r7  _offset_clause_simple_int_clauserender_literal_execute	_generate_for_update_argof_clone_copy_internalsselected_columnscontains_columnadd_columnsaliasr   r.   ccorresponding_columnoptimize_limitsprefix_withr*   r   r   _is_wrappersql_utilClauseAdaptertraverseliteral_columnlabel)rD   select_stmtr   r.   r  whereclauselimit_clauseoffset_clauseorig_select
for_updateeleminner_subqueryrK  limitselectadaptermax_rowlimitselect_colslimit_subqueryorigselect_colsoffsetselects                       rG   translate_select_structurez)OracleCompiler.translate_select_structure  s   v5<<((66FJJx7 #@@G*)V\\+6F+/F( //;;((0%33 & 5 5,6,,\:#/#F#F#HL,6,,];$1$H$H$JM %)))+'+$ $33
)jmm!+!2!2!4J..0 *%66FFtL%7V%7%7%=F !.
 ".!jj "0!1!1!1A&77LLQO#$ !1 !,44111,?"-"9"9"3*dll<B6BC#K -1)*.' )jmm&44^DG;E==%;H4((.=%JM
  +0v00>%-46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($.MMD 0 E Ed K#'!( /:.E.Ed.K %2 &1%6%6%8N&1&B&BO#&:: &4%5%5%5.CCAF#' ( %5$L 26L./3L,!-*--"*"8"8"H?I}})?LtG,,T2})
 $0#5#5**84}D$L 4>L0)FC4%^)s   %RR%RR$c                     yr   r]   )rD   r.   rF   s      rG   rW  zOracleCompiler.limit_clause^  s    rJ   c                     y)NzSELECT 1 FROM DUAL WHERE 1!=1r]   rC   s      rG   visit_empty_set_exprz#OracleCompiler.visit_empty_set_expra  s    .rJ   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 )NrX   z FOR UPDATEz OF r   c              3  D   K   | ]  } j                   |fi   y wrA   )r   )r   r[  rF   rD   s     rG   r   z3OracleCompiler.for_update_clause.<locals>.<genexpr>k  s&      &5NTT(R(5N    z NOWAITz SKIP LOCKED)is_subqueryrC  rD  r   nowaitskip_locked)rD   r.   rF   tmps   ` ` rG   for_update_clausez OracleCompiler.for_update_claused  s    !!$$6DII &5;5K5K5N5N&   C !!((9C!!-->!C
rJ   c                x    d| j                  |j                        d| j                  |j                        dS )NDECODE(r   z, 0, 1) = 1r   r   s       rG   visit_is_distinct_from_binaryz,OracleCompiler.visit_is_distinct_from_binaryv  r   rJ   c                x    d| j                  |j                        d| j                  |j                        dS )Nrq  r   z, 0, 1) = 0r   r   s       rG   !visit_is_not_distinct_from_binaryz0OracleCompiler.visit_is_not_distinct_from_binary|  r   rJ   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)rD   r   r   rF   stringpatternrv  s          rG   visit_regexp_match_op_binaryz+OracleCompiler.visit_regexp_match_op_binary  s    fkk0R0$,,v||2r2  )=,2G<<  ))%1D1DE rJ   c                0    d | j                   ||fi |z  S )NzNOT %s)r}  r   s       rG    visit_not_regexp_match_op_binaryz/OracleCompiler.visit_not_regexp_match_op_binary  s,    ;$;;H
 "
 
 	
rJ   c           	          | j                   |j                  fi |} | j                   |j                  fi |}|j                  d   }|	d|d|dS d|d|d| j	                  |t
        j                        dS )Nrv  zREGEXP_REPLACE(r   r   rw  )rD   r   r   rF   r{  pattern_replacerv  s          rG   visit_regexp_replace_op_binaryz-OracleCompiler.visit_regexp_replace_op_binary  s    fkk0R0&$,,v||:r:  )=   ))%1D1DE rJ   c                .    d | j                   |fi |z  S )Nz	LISTAGG%sr   r   s      rG   visit_aggregate_strings_funcz+OracleCompiler.visit_aggregate_strings_func  s     2T222<<<<rJ   c                     | j                   |j                  fi |} | j                   ||n|j                  fi |}| d| d| dS )N(r   r   r   )rD   r   fn_namecustom_rightrF   r   r   s          rG   _visit_bitwisezOracleCompiler._visit_bitwise  s\    t||FKK.2.(4L&,,
JL
 !D6E7!,,rJ   c                *     | j                   |dfi |S )NBITXORr  r   s       rG   visit_bitwise_xor_op_binaryz*OracleCompiler.visit_bitwise_xor_op_binary      "t""68:r::rJ   c                *     | j                   |dfi |S )NBITORr  r   s       rG   visit_bitwise_or_op_binaryz)OracleCompiler.visit_bitwise_or_op_binary  s    "t""679b99rJ   c                *     | j                   |dfi |S )NBITANDr  r   s       rG   visit_bitwise_and_op_binaryz*OracleCompiler.visit_bitwise_and_op_binary  r  rJ   c                ,    t        j                  d      )Nz'Cannot compile bitwise_rshift in oracler   CompileErrorr   s       rG   visit_bitwise_rshift_op_binaryz-OracleCompiler.visit_bitwise_rshift_op_binary      HIIrJ   c                ,    t        j                  d      )Nz'Cannot compile bitwise_lshift in oracler  r   s       rG   visit_bitwise_lshift_op_binaryz-OracleCompiler.visit_bitwise_lshift_op_binary  r  rJ   c                ,    t        j                  d      )Nz$Cannot compile bitwise_not in oracler  )rD   r   r   rF   s       rG   #visit_bitwise_not_op_unary_operatorz2OracleCompiler.visit_bitwise_not_op_unary_operator  s    EFFrJ   rA   )3rx   r   r   __doc__r    update_copyr)   r   compound_keywordsr*   CompoundSelectEXCEPTr   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r.  r4  r5  rd  rW  rg  ro  rr  rt  r}  r  r  r  r  r  r  r  r  r  r  __classcell__rw   s   @rG   r   r     s   
 )((..		"	"	)	)73
*
#:
O
((&T5?%
@OD*(Rh/$



 =-;:;JJGrJ   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 )NrX   z ON DELETE %szOracle Database 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  )rD   
constraintr   s      rG   define_constraint_cascadesz,OracleDDLCompiler.define_constraint_cascades  sN    *Oj&9&999D
 *II rJ   c                R    d| j                   j                  |j                        z  S )NzCOMMENT ON TABLE %s IS '')r
  format_tabler   )rD   droprF   s      rG   visit_drop_table_commentz*OracleDDLCompiler.visit_drop_table_comment  s'    *T]]-G-GLL.
 
 	
rJ   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   rD   s     rG   r   z7OracleDDLCompiler.visit_create_index.<locals>.<genexpr>  s:       .D !!))T *  .s   (+r   compressFz	 COMPRESSz COMPRESS %d)
r   _verify_index_tabler
  uniquedialect_options_prepared_index_namer  r   r   expressions)rD   createrF   indexr
  r   s   `     rG   visit_create_indexz$OracleDDLCompiler.visit_create_index  s      '==<<ID  *84ID%%eD%A!!%++$!?II  "--	 	
 		
   *:6eC$$X.z:dB#
  ))(3J?  rJ   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
   r0|j                  d| j                  j                  |d
         z         dj                  |      S )Nr  	on_commit_r   z
 ON COMMIT %sr  Tz

 COMPRESSz
 COMPRESS FOR %s
tablespacez
 TABLESPACE %srX   )r  replacer   r   r
  quoter   )rD   r   
table_optsoptson_commit_optionss        rG   post_create_tablez#OracleDDLCompiler.post_create_table  s    
$$X. $[ 1 9 9#s C I I K/2CCD
J4'!!-0!!"6$z:J"KL"T]]%8%8l9K%LL wwz""rJ   c                    t         |   |      }|j                  dd      }|j                  dd      }|j                  dd      }|j                  ||j                  rdndz  }|j	                         S )	NzNO MINVALUE
NOMINVALUEzNO MAXVALUE
NOMAXVALUEzNO CYCLENOCYCLEz ORDERz NOORDER)r   get_identity_optionsr  orderstrip)rD   identity_optionsr   rw   s      rG   r  z&OracleDDLCompiler.get_identity_options  sp    w+,<=||M<8||M<8||J	2!!- 0 6 6HJFDzz|rJ   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  zOracle Database computed columns do not support 'stored' persistence; set the 'persisted' flag to None or False for Oracle Database support.z VIRTUAL)r  r   sqltext	persistedr   r  )rD   	generatedrF   r   s       rG   visit_computed_columnz'OracleDDLCompiler.visit_computed_column  sy    )D,=,=,E,EU$ -F -
 
 $&""+ 
   E)JDrJ   c                    |j                   d}n|j                   rdnd}d|z  }|j                  r|dz  }|dz  }| j                  |      }|r|d|z  z  }|S )NrX   ALWAYSz
BY DEFAULTzGENERATED %sz ON NULLz AS IDENTITYz (%s))alwayson_nullr  )rD   identityrF   kindr   optionss         rG   visit_identity_columnz'OracleDDLCompiler.visit_identity_column  sl    ??"D'8LD$JD++H5Gg%%DrJ   )rx   r   r   r  r  r  r  r  r  r  r  r  s   @rG   r  r    s&    $

8#&rJ   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s8 |d   | j                  v xs% | j                  j	                  t        |             S )z5Return True if the given identifier requires quoting.r   )r   reserved_wordsillegal_initial_characterslegal_charactersmatchstr)rD   valuelc_values      rG   _bindparam_requires_quotesz3OracleIdentifierPreparer._bindparam_requires_quotes4  sW    ;;=+++ ;Qx4:::;((..s5z::	
rJ   c                Z    |j                   j                  d      }t        |   ||      S )Nr  )identlstripr   format_savepoint)rD   	savepointrt   rw   s      rG   r  z)OracleIdentifierPreparer.format_savepoint=  s)    %%c*w'	488rJ   )rx   r   r   RESERVED_WORDSr   r  ranger  unionr  r  r  r  )r   xdigr  rw   s   0000@rG   r  r  .  se    )78Aaggi8N6;Arl!Cls#c(l!C!I!I	c
"
9 9 9!Cs
   A'A-r  c                      e Zd 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  )rD   r  rE   s      rG   fire_sequencez$OracleExecutionContext.fire_sequenceC  s>    ##&&66s;<"# 	
 	
rJ   c                    | j                   rLd| j                  v r=| j                   j                  t        j                  | j                  d         | _         y y y )N_oracle_dblink)	statementexecution_optionsr  r	   DB_LINK_PLACEHOLDERr   s    rG   pre_execzOracleExecutionContext.pre_execK  sM    >>.$2H2HH!^^33..&&'78DN I>rJ   N)rx   r   r   r  r  r]   rJ   rG   r  r  B  s    
rJ   r  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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'jP                  dddddfe'jR                  ddd	fgZ* e+jX                  d
      	 	 	 	 	 	 dOd       Z- fdZ.d Z/e0d        Z1e0d        Z2e0d        Z3e0d        Z4e0d        Z5e0d        Z6d Z7d Z8d Z9d Z:	 dPdZ;e+jx                  d        Z=e>j~                  	 dQd       Z@e>j~                  	 dQd       ZAd ZB fdZC e>j                  deEj                  fd eEj                  fd!eEj                  f      d"        ZH eI       d#        ZJ e>j                  deEj                  fd$eEj                  fd%eEj                  fd eEj                  fd!eEj                  f      d&        ZLd' ZMd( ZNe>j~                  dPd)       ZOe>j~                  dQd*       ZPe>j~                  dPd+       ZQe>j~                  	 dRd,       ZRe>j~                  dQd-       ZSe>j~                  dQd.       ZTd/ ZUd0 ZVe>j~                  dPd1       ZW eI       d2        ZXeMdd3d4       ZYe>j~                  dPd5       ZZd6 Z[ eI       d7        Z\eMdd3d8       Z]d9 Z^e>j~                  dPd:       Z_ eI       d;        Z`eMdd3d<       Zae>j~                  dPd=       Zb eI       d>        Zc e>j                  deEj                  fd!eEj                  fd?eEj                  f      d@        ZdeMdd3dA       Zee>j~                  dPdB       Zf eI       dC        Zg e>j                  deEj                  fd!eEj                  fd?eEj                  f      dD        ZheMdd3dE       Zie>j~                  	 dPdF       ZjeMdd3dG       Zke>j~                  	 dPdH       ZleMdd3dI       Zme>j~                  	 	 dQdJ       Zne>j~                  	 dSdK       ZoeMdddLdM       ZpdPdNZq xZrS )TOracleDialectr  T   Fnamed)oracle_resolve_synonymsN)resolve_synonymsr  r  r  )r  r  )z1.4a  The ``use_binds_for_limits`` Oracle Database 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 | || _        || _        || _        || _        |x| _        | _        y rA   )	r!   DefaultDialectr   rS   r   rM  exclude_tablespacesenable_offset_fetchr3  )rD   r   rM  r  use_nchar_for_unicoder  r  r   s           rG   r   zOracleDialect.__init__  sN    ( 	''77&;# .#6 	
 4#>rJ   c                F   t         |   |       | j                  rO| j                  j	                         | _        | j                  j                  t        j                         d| _        | j                  dk\  | _
        | j                  xr | j                  dk\  | _        y )NF   )r   
initialize_is_oracle_8colspecscopypopr/   Intervalr   server_version_infosupports_identity_columnsr  r3  )rD   
connectionrw   s     rG   r  zOracleDialect.initialize  s    :&  MM..0DMMMh//0!DM)-)A)AU)J&$$J)A)AU)J 	#rJ   c                4   | j                   dk  r| j                   S 	 |j                  d      j                         }|r"	 t        d |j                  d      D              S | j                   S # t        j                  $ r d }Y Gw 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rA   )ru   )r   r  s     rG   r   zJOracleDialect._get_effective_compat_server_version_info.<locals>.<genexpr>  s     ?->SV->s   .)r  exec_driver_sqlscalarr   
DBAPIErrortuplesplit)rD   r  compats      rG   )_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    rG   r  zOracleDialect._is_oracle_8  s    ''KD,D,Dt,KKrJ   c                <    | j                   xr | j                   dk\  S )N)r  r   r+  r   s    rG   _supports_table_compressionz)OracleDialect._supports_table_compression  s    ''OD,D,D,OOrJ   c                <    | j                   xr | j                   dk\  S )N)   r+  r   s    rG   _supports_table_compress_forz*OracleDialect._supports_table_compress_for      ''MD,D,D,MMrJ   c                    | j                    S rA   )r  r   s    rG   r   z#OracleDialect._supports_char_length  s    $$$$rJ   c                <    | j                   xr | j                   dk\  S )N)   r+  r   s    rG   r  z6OracleDialect._supports_update_returning_computed_cols  s      ''MD,D,D,MMrJ   c                <    | j                   xr | j                   dk\  S )N)   r+  r   s    rG   _supports_except_allz"OracleDialect._supports_except_all  r1  rJ   c                     y rA   r]   )rD   r  rt   s      rG   do_release_savepointz"OracleDialect.do_release_savepoint  s    rJ   c                .    | j                  |      dk  ryy )Nr     )r(  rD   r  s     rG   _check_max_identifier_lengthz*OracleDialect._check_max_identifier_length  s%    99*E I
 
  rJ   c                
    ddgS )NREAD COMMITTEDSERIALIZABLEr]   )rD   dbapi_connections     rG   get_isolation_level_valuesz(OracleDialect.get_isolation_level_values  s     .11rJ   c                F    	 | j                  |      S # t        $ r   Y yxY w)Nr?  )get_isolation_levelNotImplementedError)rD   
dbapi_conns     rG   get_default_isolation_levelz)OracleDialect.get_default_isolation_level  s-    	$++J77" 		$#s     c                    |r|j                  d      sd| }|xs dd d}|r|rd }t        j                  |i d|i      }|j                  |||      S )N@rX   )r   schema_translate_mapc                    d| _         y )NT)literal_executer'   s    rG   visit_bindparamz:OracleDialect._execute_reflection.<locals>.visit_bindparam  s
    ,0	)rJ   r(   )r  )
startswithr0   r   execute)rD   r  querydblinkreturns_longparamsr  rM  s           rG   _execute_reflectionz!OracleDialect._execute_reflection  s     &++C0\F %l$(	
 l1 ,,rK9E !!6-> " 
 	
rJ   c                z   t        t        j                  j                  j                  t        j                  j                  j
                        j                  t        t        j                  j                  j                  j                  d      t        j                  j                  j
                              j                  d      }t        |j                  j                        j                  |j                  j                  t        d      k(  |j                  j
                  t        d      k(        }|S )N
table_nametables_and_viewsowner)r.   r	   
all_tablesrK  rV  rX  	union_all	all_views	view_namerT  subqueryr=  r(   )rD   tablesrP  s      rG   _has_table_queryzOracleDialect._has_table_query   s     %%''22%%''-- Y((**44::<H((**00 X() 	 vxx**+11HH9\#::HHNNi00
 rJ   c                    | j                  |       |s| j                  }| j                  |      | j                  |      d}| j	                  || j
                  |d|      }t        |j                               S )@Supported kw arguments are: ``dblink`` to reflect via a db link.)rV  rX  FrR  rS  )_ensure_has_table_connectiondefault_schema_namedenormalize_namedenormalize_schema_namerT  r_  boolr#  )rD   r  rV  r   rQ  rF   rS  cursors           rG   	has_tablezOracleDialect.has_table7  s    
 	))*5--F //
;11&9
 ))!! * 
 FMMO$$rJ   c                   |s| j                   }t        t        j                  j                  j
                        j                  t        j                  j                  j
                  | j                  |      k(  t        j                  j                  j                  | j                  |      k(        }| j                  |||d      }t        |j                               S ra  FrR  )rd  r.   r	   all_sequencesrK  sequence_namer=  rf  sequence_ownerrT  rg  r#  )rD   r  rn  r   rQ  rF   rP  rh  s           rG   has_sequencezOracleDialect.has_sequenceN  s    
 --Fz//11??@FF$$&&44++M:;$$&&55++F34
 ))vE * 
 FMMO$$rJ   c                ^    | j                  |j                  d      j                               S )Nz;select sys_context( 'userenv', 'current_schema' ) from dual)normalize_namer"  r#  r<  s     rG   _get_default_schema_namez&OracleDialect._get_default_schema_nameb  s-    ""&&Mfh
 	
rJ   c                L    t        |dd       }||dk(  ryt        | 	  |      S )Nr  publicPUBLIC)rb   r   re  )rD   rt   forcerw   s      rG   rf  z%OracleDialect.denormalize_schema_namei  s0    gt,=TX-w'--rJ   r   filter_namesrQ  c                   | j                  |xs | j                        }| j                  |      \  }}t        t        j
                  j                  j                  t        j
                  j                  j                  t        j
                  j                  j                  t        j
                  j                  j                        j                  t        j
                  j                  j                  |k(        }	|rE|	j                  t        j
                  j                  j                  j                  |d               }	| j                  ||	|d      j                         }
|
j!                         S )Nrx  Frl  )rf  rd  _prepare_filter_namesr.   r	   all_synonymsrK  synonym_namerV  table_ownerdb_linkr=  rX  in_rT  mappingsall)rD   r  r   rx  rQ  rF   rX  has_filter_namesrS  rP  results              rG   _get_synonymszOracleDialect._get_synonymsq  s1    ,,.d..
 $(#=#=l#K &##%%22##%%00##%%11##%%--	

 %
''))//58
9 	 KK''))66::>*E
 ))vE * 

(* 	 zz|rJ   c                   t        t        j                  j                  j                        j                  t        j                        j                  t        j                  j                  j                  |k(        }|t        j                  u rD|j                  t        j                  j                  j                  j                  d            }ng }t        j                  |v r|j                  d       t        j                  |v r#t        j                  |vr|j                  d       t        j                  |v rp|j                  d       |r]t        j                  |vrK|j                  t        j                  j                  j                  j!                  t#        d                  }|j                  t        j                  j                  j                  j                  |            }|t$        j&                  u r7|j                  t        j                  j                  j(                  dk(        }nH|t$        j*                  u r6|j                  t        j                  j                  j(                  dk(        }|rK|j                  t        j                  j                  j                  j                  t#        d                  }|S )	N)TABLEVIEWr  zMATERIALIZED VIEWr  	mat_viewsr   Yrx  )r.   r	   all_objectsrK  object_nameselect_fromr=  rX  r"   ANYobject_typer  r  r   MATERIALIZED_VIEWr  not_inr(   r#   DEFAULT	temporary	TEMPORARY)rD   rX  scoper  r  has_mat_viewsrP  r  s           rG   _all_objects_queryz OracleDialect._all_objects_query  s   
 :))++778[//0U:))++11U:; 	 :>>! KK&&((44889JKE K$&""6*,,4$$D0 ""#674'""7+ Z%A%A%M "KK"..00<<CC%k2E
 KK&&((4488EE
 K'''KK
 6 6 8 8 B Bc IJEk+++KK
 6 6 8 8 B Bc IJEKK&&((4488n-E
 rJ   r  r  c                   | j                  |xs | j                        }| j                  |      \  }	}
d}t        j                  |v r2t        j
                  |vr  | j                  |||fddi|}|r||
d<   d}| j                  ||||	|      }| j                  |||d|
      j                         }|j                         S )NF
_normalizer  Trb  )rf  rd  rz  r"   r  r  get_materialized_view_namesr  rT  scalarsr  )rD   r  r   r  r  rx  rQ  rF   rX  r  rS  r  r  rP  r  s                  rG   _get_all_objectszOracleDialect._get_all_objects  s     ,,.d..
 $(#=#=l#K &$,,D8 988FF7<@BI &/{# $''5$ 0-
 ))vE& * 

') 	 zz|rJ   c                .     t                fd       }|S )Nc                0     | j                   g|i |S rA   )_handle_synonyms)rD   r   r   r   s      rG   wrapperz9OracleDialect._handle_synonyms_decorator.<locals>.wrapper  s     (4((=d=f==rJ   r   )r   r  s   ` rG   _handle_synonyms_decoratorz(OracleDialect._handle_synonyms_decorator  s     	r	> 
	> rJ   c           
        |j                  dd      s || |g|i |S |j                         }|j                  dd       }| j                  |||j                  dd       |j                  dd       |j                  dd             }t	        t
              }|D ]+  }	|	d   |	d	   f}
| j                  |	d
         }|	d   ||
   |<   - |s || |g|i |S i }|j                         D ]d  \  \  }}}i ||| j                  |      |j                         d} || |g|i |}|D ]#  \  \  }}}| j                  ||         }||||f<   % f |j                         S )Nr	  Fr   rx  rQ  
info_cache)r   rx  rQ  r  r~  r}  rV  r|  )r   rQ  rx  )	r   r  r  r  r   dictrr  r   keys)rD   r   r  r   r   original_kwr   r  dblinks_ownersrowr  tndatarQ  r}  mappingcall_kwcall_resultr  r  r|  s                        rG   r  zOracleDialect._handle_synonyms  s   zz3U;dJ8888kkmHd+##ND9::h-zz,5 $ 
 %T*Ci.#m"44C$$S%67B&).&9N3# 
 dJ====.<.B.B.D*!V[7%--f5 '	G T:@@@K"-B#2272;?/4fl+, #. /E zz|rJ   c                L   t        t        j                  j                  j                        j                  t        j                  j                  j                        }| j                  |||d      j                         }|D cg c]  }| j                  |       c}S c c}w rk  )	r.   r	   	all_usersrK  usernameorder_byrT  r  rr  )rD   r  rQ  rF   rP  r  r  s          rG   get_schema_nameszOracleDialect.get_schema_names  s     z++--667@@  ""++
 ))vE * 

') 	 5;;FS##C(F;;;s   B!c                	   || j                   }| j                  |      }|j                  dd      rt        t        j
                  j                  j                  t        j
                  j                  j                  t        j
                  j                  j                  t        j
                  j                  j                  t        j
                  j                  j                        j                  t        t        j                  j                  j                  j                  d      t        j                  j                  j                  t        j
                  j                  j                  t        j
                  j                  j                  t        j
                  j                  j                        j!                  t        j
                        j#                  t        j                  t%        t        j
                  j                  j                  t        j                  j                  j                  k(  t        j
                  j                  j                  t'        j(                  t        j                  j                  j*                  t        j                  j                  j                        k(                    j-                  d      }nt        j
                  }t        |j                  j                        }| j.                  rR|j1                  t'        j(                  |j                  j                  d      j3                  | j.                              }|j1                  |j                  j                  |k(  |j                  j                  j5                  t7                     |j                  j                  j5                  t7                           }t        t        j8                  j                  j:                  j                  d            j1                  t        j8                  j                  j                  |k(        }| j<                  r|j?                  |      n|jA                  |      }| jC                  |||d      jE                         }	|	D 
cg c]  }
| jG                  |
       c}
S c c}
w )ra  r	  FrV  available_tablesno tablespacerl  )$rd  rf  r   r.   r	   rY  rK  rV  rX  iot_namedurationtablespace_namerZ  r{  r|  rT  r  r   r&   r+   coalescer}  r]  r  r=  r  is_r,   
all_mviews
mview_namer7  
except_allexcept_rT  r  rr  )rD   r  r   rQ  rF   
den_schemar^  rP  	mat_queryr  r  s              rG   get_table_nameszOracleDialect.get_table_names(  st    >--F11&9
66+U3))++66))++11))++44))++44))++;; "//11>>DD( #//1177"--//88"--//88"--//?? ![!6!67T"//&1133>>)6688CCD&113399#}} * 7 7 9 9 E E * 7 7 9 9 ? ? 0 ,-A F  **Fvxx**+##KKHH,,o&112E
 HHNNj(HH!!$&)HH!!$&)
 !!##..44\B

%
%%''--;
< 	 (( Y'y) 	 ))vE * 

') 	 5;;FS##C(F;;;s   ,Sc                L   | j                  | j                        }t        t        j                  j
                  j                        }| j                  r`|j                  t        j                  t        j                  j
                  j                  d      j                  | j                              }|j                  t        j                  j
                  j                  |k(  t        j                  j
                  j                  j                  t!                     t        j                  j
                  j"                  j%                  t!                           }| j'                  |||d      j)                         }|D cg c]  }| j+                  |       c}S c c}w )ra  r  Frl  )rf  rd  r.   r	   rY  rK  rV  r  r=  r+   r  r  r  rX  r  r  r,   r  is_notrT  r  rr  )rD   r  rQ  rF   r   rP  r  r  s           rG   get_temp_table_namesz"OracleDialect.get_temp_table_namess  s=    --d.F.FGz,,..99:##KK))++;;_&112E
 !!##))V3!!##,,008!!##,,33DF;
 ))vE * 

') 	 5;;FS##C(F;;;s   F!c                   |s| j                   }t        t        j                  j                  j
                        j                  t        j                  j                  j                  | j                  |      k(        }| j                  |||d      j                         }|r|D cg c]  }| j                  |       c}S |j                         S c c}w rk  )rd  r.   r	   r  rK  r  r=  rX  rf  rT  r  rr  r  )	rD   r  r   rQ  r  rF   rP  r  r  s	            rG   r  z)OracleDialect.get_materialized_view_names  s    
 --Fz,,..99:@@!!##))++F34
 ))vE * 

') 	 8>?D'',??::< @s   (Cc                   |s| j                   }t        t        j                  j                  j
                        j                  t        j                  j                  j                  | j                  |      k(        }| j                  |||d      j                         }|D cg c]  }| j                  |       c}S c c}w rk  )rd  r.   r	   r[  rK  r\  r=  rX  rf  rT  r  rr  rD   r  r   rQ  rF   rP  r  r  s           rG   get_view_nameszOracleDialect.get_view_names  s     --Fz++--778>>  ""((++F34
 ))vE * 

') 	 5;;FS##C(F;;;   &Cc                   |s| j                   }t        t        j                  j                  j
                        j                  t        j                  j                  j                  | j                  |      k(        }| j                  |||d      j                         }|D cg c]  }| j                  |       c}S c c}w rk  )rd  r.   r	   rm  rK  rn  r=  ro  rf  rT  r  rr  r  s           rG   get_sequence_namesz OracleDialect.get_sequence_names  s     --Fz//11??@FF$$&&55++F34

 ))vE * 

') 	 5;;FS##C(F;;;r  c                    | j                  t        |            }	 t        |      ||f   S # t        $ r% t	        j
                  |r| d|       d |      d w xY w)Nr!  )rr  r  r  KeyErrorr   NoSuchTableError)rD   r  r   r   s       rG   _value_or_raisezOracleDialect._value_or_raise  ss    ##CJ/	:vuo.. 	&&'-6(!E7#38	s	   , .Ac                `    |r$|D cg c]  }| j                  |       }}dd|ifS di fS c c}w )NTrx  F)re  )rD   rx  rt   r   s       rG   rz  z#OracleDialect._prepare_filter_names  sD    :FG,$$''-,BG."---"9 Hs   +c                     | j                   |f||gt        j                  t        j                  d|}| j	                  |||      S Supported kw arguments are: ``dblink`` to reflect via a db link;
        ``oracle_resolve_synonyms`` to resolve names to synonyms
        )r   rx  r  r  )get_multi_table_optionsr#   r  r"   r  rD   r  rV  r   rF   r  s         rG   get_table_optionszOracleDialect.get_table_options  U    
 ,t++
$//
 
 ##D*f==rJ   c                &   t        t        j                  j                  j                  | j
                  r$t        j                  j                  j                  n"t        j                         j                  d      | j                  r$t        j                  j                  j                  n"t        j                         j                  d      t        j                  j                  j                        j                  t        j                  j                  j                  |k(        }|rK|j                  t        j                  j                  j                  j                  t!        d                  }|t"        j$                  u rK|j                  t        j                  j                  j&                  j)                  t                           }n\|t"        j*                  u rJ|j                  t        j                  j                  j&                  j-                  t                           }|rqt.        j0                  |v r_t.        j2                  |vrM|j                  t        j                  j                  j                  j5                  t!        d                  }|S t.        j0                  |vr]t.        j2                  |v rK|j                  t        j                  j                  j                  j                  t!        d                  }|S )Ncompressioncompress_forrx  r  )r.   r	   rY  rK  rV  r-  r  r   r,   rT  r0  r  r  r=  rX  r  r(   r#   r  r  r  r  r  r"   r  r  r  )rD   rX  r  r  r  r  rP  s          rG   _table_options_queryz"OracleDialect._table_options_query  s8    !!##.. 33 %%''33XXZ%%m4 44 %%''44XXZ%%n5!!##33
 %
%%''--6
7 	 KK%%''2266n-E
 K'''KK
 5 5 7 7 @ @ D DTV LMEk+++KK%%''0077?E
   D(,,D8 KK%%''2299k*E  D(,,4KK%%''2266y7MNE rJ   )rQ  c               n   | j                  |xs | j                        }| j                  |      \  }	}
d}t        j                  |v r3t        j
                  |vr! | j                  |||fddi|}|rH||
d<   d}n@t        j                  |vr.t        j
                  |v r | j                  |||fddi|}||
d<   i }t        j                  }t        j                  |v st        j
                  |v re| j                  ||||	|      }| j                  |||d|
      }|D ]5  \  }}}} |       }|dk(  r||d<   |r||d<   |||| j                  |      f<   7 t        j                  |v r?t        j                  |v r- | j                  |||fi |D ]  }|r||v s
 |       |||f<    |j!                         S )	r  Fr  r  Trb  ENABLEDoracle_compressoracle_tablespace)rf  rd  rz  r"   r  r  r  r%   table_optionsr  rT  rr  r  r#   r  r  r   )rD   r  r   rx  r  r  rQ  rF   rX  r  rS  r  r  r  r!   rP  r  r   r  r  r  r  views                          rG   r  z%OracleDialect.get_multi_table_options	  s    ,,.d..
 $(#=#=l#K & $,,D8 988FF7<@BI &/{# $D(,,4888FF7<@BI #,F;$22t#z'C'Ct'K--ud$4mE --E6f . F AG<{L*y)+.:D*+0:D,-@D!4!4U!;<= AG ??d"{':':e'C+++JM"M#t|';.5iGVTN+ N }}rJ   c                     | j                   |f||gt        j                  t        j                  d|}| j	                  |||      S r  )get_multi_columnsr#   r  r"   r  r  s         rG   get_columnszOracleDialect.get_columnsV	  sU     &t%%
$//
 
 ##D*f==rJ   c              #     K   d}t        |      }|rK|d| }	g |d| | j                  ||||d|	i      }
|r|
j                         E d {    n
|
E d {    |rJy y 7 7 w)Ni  r   r  rb  )listrT  r  )rD   r  rP  rQ  rR  r  r  
each_batchbatchesbatchr  s              rG   _run_batcheszOracleDialect._run_batchesf	  s      
{#Aj)E$&GAj!--)%u- . F !??,,,!!!  -!s*   AA"	A

A"A A"A" A"c                   t         j                  }t         j                  }t         j                  }| j                  dk\  r|j
                  j                  t        j                  |j
                  j                  j                  d       t        j                         f|j
                  j                  dz   |j
                  j                  z         j                  d      f}d}nHt        j                         j                  d      t        j                         j                  d      f}d}t        |j
                  j                  |j
                  j                   |j
                  j"                  |j
                  j$                  |j
                  j&                  |j
                  j(                  |j
                  j*                  |j
                  j,                  |j
                  j.                  |j
                  j0                  g
| j3                  |      j5                  |t7        |j
                  j                  |j
                  j                  k(  |j
                  j                   |j
                  j                   k(  |j
                  j8                  |j
                  j8                  k(              }|r|j5                  |t7        |j
                  j                  |j
                  j                  k(  |j
                  j                   |j
                  j                   k(  |j
                  j8                  |j
                  j8                  k(              }|j;                  |j
                  j                  j=                  t?        d            |j
                  j@                  d	k(  |j
                  j8                  |k(        jC                  |j
                  j                  |j
                  jD                        }|S )
Nr  ,)else_r  Tdefault_on_nullFr  NO)#r	   all_tab_colsall_col_commentsall_tab_identity_colsr  rK  r  r   caserV  r  r,   generation_typer  rT  r.   column_name	data_typechar_lengthdata_precision
data_scalenullabledata_defaultcommentsvirtual_columnr  	outerjoinr&   rX  r=  r  r(   hidden_columnr  	column_id)rD   rX  all_colsall_commentsall_idsadd_colsjoin_identity_colsrP  s           rG   _column_queryzOracleDialect._column_query{	  s   **!2222##u,

**YY))--d3SXXZ@!))33ii001
 %*+H "& 
  !23
  !34H "' 

%%

&&

$$

&&

))

%%

##

''''

))  k(# YJJ))\^^-F-FFJJ**lnn.H.HHJJ$$(<(<<# 	4 OOJJ))WYY-A-AAJJ**gii.C.CCJJ$$		7E JJ!!%%i&>?JJ$$,JJ%
 (8::(((***>*>
?	 	
 rJ   c          	        | j                  |xs | j                        }| j                  |      }	|rC|t        j                  u r1|t
        j                  u r|D 
cg c]  }
| j                  |
       }}
n | j                  ||||||fi |}t        t              }| j                  ||	|dd|      }d }t        j                  d      }|D ]  }| j                  |d         }|d   }| j                  |      }|d   } ||d         }|d	k(  r* ||d
         }||dk(  rt               }nt        ||      }n|dk(  r-|dk(  rt!               }n|dk(  rt#               }nt%        |      }nz|dv r- ||d         } | j&                  j)                  |      |      }nId|v rt+        d      }n8d|v rt+        d      }n't        j,                  |d|      }	 | j&                  |   }|d   }|d   dk(  rt9        |      }d}nd}|d   }|| j;                  ||d          }d}nd}|||d!   d"k(  ||d#   d$}|j=                         |k(  rd|d%<   |||d&<   |||d'<   |||f   j?                  |        |jA                         S c c}
w # t.        $ r/ t1        j2                  d|d|d       t4        j6                  }Y w xY w)(r  TrR  r  r  c                \    t        | t              r| j                         rt        |       S | S rA   )r   float
is_integerru   )r  s    rG   	maybe_intz2OracleDialect.get_multi_columns.<locals>.maybe_int	  s&    %'E,<,<,>5z!rJ   z\(\d+\)rV  r  r  r  r   r  Nr   r   ~   ?   )rr   )r   r   r3   r7   r  zWITH TIME ZONE)rc   zWITH LOCAL TIME ZONE)ra   rX   zDid not recognize type 'z' of column ''r  r  YES)r  r  r  r  r  r  )rt   r  r  r!   commentr  computedr  )!rf  rd  r  r"   r  r#   re  r  r   r  r  recompilerr  r6   r   r5   r9   r   ischema_namesr   r   subr  r    r  r/   NULLTYPEr  _parse_identity_optionsr   r   r   )rD   r  r   rx  r  r  rQ  rF   rX  rP  rz   r  r+  r  r  remove_sizerow_dictrV  orig_colnamecolnamecoltyperq   rs   r  r!   r  r  r  cdicts                                rG   r  zOracleDialect.get_multi_columns	  sN    ,,.d..
 ""5) 
&(=IJ\4003\KJ/$//FE4vIKK d# ""# # 
	 jj,H,,Xl-CDJ#M2L)),7G{+G!(+;"<=I("!(<"89$!%iG$Y6GG## /0G"_ #fG $Y?GFF'(?@9$,,009+F!W,#T2'72#48&&b':0"009G ~.G()U20'(:;+77$h/@&A   $Z0C7"#J/E !!#|3!%g#$,j!#$,j!VZ()007W f }}[ K@   0II"G- '//G0s   JJ5KKc                   |j                  d      D cg c]  }|j                          }}|d   dk(  |dk(  d}|dd  D ]  }|j                  d      \  }}|j                         }d|v rt        |      |d	<   :d
|v rt        |      |d<   Md|v rt        |      |d<   `d|v rt        |      |d<   sd|v r	|dk(  |d<   d|v rt        |      |d<   d|v s|dk(  |d<    |S c c}w )Nr  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_FLAGr  )r&  r  ru   )	rD   r  r  ppartsr  partoptionr  s	            rG   r  z%OracleDialect._parse_identity_optionsL
  s    %5$:$:3$?@$?q$?@Ah(*&%/

 !"ID JJsOMFEKKMEv%$'J!6)(+E
%&'*5z$&'*5z$'$)SL!'$'J!'$)SL!# $ 1 As   C$c                     | j                   |f||gt        j                  t        j                  d|}| j	                  |||      S r  )get_multi_table_commentr#   r  r"   r  r  s         rG   get_table_commentzOracleDialect.get_table_commentl
  r  rJ   c           	        g }t         j                  |v st         j                  |v rXt        t        j
                  j                  j                  t        j
                  j                  j                        j                  t        j
                  j                  j                  |k(  t        j
                  j                  j                  j                  d            }t         j                  |vr7|j                  t        j
                  j                  j                  dk(        }nHt         j                  |vr6|j                  t        j
                  j                  j                  dk(        }|j                  |       t         j                  |v rt        t        j                  j                  j                   j#                  d      t        j                  j                  j                        j                  t        j                  j                  j                  |k(  t        j                  j                  j                   j                  d            }|j                  |       t%        |      dk(  r|d   }nUt'        j(                  | j+                  d      }	t        |	j                  j                  |	j                  j                        }|j,                  j                  }
|t.        j0                  t.        j2                  fv r|t.        j2                  u rdnd	}|j5                         j7                  t        j8                  t;        t        j8                  j                  j                  |k(  t        j8                  j                  j<                  |
k(  t        j8                  j                  j>                  |k(              }|r)|j                  |
jA                  tC        d
                  }|S )NzBIN$%r  r  rV  r   r   rW  r  r   rx  )"r"   r  r  r.   r	   all_tab_commentsrK  rV  r  r=  rX  not_like
table_typer   r  all_mview_commentsr  rT  r   r   rZ  r]  rG  r#   r  r  distinctr   r  r&   r  r  r  r(   )rD   rX  r  r  r  queriestbl_viewmat_viewrP  r  name_coltemps               rG   _comment_queryzOracleDialect._comment_query{
  s    t#z$'>++--88++--66 e++--33u<++--88AA'J  d*#>>//11<<G !!-#>>//11<<F NN8$''4/--//::@@N--//88 e--//55>--//::CCGL  NN8$w<1AJEMM7+445GHE577--uww/?/?@E))44[((+*?*?@@;#8#883cD NN$))&&**,,22e;**,,88HD**,,66$>E KKY~-F GHErJ   c                    j                  xs  j                        } j                  |      \  }	}
 j                  ||||	      } j	                  |||d|
      }t
        j                  d fd|D        S )r  Frb  zsnapshot table for snapshot c              3     K   | ]8  \  }}j                  |      f||j                        sd|in        f : y w)Nr   )rr  rN  )r   r   r  r!   ignore_mat_viewr   rD   s      rG   r   z8OracleDialect.get_multi_table_comment.<locals>.<genexpr>
  s]      
 #)w ,,U34 *#..? W% ! #)s   >A)rf  rd  rz  r=  rT  r%   table_comment)rD   r  r   rx  r  r  rQ  rF   rX  r  rS  rP  r  r!   r@  s   ` `          @@rG   r0  z%OracleDialect.get_multi_table_comment
  s     ,,.d..
 $(#=#=l#K &##E5$8HI))vE& * 
 %22 9
 #)
 	
rJ   c                     | j                   |f||gt        j                  t        j                  d|}| j	                  |||      S r  )get_multi_indexesr#   r  r"   r  r  s         rG   get_indexeszOracleDialect.get_indexes
  sU    
 &t%%
$//
 
 ##D*f==rJ   c                   t        t        j                  j                  j                  t        j                  j                  j
                  t        j                  j                  j                  t        j                  j                  j                  t        j                  j                  j                  t        j                  j                  j                  t        j                  j                  j                  t        j                  j                  j                  t        j                  j                  j                  	      j                  t        j                        j!                  t        j                  t#        j$                  t        j                  j                  j
                  t        j                  j                  j
                  k(  t        j                  j                  j&                  t        j                  j                  j(                  k(              j+                  t        j                  t#        j$                  t        j                  j                  j
                  t        j                  j                  j
                  k(  t        j                  j                  j&                  t        j                  j                  j&                  k(  t        j                  j                  j,                  t        j                  j                  j,                  k(              j/                  t        j                  j                  j0                  |k(  t        j                  j                  j                  j3                  t5        d                  j7                  t        j                  j                  j
                  t        j                  j                  j,                        S )Nr  )r.   r	   all_ind_columnsrK  rV  
index_namer  all_indexes
index_type
uniquenessr  prefix_lengthdescendall_ind_expressionsr  r  r   r   r&   index_ownerrX  r  column_positionr=  r}  r  r(   r  )rD   rX  s     rG   _index_queryzOracleDialect._index_query
  s    **,,77**,,77**,,88&&((33&&((33&&((44&&((66**,,44..00BB
 [334T&&..00;;!--//::;..00<<!--//556 Y ..2244??!1133>>?2244@@!1133??@2244DD!1133CCD" U&&((44=&&((3377m, X**,,77**,,<<[1	
rJ   r  c                .   | j                  |xs | j                        }| j                  |      } | j                  ||||fi |D ch c]  }|d   dk(  r|d    }	}| j	                  |||dd|      }
|
D cg c]  }|d   |	vr| c}S c c}w c c}w )Nconstraint_typePconstraint_nameTr  rG  )rf  rd  rP  _get_all_constraint_rowsr  )rD   r  r   rQ  r  rF   rX  rP  r  pksr  s              rG   _get_indexes_rowszOracleDialect._get_indexes_rows   s     ,,.d..
 !!%( :D99FFK;=
 )*c1	 &' 	 
 ""# # 
 #
"%S0 "
 	
%
$
s   	B:Bc                     j                   |||||fi |}ddd}	ddd}
ddh}t        t                j                  |||fi |D ]~  } j	                  |d         } j	                  |d         }|f   }||vrN|g i |	j                  |d	   d      d
x||<   }|d   }|d   |v rd|d<   |
j                  |d   d      r|d   |d<   n||   }|d   }||d   j                  d       d|v r|d   j                  |       n|d   dd |d<   |d   j                  |       |d   j                         dk7  s|d   j                         dk(  sJ |j                  di       }d||<   %|d   j                         dk(  sJ  j	                  |d         }|d   j                  |       d|v sk|d   j                  |        t        j                  fd fd|D        D        S )r  FT)	NONUNIQUEUNIQUE)DISABLEDr  BITMAPzFUNCTION-BASED BITMAPrG  rV  rJ  )rt   column_namesr  r  r  rI  oracle_bitmapr  rK  r  r  Nr]  r  rL  ascdesccolumn_sorting)ra  r  c              3  p   K   | ]-  }||v rt        |   j                               n        f / y wrA   r  values)r   r  r!   indexess     rG   r   z2OracleDialect.get_multi_indexes.<locals>.<genexpr>  s>      
 $ws|**,-WYO   36c              3  D   K   | ]  }j                  |      f  y wrA   rr  r   obj_namer   rD   s     rG   r   z2OracleDialect.get_multi_indexes.<locals>.<genexpr>  )       +H ,,X67 +rj  )r  r   r  rW  rr  r   r   r   
setdefaultr%   rf  )rD   r  r   rx  r  r  rQ  rF   r  rJ  enabled	is_bitmapr  rG  rV  table_indexes
index_dictdor   cscnr!   rf  s   ` `                  @@rG   rC  zOracleDialect.get_multi_indexesD  s    ,d++t\6
EG
 $)D9
$667	d#...
79
H ,,Xl-CDJ,,Xl-CDJ#VZ$89M.&$&')(nnXl-CUK	: j)J   12L)Y6*.B';;x6>,4_,EB() +:6
/0D>*11$7 J.}-44T:0:>0J3B0OJ}-}-44T:I&,,.%7#I.446&@@@#../?DB(BtH	*002e;;;((-)@A>*11"5 J.}-44R8S
V %,,
 +
 	
rJ   c                     | j                   |f||gt        j                  t        j                  d|}| j	                  |||      S r  )get_multi_pk_constraintr#   r  r"   r  r  s         rG   get_pk_constraintzOracleDialect.get_pk_constraint  r  rJ   c                   t         j                  j                  d      }t         j                  j                  d      }t        t         j                  j
                  j                  t         j                  j
                  j                  t         j                  j
                  j                  |j
                  j                  j                  d      |j
                  j                  j                  d      |j
                  j                  j                  d      |j
                  j                  j                  d      t         j                  j
                  j                  t         j                  j
                  j                  	      j                  t         j                        j                  |t!        |j
                  j                  t         j                  j
                  j                  k(  t         j                  j
                  j                  |j
                  j                  k(              j#                  |t!        t         j                  j
                  j$                  |j
                  j                  k(  t         j                  j
                  j&                  |j
                  j                  k(  t)        |j
                  j*                  j-                  t/        j0                               |j
                  j*                  |j
                  j*                  k(                    j3                  t         j                  j
                  j                  |k(  t         j                  j
                  j                  j5                  t7        d            t         j                  j
                  j                  j5                  d            j9                  t         j                  j
                  j                  |j
                  j*                        S )	Nlocalremotelocal_columnremote_tableremote_columnremote_ownerr  )RrS  UC)r	   all_cons_columnsrJ  r.   all_constraintsrK  rV  rR  rT  r  rT  rX  search_conditiondelete_ruler  r   r&   r  r_ownerr_constraint_namer-   positionr  r   r,   r=  r  r(   r  )rD   rX  ry  rz  s       rG   _constraint_queryzOracleDialect._constraint_query  s   ++11':,,228<**,,77**,,<<**,,<<##)).9##)).9$$**?;$$^4**,,==**,,88
 [334TGGMMZ%?%?%A%A%G%GG..00@@ww../ Y..0088FHHNNJ..00BBxx//0))--chhj9((FHH,=,==	 U**,,22e;**,,77;;m, **,,<<@@( X**,,<<egg>N>NU-	
rJ   c           
         | j                  |xs | j                        }| j                  |      }t        | j	                  |||dd|            }|S )NFTr  )rf  rd  r  r  r  )	rD   r  r   rQ  r  rF   rX  rP  re  s	            rG   rU  z&OracleDialect._get_all_constraint_rows  sl     ,,.d..
 &&u- "'  	
 rJ   c                     j                   |||||fi |}t        t              t        j                    j
                  |||fi |D ]p  }	|	d   dk7  r j                  |	d         }
 j                  |	d         } j                  |	d         }|
f   }|s||d<   |g|d<   ]|d   j                  |       r fd fd	|D        D        S )
r  rR  rS  rV  rT  r{  rt   constrained_columnsc              3  B   K   | ]  }||v r|   n        f  y wrA   r]   )r   r  r!   primary_keyss     rG   r   z8OracleDialect.get_multi_pk_constraint.<locals>.<genexpr>  s2      
 sl':,s#	J   c              3  D   K   | ]  }j                  |      f  y wrA   ri  rj  s     rG   r   z8OracleDialect.get_multi_pk_constraint.<locals>.<genexpr>  rl  rj  )r  r   r  r%   pk_constraintrU  rr  r   )rD   r  r  r   rx  r  rQ  rF   r  r  rV  rT  r  table_pkr!   r  s   `  `          @@rG   rv  z%OracleDialect.get_multi_pk_constraint  s    ,d++t\6
EG
 #4($22555
79
H )*c1,,Xl-CDJ"11(;L2MNO--h~.FGK#VZ$89H#2 3>-././66{C
 
 +
 	
rJ   c                     | j                   |f||gt        j                  t        j                  d|}| j	                  |||      S r  )get_multi_foreign_keysr#   r  r"   r  r  s         rG   get_foreign_keyszOracleDialect.get_foreign_keys  sU     +t**
$//
 
 ##D*f==rJ   c               t   "#   j                   |||||fi |}|j                  dd      }	 j                  xs  j                        }
t	               }t        t              #  j                  |||fi |D ]A  }|d   dk7  r j                  |d         } j                  |d         }#|f   }|J  j                  |d         } j                  |d	         } j                  |d
         }|d   } j                  |      }||j                  |       |6|r|j                  d      sd| }t        j                  d|xs d d       ||vr4|g d|g i dx||<   }|	r||d<   ||
k7  r||d<   |d   }|dk7  r||d   d<   n||   }|d   j                  |       |d   j                  |       D |	r|rt        t        j                   j"                  j$                  t        j                   j"                  j&                  t        j                   j"                  j(                  t        j                   j"                  j*                        j-                  t        j                   j"                  j$                  j/                  |            } j1                  |||d      j3                         }i }|D ]9  } j                  |d         } j                  |d         }|d   |d   f|||f<   ; d}#j5                         D ]~  }|j5                         D ]i  }|j7                  d      |d   f}|j                  ||      \  }}|s1 j                  |      } | |d<   ||
k7  r j                  |      }!|!|d<   ed|d<   k  t8        j:                  ""#fd fd |D        D        S )!r  r	  FrR  r  rV  rT  Nr{  r|  r}  r~  rI  z6Got 'None' querying 'table_name' from all_cons_columnsrX   z1 - does the user have proper rights to the table?)rt   r  referred_schemareferred_tablereferred_columnsr  _ref_schemar  r  z	NO ACTIONr  r  r  r  rl  rX  r}  r|  NNr  c              3  p   K   | ]-  }||v rt        |   j                               n        f / y wrA   rd  )r   r  r!   fkeyss     rG   r   z7OracleDialect.get_multi_foreign_keys.<locals>.<genexpr>  s>      
 se|$uSz((*+Krg  c              3  D   K   | ]  }j                  |      f  y wrA   ri  rj  s     rG   r   z7OracleDialect.get_multi_foreign_keys.<locals>.<genexpr>  rl  rj  )r  r   rf  rd  setr   r  rU  rr  r   rN  r    r  r   r.   r	   r{  rK  rX  rV  r}  r|  r=  r  rT  r  re  r  r%   foreign_keys)$rD   r  r  r   rx  r  rQ  rF   r  r
  rX  all_remote_ownersr  rV  rT  
table_fkeyr{  r|  r}  remote_owner_origr~  fkeyr  rP  r  remote_owners_lutr  synonym_owneremptytable_fkeysr  syn_namesnror!   r  s$   `  `                              @@rG   r  z$OracleDialect.get_multi_foreign_keys1  sN    ,d++t\6
EG
 66";UC,,.d..
  ED!555
79
H )*c1,,Xl-CDJ"11(;L2MNO
34J".....x/GHL..x/GHL //0IJM ( 8../@AL ,!%%&78#&"3"3C"8 \F		''-|n 522
 j0++-'+&2(*!6 
?+d $*6D'%):e)C.:D*+&}5+-2=DOJ/ "/2&'..|<#$++M:q
t  1''))//''))44''))55''))66	
 eJ++--33778IJK  --E6 . hj  !# $ 3 3CL A!00\1BC
 &'B!=*"=>	  !E$||~"-"4"4"6J"}5"#34C .?-B-B3-N*L(!00:79
#34!-1F!%!4!4\!BB<>J'89<@J'89 #7  . %11
 +
 	
rJ   c                     | j                   |f||gt        j                  t        j                  d|}| j	                  |||      S r  )get_multi_unique_constraintsr#   r  r"   r  r  s         rG   get_unique_constraintsz$OracleDialect.get_unique_constraints  sU     1t00
$//
 
 ##D*f==rJ   c               2      j                   |||||fi |}t        t                j                  |||fi |D 	ch c]  }	|	d   	 }
}	  j                  |||fi |D ]  }	|	d   dk7  r j                  |	d         }|	d   } j                  |      } j                  |	d         }|f   }|J ||vr|g ||
v r|nddx||<   }n||   }|d	   j                  |        t        j                  fd
 fd|D        D        S c c}	w )r  rG  rR  r  rV  rT  r{  N)rt   r]  duplicates_indexr]  c              3  p   K   | ]-  }||v rt        |   j                               n        f / y wrA   rd  )r   r  r!   unique_conss     rG   r   z=OracleDialect.get_multi_unique_constraints.<locals>.<genexpr>  sI      
  k) S)0023 rg  c              3  D   K   | ]  }j                  |      f  y wrA   ri  rj  s     rG   r   z=OracleDialect.get_multi_unique_constraints.<locals>.<genexpr>  rl  rj  )	r  r   r  rW  rU  rr  r   r%   unique_constraints)rD   r  r  r   rx  r  rQ  rF   r  r  index_namesrV  constraint_name_origrT  r  table_ucucr!   r  s   `  `             @@rG   r  z*OracleDialect.get_multi_unique_constraints  s    ,d++t\6
EG
 "$' 3D22FFK;=
 \" 	 
 655
79
H )*c1,,Xl-CDJ#+,=#> "112FGO--h~.FGK"FJ#78H"...h.+$& 0;> (!2 )B o.~%%k25
8 %77
 +
 	
K
s   Dc                   |j                  dd      rK| j                  |||g|      }|r3t        |      dk(  sJ |d   }| j                  |d         }|d   }|d   }| j	                  |      }| j                  |xs | j                        }	t        t        j                  j                  j                        j                  t        j                  j                  j                  |k(  t        j                  j                  j                  |	k(        j                  t        t        j                   j                  j"                        j                  t        j                   j                  j$                  |k(  t        j                   j                  j                  |	k(              }
| j'                  ||
|d	      j)                         }|"t+        j,                  |r| d
|       |      |S )r  r	  F)rx  rQ  r   r   r~  r}  rV  rl  r!  )r   r  r   rr  re  rf  rd  r.   r	   r[  rK  r   r=  r\  rX  rZ  r  rP  r  rT  r#  r   r  )rD   r  r\  r   rQ  rF   synonymsr  rt   rX  rP  rps               rG   get_view_definitionz!OracleDialect.get_view_definition  s    66+U3))F)V * H 8})))#A;,,Xi-@A!-0$\2	$$Y/,,.d..
 :''))../U$$&&00D8$$&&,,5 Yz,,..445;;))++66$>))++11U: 	 %%vE & 

&( 	 :&&+16(!I;' 7@  IrJ   c           	          | j                   |f||gt        j                  |t        j                  d|}| j	                  |||      S )r  )r   rx  r  include_allr  )get_multi_check_constraintsr#   r  r"   r  )rD   r  rV  r   r  rF   r  s          rG   get_check_constraintsz#OracleDialect.get_check_constraintsD  sX     0t//
$//#
 
 ##D*f==rJ   )rQ  r  c                     j                   |||||fi |}	t        j                  d      }
t        t                j
                  |||	fi |D ]j  }|d   dk7  r j                  |d         } j                  |d         }|d   }|f   }|C|s|
j                  |      rW|j                  ||d       l t        j                  fd fd	|	D        D        S )
r  z..+?. IS NOT NULL$rR  r  rV  rT  r  )rt   r  c              3  B   K   | ]  }||v r|   n        f  y wrA   r]   )r   r  check_constraintsr!   s     rG   r   z<OracleDialect.get_multi_check_constraints.<locals>.<genexpr>  s<      
  // &c* r  c              3  D   K   | ]  }j                  |      f  y wrA   ri  rj  s     rG   r   z<OracleDialect.get_multi_check_constraints.<locals>.<genexpr>  rl  rj  )r  r  r  r   r  rU  rr  r  r   r%   r  )rD   r  r   rx  rQ  r  r  r  rF   r  not_nullr  rV  rT  r  table_checksr  r!   s   ` `             @@rG   r  z)OracleDialect.get_multi_check_constraintsV  s     ,d++t\6
EG
 ::34'-555
79
H )*c1,,Xl-CDJ"11(;L2MNO'(:;,fj-ABL*8>>2B#C##,9IJ
" %66
 +
 	
rJ   c                    t        t        j                  j                  j                        }| j                  |||d      j                         }|D cg c]  }| j                  |       c}S c c}w )NFrl  )r.   r	   all_db_linksrK  r~  rT  r  rr  )rD   r  rQ  rP  linkslinks         rG   _list_dblinkszOracleDialect._list_dblinks  sk    z..00889((vE ) 

') 	 7<<ed##D)e<<<s   A0)TFNF)SYSTEMSYSAUXTrA   r  )NNT)NF)srx   r   r   rt   supports_statement_cachesupports_altermax_identifier_lengthr3  insert_returningupdate_returningdelete_returningdiv_is_floordivsupports_simple_order_by_labelcte_follows_insertreturns_native_bytes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_compilerr?   type_compiler_clsr  r
  r  execution_ctx_clsreflection_optionsrS   r  TableIndexconstruct_argumentsr    deprecated_paramsr   r  r(  propertyr  r-  r0  r   r  r7  r9  r=  rB  rG  rT  memoized_propertyr_  r$   r)  ri  rp  rs  rf  flexi_cacher1   	dp_stringdp_string_listr  r   r  dp_plain_objr  r  r  r  r  r  r  r  r  r  rz  r  r  r  r  r  r  r  r  r1  r=  r0  rD  rP  rW  rC  rw  r  rU  rv  r  r  r  r  r  r  r  r  r  r  s   @rG   r  r  S  s   D#N!O%*" H!M"#!%! $'$L*'H.5" OO$)!!"		
 
U>? T
	 !#0 
	
&
&,* L L P P N N % % N N
 N N2$ ?C
8 
 , :>% %, =A% %&
. Z	$../	*99:	$../

. [: :x Z	$../	#001	"//0	*99:	$../>$L < < H< H<T < <, ?C   & < < < < > > [4 4l   A  AF > >"* [F FP   E  EN@ > > [5 5n   &
  &
P > > [2
 2
h Z	$../	$../	)889



>   K
  K
Z > > [0
 0
d Z	$../	$../	)889

*   +
  +
Z 
 	> >(   C
  C
J -1> >    F
  F
P 
 0 0d ?D> >"    7
  7
r=rJ   r  c                      e Zd ZdZd Zy)r   outer_join_columnc                    || _         y rA   )r  )rD   r  s     rG   r   z_OuterJoinColumn.__init__  s	    rJ   N)rx   r   r   __visit_name__r   r]   rJ   rG   r   r     s    (NrJ   r   )Xr  
__future__r   collectionsr   	functoolsr   r   r  rX   r	   typesr
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r    enginer!   r"   r#   r$   engine.reflectionr%   r&   r(   r)   r*   r+   r,   r-   r.   r/   rP  r0   sql.visitorsr1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r  r&  r  r   Booleanr  DateTimeDater  r  GenericTypeCompilerr?   r   r   DDLCompilerr  IdentifierPreparerr  DefaultExecutionContextr  r  r  ClauseElementr   r]   rJ   rG   <module>r     s  KZ # #   	  !                    #      !   3          #  -    %     ? @Euw
 BHHJ
 nxtMM;	 D U	
 D f D U D U  	 %i h 
3  U!" (#$ " -4X55 XvaGX)) aGHj,, jZ9x:: 9(W<< "B=G** B=J:s(( rJ   