U a)@sRdZddlmZddlZddlZddlZddlmZddlm Z ddlm Z ddlm Z d d lm Z d d lm Z d d lmZd d lmZd dlmZd dlmZGdddejZGdddejZGdddeZGdddeejZGdddeejZGdddeZGdddejZ Gdddej!Z"Gd d!d!ej#Z$Gd"d#d#ej%Z&Gd$d%d%ej'Z(Gd&d'd'ej)Z*Gd(d)d)ej+Z,Gd*d+d+ej-Z.Gd,d-d-ej/Z0Gd.d/d/ej1Z2Gd0d1d1ej3Z4Gd2d3d3ej5Z6Gd4d5d5ej7Z8Gd6d7d7ej9Z:Gd8d9d9ej;ZGd>d?d?e Z?e?Z@dS)@a> .. dialect:: oracle+cx_oracle :name: cx-Oracle :dbapi: cx_oracle :connectstring: oracle+cx_oracle://user:pass@host:port/dbname[?key=value&key=value...] :url: https://oracle.github.io/python-cx_Oracle/ DSN vs. Hostname connections ----------------------------- The dialect will connect to a DSN if no database name portion is presented, such as:: engine = create_engine("oracle+cx_oracle://scott:tiger@oracle1120/?encoding=UTF-8&nencoding=UTF-8") Above, ``oracle1120`` is passed to cx_Oracle as an Oracle datasource name. Alternatively, if a database name is present, the ``cx_Oracle.makedsn()`` function is used to create an ad-hoc "datasource" name assuming host and port:: engine = create_engine("oracle+cx_oracle://scott:tiger@hostname:1521/dbname?encoding=UTF-8&nencoding=UTF-8") Above, the DSN would be created as follows:: >>> import cx_Oracle >>> cx_Oracle.makedsn("hostname", 1521, sid="dbname") '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=hostname)(PORT=1521))(CONNECT_DATA=(SID=dbname)))' The ``service_name`` parameter, also consumed by ``cx_Oracle.makedsn()``, may be specified in the URL query string, e.g. ``?service_name=my_service``. Passing cx_Oracle connect arguments ----------------------------------- Additional connection arguments can usually be passed via the URL query string; particular symbols like ``cx_Oracle.SYSDBA`` are intercepted and converted to the correct symbol:: e = create_engine( "oracle+cx_oracle://user:pass@dsn?encoding=UTF-8&nencoding=UTF-8&mode=SYSDBA&events=true") .. versionchanged:: 1.3 the cx_oracle dialect now accepts all argument names within the URL string itself, to be passed to the cx_Oracle DBAPI. As was the case earlier but not correctly documented, the :paramref:`_sa.create_engine.connect_args` parameter also accepts all cx_Oracle DBAPI connect arguments. To pass arguments directly to ``.connect()`` without using the query string, use the :paramref:`_sa.create_engine.connect_args` dictionary. Any cx_Oracle parameter value and/or constant may be passed, such as:: import cx_Oracle e = create_engine( "oracle+cx_oracle://user:pass@dsn", connect_args={ "encoding": "UTF-8", "nencoding": "UTF-8", "mode": cx_Oracle.SYSDBA, "events": True } ) Options consumed by the SQLAlchemy cx_Oracle dialect outside of the driver -------------------------------------------------------------------------- There are also options that are consumed by the SQLAlchemy cx_oracle dialect itself. These options are always passed directly to :func:`_sa.create_engine` , such as:: e = create_engine( "oracle+cx_oracle://user:pass@dsn", coerce_to_unicode=False) The parameters accepted by the cx_oracle dialect are as follows: * ``arraysize`` - set the cx_oracle.arraysize value on cursors, defaulted to 50. This setting is significant with cx_Oracle as the contents of LOB objects are only readable within a "live" row (e.g. within a batch of 50 rows). * ``auto_convert_lobs`` - defaults to True; See :ref:`cx_oracle_lob`. * ``coerce_to_unicode`` - see :ref:`cx_oracle_unicode` for detail. * ``coerce_to_decimal`` - see :ref:`cx_oracle_numeric` for detail. * ``encoding_errors`` - see :ref:`cx_oracle_unicode_encoding_errors` for detail. .. _cx_oracle_sessionpool: Using cx_Oracle SessionPool --------------------------- The cx_Oracle library provides its own connectivity services that may be used in place of SQLAlchemy's pooling functionality. This can be achieved by using the :paramref:`_sa.create_engine.creator` parameter to provide a function that returns a new connection, along with setting :paramref:`_sa.create_engine.pool_class` to ``NullPool`` to disable SQLAlchemy's pooling:: import cx_Oracle from sqlalchemy import create_engine from sqlalchemy.pool import NullPool pool = cx_Oracle.SessionPool( user="scott", password="tiger", dsn="oracle1120", min=2, max=5, increment=1, threaded=True ) engine = create_engine("oracle://", creator=pool.acquire, poolclass=NullPool) The above engine may then be used normally where cx_Oracle's pool handles connection pooling:: with engine.connect() as conn: print(conn.scalar("select 1 FROM dual")) .. _cx_oracle_unicode: Unicode ------- As is the case for all DBAPIs under Python 3, all strings are inherently Unicode strings. Under Python 2, cx_Oracle also supports Python Unicode objects directly. In all cases however, the driver requires an explicit encoding configuration. Ensuring the Correct Client Encoding ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The long accepted standard for establishing client encoding for nearly all Oracle related software is via the `NLS_LANG `_ environment variable. cx_Oracle like most other Oracle drivers will use this environment variable as the source of its encoding configuration. The format of this variable is idiosyncratic; a typical value would be ``AMERICAN_AMERICA.AL32UTF8``. The cx_Oracle driver also supports a programmatic alternative which is to pass the ``encoding`` and ``nencoding`` parameters directly to its ``.connect()`` function. These can be present in the URL as follows:: engine = create_engine("oracle+cx_oracle://scott:tiger@oracle1120/?encoding=UTF-8&nencoding=UTF-8") For the meaning of the ``encoding`` and ``nencoding`` parameters, please consult `Characters Sets and National Language Support (NLS) `_. .. seealso:: `Characters Sets and National Language Support (NLS) `_ - in the cx_Oracle documentation. Unicode-specific Column datatypes ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The Core expression language handles unicode data by use of the :class:`.Unicode` and :class:`.UnicodeText` datatypes. These types correspond to the VARCHAR2 and CLOB Oracle datatypes by default. When using these datatypes with Unicode data, it is expected that the Oracle database is configured with a Unicode-aware character set, as well as that the ``NLS_LANG`` environment variable is set appropriately, so that the VARCHAR2 and CLOB datatypes can accommodate the data. In the case that the Oracle database is not configured with a Unicode character set, the two options are to use the :class:`_types.NCHAR` and :class:`_oracle.NCLOB` datatypes explicitly, or to pass the flag ``use_nchar_for_unicode=True`` to :func:`_sa.create_engine`, which will cause the SQLAlchemy dialect to use NCHAR/NCLOB for the :class:`.Unicode` / :class:`.UnicodeText` datatypes instead of VARCHAR/CLOB. .. versionchanged:: 1.3 The :class:`.Unicode` and :class:`.UnicodeText` datatypes now correspond to the ``VARCHAR2`` and ``CLOB`` Oracle datatypes unless the ``use_nchar_for_unicode=True`` is passed to the dialect when :func:`_sa.create_engine` is called. Unicode Coercion of result rows under Python 2 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ When result sets are fetched that include strings, under Python 3 the cx_Oracle DBAPI returns all strings as Python Unicode objects, since Python 3 only has a Unicode string type. This occurs for data fetched from datatypes such as VARCHAR2, CHAR, CLOB, NCHAR, NCLOB, etc. In order to provide cross- compatibility under Python 2, the SQLAlchemy cx_Oracle dialect will add Unicode-conversion to string data under Python 2 as well. Historically, this made use of converters that were supplied by cx_Oracle but were found to be non-performant; SQLAlchemy's own converters are used for the string to Unicode conversion under Python 2. To disable the Python 2 Unicode conversion for VARCHAR2, CHAR, and CLOB, the flag ``coerce_to_unicode=False`` can be passed to :func:`_sa.create_engine`. .. versionchanged:: 1.3 Unicode conversion is applied to all string values by default under python 2. The ``coerce_to_unicode`` now defaults to True and can be set to False to disable the Unicode coercion of strings that are delivered as VARCHAR2/CHAR/CLOB data. .. _cx_oracle_unicode_encoding_errors: Encoding Errors ^^^^^^^^^^^^^^^ For the unusual case that data in the Oracle database is present with a broken encoding, the dialect accepts a parameter ``encoding_errors`` which will be passed to Unicode decoding functions in order to affect how decoding errors are handled. The value is ultimately consumed by the Python `decode `_ function, and is passed both via cx_Oracle's ``encodingErrors`` parameter consumed by ``Cursor.var()``, as well as SQLAlchemy's own decoding function, as the cx_Oracle dialect makes use of both under different circumstances. .. versionadded:: 1.3.11 .. _cx_oracle_setinputsizes: Fine grained control over cx_Oracle data binding performance with setinputsizes ------------------------------------------------------------------------------- The cx_Oracle DBAPI has a deep and fundamental reliance upon the usage of the DBAPI ``setinputsizes()`` call. The purpose of this call is to establish the datatypes that are bound to a SQL statement for Python values being passed as parameters. While virtually no other DBAPI assigns any use to the ``setinputsizes()`` call, the cx_Oracle DBAPI relies upon it heavily in its interactions with the Oracle client interface, and in some scenarios it is not possible for SQLAlchemy to know exactly how data should be bound, as some settings can cause profoundly different performance characteristics, while altering the type coercion behavior at the same time. Users of the cx_Oracle dialect are **strongly encouraged** to read through cx_Oracle's list of built-in datatype symbols at https://cx-oracle.readthedocs.io/en/latest/api_manual/module.html#database-types. Note that in some cases, significant performance degradation can occur when using these types vs. not, in particular when specifying ``cx_Oracle.CLOB``. On the SQLAlchemy side, the :meth:`.DialectEvents.do_setinputsizes` event can be used both for runtime visibility (e.g. logging) of the setinputsizes step as well as to fully control how ``setinputsizes()`` is used on a per-statement basis. .. versionadded:: 1.2.9 Added :meth:`.DialectEvents.setinputsizes` Example 1 - logging all setinputsizes calls ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The following example illustrates how to log the intermediary values from a SQLAlchemy perspective before they are converted to the raw ``setinputsizes()`` parameter dictionary. The keys of the dictionary are :class:`.BindParameter` objects which have a ``.key`` and a ``.type`` attribute:: from sqlalchemy import create_engine, event engine = create_engine("oracle+cx_oracle://scott:tiger@host/xe") @event.listens_for(engine, "do_setinputsizes") def _log_setinputsizes(inputsizes, cursor, statement, parameters, context): for bindparam, dbapitype in inputsizes.items(): log.info( "Bound parameter name: %s SQLAlchemy type: %r " "DBAPI object: %s", bindparam.key, bindparam.type, dbapitype) Example 2 - remove all bindings to CLOB ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The ``CLOB`` datatype in cx_Oracle incurs a significant performance overhead, however is set by default for the ``Text`` type within the SQLAlchemy 1.2 series. This setting can be modified as follows:: from sqlalchemy import create_engine, event from cx_Oracle import CLOB engine = create_engine("oracle+cx_oracle://scott:tiger@host/xe") @event.listens_for(engine, "do_setinputsizes") def _remove_clob(inputsizes, cursor, statement, parameters, context): for bindparam, dbapitype in list(inputsizes.items()): if dbapitype is CLOB: del inputsizes[bindparam] .. _cx_oracle_returning: RETURNING Support ----------------- The cx_Oracle dialect implements RETURNING using OUT parameters. The dialect supports RETURNING fully, however cx_Oracle 6 is recommended for complete support. .. _cx_oracle_lob: LOB Objects ----------- cx_oracle returns oracle LOBs using the cx_oracle.LOB object. SQLAlchemy converts these to strings so that the interface of the Binary type is consistent with that of other backends, which takes place within a cx_Oracle outputtypehandler. cx_Oracle prior to version 6 would require that LOB objects be read before a new batch of rows would be read, as determined by the ``cursor.arraysize``. As of the 6 series, this limitation has been lifted. Nevertheless, because SQLAlchemy pre-reads these LOBs up front, this issue is avoided in any case. To disable the auto "read()" feature of the dialect, the flag ``auto_convert_lobs=False`` may be passed to :func:`_sa.create_engine`. Under the cx_Oracle 5 series, having this flag turned off means there is the chance of reading from a stale LOB object if not read as it is fetched. With cx_Oracle 6, this issue is resolved. .. versionchanged:: 1.2 the LOB handling system has been greatly simplified internally to make use of outputtypehandlers, and no longer makes use of alternate "buffered" result set objects. Two Phase Transactions Not Supported ------------------------------------- Two phase transactions are **not supported** under cx_Oracle due to poor driver support. As of cx_Oracle 6.0b1, the interface for two phase transactions has been changed to be more of a direct pass-through to the underlying OCI layer with less automation. The additional logic to support this system is not implemented in SQLAlchemy. .. _cx_oracle_numeric: Precision Numerics ------------------ SQLAlchemy's numeric types can handle receiving and returning values as Python ``Decimal`` objects or float objects. When a :class:`.Numeric` object, or a subclass such as :class:`.Float`, :class:`_oracle.DOUBLE_PRECISION` etc. is in use, the :paramref:`.Numeric.asdecimal` flag determines if values should be coerced to ``Decimal`` upon return, or returned as float objects. To make matters more complicated under Oracle, Oracle's ``NUMBER`` type can also represent integer values if the "scale" is zero, so the Oracle-specific :class:`_oracle.NUMBER` type takes this into account as well. The cx_Oracle dialect makes extensive use of connection- and cursor-level "outputtypehandler" callables in order to coerce numeric values as requested. These callables are specific to the specific flavor of :class:`.Numeric` in use, as well as if no SQLAlchemy typing objects are present. There are observed scenarios where Oracle may sends incomplete or ambiguous information about the numeric types being returned, such as a query where the numeric types are buried under multiple levels of subquery. The type handlers do their best to make the right decision in all cases, deferring to the underlying cx_Oracle DBAPI for all those cases where the driver can make the best decision. When no typing objects are present, as when executing plain SQL strings, a default "outputtypehandler" is present which will generally return numeric values which specify precision and scale as Python ``Decimal`` objects. To disable this coercion to decimal for performance reasons, pass the flag ``coerce_to_decimal=False`` to :func:`_sa.create_engine`:: engine = create_engine("oracle+cx_oracle://dsn", coerce_to_decimal=False) The ``coerce_to_decimal`` flag only impacts the results of plain string SQL statements that are not otherwise associated with a :class:`.Numeric` SQLAlchemy type (or a subclass of such). .. versionchanged:: 1.2 The numeric handling system for cx_Oracle has been reworked to take advantage of newer cx_Oracle features as well as better integration of outputtypehandlers. )absolute_importN)base)OracleCompiler) OracleDialect)OracleExecutionContext)exc) processors)types)util)cursor)compatc@s$eZdZddZddZddZdS)_OracleIntegercCstSNintselfdbapireC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-nyjtotrf\sqlalchemy\dialects\oracle\cx_oracle.pyget_dbapi_typesz_OracleInteger.get_dbapi_typecCs|j}|j|jd|jtdS)N arraysize outconverter)rvarSTRINGrr)rdialectr cx_Oraclerrr_cx_oracle_varsz_OracleInteger._cx_oracle_varcsfdd}|S)Ncs |Sr)r!r name default_typesize precisionscalerrrrhandlersz<_OracleInteger._cx_oracle_outputtypehandler..handlerrrrr)rr(r_cx_oracle_outputtypehandlersz+_OracleInteger._cx_oracle_outputtypehandlerN)__name__ __module__ __qualname__rr!r+rrrrrsrc@s(eZdZdZddZddZddZdS) _OracleNumericFcs>|jdkrdS|jr4ttj|jfdd}|StjSdS)Nrcs6t|ttfr|S|dk r.|r.t|S|SdSr) isinstancerfloat is_infinitevalue processorrrprocesss z._OracleNumeric.bind_processor..process)r' asdecimalr Zto_decimal_processor_factorydecimalDecimalZ_effective_decimal_return_scaleZto_floatrrr7rr5rbind_processors  z_OracleNumeric.bind_processorcCsdSrrrrcoltyperrrresult_processorsz_OracleNumeric.result_processorcs"jjfdd}|S)Ncsd}|rXjr>|jkr$|}tj}qVr0tj}qVj}j}qjrP|dkrPdSj}nNjr|jkrt|}tj}qrtj}qj}j}njr|dkrdSj}|j|d|j|dS)Nrrr) r8 NATIVE_FLOATr9r:r _to_decimal is_numberrr)r r#r$r%r&r'rtype_r rZis_cx_oracle_6rrrr)s<  z<_OracleNumeric._cx_oracle_outputtypehandler..handler)r_is_cx_oracle_6r*rrDrr+s2z+_OracleNumeric._cx_oracle_outputtypehandlerN)r,r-r.rBr<r?r+rrrrr/sr/c@seZdZddZdS)_OracleBinaryFloatcCs|jSr)r@rrrrrsz!_OracleBinaryFloat.get_dbapi_typeNr,r-r.rrrrrrFsrFc@s eZdZdS)_OracleBINARY_FLOATNr,r-r.rrrrrHsrHc@s eZdZdS)_OracleBINARY_DOUBLENrIrrrrrJsrJc@seZdZdZdS) _OracleNUMBERTN)r,r-r.rBrrrrrKsrKc@seZdZddZddZdS) _OracleDatecCsdSrrrrrrrr<sz_OracleDate.bind_processorcCs dd}|S)NcSs|dk r|S|SdSr)dater3rrrr7sz-_OracleDate.result_processor..processr)rrr>r7rrrr?sz_OracleDate.result_processorN)r,r-r.r<r?rrrrrLsrLc@seZdZddZdS) _OracleCharcCs|jSr) FIXED_CHARrrrrrsz_OracleChar.get_dbapi_typeNrGrrrrrOsrOc@seZdZddZdS) _OracleNCharcCs|jSr) FIXED_NCHARrrrrrsz_OracleNChar.get_dbapi_typeNrGrrrrrQsrQc@seZdZddZdS)_OracleUnicodeStringNCHARcCs|jSr)NCHARrrrrrsz(_OracleUnicodeStringNCHAR.get_dbapi_typeNrGrrrrrSsrSc@seZdZddZdS)_OracleUnicodeStringCHARcCs|jSr LONG_STRINGrrrrr!sz'_OracleUnicodeStringCHAR.get_dbapi_typeNrGrrrrrU srUc@seZdZddZdS)_OracleUnicodeTextNCLOBcCs|jSr)NCLOBrrrrr&sz&_OracleUnicodeTextNCLOB.get_dbapi_typeNrGrrrrrX%srXc@seZdZddZdS)_OracleUnicodeTextCLOBcCs|jSrCLOBrrrrr+sz%_OracleUnicodeTextCLOB.get_dbapi_typeNrGrrrrrZ*srZc@seZdZddZdS) _OracleTextcCs|jSrr[rrrrr0sz_OracleText.get_dbapi_typeNrGrrrrr]/sr]c@seZdZddZdS) _OracleLongcCs|jSrrVrrrrr5sz_OracleLong.get_dbapi_typeNrGrrrrr^4sr^c@s eZdZdS) _OracleStringNrIrrrrr_9sr_c@seZdZddZdS) _OracleEnumcstj||fdd}|S)Ncs |}|Srr)r4Zraw_strZ enum_procrrr7Asz+_OracleEnum.bind_processor..process)sqltypesEnumr<r;rrarr<>s z_OracleEnum.bind_processorN)r,r-r.r<rrrrr`=sr`cs,eZdZddZddZfddZZS) _OracleBinarycCs|jSr)BLOBrrrrrIsz_OracleBinary.get_dbapi_typecCsdSrrrMrrrr<Lsz_OracleBinary.bind_processorcs |js dStt|||SdSr)auto_convert_lobssuperrdr?r= __class__rrr?Os  z_OracleBinary.result_processor)r,r-r.rr<r? __classcell__rrrhrrdHsrdc@seZdZddZdS)_OracleIntervalcCs|jSr)INTERVALrrrrrYsz_OracleInterval.get_dbapi_typeNrGrrrrrkXsrkc@s eZdZdS) _OracleRawNrIrrrrrm]srmc@seZdZddZdS) _OracleRowidcCs|jSr)ROWIDrrrrrbsz_OracleRowid.get_dbapi_typeNrGrrrrrnasrnc@seZdZdZddZdS)OracleCompiler_cx_oracleTcKsXt|dd}|dks4|dk rH|j|rH|ddsHd|}||d<|}tj||f|S)NquoteTFZ post_compilez"%s"Z escaped_from)getattrpreparerZ_bindparam_requires_quotesgetrbindparam_string)rr#kwrqZ quoted_namerrrruis    z)OracleCompiler_cx_oracle.bindparam_stringN)r,r-r._oracle_cx_sql_compilerrurrrrrpfsrpc@sHeZdZdZddZddZddZdd Zd d Zd d Z ddZ dS) OracleExecutionContext_cx_oracleNcs|jjs|jjr|jj}|jjD]l}|jr&|jj|}|j |j }t |drp| |j |j |j|<n||j j}|j j}|dkrtd|j|jftjr||j|jfkrtj|j j|j jd|j j|fddd|j|<n||j|j|jfkr"|j j|ddd|j|<nVtjrft|tj rftj|j j|j jd|j j|d|j|<n|j ||j|<|j||j!d|"||<q&dS) Nr!zXCannot create out parameter for parameter %r - its type %r is not supported by cx_oracleerrorscs |Srreadr3rrrszOOracleExecutionContext_cx_oracle._generate_out_parameter_vars..r}cSs|Srr{r3rrrr~r)#compiled returningZhas_out_parametersZescaped_bind_namesZbindsvaluesZ isoutparamZ bind_namestypeZ dialect_implrhasattrr!r out_parametersrrr InvalidRequestErrorkeyrpy2kr\rYr to_unicode_processor_factoryencodingencoding_errorsrrer0rbUnicode parametersrt)rZquoted_bind_namesZ bindparamr#Z type_impldbtyper rr}r_generate_out_parameter_varssv      z=OracleExecutionContext_cx_oracle._generate_out_parameter_varscsji|jjD]6\}}}}||jd|j}|r |j|}||<q rf|jjfdd}||j_dS)NZcx_oracle_outputtypehandlercs4|kr|||||||S||||||SdSrrr"Zdefault_handlerZoutput_handlersrroutput_type_handlers"zaOracleExecutionContext_cx_oracle._generate_cursor_outputtype_handler..output_type_handler) rZ_result_columnsZ_cached_custom_processorr_get_cx_oracle_type_handlerZdenormalize_name_dbapi_connectionoutputtypehandlerr )rkeynamer#ZobjectsrCr)Zdenormalized_namerrrr#_generate_cursor_outputtype_handlers   zDOracleExecutionContext_cx_oracle._generate_cursor_outputtype_handlercCst|dr||jSdSdS)Nr+)rr+r)rimplrrrrs  zsz>OracleExecutionContext_cx_oracle.post_exec..cSsg|]}t|d|jdfqS)r#N)rrZ_anon_name_label)rcolrrrrs)Zinitial_buffer) rrrrangelen_cursorZ FullyBufferedCursorFetchStrategyr tupleZcursor_fetch_strategy)rZreturning_paramsZfetch_strategyrrr post_execs   z*OracleExecutionContext_cx_oracle.post_execcCs |j}|jjr|jj|_|Sr)rr rr)rcrrr create_cursor s  z.OracleExecutionContext_cx_oracle.create_cursorcsjjr tfdd|DS)Ncsg|]}jj|qSr)r _paramvalr)rr#rrrrszMOracleExecutionContext_cx_oracle.get_out_parameter_values..)rrAssertionError)rZout_param_namesrrrget_out_parameter_valuess  z9OracleExecutionContext_cx_oracle.get_out_parameter_values) r,r-r.rrrrrrrrrrrrrx}sF rxc.seZdZdZeZeZdZdZ dZ dZ dZ dZ ejeejeejeejeejeejeejeejeejej ej!e"ej#e"ej$e%ej&e'ej(e)ej*e+ej,e-ej.e/ej0e1ej2e3ej4e5ej6e7ej8e9ej:e;iZdZ?e@jAddd4ddZBeCd d ZDd d ZEeFd dZGfddZHddZIddZJddZKddZLeMjNZOddZPddZQddZRdd ZSd!d"ZTd#d$ZUd5d%d&ZVd'd(ZWd)d*ZXd6d,d-ZYd7d.d/ZZd0d1Z[d2d3Z\Z]S)8OracleDialect_cx_oracleTZ cx_oracleN)1.3a8The 'threaded' parameter to the cx_oracle dialect is deprecated as a dialect-level argument, and will be removed in a future release. As of version 1.3, it defaults to False rather than True. The 'threaded' option can be passed to cx_Oracle directly in the URL query string passed to :func:`_sa.create_engine`.)threaded2c Ks*tj|f|||_||_|dk r(||_||_||_||_|jrd|j |_ t |j t j <t|j t j<|j}|dkri|_d|_n||j|_|jdkr|jdkrtd|j|j|j|j|j|j|j|j|jt t!t"h |_dd|_#|jdk|_$|j$rd|j%_&dd } | |_'n|j#|_'|jd k|_(dS) Nrrr)z-cx_Oracle version 5.2 and above are supportedcSs|Sr)getvaluer3rrrr~rz2OracleDialect_cx_oracle.__init__..)rTcSs,z|jddWStk r&YdSXdSNr)r IndexErrorr3rrrrsz7OracleDialect_cx_oracle.__init__.._returningval)r))r__init__rr_cx_oracle_threadedrfcoerce_to_unicodecoerce_to_decimalZ_use_nchar_for_unicodecolspecscopyrSrbrrX UnicodeTextrr cx_oracle_ver_parse_cx_oracle_verversionr rZDATETIMErYr\ZLOBrTrRrerP TIMESTAMPrrHrJrZ_values_are_lists __future__Zdml_ret_array_valrrE) rrfrrrrrkwargsr rrrrrLsT     z OracleDialect_cx_oracle.__init__cCs0|jr,|jdkrd|jiStd|jfiS)N)rZencodingErrorsz4cx_oracle version %r does not support encodingErrors)rrr warnrrrr_cursor_var_unicode_kwargss  z2OracleDialect_cx_oracle._cursor_var_unicode_kwargscCs4td|}|r,tdd|dddDSdSdS)Nz(\d+)\.(\d+)(?:\.(\d+))?css|]}|dk rt|VqdSrrrxrrr sz?OracleDialect_cx_oracle._parse_cx_oracle_ver..rrrr)rematchrgroup)rrmrrrrs z,OracleDialect_cx_oracle._parse_cx_oracle_vercCs ddl}|Sr)r )clsr rrrrszOracleDialect_cx_oracle.dbapics*tt|||jrd|_||dS)NF)rgr initializeZ _is_oracle_8supports_unicode_binds_detect_decimal_charr connectionrhrrrsz"OracleDialect_cx_oracle.initializec Cs|p}|t}|dd|i|}|dd\}}}|d|||d|}|dkrltd|d} W5QRX| S) Nz begin :trans_id := dbms_transaction.local_transaction_id( TRUE ); end; trans_id.rzSELECT CASE BITAND(t.flag, POWER(2, 28)) WHEN 0 THEN 'READ COMMITTED' ELSE 'SERIALIZABLE' END AS isolation_level FROM v$transaction t WHERE (t.xidusn, t.xidslot, t.xidsqn) = ((:xidusn, :xidslot, :xidsqn)))xidusnxidslotxidsqnz"could not retrieve isolation levelr) r rstrexecutersplitZfetchoner r) rrr Zoutvalrrrrrowresultrrrget_isolation_levels&    z+OracleDialect_cx_oracle.get_isolation_levelc CsZt|dr|j}n|}|dkr&d|_n0d|_||}|d|W5QRXdS)NrZ AUTOCOMMITTFz$ALTER SESSION SET ISOLATION_LEVEL=%s)rrZ autocommitrollbackr r)rrlevelZdbapi_connectionr rrrset_isolation_levels  z+OracleDialect_cx_oracle.set_isolation_levelcsN|dd_jdkrJjjfdd_fdd_dS)NzSselect value from nls_session_parameters where parameter = 'NLS_NUMERIC_CHARACTERS'rrcs|jdSNrreplace _decimal_charr3)_detect_decimalrrrr~ s z>OracleDialect_cx_oracle._detect_decimal_char..cs|jdSrrr3)rArrrr~ s )Zexec_driver_sqlZscalarrrrArr)rrArrrs z,OracleDialect_cx_oracle._detect_decimal_charcCsd|kr||St|SdSr)rAr)rr4rrrrs z'OracleDialect_cx_oracle._detect_decimalcs@|jtddtddfdd}|S)z^establish the default outputtypehandler established at the connection level. T)r8Fcs||jkrz|jk rzjsdS|dkrF|dkrF|jjdj|jdS|rd|dkrd||||||S||||||Snjr|jjfkr|j k r|j k rt j rt jjjd}|jj||j|dS|jtj||jfjSnjrP|j j fkrPt j r6t jjjd}|jj||j|dS|jj||jfjSn(jrx|jfkrx|j||jSdS)Nr)rir)rrryr})NUMBERr@rrrrrrrPr\rYrrr rrrr text_typerrfrWreZ LONG_BINARY)r r#r$r%r&r'rr rZ float_handlerZnumber_handlerrrr)s    z\OracleDialect_cx_oracle._generate_connection_outputtype_handler..output_type_handler)rrKr+)rrrrr'_generate_connection_outputtype_handlersXz?OracleDialect_cx_oracle._generate_connection_outputtype_handlercs|fdd}|S)Ncs |_dSr)r)connrrr on_connectsz6OracleDialect_cx_oracle.on_connect..on_connect)r)rrrrrrs z"OracleDialect_cx_oracle.on_connectc sdt|j}dD]>}||krtjd|ddt||tt|||q|j}|dd}|sh|r|j }|r|t |}nd}|r|rt d|rd|i}|rd|i}j j|j|f|}n|j}|dk r||d <|jdk r|j|d <|jdk r|j|d <jdk r|d jfd d} t|d| t|d tt|dtt|d| g|fS)N)Zuse_ansirfzfcx_oracle dialect option %r should only be passed to create_engine directly, not within the URL stringr)r service_nameizI"service_name" option shouldn't be used with a "database" part of the urlZsiddsnpassworduserrcsPt|tjrHz t|}Wn(tk r@|}tj|YSX|Sn|SdSr)r0r string_typesr ValueErrorupperrrr)r4Zint_valrrrconvert_cx_oracle_constants  zOOracleDialect_cx_oracle.create_connect_args..convert_cx_oracle_constantmodeeventsZpurity)dictqueryr Zwarn_deprecatedZcoerce_kw_typeboolsetattrpopdatabaseportrr rrZmakedsnhostrusernamer setdefault) rurloptsoptrrrZmakedsn_kwargsrrrrrcreate_connect_argssT         z+OracleDialect_cx_oracle.create_connect_argscCstdd|jjdDS)Ncss|]}t|VqdSrrrrrrrszCOracleDialect_cx_oracle._get_server_version_info..r)rrrrrrrr_get_server_version_infosz0OracleDialect_cx_oracle._get_server_version_infocCsJ|j\}t||jj|jjfr.dt|kr.dSt|drB|jdkSdSdS)Nz not connectedTcode)i* i) i? i i\ F)argsr0rZInterfaceErrorZ DatabaseErrorrrr)rerr errorrrr is_disconnects   z%OracleDialect_cx_oracle.is_disconnectcCs"tddd}dd|ddfS)zcreate a two-phase transaction ID. this id will be passed to do_begin_twophase(), do_rollback_twophase(), do_commit_twophase(). its format is unspecified. rri4z%032x )randomrandint)rZid_rrr create_xidsz"OracleDialect_cx_oracle.create_xidcCs"t|trt|}|||dSr)r0rlistZ executemany)rr Z statementrcontextrrrdo_executemanys z&OracleDialect_cx_oracle.do_executemanycCs|jj|||jjd<dS)NZ cx_oracle_xid)rbegininfo)rrxidrrrdo_begin_twophases z)OracleDialect_cx_oracle.do_begin_twophasecCs|j}||jd<dS)Ncx_oracle_prepared)rpreparer)rrrrrrrdo_prepare_twophases z+OracleDialect_cx_oracle.do_prepare_twophaseFcCs||jdSr)Z do_rollbackr)rrr is_preparedrecoverrrrdo_rollback_twophasesz,OracleDialect_cx_oracle.do_rollback_twophasecCs<|s||jn&|rtd|jd}|r8||jdS)Nz*2pc recovery not implemented for cx_Oracler)Z do_commitrNotImplementedErrorr)rrrrrZ oci_preparedrrrdo_commit_twophases z*OracleDialect_cx_oracle.do_commit_twophasecs\jr|jdd|DnOracleDialect_cx_oracle.do_set_input_sizes..css |]\}}}|r||fVqdSrrrrrrrsz=OracleDialect_cx_oracle.do_set_input_sizes..c3s&|]\}}j|d|fVqdS)rN)r_encoderrrrrrrr"scSsi|]\}}||qSrrr!rrr 'sz>OracleDialect_cx_oracle.do_set_input_sizes..) positionalZ setinputsizesr)rr Zlist_of_tuplesrZ collectionrrrdo_set_input_sizess  z*OracleDialect_cx_oracle.do_set_input_sizescCs tddS)Nz5recover two phase query for cx_Oracle not implemented)rrrrrdo_recover_twophase)sz+OracleDialect_cx_oracle.do_recover_twophase)TTTrNN)N)TF)TF)^r,r-r.Zsupports_statement_cacherxZexecution_ctx_clsrpZstatement_compilerZsupports_sane_rowcountZsupports_sane_multi_rowcountZsupports_unicode_statementsrZuse_setinputsizesZdriverrbNumericr/ZFloatoracle BINARY_FLOATrH BINARY_DOUBLErJIntegerrrrKDaterL LargeBinaryrdBooleanZ_OracleBooleanZIntervalrkrlTextr]Stringr_rrZCHARrOrTrQrcr`LONGr^RAWrmrrUZNVARCHARrSrYrXrornrrZexecute_sequence_formatrr Zdeprecated_paramsrpropertyrr classmethodrrrrrrr9r:rArrrrr rrrrrrr$r%rjrrrhrrs  G   / j B   r)A__doc__rrr9r rrr'rrrr r r rbr Zenginer rrr*rr&r/rFr(rHr)rJrKr+rLr0rOrTrQZ NVARCHAR2rSrrUrYrXrrZr.r]r1r^r/r_rcr`r,rdrlrkr2rmrornrprxrrrrrrs\r           T #