File: //opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/pyodbc.pyo
�
��4]c @ sm d Z d d l Z d d l Z d d l m Z d d l m Z d d l m Z d d l m Z d d l m Z d d
l m
Z d d l m Z d d l
m Z d
e f d � � YZ d e e j f d � � YZ d e e j f d � � YZ d e f d � � YZ d e e f d � � YZ d e e f d � � YZ d e f d � � YZ d e e f d � � YZ e Z d S( s
.. 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
i����Ni ( t BINARY( t MSDialect( t MSExecutionContext( t VARBINARYi ( t exc( t types( t util( t PyODBCConnectort _ms_numeric_pyodbcc B s) e Z d Z d � Z d � Z d � Z RS( s� 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 � � j | � � | j s% � S� � f d � } | S( Nc st � j r\ t | t j � r\ | j � } | d k r@ � j | � S| d k r\ � j | � Sn � rl � | � S| Sd S( Ni i ( t asdecimalt
isinstancet decimalt Decimalt adjustedt _small_dec_to_stringt _large_dec_to_string( t valueR
( t selft
super_process( sS /opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/pyodbc.pyt process� s
( t superR t bind_processort _need_decimal_fix( R t dialectR ( ( R R sS /opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/pyodbc.pyR � s
c C sc d | d k r d p d d t | j � � d d j g | j � d D] } t | � ^ qF � f S( Ns %s0.%s%si t -t t 0i ( t absR
t joint as_tuplet str( R R t nint( ( sS /opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/pyodbc.pyR � s c C s� | j � d } d t | � k r� d | d k r7 d p: d d j g | D] } t | � ^ qG � d | j � t | � d f } n� t | � d | j � k r+d | d k r� d p� d d j g | D] } t | � ^ q� d | j � d !� d j g | D] } t | � ^ q� | j � d � f } nU d | d k r@d pCd d j g | D] } t | � ^ qPd | j � d !� f } | S(
Ni t Es %s%s%si R R R s %s%s.%ss %s%s( R R R R
t len( R R t _intt st result( ( sS /opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/pyodbc.pyR � s %%6==( t __name__t
__module__t __doc__R R R ( ( ( sS /opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/pyodbc.pyR � s t _MSNumeric_pyodbcc B s e Z RS( ( R% R&