
H`Tc           @@  s  d  Z  d d l m Z d d l m Z m Z m Z d d l m Z d d l	 m
 Z d d l m Z m Z m Z m Z d d	 l Z d d	 l Z d d	 l Z d d	 l Z d
 e j f d     YZ d e j f d     YZ d e f d     YZ d e f d     YZ d e e j f d     YZ d e e j f d     YZ  d e e j! f d     YZ" d e j# f d     YZ$ d e e j% f d     YZ& d e e e j' f d     YZ( d e j) f d     YZ* d  e e j+ f d!     YZ, d" e j- f d#     YZ. d$ e j/ f d%     YZ0 d& e j1 f d'     YZ2 d( e f d)     YZ3 d* e f d+     YZ4 d, e4 f d-     YZ5 d. e j6 f d/     YZ7 d0 e f d1     YZ8 e8 Z9 d	 S(2   s/  

.. dialect:: oracle+cx_oracle
    :name: cx-Oracle
    :dbapi: cx_oracle
    :connectstring: oracle+cx_oracle://user:pass@host:port/dbname[?key=value&key=value...]
    :url: http://cx-oracle.sourceforge.net/

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

When connecting with ``dbname`` present, the host, port, and dbname tokens are
converted to a TNS name using
the cx_oracle ``makedsn()`` function.  Otherwise, the host token is taken
directly as a TNS name.

Additional arguments which may be specified either as query string arguments
on the URL, or as keyword arguments to :func:`.create_engine()` are:

* ``allow_twophase`` - enable two-phase transactions.  Defaults to ``True``.

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

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

* ``auto_setinputsizes`` - the cx_oracle.setinputsizes() call is issued for
  all bind parameters.  This is required for LOB datatypes but can be
  disabled to reduce overhead.  Defaults to ``True``.  Specific types
  can be excluded from this process using the ``exclude_setinputsizes``
  parameter.

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

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

* ``exclude_setinputsizes`` - a tuple or list of string DBAPI type names to
  be excluded from the "auto setinputsizes" feature.  The type names here
  must match DBAPI types that are found in the "cx_Oracle" module namespace,
  such as cx_Oracle.UNICODE, cx_Oracle.NCLOB, etc.   Defaults to
  ``(STRING, UNICODE)``.

  .. versionadded:: 0.8 specific DBAPI types can be excluded from the
     auto_setinputsizes feature via the exclude_setinputsizes attribute.

* ``mode`` - This is given the string value of SYSDBA or SYSOPER, or
  alternatively an integer value.  This value is only available as a URL query
  string argument.

* ``threaded`` - enable multithreaded access to cx_oracle connections.
  Defaults to ``True``.  Note that this is the opposite default of the
  cx_Oracle DBAPI itself.

.. _cx_oracle_unicode:

Unicode
-------

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

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

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

* the cx_Oracle DBAPI has the ability to coerce all string results to Python
  unicode objects unconditionally using output type handlers.  This has
  the advantage that the unicode conversion is global to all statements
  at the cx_Oracle driver level, meaning it works with raw textual SQL
  statements that have no typing information associated.  However, this system
  has been observed to incur signfiicant performance overhead, not only
  because it takes effect for all string values unconditionally, but also
  because cx_Oracle under Python 2 seems to use a pure-Python function call in
  order to do the decode operation, which under cPython can orders of
  magnitude slower than doing it using C functions alone.

* SQLAlchemy has unicode-decoding services built in, and when using
  SQLAlchemy's C extensions, these functions do not use any Python function
  calls and are very fast.  The disadvantage to this approach is that the
  unicode conversion only takes effect for statements where the
  :class:`.Unicode` type or :class:`.String` type with
  ``convert_unicode=True`` is explicitly associated with the result column.
  This is the case for any ORM or Core query or SQL expression as well as for
  a :func:`.text` construct that specifies output column types, so in the vast
  majority of cases this is not an issue. However, when sending a completely
  raw string to :meth:`.Connection.execute`, this typing information isn't
  present, unless the string is handled within a :func:`.text` construct that
  adds typing information.

As of version 0.9.2 of SQLAlchemy, the default approach is to use SQLAlchemy's
typing system.  This keeps cx_Oracle's expensive Python 2 approach
disabled unless the user explicitly wants it.  Under Python 3, SQLAlchemy
detects that cx_Oracle is returning unicode objects natively and cx_Oracle's
system is used.

To re-enable cx_Oracle's output type handler under Python 2, the
``coerce_to_unicode=True`` flag (new in 0.9.4) can be passed to
:func:`.create_engine`::

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

Alternatively, to run a pure string SQL statement and get ``VARCHAR`` results
as Python unicode under Python 2 without using cx_Oracle's native handlers,
the :func:`.text` feature can be used::

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

.. versionchanged:: 0.9.2 cx_Oracle's outputtypehandlers are no longer used
   for unicode results of non-unicode datatypes in Python 2, after they were
   identified as a major performance bottleneck.  SQLAlchemy's own unicode
   facilities are used instead.

.. versionadded:: 0.9.4 Added the ``coerce_to_unicode`` flag, to re-enable
   cx_Oracle's outputtypehandler and revert to pre-0.9.2 behavior.

.. _cx_oracle_returning:

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

The cx_oracle DBAPI supports a limited subset of Oracle's already limited
RETURNING support.  Typically, results can only be guaranteed for at most one
column being returned; this is the typical case when SQLAlchemy uses RETURNING
to get just the value of a primary-key-associated sequence value.
Additional column expressions will cause problems in a non-determinative way,
due to cx_oracle's lack of support for the OCI_DATA_AT_EXEC API which is
required for more complex RETURNING scenarios.

For this reason, stability may be enhanced by disabling RETURNING support
completely; SQLAlchemy otherwise will use RETURNING to fetch newly
sequence-generated primary keys.  As illustrated in :ref:`oracle_returning`::

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

.. seealso::

    http://docs.oracle.com/cd/B10501_01/appdev.920/a96584/oci05bnd.htm#420693
    - OCI documentation for RETURNING

    http://sourceforge.net/mailarchive/message.php?msg_id=31338136
    - cx_oracle developer commentary

.. _cx_oracle_lob:

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

cx_oracle returns oracle LOBs using the cx_oracle.LOB object.  SQLAlchemy
converts these to strings so that the interface of the Binary type is
consistent with that of other backends, and so that the linkage to a live
cursor is not needed in scenarios like result.fetchmany() and
result.fetchall().   This means that by default, LOB objects are fully fetched
unconditionally by SQLAlchemy, and the linkage to a live cursor is broken.

To disable this processing, pass ``auto_convert_lobs=False`` to
:func:`.create_engine()`.

Two Phase Transaction Support
-----------------------------

Two Phase transactions are implemented using XA transactions, and are known
to work in a rudimental fashion with recent versions of cx_Oracle
as of SQLAlchemy 0.8.0b2, 0.7.10.   However, the mechanism is not yet
considered to be robust and should still be regarded as experimental.

In particular, the cx_Oracle DBAPI as recently as 5.1.2 has a bug regarding
two phase which prevents
a particular DBAPI connection from being consistently usable in both
prepared transactions as well as traditional DBAPI usage patterns; therefore
once a particular connection is used via :meth:`.Connection.begin_prepared`,
all subsequent usages of the underlying DBAPI connection must be within
the context of prepared transactions.

The default behavior of :class:`.Engine` is to maintain a pool of DBAPI
connections.  Therefore, due to the above glitch, a DBAPI connection that has
been used in a two-phase operation, and is then returned to the pool, will
not be usable in a non-two-phase context.   To avoid this situation,
the application can make one of several choices:

* Disable connection pooling using :class:`.NullPool`

* Ensure that the particular :class:`.Engine` in use is only used
  for two-phase operations.   A :class:`.Engine` bound to an ORM
  :class:`.Session` which includes ``twophase=True`` will consistently
  use the two-phase transaction style.

* For ad-hoc two-phase operations without disabling pooling, the DBAPI
  connection in use can be evicted from the connection pool using the
  :meth:`.Connection.detach` method.

.. versionchanged:: 0.8.0b2,0.7.10
    Support for cx_oracle prepared transactions has been implemented
    and tested.

.. _cx_oracle_numeric:

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

The SQLAlchemy dialect goes through a lot of steps to ensure
that decimal numbers are sent and received with full accuracy.
An "outputtypehandler" callable is associated with each
cx_oracle connection object which detects numeric types and
receives them as string values, instead of receiving a Python
``float`` directly, which is then passed to the Python
``Decimal`` constructor.  The :class:`.Numeric` and
:class:`.Float` types under the cx_oracle dialect are aware of
this behavior, and will coerce the ``Decimal`` to ``float`` if
the ``asdecimal`` flag is ``False`` (default on :class:`.Float`,
optional on :class:`.Numeric`).

Because the handler coerces to ``Decimal`` in all cases first,
the feature can detract significantly from performance.
If precision numerics aren't required, the decimal handling
can be disabled by passing the flag ``coerce_to_decimal=False``
to :func:`.create_engine`::

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

.. versionadded:: 0.7.6
    Add the ``coerce_to_decimal`` flag.

Another alternative to performance is to use the
`cdecimal <http://pypi.python.org/pypi/cdecimal/>`_ library;
see :class:`.Numeric` for additional notes.

The handler attempts to use the "precision" and "scale"
attributes of the result set column to best determine if
subsequent incoming values should be received as ``Decimal`` as
opposed to int (in which case no processing is added). There are
several scenarios where OCI_ does not provide unambiguous data
as to the numeric type, including some situations where
individual rows may return a combination of floating point and
integer values. Certain values for "precision" and "scale" have
been observed to determine this scenario.  When it occurs, the
outputtypehandler receives as string and then passes off to a
processing function which detects, for each returned value, if a
decimal point is present, and if so converts to ``Decimal``,
otherwise to int.  The intention is that simple int-based
statements like "SELECT my_seq.nextval() FROM DUAL" continue to
return ints and not ``Decimal`` objects, and that any kind of
floating point value is received as a string so that there is no
floating point loss of precision.

The "decimal point is present" logic itself is also sensitive to
locale.  Under OCI_, this is controlled by the NLS_LANG
environment variable. Upon first connection, the dialect runs a
test to determine the current "decimal" character, which can be
a comma "," for European locales. From that point forward the
outputtypehandler uses that character to represent a decimal
point. Note that cx_oracle 5.0.3 or greater is required
when dealing with numerics with locale settings that don't use
a period "." as the decimal character.

.. versionchanged:: 0.6.6
    The outputtypehandler supports the case where the locale uses a
    comma "," character to represent a decimal point.

.. _OCI: http://www.oracle.com/technetwork/database/features/oci/index.html

i    (   t   absolute_importi   (   t   OracleCompilert   OracleDialectt   OracleExecutionContext(   t   basei   (   t   result(   t   typest   utilt   exct
   processorsNt   _OracleNumericc           B@  s   e  Z d    Z d   Z RS(   c         C@  s   d  S(   N(   t   None(   t   selft   dialect(    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyt   bind_processor'  s    c         @  s   | j  r |  j r2 d |  j     f d   } | S|  j d  k rW |  j d  k rW t j St |  d t	  r |  j d  k	 r t j Sd  Sn t
 t |   j | |  Sd  S(   Ns   %%.%dfc         @  s;   |  d  k r d  St |  t j  r& |  St j   |   Sd  S(   N(   R   t
   isinstancet   decimalt   Decimal(   t   value(   t   fstring(    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyt
   to_decimal9  s
    t   _is_oracle_number(   t   supports_native_decimalt	   asdecimalt   _effective_decimal_return_scalet	   precisionR   t   scaleR	   t   to_floatt   getattrt   Falset   superR
   t   result_processor(   R   R   t   coltypeR   (    (   R   sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR   +  s    
		(   t   __name__t
   __module__R   R   (    (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR
   &  s   	t   _OracleDatec           B@  s   e  Z d    Z d   Z RS(   c         C@  s   d  S(   N(   R   (   R   R   (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR   R  s    c         C@  s   d   } | S(   Nc         S@  s   |  d  k	 r |  j   S|  Sd  S(   N(   R   t   date(   R   (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyt   processV  s    
(    (   R   R   R    R%   (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR   U  s    	(   R!   R"   R   R   (    (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR#   Q  s   	t	   _LOBMixinc           B@  s   e  Z d    Z RS(   c         C@  s   | j  s d  Sd   } | S(   Nc         S@  s   |  d  k	 r |  j   S|  Sd  S(   N(   R   t   read(   R   (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR%   d  s    
(   t   auto_convert_lobsR   (   R   R   R    R%   (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR   _  s    		(   R!   R"   R   (    (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR&   ^  s   t   _NativeUnicodeMixinc           B@  s   e  Z e j r d    Z n  RS(   c         C@  s0   | j  r d   } | St t |   j |  Sd  S(   Nc         S@  s   |  d  k r |  St |   Sd  S(   N(   R   t   unicode(   R   (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR%   p  s    (   t   _cx_oracle_with_unicodeR   R)   R   (   R   R   R%   (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR   n  s
    		(   R!   R"   R   t   py2kR   (    (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR)   l  s   	t   _OracleCharc           B@  s   e  Z d    Z RS(   c         C@  s   | j  S(   N(   t
   FIXED_CHAR(   R   t   dbapi(    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyt   get_dbapi_type  s    (   R!   R"   R0   (    (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR-     s   t   _OracleNVarCharc           B@  s   e  Z d    Z RS(   c         C@  s   t  | d | j  S(   Nt   UNICODE(   R   t   STRING(   R   R/   (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR0     s    (   R!   R"   R0   (    (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR1     s   t   _OracleTextc           B@  s   e  Z d    Z RS(   c         C@  s   | j  S(   N(   t   CLOB(   R   R/   (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR0     s    (   R!   R"   R0   (    (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR4     s   t   _OracleLongc           B@  s   e  Z d    Z RS(   c         C@  s   | j  S(   N(   t   LONG_STRING(   R   R/   (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR0     s    (   R!   R"   R0   (    (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR6     s   t   _OracleStringc           B@  s   e  Z RS(    (   R!   R"   (    (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR8     s   t   _OracleUnicodeTextc           B@  s   e  Z d    Z d   Z RS(   c         C@  s   | j  S(   N(   t   NCLOB(   R   R/   (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR0     s    c         @  sg   t  j |  | |      d  k r% d  St j j |  | |    d  k rM   S   f d   } | Sd  S(   Nc         @  s      |    S(   N(    (   R   (   t   string_processort   lob_processor(    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR%     s    (   R&   R   R   t   sqltypest   UnicodeText(   R   R   R    R%   (    (   R<   R;   sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR     s    	(   R!   R"   R0   R   (    (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR9     s   	t   _OracleIntegerc           B@  s   e  Z d    Z RS(   c         C@  s   d   } | S(   Nc         S@  s   |  d  k	 r t |   }  n  |  S(   N(   R   t   int(   t   val(    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyt   to_int  s    (    (   R   R   R    RB   (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR     s    	(   R!   R"   R   (    (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR?     s   t   _OracleBinaryc           B@  s   e  Z d    Z d   Z RS(   c         C@  s   | j  S(   N(   t   BLOB(   R   R/   (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR0     s    c         C@  s   d  S(   N(   R   (   R   R   (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR     s    (   R!   R"   R0   R   (    (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyRC     s   	t   _OracleIntervalc           B@  s   e  Z d    Z RS(   c         C@  s   | j  S(   N(   t   INTERVAL(   R   R/   (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR0     s    (   R!   R"   R0   (    (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyRE     s   t
   _OracleRawc           B@  s   e  Z RS(    (   R!   R"   (    (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyRG     s   t   _OracleRowidc           B@  s   e  Z d    Z RS(   c         C@  s   | j  S(   N(   t   ROWID(   R   R/   (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR0     s    (   R!   R"   R0   (    (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyRH     s   t   OracleCompiler_cx_oraclec           B@  s   e  Z d    Z RS(   c         K@  s}   t  | d d   } | t k s< | t k	 rf |  j j |  rf d | } | |  j | <t j |  | |  St j |  | |  Sd  S(   Nt   quotes   "%s"(	   R   R   t   TrueR   t   preparert   _bindparam_requires_quotest   _quoted_bind_namesR   t   bindparam_string(   R   t   namet   kwRK   t   quoted_name(    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyRP     s    
(   R!   R"   RP   (    (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyRJ     s   t    OracleExecutionContext_cx_oraclec           B@  s#   e  Z d    Z d   Z d   Z RS(   c         @  s  t    j d d   } | r   j j sL t   f d   | j   D  } n  xF   j D]8 } x/ | j   D]! \ } } | | | | <| | =qi WqV Wn    j j r   j	 | d   j j
 n  t   j  d k rx   j j j   D] } | j r | j j   j  j   j j  } t   d  s3i    _ n  | d  k rat j d | j | j f   n    j j | }   j j |    j | <  j |   j d | j | |  <q q Wn  d  S(   NRO   c         3@  s?   |  ]5 \ } } | j    j j  | j    j j  f Vq d  S(   N(   t   encodeR   t   encoding(   t   .0t   fromnamet   toname(   R   (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pys	   <genexpr>  s   t   exclude_typesi   t   out_parameterssX   Cannot create out parameter for parameter %r - its type %r is not supported by cx_oraclei    (   R   t   compiledR   R   t   supports_unicode_statementst   dictt   itemst
   parameterst   auto_setinputsizest   set_input_sizest   exclude_setinputsizest   lent   compiled_parameterst   bindst   valuest
   isoutparamt   typet   dialect_implR0   R/   t   hasattrR[   R   t   InvalidRequestErrort   keyt
   bind_namest   cursort   vart   get(   R   t   quoted_bind_namest   paramRX   RY   t	   bindparamt   dbtypeRQ   (    (   R   sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyt   pre_exec  s8    	c         C@  s1   |  j  j   } |  j j r- |  j j | _ n  | S(   N(   t   _dbapi_connectionRo   R   t	   arraysize(   R   t   c(    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyt   create_cursor  s    c         C@  s  t  |  d  rG |  j j rG t d   |  j j   D  } t |  |  Sd  } |  j j	 d  k	 r xE |  j j	 D]4 } | d } | |  j
 j k rl t j |   } ql ql Wn  | d  k r t j |   } n  t  |  d  r|  j d  k	 rt |  j  d k ri  | _ } x |  j j j   D] \ } } | |  j k r| j } | j |  j
  }	 |	 j |  j
 j  }
 |	 j |  j
 |
  } | d  k	 r| |  j | j    | | <q|  j | j   | | <qqWqt d   |  j j   D  | _ n  | S(   NR[   c         s@  s'   |  ] \ } } | | j    f Vq d  S(   N(   t   getvalue(   RW   t   kt   v(    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pys	   <genexpr>  s   i   c         s@  s'   |  ] \ } } | | j    f Vq d  S(   N(   R{   (   RW   R|   R}   (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pys	   <genexpr>>  s   (   Rk   R\   t	   returningR^   R[   R_   t   ReturningResultProxyR   Ro   t   descriptionR   t   _cx_oracle_binary_typest   _resultt   BufferedColumnResultProxyt   ResultProxyRe   Rd   Rn   Ri   Rj   R0   R/   R   R{   (   R   t   returning_paramsR   t   columnt	   type_codeR[   t   bindRQ   Ri   t	   impl_typet
   dbapi_typeR   (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyt   get_result_proxy  sF    
		(   R!   R"   Rv   Rz   R   (    (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyRT     s   	2	t-   OracleExecutionContext_cx_oracle_with_unicodec           B@  s    e  Z d  Z d   Z d   Z RS(   s  Support WITH_UNICODE in Python 2.xx.

    WITH_UNICODE allows cx_Oracle's Python 3 unicode handling
    behavior under Python 2.x. This mode in some cases disallows
    and in other cases silently passes corrupted data when
    non-Python-unicode strings (a.k.a. plain old Python strings)
    are passed as arguments to connect(), the statement sent to execute(),
    or any of the bind parameter keys or values sent to execute().
    This optional context therefore ensures that all statements are
    passed as Python unicode objects.

    c         O@  s,   t  j |  | |  t j |  j  |  _ d  S(   N(   RT   t   __init__R   t	   text_typet	   statement(   R   t   argRR   (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR   T  s    c         C@  s   t  t |   j t j |   S(   N(   R   R   t   _execute_scalarR   R   (   R   t   stmt(    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR   X  s    (   R!   R"   t   __doc__R   R   (    (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR   E  s   	R   c           B@  s)   e  Z d  Z d   Z d   Z d   Z RS(   sO   Result proxy which stuffs the _returning clause + outparams
    into the fetch.c         C@  s#   | |  _  t t |   j |  d  S(   N(   t   _returning_paramsR   R   R   (   R   t   contextR   (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR   a  s    	c         C@  s<   |  j  j j } g  t |  D] \ } } d | d  f ^ q S(   Ns   ret_%d(   R   R\   R~   t	   enumerateR   (   R   R~   t   it   col(    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyt   _cursor_descriptione  s    c         @  s/   t  j t   f d   t   j  D  g  S(   Nc         3@  s&   |  ] \ } }   j  d  | Vq d S(   s   ret_%dN(   R   (   RW   R   Ry   (   R   (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pys	   <genexpr>n  s   (   t   collectionst   dequet   tupleR   R   (   R   (    (   R   sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyt   _buffer_rowsl  s    (   R!   R"   R   R   R   R   (    (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR   ]  s   		t   OracleDialect_cx_oraclec        	   B@  s  e  Z e Z e Z d  Z i e e j	 6e
 e j 6e e j 6e j e j 6e e j 6e e j 6e e j 6e e j 6e e j 6e e j 6e e j 6e e j 6e  e j! 6e" e j# 6e" e j$ 6e% e j& 6Z' Z' e( Z) e* d e* e* e* e* e+ d d  Z, e- d    Z. d   Z/ d   Z0 d   Z1 e2 j3 Z4 d	   Z5 d
   Z6 d   Z7 d   Z8 d   Z9 d d  Z; d   Z< d   Z= e* e+ d  Z> e* e+ d  Z? d   Z@ RS(   t	   cx_oracleR3   R2   i2   c	      
   @  s  t  j   |	  |   _ |   _ |   _   j d  k pI t   j d    _ |   _	 |   _
 t   j d  r t g    j j j d  D] }
 t |
  ^ q    _ n	 d   _   f d   } | | p d     _ | d d d d	    _ | d d    _ | d
 d	 d d    _   j d k   _   j d k o@|   _   j d k oX|   _   j d k   _   j d  k rt     _ t   _ nk   j d k rt   j d  rt   _ t   _ t   _ t j rt j d  t    _! qn	 t   _   j d  k s.  j
 s.t   j d	  r:i    _" nU i t# j$     j j$ 6t# j%     j j% 6t# j&     j j& 6t# j'     j j( 6  _" d  S(   Nt	   TIMESTAMPt   versiont   .i    c          @  s&   t    f d   |  D  j d  g  S(   Nc         3@  s$   |  ] } t    j | d   Vq d  S(   N(   R   R/   R   (   RW   RQ   (   R   (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pys	   <genexpr>  s    (   t   sett
   differenceR   (   t   names(   R   (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR     s    R3   R2   R:   R5   t   BFILERD   i   s  cx_Oracle is compiled under Python 2.xx using the WITH_UNICODE flag.  Consider recompiling cx_Oracle without this flag, which is in no way necessary for full support of Unicode. Otherwise, all string-holding bind parameters must be explicitly typed using SQLAlchemy's String type or one of its subtypes,or otherwise be passed as Python unicode.  Plain Python strings passed as bind parameters will be silently corrupted by cx_Oracle.(   i    i    i    (    (   i   i    (   i   i    (   i   i    (   i   i    (   i   ()   R   R   t   threadedRx   t   allow_twophaseR/   R   Rk   t   supports_timestampRa   R(   R   R   t   splitR@   t   cx_oracle_verRc   t   _cx_oracle_string_typest   _cx_oracle_unicode_typesR   t   supports_unicode_bindst   coerce_to_unicodeR   t   _cx_oracle_native_nvarcharR   R   R+   RL   R]   R   R,   t   warnR   t   execution_ctx_clst   dbapi_type_mapt   oracleR5   R:   RD   t   RAWt   BINARY(   R   Ra   Rc   R(   R   R   t   coerce_to_decimalR   Rx   t   kwargst   xR   (    (   R   sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR     s\    						4									
c         C@  s   d d  l  } | S(   Ni    (   t	   cx_Oracle(   t   clsR   (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR/     s    c         C@  s<   t  t |   j |  |  j r+ t |  _ n  |  j |  d  S(   N(   R   R   t
   initializet   _is_oracle_8R   R   t   _detect_decimal_char(   R   t
   connection(    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR     s    	c         @  s   |  j  d k  r d S|  j  | j }  f d   } | j   } | | _ | j d  | j   d } | j   t j	 d |  j
 d      d k r |  j     f d	   |  _   f d
   |  _ n  d S(   s^  detect if the decimal separator character is not '.', as
        is the case with European locale settings for NLS_LANG.

        cx_oracle itself uses similar logic when it formats Python
        Decimal objects to strings on the bind side (as of 5.0.3),
        as Oracle sends/receives string numerics only in the
        current locale.

        i   Nc         @  s   |  j    j d d |  j S(   Ni   Rx   (   Rp   R3   Rx   (   Ro   RQ   t   defaultTypet   sizeR   R   (   R   (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyt   output_type_handler  s    s   SELECT 0.1 FROM DUALi    s   ([\.,])i   R   c         @  s    |  j    d   S(   NR   (   t   replace(   R   (   t   chart   _detect_decimal(    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyt   <lambda>#  s    c         @  s   t  j |  j   d   S(   NR   (   R   R   R   (   R   (   R   (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR   %  s    (   i   (   R   R/   R   Ro   t   outputtypehandlert   executet   fetchonet   closet   ret   matcht   groupR   t   _to_decimal(   R   R   t   connR   Ro   RA   (    (   R   R   R   sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR     s    
			
	c         C@  s'   d | k r t  j |  St |  Sd  S(   NR   (   R   R   R@   (   R   R   (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR   '  s    c         @  sA     j  d k  r d  S  j     f d     f d   } | S(   Ni   c         @  s     j  rO |  j k rO | rO | d k rO |  j  j d d   j d |  j S  j  r |  j k r | r | d k r |  j  j d d   j d |  j S  j r |  j  j f k r |  j t	 j
 | |  j  Sd  S(   Ni    i   t   outconverterRx   (   R   t   NUMBERRp   R3   R   Rx   R   R   R.   R   R   (   Ro   RQ   R   R   R   R   (   R   R   (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR   6  s&    		
		
	c         @  s     |  _  d  S(   N(   R   (   R   (   R   (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyt
   on_connectT  s    (   i   (   R   R/   (   R   R   (    (   R   R   R   sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR   /  s    	c   
      C@  s  t  | j  } xD d D]< } | | k r t j | | t  t |  | | |  q q W| j r | j } | r} t |  } n d } |  j	 j
 | j | | j  } n	 | j } t  d | j d | j d	 | d |  j d
 |  j  } t j rv|  j r4x~ | j   D]. \ } } t | t  r t |  | | <q q Wqvx? | j   D]. \ } } t | t  rAt |  | | <qAqAWn  d | j k r| j d | d <t | d t j  r| d j   }	 |	 d k r|  j	 j | d <q|	 d k r|  j	 j | d <qt j | d t  qn  g  | f S(   Nt   use_ansiRa   R(   R   R   i  t   usert   passwordt   dsnt   twophaset   modet   SYSDBAt   SYSOPER(   R   s   auto_setinputsizess   auto_convert_lobss   threadeds   allow_twophase(   R^   t   queryR   t   coerce_kw_typet   boolt   setattrt   databaset   portR@   R/   t   makedsnt   hostt   usernameR   R   R   R,   R+   R_   R   t   strR*   t   string_typest   upperR   R   (
   R   t   urlt   dialect_optst   optR   R   t   optsR|   R}   R   (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyt   create_connect_argsY  sJ    
		!						c         C@  s#   t  d   | j j j d  D  S(   Nc         s@  s   |  ] } t  |  Vq d  S(   N(   R@   (   RW   R   (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pys	   <genexpr>  s   R   (   R   R   R   R   (   R   R   (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyt   _get_server_version_info  s    c         C@  sU   | j  \ } t | |  j j  r1 d t |  k St | d  rM | j d	 k St Sd  S(
   Ns   not connectedt   codei   i*  i)  i?  i	  i\	  (   i   i*  i)  i?  i	  i\	  (   t   argsR   R/   t   InterfaceErrorR   Rk   R   R   (   R   t   eR   Ro   t   error(    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyt   is_disconnect  s    c         C@  s'   t  j d d  } d d | d d f S(   s   create a two-phase transaction ID.

        this id will be passed to do_begin_twophase(), do_rollback_twophase(),
        do_commit_twophase().  its format is unspecified.i    i   i   i4  s   %032xi	   l	                    (   t   randomt   randint(   R   t   id(    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyt
   create_xid  s    c         C@  s2   t  | t  r t |  } n  | j | |  d  S(   N(   R   R   t   listt   executemany(   R   Ro   R   R`   R   (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyt   do_executemany  s    c         C@  s   | j  j |   d  S(   N(   R   t   begin(   R   R   t   xid(    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyt   do_begin_twophase  s    c         C@  s    | j  j   } | | j d <d  S(   Nt   cx_oracle_prepared(   R   t   preparet   info(   R   R   R   R   (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyt   do_prepare_twophase  s    c         C@  s   |  j  | j  d  S(   N(   t   do_rollbackR   (   R   R   R   t   is_preparedt   recover(    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyt   do_rollback_twophase  s    c         C@  sC   | s |  j  | j  n& | j d } | r? |  j  | j  n  d  S(   NR   (   t	   do_commitR   R   (   R   R   R   R  R  t   oci_prepared(    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyt   do_commit_twophase  s
    c         C@  s   | j  j d d   d  S(   NR   (   R   t   popR   (   R   R   (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyt   do_recover_twophase  s    (   s   STRINGs   UNICODEN(A   R!   R"   RT   R   RJ   t   statement_compilert   driverR
   R=   t   NumericR#   t   DateRC   t   LargeBinaryR   t   _OracleBooleant   BooleanRE   t   IntervalRF   R4   t   TextR8   t   StringR9   R>   R-   t   CHARR6   t   LONGR?   t   IntegerRG   R   R1   t   Unicodet   NVARCHARRH   RI   t   colspecsR   t   execute_sequence_formatRL   R   R   t   classmethodR/   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R  R  R	  (    (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyR   s  s^   













V		(			*	2						(:   R   t
   __future__R    R   R   R   R   t    R   t   engineR   R   t
   sqlalchemyR   R=   R   R   R	   R   R   R   R   R  R
   R  R#   t   objectR&   R)   R  R-   R  R1   R  R4   R  R6   R  R8   R>   R9   R  R?   R  RC   RF   RE   R   RG   RI   RH   RJ   RT   R   t   FullyBufferedResultProxyR   R   R   (    (    (    sj   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/dialects/oracle/cx_oracle.pyt   <module>  sB   "+	k T