Hacked By AnonymousFox

Current Path : /opt/cloudlinux/venv/lib64/python3.11/site-packages/sqlalchemy/dialects/mssql/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib64/python3.11/site-packages/sqlalchemy/dialects/mssql/__pycache__/pyodbc.cpython-311.pyc

�

�܋f�?���dZddlZddlZddlZddlZddlmZddlmZddlmZddlm	Z	ddlm
Z
d	d
lmZd	dlm
Zd	dlmZd	d
lmZGd�de��ZGd�deej��ZGd�deej��ZGd�de��ZGd�de��ZGd�dee
��ZGd�dee��ZGd�de	��ZGd�dee��ZeZdS) a�
.. dialect:: mssql+pyodbc
    :name: PyODBC
    :dbapi: pyodbc
    :connectstring: mssql+pyodbc://<username>:<password>@<dsnname>
    :url: http://pypi.python.org/pypi/pyodbc/

Connecting to PyODBC
--------------------

The URL here is to be translated to PyODBC connection strings, as
detailed in `ConnectionStrings <https://code.google.com/p/pyodbc/wiki/ConnectionStrings>`_.

DSN Connections
^^^^^^^^^^^^^^^

A DSN connection in ODBC means that a pre-existing ODBC datasource is
configured on the client machine.   The application then specifies the name
of this datasource, which encompasses details such as the specific ODBC driver
in use as well as the network address of the database.   Assuming a datasource
is configured on the client, a basic DSN-based connection looks like::

    engine = create_engine("mssql+pyodbc://scott:tiger@some_dsn")

Which above, will pass the following connection string to PyODBC::

    dsn=mydsn;UID=user;PWD=pass

If the username and password are omitted, the DSN form will also add
the ``Trusted_Connection=yes`` directive to the ODBC string.

Hostname Connections
^^^^^^^^^^^^^^^^^^^^

Hostname-based connections are also supported by pyodbc.  These are often
easier to use than a DSN and have the additional advantage that the specific
database name to connect towards may be specified locally in the URL, rather
than it being fixed as part of a datasource configuration.

When using a hostname connection, the driver name must also be specified in the
query parameters of the URL.  As these names usually have spaces in them, the
name must be URL encoded which means using plus signs for spaces::

    engine = create_engine("mssql+pyodbc://scott:tiger@myhost:port/databasename?driver=SQL+Server+Native+Client+10.0")

Other keywords interpreted by the Pyodbc dialect to be passed to
``pyodbc.connect()`` in both the DSN and hostname cases include:
``odbc_autotranslate``, ``ansi``, ``unicode_results``, ``autocommit``,
``authentication`` (e.g., ``authentication=ActiveDirectoryIntegrated``).
Note that in order for the dialect to recognize these keywords
(including the ``driver`` keyword above) they must be all lowercase.

Pass through exact Pyodbc string
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

A PyODBC connection string can also be sent in pyodbc's format directly, as
specified in `ConnectionStrings
<https://code.google.com/p/pyodbc/wiki/ConnectionStrings>`_ into the driver
using the parameter ``odbc_connect``.  The delimeters must be URL encoded, as
illustrated below using ``urllib.parse.quote_plus``::

    import urllib
    params = urllib.parse.quote_plus("DRIVER={SQL Server Native Client 10.0};SERVER=dagger;DATABASE=test;UID=user;PWD=password")

    engine = create_engine("mssql+pyodbc:///?odbc_connect=%s" % params)

Pyodbc Pooling / connection close behavior
------------------------------------------

PyODBC uses internal `pooling
<https://github.com/mkleehammer/pyodbc/wiki/The-pyodbc-Module#pooling>`_ by
default, which means connections will be longer lived than they are within
SQLAlchemy itself.  As SQLAlchemy has its own pooling behavior, it is often
preferable to disable this behavior.  This behavior can only be disabled
globally at the PyODBC module level, **before** any connections are made::

    import pyodbc

    pyodbc.pooling = False

    # don't use the engine before pooling is set to False
    engine = create_engine("mssql+pyodbc://user:pass@dsn")

If this variable is left at its default value of ``True``, **the application
will continue to maintain active database connections**, even when the
SQLAlchemy engine itself fully discards a connection or if the engine is
disposed.

.. seealso::

    `pooling <https://github.com/mkleehammer/pyodbc/wiki/The-pyodbc-Module#pooling>`_ -
    in the PyODBC documentation.

Driver / Unicode Support
-------------------------

PyODBC works best with Microsoft ODBC drivers, particularly in the area
of Unicode support on both Python 2 and Python 3.

Using the FreeTDS ODBC drivers on Linux or OSX with PyODBC is **not**
recommended; there have been historically many Unicode-related issues
in this area, including before Microsoft offered ODBC drivers for Linux
and OSX.   Now that Microsoft offers drivers for all platforms, for
PyODBC support these are recommended.  FreeTDS remains relevant for
non-ODBC drivers such as pymssql where it works very well.


Rowcount Support
----------------

Pyodbc only has partial support for rowcount.  See the notes at
:ref:`mssql_rowcount_versioning` for important notes when using ORM
versioning.

.. _mssql_pyodbc_fastexecutemany:

Fast Executemany Mode
---------------------

The Pyodbc driver has added support for a "fast executemany" mode of execution
which greatly reduces round trips for a DBAPI ``executemany()`` call when using
Microsoft ODBC drivers, for **limited size batches that fit in memory**.  The
feature is enabled by setting the flag ``.fast_executemany`` on the DBAPI
cursor when an executemany call is to be used.   The SQLAlchemy pyodbc SQL
Server dialect supports setting this flag automatically when the
``.fast_executemany`` flag is passed to
:func:`_sa.create_engine` ; note that the ODBC driver must be the Microsoft
driver in order to use this flag::

    engine = create_engine(
        "mssql+pyodbc://scott:tiger@mssql2017:1433/test?driver=ODBC+Driver+13+for+SQL+Server",
        fast_executemany=True)

.. warning:: The pyodbc fast_executemany mode **buffers all rows in memory** and is
   not compatible with very large batches of data.    A future version of SQLAlchemy
   may support this flag as a per-execution option instead.

.. versionadded:: 1.3

.. seealso::

    `fast executemany <https://github.com/mkleehammer/pyodbc/wiki/Features-beyond-the-DB-API#fast_executemany>`_
    - on github


�N�)�BINARY)�DATETIMEOFFSET)�	MSDialect)�MSExecutionContext)�	VARBINARY�)�exc)�types)�util)�PyODBCConnectorc�.��eZdZdZ�fd�Zd�Zd�Z�xZS)�_ms_numeric_pyodbcz�Turns Decimals with adjusted() < 0 or > 7 into strings.

    The routines here are needed for older pyodbc versions
    as well as current mxODBC versions.

    c�z����tt����|���|js�S��fd�}|S)Nc����jrdt|tj��rJ|���}|dkr��|��S|dkr��|��S�r�|��S|S)Nr�)�	asdecimal�
isinstance�decimal�Decimal�adjusted�_small_dec_to_string�_large_dec_to_string)�valuer�self�
super_processs  ���s/builddir/build/BUILD/cloudlinux-venv-1.0.6/venv/lib64/python3.11/site-packages/sqlalchemy/dialects/mssql/pyodbc.py�processz2_ms_numeric_pyodbc.bind_processor.<locals>.process�s�����~�
<�*�U�G�O�"D�"D�
<� �>�>�+�+���a�<�<��4�4�U�;�;�;���\�\��4�4�U�;�;�;��
�$�}�U�+�+�+���)�superr�bind_processor�_need_decimal_fix)r�dialectrr�	__class__s`  @�rr!z!_ms_numeric_pyodbc.bind_processor�sY������0�$�7�7�F�F�w�O�O�
��(�	!� � �	�	�	�	�	�	��rc���|dkrdpd�ddt|�����dz
z�d�d�|���dD������S)Nr�-�z0.�0rc�,�g|]}t|����S���str)�.0�nints  r�
<listcomp>z;_ms_numeric_pyodbc._small_dec_to_string.<locals>.<listcomp>�s��?�?�?�4�S��Y�Y�?�?�?r)�absr�join�as_tuple)rrs  rrz'_ms_numeric_pyodbc._small_dec_to_string�su��
�Q�Y�
�3�
$�"�
$�
$��3�u�~�~�'�'�(�(�1�,�-�-��G�G�?�?�5�>�>�+;�+;�A�+>�?�?�?�@�@�@�
�	
rc���|���d}dt|��vrV|dkrdpd�d�d�|D�����d|���t	|��dz
z
z��}n�t	|��dz
|���kr�|dkrdpd�d�d�|D��d|���dz����d	d�d
�|D��|���dzd�����}nH|dkrdpd�d�d�|D��d|���dz�����}|S)Nr�Err&r'c�,�g|]}t|����Sr*r+�r-�ss  rr/z;_ms_numeric_pyodbc._large_dec_to_string.<locals>.<listcomp>�s��.�.�.�A��Q���.�.�.rr(c�,�g|]}t|����Sr*r+r6s  rr/z;_ms_numeric_pyodbc._large_dec_to_string.<locals>.<listcomp>����2�2�2��S��V�V�2�2�2r�.c�,�g|]}t|����Sr*r+r6s  rr/z;_ms_numeric_pyodbc._large_dec_to_string.<locals>.<listcomp>�r9rc�,�g|]}t|����Sr*r+r6s  rr/z;_ms_numeric_pyodbc._large_dec_to_string.<locals>.<listcomp>�r9r)r2r,r1r�len)rr�_int�results    rrz'_ms_numeric_pyodbc._large_dec_to_string�s����~�~����"���#�e�*�*������"�s�(�b�(����.�.��.�.�.�/�/�/��u�~�~�'�'�3�t�9�9�q�=�9�:�:��F�F��D�	�	�A�
����!1�!1�1�1��Q�Y�&�3�,�"�,��G�G�2�2�T�2�2�2�1�u�~�~�7G�7G�!�7K�3K�L�M�M�M�M��G�G�2�2�T�2�2�2�5�>�>�3C�3C�a�3G�3I�3I�J�K�K�K�����Q�Y�&�3�,�"�,��G�G�2�2�T�2�2�2�1�u�~�~�7G�7G�!�7K�3K�L�M�M�M����
r)�__name__�
__module__�__qualname__�__doc__r!rr�
__classcell__�r$s@rrr�s`��������������2
�
�
�������rrc��eZdZdS)�_MSNumeric_pyodbcN�r@rArBr*rrrGrG���������DrrGc��eZdZdS)�_MSFloat_pyodbcNrHr*rrrKrK�rIrrKc��eZdZdZd�ZdS)�_ms_binary_pyodbcz�Wraps binary values in dialect-specific Binary wrapper.
    If the value is null, return a pyodbc-specific BinaryNull
    object to prevent pyODBC [and FreeTDS] from defaulting binary
    NULL types to SQLWCHAR and causing implicit conversion errors.
    c�@����j�dS�jj���fd�}|S)Nc�6��|��|��S�jjS�N)�dbapi�
BinaryNull)r�DBAPIBinaryr#s ��rrz1_ms_binary_pyodbc.bind_processor.<locals>.processs&���� �"�{�5�)�)�)��}�/�/r)rQ�Binary)rr#rrSs ` @rr!z _ms_binary_pyodbc.bind_processor�s@�����=� ��4��m�*��	0�	0�	0�	0�	0�	0��rN)r@rArBrCr!r*rrrMrM�s-��������
�
�
�
�
rrMc��eZdZd�ZdS)�_ODBCDateTimeOffsetc��d�}|S)Nc��|�dSt|tj��r|S|�d��}t	jdd|��}|S)Nz%Y-%m-%d %H:%M:%S.%f %zz([\+\-]\d{2})([\d\.]+)$z\1:\2)rr�string_types�strftime�re�sub)r�
dto_strings  rrz3_ODBCDateTimeOffset.bind_processor.<locals>.processs\���}��t��E�4�#4�5�5�
"���#�^�^�,E�F�F�
� �V�.��*���
�"�!rr*)rr#rs   rr!z"_ODBCDateTimeOffset.bind_processors��	"�	"�	"�"�rN)r@rArBr!r*rrrVrV
s#����������rrVc��eZdZdS)�_VARBINARY_pyodbcNrHr*rrr_r_ rIrr_c��eZdZdS)�_BINARY_pyodbcNrHr*rrrara$rIrrac�,��eZdZdZ�fd�Z�fd�Z�xZS)�MSExecutionContext_pyodbcFc����tt|�����|jr?|jjr5t
|jd��rd|_|xj	dz
c_	dSdSdSdS)a�where appropriate, issue "select scope_identity()" in the same
        statement.

        Background on why "scope_identity()" is preferable to "@@identity":
        http://msdn.microsoft.com/en-us/library/ms190315.aspx

        Background on why we attempt to embed "scope_identity()" into the same
        statement as the INSERT:
        http://code.google.com/p/pyodbc/wiki/FAQs#How_do_I_retrieve_autogenerated/identity_values?

        rTz; select scope_identity()N)
r rc�pre_exec�_select_lastrowidr#�use_scope_identityr=�
parameters�_embedded_scope_identity�	statement)rr$s �rrez"MSExecutionContext_pyodbc.pre_exec+s����	�'��.�.�7�7�9�9�9�

�"�	:���/�	:��D�O�A�&�'�'�	:�
-1�D�)��N�N�9�9�N�N�N�N�	:�	:�	:�	:�	:�	:rc�H��|jrr		|j���d}n4#|jjj$r|j���YnwxYw�Ut|d��|_dStt|�����dS)NTr)ri�cursor�fetchallr#rQ�Error�nextset�int�
_lastrowidr rc�	post_exec)r�rowr$s  �rrrz#MSExecutionContext_pyodbc.post_execEs�����(�	?�	
*�*��+�.�.�0�0��3�C����|�)�/�*�*�*��K�'�'�)�)�)�)�)�*����
	
*�"�#�a�&�k�k�D�O�O�O��+�T�2�2�<�<�>�>�>�>�>s�+�-A�A)r@rArBrirerrrDrEs@rrcrc(sW�������$��:�:�:�:�:�4?�?�?�?�?�?�?�?�?rrcc����eZdZdZeZejej	e
jee
j
eeeeeeee
jee
jei��Z		d	�fd�	Z�fd�Z�fd�Zd�Zd
�fd�	Z�fd�Z�xZS)�MSDialect_pyodbcFNc�4��d|vr|�d��|_tt|��jdi|��|jo |jot|jjd��|_|jo|�	��dk|_
||_dS)N�description_encodingro)�r�r*)�poprwr ru�__init__rgrQ�hasattr�Cursor�_dbapi_versionr"�fast_executemany)rrwr�paramsr$s    �rr{zMSDialect_pyodbc.__init__qs����"�V�+�+�(.�
�
�3I�(J�(J�D�%�.����%�%�.�8�8��8�8�8��#�
6��
�
6���
�)�9�5�5�	
��
"&��"
��0C�0C�0E�0E�I
�1
���
!1����rc���	|�d��}g}tjd��}|�|��D]5}	|�t|�����&#t$rY�2wxYwt|��S#tj	$r-tt|���|d���cYSwxYw)Nz8SELECT CAST(SERVERPROPERTY('ProductVersion') AS VARCHAR)z[.\-]F)�allow_chars)
�scalarr[�compile�split�appendrp�
ValueError�tupler
�
DBAPIErrorr ru�_get_server_version_info)r�
connection�raw�version�r�nr$s      �rr�z)MSDialect_pyodbc._get_server_version_info�s����	"��#�#�J���C��G��
�8�$�$�A��W�W�S�\�\�
�
����N�N�3�q�6�6�*�*�*�*��!�����D�������>�>�!���~�	�	�	��)�4�0�0�I�I���J���
�
�
�		���s#�B�"A)�)
A6�5A6�9C�Cc�f����tt���������fd�}|S)Nc�L�����|����|��dSrP)�_setup_timestampoffset_type)�connr�super_s ��r�
on_connectz/MSDialect_pyodbc.on_connect.<locals>.on_connect�s0����!���t�����,�,�T�2�2�2�2�2r)r rur�)rr�r�r$s` @�rr�zMSDialect_pyodbc.on_connect�sG������'��.�.�9�9�;�;��	3�	3�	3�	3�	3�	3��rc�<�d�}d}|�||��dS)Nc� �tjd|��}tj|d|d|d|d|d|d|dd	ztjtj|d
|d�������S)
Nz<6hI2hrrrxr	���i�rry)�hours�minutes)�struct�unpack�datetimer�timezone�	timedelta)�	dto_value�tups  r�_handle_datetimeoffsetzLMSDialect_pyodbc._setup_timestampoffset_type.<locals>._handle_datetimeoffset�s����-��)�4�4�C��$��A���A���A���A���A���A���A��$���
��&�S��V�S��V�D�D�D�����
rie���)�add_output_converter)rr�r��odbc_SQL_SS_TIMESTAMPOFFSETs    rr�z,MSDialect_pyodbc._setup_timestampoffset_type�sA��
	�
	�
	�'+�#��'�'�'�)?�	
�	
�	
�	
�	
rc�|��|jrd|_tt|���||||���dS)NT)�context)rr ru�do_executemany)rrlrjrhr�r$s     �rr�zMSDialect_pyodbc.do_executemany�sQ���� �	+�&*�F�#�
���%�%�4�4��I�z�7�	5�	
�	
�	
�	
�	
rc���t||jj��r|jd}|dvrdSt	t
|���|||��S)Nr>
�01000�01002�08001�08003�08007�08S01�08S02�10054�HY010�HYT00T)rrQrn�argsr ru�
is_disconnect)r�er�rl�coder$s     �rr�zMSDialect_pyodbc.is_disconnect�sh����a���)�*�*�	��6�!�9�D������t��%�t�,�,�:�:�
�z�6�
�
�	
r)NFrP)r@rArB� supports_sane_rowcount_returningrc�execution_ctx_clsr�update_copyr�colspecs�sqltypes�NumericrG�FloatrKrrarrVrr_�LargeBinaryr{r�r�r�r�r�rDrEs@rruruZs�������(-�$�1���t������/��N�O��N��/�
�(��� 1�� �"3�	
���H�";@�1�1�1�1�1�1�$"�"�"�"�"�0	�	�	�	�	�
�
�
�,
�
�
�
�
�
�
�
�
�
�
�
�
�
�
rru)rCr�rr[r��baserrrrrr'r
rr�r�connectors.pyodbcr
�objectrr�rGr�rKrMrVr_rarcrur#r*rr�<module>r�s~��Q�Q�f��������	�	�	�	�
�
�
�
������� � � � � � �������$�$�$�$�$�$�������������!�!�!�!�!�!�������0�0�0�0�0�0�=�=�=�=�=��=�=�=�@	�	�	�	�	�*�H�,<�	�	�	�	�	�	�	�	�(�(�.�	�	�	����������.�����.����,	�	�	�	�	�)�9�	�	�	�	�	�	�	�	�&��	�	�	�/?�/?�/?�/?�/?� 2�/?�/?�/?�d{
�{
�{
�{
�{
��	�{
�{
�{
�|���r

Hacked By AnonymousFox1.0, Coded By AnonymousFox