
    +h                     N    d Z ddlZddlZddlZddlmZ ddlmZ  G d de      Zy)	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 https://www.egenix.com/

.. deprecated:: 1.4 The mxODBC DBAPI is deprecated and will be removed
   in a future version. Please use one of the supported DBAPIs to
   connect to mssql.

    N   )	Connector   )warn_deprecatedc                   t    e Zd ZdZdZdZdZdZed        Z	ed        Z
d Zd Zd Zd	 Zd
 Zd ZddZddZy)MxODBCConnectormxodbcFTc                     | j                          t        j                  }|dk(  rddlm} n"d|v rddlm} n|dk(  rddlm} nt        d      t        d	d
       |S )Nwin32r   )Windowslinux)unixODBCdarwin)iODBCz'Unrecognized platform for mxODBC importzThe mxODBC DBAPI is deprecated and will be removedin a future version. Please use one of the supported DBAPIs toconnect to mssql.z1.4)version)	_load_mx_exceptionssysplatformmx.ODBCr   r   r   ImportErrorr   )clsr   Modules      O/var/www/html/venv/lib/python3.12/site-packages/sqlalchemy/connectors/mxodbc.pydbapizMxODBCConnector.dbapi+   s_     	!<<w1 2!/GHH  		
     c                     ddl ma ddl ma y)zImport 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)r   r   r   )r   s    r   r   z#MxODBCConnector._load_mx_exceptionsC   s
     	+,r   c                       fd}|S )Nc                     j                   j                  | _        j                   j                  | _        j                   j
                  | _        j                         | _        y N)	r   MIXED_STRINGFORMATstringformatPYDATETIME_DATETIMEFORMATdatetimeformatDECIMAL_DECIMALFORMATdecimalformat_error_handlererrorhandler)connselfs    r   connectz+MxODBCConnector.on_connect.<locals>.connectN   sJ     $

 = =D"&**"F"FD!%!A!AD $ 3 3 5Dr    )r+   r,   s   ` r   
on_connectzMxODBCConnector.on_connectM   s    	6 r   c                     ddl m fd}|S )ziReturn a handler that adjusts mxODBC's raised Warnings to
        emit Python standard warnings.
        r   )Warningc                     t        |      r.t        f|_        t        j                  t        |      |d       y  ||      )Nr   )messagecategory
stacklevel)
issubclassr0   	__bases__warningswarnstr)
connectioncursor
errorclass
errorvalueMxOdbcWarnings       r   error_handlerz5MxODBCConnector._error_handler.<locals>.error_handler\   s;    *m4(/z
$
OjQ !,,r   )mx.ODBC.Errorr0   )r+   r?   r>   s     @r   r(   zMxODBCConnector._error_handlerV   s     	;	- r   c                     |j                  d      }|j                  |j                         |j                  d      }|j                  dd       |j                  dd       |f|fS )a  Return 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)usernamehostportNdatabase)translate_connect_argsupdatequerypop)r+   urloptsargss       r   create_connect_argsz#MxODBCConnector.create_connect_argsg   s]     ))6):CIIxxT"w}r   c                     t        || j                  j                        rdt        |      v S t        || j                  j                        rdt        |      v S y)Nzconnection already closedz[08S01]F)
isinstancer   r   r9   Error)r+   er:   r;   s       r   is_disconnectzMxODBCConnector.is_disconnect}   sM     a445.#a&884::++,A&&r   c                 $   |j                   }g }t        j                  d      }|j                  |j	                  d      d         D ]  }	 |j                  t        |              t        |      S # t        $ r |j                  |       Y Gw xY w)Nz[.\-]   r   )	r:   recompilesplitgetinfoappendint
ValueErrortuple)r+   r:   	dbapi_conr   rns         r   _get_server_version_infoz(MxODBCConnector._get_server_version_info   s     ))	JJx **2.q12 	"A"s1v&	"
 W~  "q!"s   A22BBc                 P    |r$|j                   j                  dd      }|du rdS dS y)Nnative_odbc_executeautoTF)execution_optionsget)r+   contextrc   s      r   _get_directzMxODBCConnector._get_direct   s8    ")";";"?"?%v#
 0475ATAr   Nc                 J    |j                  ||| j                  |             y N)direct)executemanyrh   r+   r;   	statement
parametersrg   s        r   do_executemanyzMxODBCConnector.do_executemany   s'    z$*:*:7*C 	 	
r   c                 J    |j                  ||| j                  |             y rj   )executerh   rm   s        r   
do_executezMxODBCConnector.do_execute   s    y*T5E5Eg5NOr   r!   )__name__
__module____qualname__driversupports_sane_multi_rowcountsupports_unicode_statementssupports_unicode_bindssupports_native_decimalclassmethodr   r   r.   r(   rN   rS   ra   rh   rp   rs   r-   r   r   r   r   "   sn    F#( "&!" . - -",	

Pr   r   )	__doc__rV   r   r7    r   utilr   r   r-   r   r   <module>r      s+   $ 
 
   "DPi DPr   