<s> """<STR_LIT>""" <EOL> import decimal <EOL> import re <EOL> from sqlalchemy import sql , types as sqltypes , util <EOL> from sqlalchemy . connectors . zxJDBC import ZxJDBCConnector <EOL> from sqlalchemy . dialects . oracle . base import ( OracleCompiler , <EOL> OracleDialect , <EOL> OracleExecutionContext ) <EOL> from sqlalchemy . engine import result as _result <EOL> from sqlalchemy . sql import expression <EOL> import collections <EOL> SQLException = zxJDBC = None <EOL> class _ZxJDBCDate ( sqltypes . Date ) : <EOL> def result_processor ( self , dialect , coltype ) : <EOL> def process ( value ) : <EOL> if value is None : <EOL> return None <EOL> else : <EOL> return value . date ( ) <EOL> return process <EOL> class _ZxJDBCNumeric ( sqltypes . Numeric ) : <EOL> def result_processor ( self , dialect , coltype ) : <EOL> if self . asdecimal : <EOL> def process ( value ) : <EOL> if isinstance ( value , decimal . Decimal ) : <EOL> return value <EOL> else : <EOL> return decimal . Decimal ( str ( value ) ) <EOL> else : <EOL> def process ( value ) : <EOL> if isinstance ( value , decimal . Decimal ) : <EOL> return float ( value ) <EOL> else : <EOL> return value <EOL> return process <EOL> class OracleCompiler_zxjdbc ( OracleCompiler ) : <EOL> def returning_clause ( self , stmt , returning_cols ) : <EOL> self . returning_cols = list ( <EOL> expression . _select_iterables ( returning_cols ) ) <EOL> columns = [ self . process ( c , within_columns_clause = False ) <EOL> for c in self . returning_cols ] <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> self . returning_parameters = [ ] <EOL> binds = [ ] <EOL> for i , col in enumerate ( self . returning_cols ) : <EOL> dbtype = col . type . dialect_impl ( <EOL> self . dialect ) . get_dbapi_type ( self . dialect . dbapi ) <EOL> self . returning_parameters . append ( ( i + <NUM_LIT:1> , dbtype ) ) <EOL> bindparam = sql . bindparam ( <EOL> "<STR_LIT>" % i , value = ReturningParam ( dbtype ) ) <EOL> self . binds [ bindparam . key ] = bindparam <EOL> binds . append ( <EOL> self . bindparam_string ( self . _truncate_bindparam ( bindparam ) ) ) <EOL> return '<STR_LIT>' + '<STR_LIT:U+002CU+0020>' . join ( columns ) + "<STR_LIT>" + "<STR_LIT:U+002CU+0020>" . join ( binds ) <EOL> class OracleExecutionContext_zxjdbc ( OracleExecutionContext ) : <EOL> def pre_exec ( self ) : <EOL> if hasattr ( self . compiled , '<STR_LIT>' ) : <EOL> self . statement = self . cursor . prepare ( self . statement ) <EOL> def get_result_proxy ( self ) : <EOL> if hasattr ( self . compiled , '<STR_LIT>' ) : <EOL> rrs = None <EOL> try : <EOL> try : <EOL> rrs = self . statement . __statement__ . getReturnResultSet ( ) <EOL> next ( rrs ) <EOL> except SQLException as sqle : <EOL> msg = '<STR_LIT>' % ( <EOL> sqle . getMessage ( ) , sqle . getErrorCode ( ) ) <EOL> if sqle . getSQLState ( ) is not None : <EOL> msg += '<STR_LIT>' % sqle . getSQLState ( ) <EOL> raise zxJDBC . Error ( msg ) <EOL> else : <EOL> row = tuple ( <EOL> self . cursor . datahandler . getPyObject ( <EOL> rrs , index , dbtype ) <EOL> for index , dbtype in <EOL> self . compiled . returning_parameters ) <EOL> return ReturningResultProxy ( self , row ) <EOL> finally : <EOL> if rrs is not None : <EOL> try : <EOL> rrs . close ( ) <EOL> except SQLException : <EOL> pass <EOL> self . statement . close ( ) <EOL> return _result . ResultProxy ( self ) <EOL> def create_cursor ( self ) : <EOL> cursor = self . _dbapi_connection . cursor ( ) <EOL> cursor . datahandler = self . dialect . DataHandler ( cursor . datahandler ) <EOL> return cursor <EOL> class ReturningResultProxy ( _result . FullyBufferedResultProxy ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , context , returning_row ) : <EOL> self . _returning_row = returning_row <EOL> super ( ReturningResultProxy , self ) . __init__ ( context ) <EOL> def _cursor_description ( self ) : <EOL> ret = [ ] <EOL> for c in self . context . compiled . returning_cols : <EOL> if hasattr ( c , '<STR_LIT:name>' ) : <EOL> ret . append ( ( c . name , c . type ) ) <EOL> else : <EOL> ret . append ( ( c . anon_label , c . type ) ) <EOL> return ret <EOL> def _buffer_rows ( self ) : <EOL> return collections . deque ( [ self . _returning_row ] ) <EOL> class ReturningParam ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , type ) : <EOL> self . type = type <EOL> def __eq__ ( self , other ) : <EOL> if isinstance ( other , ReturningParam ) : <EOL> return self . type == other . type <EOL> return NotImplemented <EOL> def __ne__ ( self , other ) : <EOL> if isinstance ( other , ReturningParam ) : <EOL> return self . type != other . type <EOL> return NotImplemented <EOL> def __repr__ ( self ) : <EOL> kls = self . __class__ <EOL> return '<STR_LIT>' % ( <EOL> kls . __module__ , kls . __name__ , id ( self ) , self . type ) <EOL> class OracleDialect_zxjdbc ( ZxJDBCConnector , OracleDialect ) : <EOL> jdbc_db_name = '<STR_LIT>' <EOL> jdbc_driver_name = '<STR_LIT>' <EOL> statement_compiler = OracleCompiler_zxjdbc <EOL> execution_ctx_cls = OracleExecutionContext_zxjdbc <EOL> colspecs = util . update_copy ( <EOL> OracleDialect . colspecs , <EOL> { <EOL> sqltypes . Date : _ZxJDBCDate , <EOL> sqltypes . Numeric : _ZxJDBCNumeric <EOL> } <EOL> ) <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( OracleDialect_zxjdbc , self ) . __init__ ( * args , ** kwargs ) <EOL> global SQLException , zxJDBC <EOL> from java . sql import SQLException <EOL> from com . ziclix . python . sql import zxJDBC <EOL> from com . ziclix . python . sql . handler import OracleDataHandler <EOL> class OracleReturningDataHandler ( OracleDataHandler ) : <EOL> """<STR_LIT>""" <EOL> def setJDBCObject ( self , statement , index , object , dbtype = None ) : <EOL> if type ( object ) is ReturningParam : <EOL> statement . registerReturnParameter ( index , object . type ) <EOL> elif dbtype is None : <EOL> OracleDataHandler . setJDBCObject ( <EOL> self , statement , index , object ) <EOL> else : <EOL> OracleDataHandler . setJDBCObject ( <EOL> self , statement , index , object , dbtype ) <EOL> self . DataHandler = OracleReturningDataHandler <EOL> def initialize ( self , connection ) : <EOL> super ( OracleDialect_zxjdbc , self ) . initialize ( connection ) <EOL> self . implicit_returning = connection . connection . driverversion >= '<STR_LIT>' <EOL> def _create_jdbc_url ( self , url ) : <EOL> return '<STR_LIT>' % ( <EOL> url . host , url . port or <NUM_LIT> , url . database ) <EOL> def _get_server_version_info ( self , connection ) : <EOL> version = re . search ( <EOL> r'<STR_LIT>' , connection . connection . dbversion ) . group ( <NUM_LIT:1> ) <EOL> return tuple ( int ( x ) for x in version . split ( '<STR_LIT:.>' ) ) <EOL> dialect = OracleDialect_zxjdbc </s>
