관리-도구
편집 파일: pyodbc.cpython-37.pyc
B ��4]�/ � @ s d Z ddlZddlZddlmZ ddlmZ ddlmZ ddlmZ dd lm Z dd lm Z ddlmZ ddl mZ G d d� de�ZG dd� deej�ZG dd� deej�ZG dd� de�ZG dd� dee�ZG dd� dee�ZG dd� de�ZG dd� 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-based connection is **preferred** overall when using ODBC. 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 **not preferred**, however are supported. The ODBC driver name must be explicitly specified:: engine = create_engine("mssql+pyodbc://scott:tiger@myhost:port/databasename?driver=SQL+Server+Native+Client+10.0") .. versionchanged:: 1.0.0 Hostname-based PyODBC connections now require the SQL Server driver name specified explicitly. SQLAlchemy cannot choose an optimal default here as it varies based on platform and installed drivers. 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``. Pass through exact Pyodbc string ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ A PyODBC connection string can also be sent exactly 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 escaped, however, 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) 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. 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:`.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) .. versionadded:: 1.3 .. seealso:: `fast executemany <https://github.com/mkleehammer/pyodbc/wiki/Features-beyond-the-DB-API#fast_executemany>`_ - on github � N� )�BINARY)� MSDialect)�MSExecutionContext)� VARBINARY� )�exc)�types)�util)�PyODBCConnectorc s0 e Zd ZdZ� fdd�Zdd� Zdd� Z� ZS )�_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 s, t t� ��|��|js�S � �fdd�}|S )Nc sR � j r>t| tj�r>| �� }|dk r,� �| �S |dkr>� �| �S �rJ�| �S | S d S )Nr � )Z asdecimal� isinstance�decimalZDecimal�adjusted�_small_dec_to_string�_large_dec_to_string)�valuer )�self� super_process� �S/opt/alt/python37/lib64/python3.7/site-packages/sqlalchemy/dialects/mssql/pyodbc.py�process� s z2_ms_numeric_pyodbc.bind_processor.<locals>.process)�superr �bind_processor�_need_decimal_fix)r �dialectr )� __class__)r r r r � s z!_ms_numeric_pyodbc.bind_processorc C sB d|dk rdpddt |�� �d d�dd� |�� d D ��f S ) Nz%s0.%s%sr �-� �0r c S s g | ]}t |��qS r )�str)�.0Znintr r r � <listcomp>� s z;_ms_numeric_pyodbc._small_dec_to_string.<locals>.<listcomp>)�absr �join�as_tuple)r r r r r r � s z'_ms_numeric_pyodbc._small_dec_to_stringc C s |� � d }dt|�krXd|dk r&dp(dd�dd� |D ��d |�� t|�d f }n�t|�d |�� kr�d |dk rzdp|dd�dd� |D �d|�� d � �d�dd� |D �|�� d d � �f }n8d |dk r�dp�dd�dd� |D �d|�� d � �f }|S )Nr �Ez%s%s%sr r r c S s g | ]}t |��qS r )r! )r"