o znh@s<dZddlZddlZddlZddlmZGdddeZdS)a Provide a SQLALchemy connector for the eGenix mxODBC commercial Python adapter for ODBC. This is not a free product, but eGenix provides SQLAlchemy with a license for use in continuous integration testing. This has been tested for use with mxODBC 3.1.2 on SQL Server 2005 and 2008, using the SQL Server Native driver. However, it is possible for this to be used on other database platforms. For more info on mxODBC, see http://www.egenix.com/ N) Connectorc@s|eZdZdZdZdZdZdZeddZ eddZ dd Z d d Z d d Z ddZddZddZdddZdddZdS)MxODBCConnectormxodbcFTcCs^|tj}|dkrddlm}|Sd|vrddlm}|S|dkr+ddlm}|Std) Nwin32r)Windowslinux)unixODBCdarwin)iODBCz'Unrecognized platform for mxODBC import)_load_mx_exceptionssysplatformmx.ODBCrr r ImportError)clsrModulerG/usr/local/lib/python3.10/dist-packages/sqlalchemy/connectors/mxodbc.pydbapi&s   zMxODBCConnector.dbapicCsddlmaddlmadS)z Import mxODBC exception classes into the module namespace, as if they had been imported normally. This is done here to avoid requiring all SQLAlchemy users to install mxODBC. r)InterfaceError)ProgrammingErrorN)rrr)rrrrr 7s z#MxODBCConnector._load_mx_exceptionscsfdd}|S)Ncs,jj|_jj|_jj|_|_dSN) rMIXED_STRINGFORMAT stringformatPYDATETIME_DATETIMEFORMATdatetimeformatDECIMAL_DECIMALFORMAT decimalformat_error_handler errorhandler)connselfrrconnectBs   z+MxODBCConnector.on_connect..connectr)r#r$rr"r on_connectAs zMxODBCConnector.on_connectcsddlmfdd}|S)zj Return a handler that adjusts mxODBC's raised Warnings to emit Python standard warnings. r)Warningcs2t|rtf|_tjt||dddS||)N)messagecategory stacklevel) issubclassr& __bases__warningswarnstr) connectioncursor errorclass errorvalue MxOdbcWarningrr error_handlerPs   z5MxODBCConnector._error_handler..error_handler) mx.ODBC.Errorr&)r#r6rr4rrJs   zMxODBCConnector._error_handlercCsD|jdd}||j|d}|dd|dd|f|fS)aReturn a tuple of \*args, \**kwargs for creating a connection. The mxODBC 3.x connection constructor looks like this: connect(dsn, user='', password='', clear_auto_commit=1, errorhandler=None) This method translates the values in the provided uri into args and kwargs needed to instantiate an mxODBC Connection. The arg 'errorhandler' is not used by SQLAlchemy and will not be populated. user)usernamehostportNdatabase)translate_connect_argsupdatequerypop)r#urloptsargsrrrcreate_connect_args[s      z#MxODBCConnector.create_connect_argscCs8t||jjr dt|vSt||jjrdt|vSdS)Nzconnection already closedz[08S01]F) isinstancerrr/Error)r#er0r1rrr is_disconnectqs   zMxODBCConnector.is_disconnectc Csd|j}g}td}||ddD]}z |t|Wqty-||Yqwt|S)Nz[.\-]r) r0recompilesplitgetinfoappendint ValueErrortuple)r#r0 dbapi_conversionrnrrr_get_server_version_info{s  z(MxODBCConnector._get_server_version_infocCs&|r|jdd}|durdSdSdS)Nnative_odbc_executeautoTF)execution_optionsget)r#contextrWrrr _get_directs zMxODBCConnector._get_directNcC|j||||ddSN)direct) executemanyr\r#r1 statement parametersr[rrrdo_executemanys  zMxODBCConnector.do_executemanycCr]r^)executer\rarrr do_executeszMxODBCConnector.do_executer)__name__ __module__ __qualname__driversupports_sane_multi_rowcountsupports_unicode_statementssupports_unicode_bindssupports_native_decimal classmethodrr r%rrDrHrVr\rdrfrrrrrs$      r)__doc__rJr r-rrrrrrs