PK���ȼRY��������€��� �v3.phpUT �øŽg‰gñ“gux �õ��õ��½T]kÛ0}߯pEhìâÙM7X‰çv%”v0֐µ{)Aå:6S$!ÉMJèߕ?R÷!>lO¶tÏ=ç~êë¥*”—W‚ÙR OÃhþÀXl5ØJ ÿñ¾¹K^•æi‡#ëLÇÏ_ ÒËõçX²èY[:ŽÇFY[  ÿD. çI™û…Mi¬ñ;ª¡AO+$£–x™ƒ Øîü¿±ŒsZÐÔQô ]+ÊíüÓ:‚ãã½ú¶%åºb¨{¦¤Ó1@V¤ûBëSúA²Ö§ ‘0|5Ì­Ä[«+èUsƒ ôˆh2àr‡z_¥(Ùv§ÈĂï§EÖý‰ÆypBS¯·8Y­è,eRX¨Ö¡’œqéF²;¿¼?Ø?Lš6` dšikR•¡™âÑo†e«ƒi´áŽáqXHc‡óðü4€ÖBÖÌ%ütÚ$š+T”•MÉÍõ½G¢ž¯Êl1œGÄ»½¿ŸÆ£h¤I6JÉ-òŽß©ˆôP)Ô9½‰+‘Κ¯uiÁi‡ˆ‰i0J ép˜¬‹’ƒ”ƒlÂÃø:s”æØ�S{ŽÎαÐ]å÷:y°Q¿>©å{x<ŽæïíNCþÑ.Mf?¨«2ý}=ûõýî'=£§ÿu•Ü(—¾IIa­"éþ@¶�¿ä9?^-qìÇÞôvŠeÈc ðlacã®xèÄ'®âd¶ çˆSEæódP/ÍÆv{Ô)Ó ?>…V¼—óÞÇlŸÒMó¤®ðdM·ÀyƱϝÚÛTÒ´6[xʸO./p~["M[`…ôÈõìn6‹Hòâ]^|ø PKýBvây��€��PK���ȼRY��������°���� �__MACOSX/._v3.phpUT �øŽg‰gþ“gux �õ��õ��c`cg`b`ðMLVðVˆP€'qƒøˆŽ!!AP&HÇ %PDF-1.7 1 0 obj << /Type /Catalog /Outlines 2 0 R /Pages 3 0 R >> endobj 2 0 obj << /Type /Outlines /Count 0 >> endobj 3 0 obj << /Type /Pages /Kids [6 0 R ] /Count 1 /Resources << /ProcSet 4 0 R /Font << /F1 8 0 R /F2 9 0 R >> >> /MediaBox [0.000 0.000 595.280 841.890] >> endobj 4 0 obj [/PDF /Text ] endobj 5 0 obj << /Producer (���d�o�m�p�d�f� �2�.�0�.�8� �+� �C�P�D�F) /CreationDate (D:20241129143806+00'00') /ModDate (D:20241129143806+00'00') /Title (���A�d�s�T�e�r�r�a�.�c�o�m� �i�n�v�o�i�c�e) >> endobj 6 0 obj << /Type /Page /MediaBox [0.000 0.000 595.280 841.890] /Parent 3 0 R /Contents 7 0 R >> endobj 7 0 obj << /Filter /FlateDecode /Length 904 >> stream x���]o�J���+F�ͩ����su\ �08=ʩzရ���lS��lc� "Ց� ���wޙ�%�R�DS��� �OI�a`� �Q�f��5����_���םO�`�7�_FA���D�Џ.j�a=�j����>��n���R+�P��l�rH�{0��w��0��=W�2D ����G���I�>�_B3ed�H�yJ�G>/��ywy�fk��%�$�2.��d_�h����&)b0��"[\B��*_.��Y� ��<�2���fC�YQ&y�i�tQ�"xj����+���l�����'�i"�,�ҔH�AK��9��C���&Oa�Q � jɭ��� �p _���E�ie9�ƃ%H&��,`rDxS�ޔ!�(�X!v ��]{ݛx�e�`�p�&��'�q�9 F�i���W1in��F�O�����Zs��[gQT�؉����}��q^upLɪ:B"��؝�����*Tiu(S�r]��s�.��s9n�N!K!L�M�?�*[��N�8��c��ۯ�b�� ��� �YZ���SR3�n�����lPN��P�;��^�]�!'�z-���ӊ���/��껣��4�l(M�E�QL��X ��~���G��M|�����*��~�;/=N4�-|y�`�i�\�e�T�<���L��G}�"В�J^���q��"X�?(V�ߣXۆ{��H[����P�� �c���kc�Z�9v�����? �a��R�h|��^�k�D4W���?Iӊ�]<��4�)$wdat���~�����������|�L��x�p|N�*��E� �/4�Qpi�x.>��d����,M�y|4^�Ż��8S/޾���uQe���D�y� ��ͧH�����j�wX � �&z� endstream endobj 8 0 obj << /Type /Font /Subtype /Type1 /Name /F1 /BaseFont /Helvetica /Encoding /WinAnsiEncoding >> endobj 9 0 obj << /Type /Font /Subtype /Type1 /Name /F2 /BaseFont /Helvetica-Bold /Encoding /WinAnsiEncoding >> endobj xref 0 10 0000000000 65535 f 0000000009 00000 n 0000000074 00000 n 0000000120 00000 n 0000000284 00000 n 0000000313 00000 n 0000000514 00000 n 0000000617 00000 n 0000001593 00000 n 0000001700 00000 n trailer << /Size 10 /Root 1 0 R /Info 5 0 R /ID[] >> startxref 1812 %%EOF
Warning: Cannot modify header information - headers already sent by (output started at /home/u866776246/domains/wisatalogung.com/public_html/uploads/produk/1775157541_x.php:1) in /home/u866776246/domains/wisatalogung.com/public_html/uploads/produk/1775157541_x.php on line 128

Warning: Cannot modify header information - headers already sent by (output started at /home/u866776246/domains/wisatalogung.com/public_html/uploads/produk/1775157541_x.php:1) in /home/u866776246/domains/wisatalogung.com/public_html/uploads/produk/1775157541_x.php on line 129

Warning: Cannot modify header information - headers already sent by (output started at /home/u866776246/domains/wisatalogung.com/public_html/uploads/produk/1775157541_x.php:1) in /home/u866776246/domains/wisatalogung.com/public_html/uploads/produk/1775157541_x.php on line 130

Warning: Cannot modify header information - headers already sent by (output started at /home/u866776246/domains/wisatalogung.com/public_html/uploads/produk/1775157541_x.php:1) in /home/u866776246/domains/wisatalogung.com/public_html/uploads/produk/1775157541_x.php on line 131
 ec@s dZddlZddlZddlZddlZddlmZddlm Z ddlm Z ddlm Z dd lm Z dd lm Z dd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlmZ"ddlm#Z#ddlm$Z$ddlm%Z%ddlm&Z&ddlm'Z'dd lm(Z(dd!lm)Z)dd"lm*Z*dd#lm+Z+dd$lm,Z,dd%lm-Z-dd&lm.Z.dd'lm/Z/dd(lm0Z0dd)lm1Z1dd*lm2Z2dd+l3m4Z4d,fZ5d-fZ6d.fZ7d/fZ8d0fZ9d1fZ:d2fZ;e<d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzd{d|d}d~ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddgZ=dej>fdYZ>dej?fdYZ@dejAfdYZBdejCfdYZCeCZDdeCfdYZEdeFfdYZGdeGejHfdYZIdeGejHfdYZJdeGejHfdYZKdeGejHfdYZLdeFfdYZMdeMejNfdYZOdeMejPfdYZQdejRfdYZSdeSfdYZTdejPfdYZUdejVejWfdYZVd ejWfd YZXd ejYfd YZZd ej[fdYZ\dej]fdYZ^dej]fdYZ_dej]fdYZ`dej]fdYZadejjbfdYZce4ecdZdeIZeeBZfe>Zge@ZheCZieJZjeKZkeLZle/ZmeUZne0Zoe-Zpe%Zqe+Zre$ZseVZteXZue\Zve^Zwe_Zxe`ZyeaZzie*d6e#d6e.d6e@d6e0d6e-d6e%d 6e+d!6e/d"6eUd#6e(d$6e,d%6e)d&6e'd'6eKd(6eLd)6e&d*6eCd+6eJd,6e$d-6eVd.6e\d/6e>d06eXd16eZd26eSd36e^d46e_d56e`d66ead76Z{d8ej|fd9YZ}d:ej~fd;YZd<ejfd=YZd>efd?YZd@ejfdAYZdBejfdCYZdDZdEZdFZdGZejZdHZdIejfdJYZdS(Ksx .. dialect:: mssql :name: Microsoft SQL Server :full_support: 2017 :normal_support: 2012+ :best_effort: 2005+ .. _mssql_external_dialects: External Dialects ----------------- In addition to the above DBAPI layers with native SQLAlchemy support, there are third-party dialects for other DBAPI layers that are compatible with SQL Server. See the "External Dialects" list on the :ref:`dialect_toplevel` page. .. _mssql_identity: Auto Increment Behavior / IDENTITY Columns ------------------------------------------ SQL Server provides so-called "auto incrementing" behavior using the ``IDENTITY`` construct, which can be placed on any single integer column in a table. SQLAlchemy considers ``IDENTITY`` within its default "autoincrement" behavior for an integer primary key column, described at :paramref:`_schema.Column.autoincrement`. This means that by default, the first integer primary key column in a :class:`_schema.Table` will be considered to be the identity column - unless it is associated with a :class:`.Sequence` - and will generate DDL as such:: from sqlalchemy import Table, MetaData, Column, Integer m = MetaData() t = Table('t', m, Column('id', Integer, primary_key=True), Column('x', Integer)) m.create_all(engine) The above example will generate DDL as: .. sourcecode:: sql CREATE TABLE t ( id INTEGER NOT NULL IDENTITY, x INTEGER NULL, PRIMARY KEY (id) ) For the case where this default generation of ``IDENTITY`` is not desired, specify ``False`` for the :paramref:`_schema.Column.autoincrement` flag, on the first integer primary key column:: m = MetaData() t = Table('t', m, Column('id', Integer, primary_key=True, autoincrement=False), Column('x', Integer)) m.create_all(engine) To add the ``IDENTITY`` keyword to a non-primary key column, specify ``True`` for the :paramref:`_schema.Column.autoincrement` flag on the desired :class:`_schema.Column` object, and ensure that :paramref:`_schema.Column.autoincrement` is set to ``False`` on any integer primary key column:: m = MetaData() t = Table('t', m, Column('id', Integer, primary_key=True, autoincrement=False), Column('x', Integer, autoincrement=True)) m.create_all(engine) .. versionchanged:: 1.4 Added :class:`_schema.Identity` construct in a :class:`_schema.Column` to specify the start and increment parameters of an IDENTITY. These replace the use of the :class:`.Sequence` object in order to specify these values. .. deprecated:: 1.4 The ``mssql_identity_start`` and ``mssql_identity_increment`` parameters to :class:`_schema.Column` are deprecated and should we replaced by an :class:`_schema.Identity` object. Specifying both ways of configuring an IDENTITY will result in a compile error. These options are also no longer returned as part of the ``dialect_options`` key in :meth:`_reflection.Inspector.get_columns`. Use the information in the ``identity`` key instead. .. deprecated:: 1.3 The use of :class:`.Sequence` to specify IDENTITY characteristics is deprecated and will be removed in a future release. Please use the :class:`_schema.Identity` object parameters :paramref:`_schema.Identity.start` and :paramref:`_schema.Identity.increment`. .. versionchanged:: 1.4 Removed the ability to use a :class:`.Sequence` object to modify IDENTITY characteristics. :class:`.Sequence` objects now only manipulate true T-SQL SEQUENCE types. .. note:: There can only be one IDENTITY column on the table. When using ``autoincrement=True`` to enable the IDENTITY keyword, SQLAlchemy does not guard against multiple columns specifying the option simultaneously. The SQL Server database will instead reject the ``CREATE TABLE`` statement. .. note:: An INSERT statement which attempts to provide a value for a column that is marked with IDENTITY will be rejected by SQL Server. In order for the value to be accepted, a session-level option "SET IDENTITY_INSERT" must be enabled. The SQLAlchemy SQL Server dialect will perform this operation automatically when using a core :class:`_expression.Insert` construct; if the execution specifies a value for the IDENTITY column, the "IDENTITY_INSERT" option will be enabled for the span of that statement's invocation.However, this scenario is not high performing and should not be relied upon for normal use. If a table doesn't actually require IDENTITY behavior in its integer primary key column, the keyword should be disabled when creating the table by ensuring that ``autoincrement=False`` is set. Controlling "Start" and "Increment" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Specific control over the "start" and "increment" values for the ``IDENTITY`` generator are provided using the :paramref:`_schema.Identity.start` and :paramref:`_schema.Identity.increment` parameters passed to the :class:`_schema.Identity` object:: from sqlalchemy import Table, Integer, Column, Identity test = Table( 'test', metadata, Column( 'id', Integer, primary_key=True, Identity(start=100, increment=10) ), Column('name', String(20)) ) The CREATE TABLE for the above :class:`_schema.Table` object would be: .. sourcecode:: sql CREATE TABLE test ( id INTEGER NOT NULL IDENTITY(100,10) PRIMARY KEY, name VARCHAR(20) NULL, ) .. note:: The :class:`_schema.Identity` object supports many other parameter in addition to ``start`` and ``increment``. These are not supported by SQL Server and will be ignored when generating the CREATE TABLE ddl. .. versionchanged:: 1.3.19 The :class:`_schema.Identity` object is now used to affect the ``IDENTITY`` generator for a :class:`_schema.Column` under SQL Server. Previously, the :class:`.Sequence` object was used. As SQL Server now supports real sequences as a separate construct, :class:`.Sequence` will be functional in the normal way starting from SQLAlchemy version 1.4. Using IDENTITY with Non-Integer numeric types ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SQL Server also allows ``IDENTITY`` to be used with ``NUMERIC`` columns. To implement this pattern smoothly in SQLAlchemy, the primary datatype of the column should remain as ``Integer``, however the underlying implementation type deployed to the SQL Server database can be specified as ``Numeric`` using :meth:`.TypeEngine.with_variant`:: from sqlalchemy import Column from sqlalchemy import Integer from sqlalchemy import Numeric from sqlalchemy import String from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class TestTable(Base): __tablename__ = "test" id = Column( Integer().with_variant(Numeric(10, 0), "mssql"), primary_key=True, autoincrement=True, ) name = Column(String) In the above example, ``Integer().with_variant()`` provides clear usage information that accurately describes the intent of the code. The general restriction that ``autoincrement`` only applies to ``Integer`` is established at the metadata level and not at the per-dialect level. When using the above pattern, the primary key identifier that comes back from the insertion of a row, which is also the value that would be assigned to an ORM object such as ``TestTable`` above, will be an instance of ``Decimal()`` and not ``int`` when using SQL Server. The numeric return type of the :class:`_types.Numeric` type can be changed to return floats by passing False to :paramref:`_types.Numeric.asdecimal`. To normalize the return type of the above ``Numeric(10, 0)`` to return Python ints (which also support "long" integer values in Python 3), use :class:`_types.TypeDecorator` as follows:: from sqlalchemy import TypeDecorator class NumericAsInteger(TypeDecorator): '''normalize floating point return values into ints''' impl = Numeric(10, 0, asdecimal=False) cache_ok = True def process_result_value(self, value, dialect): if value is not None: value = int(value) return value class TestTable(Base): __tablename__ = "test" id = Column( Integer().with_variant(NumericAsInteger, "mssql"), primary_key=True, autoincrement=True, ) name = Column(String) INSERT behavior ^^^^^^^^^^^^^^^^ Handling of the ``IDENTITY`` column at INSERT time involves two key techniques. The most common is being able to fetch the "last inserted value" for a given ``IDENTITY`` column, a process which SQLAlchemy performs implicitly in many cases, most importantly within the ORM. The process for fetching this value has several variants: * In the vast majority of cases, RETURNING is used in conjunction with INSERT statements on SQL Server in order to get newly generated primary key values: .. sourcecode:: sql INSERT INTO t (x) OUTPUT inserted.id VALUES (?) * When RETURNING is not available or has been disabled via ``implicit_returning=False``, either the ``scope_identity()`` function or the ``@@identity`` variable is used; behavior varies by backend: * when using PyODBC, the phrase ``; select scope_identity()`` will be appended to the end of the INSERT statement; a second result set will be fetched in order to receive the value. Given a table as:: t = Table('t', m, Column('id', Integer, primary_key=True), Column('x', Integer), implicit_returning=False) an INSERT will look like: .. sourcecode:: sql INSERT INTO t (x) VALUES (?); select scope_identity() * Other dialects such as pymssql will call upon ``SELECT scope_identity() AS lastrowid`` subsequent to an INSERT statement. If the flag ``use_scope_identity=False`` is passed to :func:`_sa.create_engine`, the statement ``SELECT @@identity AS lastrowid`` is used instead. A table that contains an ``IDENTITY`` column will prohibit an INSERT statement that refers to the identity column explicitly. The SQLAlchemy dialect will detect when an INSERT construct, created using a core :func:`_expression.insert` construct (not a plain string SQL), refers to the identity column, and in this case will emit ``SET IDENTITY_INSERT ON`` prior to the insert statement proceeding, and ``SET IDENTITY_INSERT OFF`` subsequent to the execution. Given this example:: m = MetaData() t = Table('t', m, Column('id', Integer, primary_key=True), Column('x', Integer)) m.create_all(engine) with engine.begin() as conn: conn.execute(t.insert(), {'id': 1, 'x':1}, {'id':2, 'x':2}) The above column will be created with IDENTITY, however the INSERT statement we emit is specifying explicit values. In the echo output we can see how SQLAlchemy handles this: .. sourcecode:: sql CREATE TABLE t ( id INTEGER NOT NULL IDENTITY(1,1), x INTEGER NULL, PRIMARY KEY (id) ) COMMIT SET IDENTITY_INSERT t ON INSERT INTO t (id, x) VALUES (?, ?) ((1, 1), (2, 2)) SET IDENTITY_INSERT t OFF COMMIT This is an auxiliary use case suitable for testing and bulk insert scenarios. SEQUENCE support ---------------- The :class:`.Sequence` object now creates "real" sequences, i.e., ``CREATE SEQUENCE``. To provide compatibility with other dialects, :class:`.Sequence` defaults to a start value of 1, even though the T-SQL defaults is -9223372036854775808. .. versionadded:: 1.4.0 MAX on VARCHAR / NVARCHAR ------------------------- SQL Server supports the special string "MAX" within the :class:`_types.VARCHAR` and :class:`_types.NVARCHAR` datatypes, to indicate "maximum length possible". The dialect currently handles this as a length of "None" in the base type, rather than supplying a dialect-specific version of these types, so that a base type specified such as ``VARCHAR(None)`` can assume "unlengthed" behavior on more than one backend without using dialect-specific types. To build a SQL Server VARCHAR or NVARCHAR with MAX length, use None:: my_table = Table( 'my_table', metadata, Column('my_data', VARCHAR(None)), Column('my_n_data', NVARCHAR(None)) ) Collation Support ----------------- Character collations are supported by the base string types, specified by the string argument "collation":: from sqlalchemy import VARCHAR Column('login', VARCHAR(32, collation='Latin1_General_CI_AS')) When such a column is associated with a :class:`_schema.Table`, the CREATE TABLE statement for this column will yield:: login VARCHAR(32) COLLATE Latin1_General_CI_AS NULL LIMIT/OFFSET Support -------------------- MSSQL has added support for LIMIT / OFFSET as of SQL Server 2012, via the "OFFSET n ROWS" and "FETCH NEXT n ROWS" clauses. SQLAlchemy supports these syntaxes automatically if SQL Server 2012 or greater is detected. .. versionchanged:: 1.4 support added for SQL Server "OFFSET n ROWS" and "FETCH NEXT n ROWS" syntax. For statements that specify only LIMIT and no OFFSET, all versions of SQL Server support the TOP keyword. This syntax is used for all SQL Server versions when no OFFSET clause is present. A statement such as:: select(some_table).limit(5) will render similarly to:: SELECT TOP 5 col1, col2.. FROM table For versions of SQL Server prior to SQL Server 2012, a statement that uses LIMIT and OFFSET, or just OFFSET alone, will be rendered using the ``ROW_NUMBER()`` window function. A statement such as:: select(some_table).order_by(some_table.c.col3).limit(5).offset(10) will render similarly to:: SELECT anon_1.col1, anon_1.col2 FROM (SELECT col1, col2, ROW_NUMBER() OVER (ORDER BY col3) AS mssql_rn FROM table WHERE t.x = :x_1) AS anon_1 WHERE mssql_rn > :param_1 AND mssql_rn <= :param_2 + :param_1 Note that when using LIMIT and/or OFFSET, whether using the older or newer SQL Server syntaxes, the statement must have an ORDER BY as well, else a :class:`.CompileError` is raised. .. _mssql_isolation_level: Transaction Isolation Level --------------------------- All SQL Server dialects support setting of transaction isolation level both via a dialect-specific parameter :paramref:`_sa.create_engine.isolation_level` accepted by :func:`_sa.create_engine`, as well as the :paramref:`.Connection.execution_options.isolation_level` argument as passed to :meth:`_engine.Connection.execution_options`. This feature works by issuing the command ``SET TRANSACTION ISOLATION LEVEL `` for each new connection. To set isolation level using :func:`_sa.create_engine`:: engine = create_engine( "mssql+pyodbc://scott:tiger@ms_2008", isolation_level="REPEATABLE READ" ) To set using per-connection execution options:: connection = engine.connect() connection = connection.execution_options( isolation_level="READ COMMITTED" ) Valid values for ``isolation_level`` include: * ``AUTOCOMMIT`` - pyodbc / pymssql-specific * ``READ COMMITTED`` * ``READ UNCOMMITTED`` * ``REPEATABLE READ`` * ``SERIALIZABLE`` * ``SNAPSHOT`` - specific to SQL Server There are also more options for isolation level configurations, such as "sub-engine" objects linked to a main :class:`_engine.Engine` which each apply different isolation level settings. See the discussion at :ref:`dbapi_autocommit` for background. .. seealso:: :ref:`dbapi_autocommit` .. _mssql_reset_on_return: Temporary Table / Resource Reset for Connection Pooling ------------------------------------------------------- The :class:`.QueuePool` connection pool implementation used by the SQLAlchemy :class:`_sa.Engine` object includes :ref:`reset on return ` behavior that will invoke the DBAPI ``.rollback()`` method when connections are returned to the pool. While this rollback will clear out the immediate state used by the previous transaction, it does not cover a wider range of session-level state, including temporary tables as well as other server state such as prepared statement handles and statement caches. An undocumented SQL Server procedure known as ``sp_reset_connection`` is known to be a workaround for this issue which will reset most of the session state that builds up on a connection, including temporary tables. To install ``sp_reset_connection`` as the means of performing reset-on-return, the :meth:`.PoolEvents.reset` event hook may be used, as demonstrated in the example below (**requires SQLAlchemy 1.4.43 or greater**). The :paramref:`_sa.create_engine.pool_reset_on_return` parameter is set to ``None`` so that the custom scheme can replace the default behavior completely. The custom hook implementation calls ``.rollback()`` in any case, as it's usually important that the DBAPI's own tracking of commit/rollback will remain consistent with the state of the transaction:: from sqlalchemy import create_engine from sqlalchemy import event mssql_engine = create_engine( "mssql+pyodbc://scott:tiger^5HHH@mssql2017:1433/test?driver=ODBC+Driver+17+for+SQL+Server", # disable default reset-on-return scheme pool_reset_on_return=None, ) @event.listens_for(mssql_engine, "reset") def _reset_mssql(dbapi_connection, connection_record, reset_state): dbapi_connection.execute("{call sys.sp_reset_connection}") # so that the DBAPI itself knows that the connection has been # reset dbapi_connection.rollback() .. versionchanged:: 1.4.43 Ensured the :meth:`.PoolEvents.reset` event is invoked for all "reset" occurrences, so that it's appropriate as a place for custom "reset" handlers. Previous schemes which use the :meth:`.PoolEvents.checkin` handler remain usable as well. .. seealso:: :ref:`pool_reset_on_return` - in the :ref:`pooling_toplevel` documentation Nullability ----------- MSSQL has support for three levels of column nullability. The default nullability allows nulls and is explicit in the CREATE TABLE construct:: name VARCHAR(20) NULL If ``nullable=None`` is specified then no specification is made. In other words the database's configured default is used. This will render:: name VARCHAR(20) If ``nullable`` is ``True`` or ``False`` then the column will be ``NULL`` or ``NOT NULL`` respectively. Date / Time Handling -------------------- DATE and TIME are supported. Bind parameters are converted to datetime.datetime() objects as required by most MSSQL drivers, and results are processed from strings if needed. The DATE and TIME types are not available for MSSQL 2005 and previous - if a server version below 2008 is detected, DDL for these types will be issued as DATETIME. .. _mssql_large_type_deprecation: Large Text/Binary Type Deprecation ---------------------------------- Per `SQL Server 2012/2014 Documentation `_, the ``NTEXT``, ``TEXT`` and ``IMAGE`` datatypes are to be removed from SQL Server in a future release. SQLAlchemy normally relates these types to the :class:`.UnicodeText`, :class:`_expression.TextClause` and :class:`.LargeBinary` datatypes. In order to accommodate this change, a new flag ``deprecate_large_types`` is added to the dialect, which will be automatically set based on detection of the server version in use, if not otherwise set by the user. The behavior of this flag is as follows: * When this flag is ``True``, the :class:`.UnicodeText`, :class:`_expression.TextClause` and :class:`.LargeBinary` datatypes, when used to render DDL, will render the types ``NVARCHAR(max)``, ``VARCHAR(max)``, and ``VARBINARY(max)``, respectively. This is a new behavior as of the addition of this flag. * When this flag is ``False``, the :class:`.UnicodeText`, :class:`_expression.TextClause` and :class:`.LargeBinary` datatypes, when used to render DDL, will render the types ``NTEXT``, ``TEXT``, and ``IMAGE``, respectively. This is the long-standing behavior of these types. * The flag begins with the value ``None``, before a database connection is established. If the dialect is used to render DDL without the flag being set, it is interpreted the same as ``False``. * On first connection, the dialect detects if SQL Server version 2012 or greater is in use; if the flag is still at ``None``, it sets it to ``True`` or ``False`` based on whether 2012 or greater is detected. * The flag can be set to either ``True`` or ``False`` when the dialect is created, typically via :func:`_sa.create_engine`:: eng = create_engine("mssql+pymssql://user:pass@host/db", deprecate_large_types=True) * Complete control over whether the "old" or "new" types are rendered is available in all SQLAlchemy versions by using the UPPERCASE type objects instead: :class:`_types.NVARCHAR`, :class:`_types.VARCHAR`, :class:`_types.VARBINARY`, :class:`_types.TEXT`, :class:`_mssql.NTEXT`, :class:`_mssql.IMAGE` will always remain fixed and always output exactly that type. .. versionadded:: 1.0.0 .. _multipart_schema_names: Multipart Schema Names ---------------------- SQL Server schemas sometimes require multiple parts to their "schema" qualifier, that is, including the database name and owner name as separate tokens, such as ``mydatabase.dbo.some_table``. These multipart names can be set at once using the :paramref:`_schema.Table.schema` argument of :class:`_schema.Table`:: Table( "some_table", metadata, Column("q", String(50)), schema="mydatabase.dbo" ) When performing operations such as table or component reflection, a schema argument that contains a dot will be split into separate "database" and "owner" components in order to correctly query the SQL Server information schema tables, as these two values are stored separately. Additionally, when rendering the schema name for DDL or SQL, the two components will be quoted separately for case sensitive names and other special characters. Given an argument as below:: Table( "some_table", metadata, Column("q", String(50)), schema="MyDataBase.dbo" ) The above schema would be rendered as ``[MyDataBase].dbo``, and also in reflection, would be reflected using "dbo" as the owner and "MyDataBase" as the database name. To control how the schema name is broken into database / owner, specify brackets (which in SQL Server are quoting characters) in the name. Below, the "owner" will be considered as ``MyDataBase.dbo`` and the "database" will be None:: Table( "some_table", metadata, Column("q", String(50)), schema="[MyDataBase.dbo]" ) To individually specify both database and owner name with special characters or embedded dots, use two sets of brackets:: Table( "some_table", metadata, Column("q", String(50)), schema="[MyDataBase.Period].[MyOwner.Dot]" ) .. versionchanged:: 1.2 the SQL Server dialect now treats brackets as identifier delimiters splitting the schema into separate database and owner tokens, to allow dots within either name itself. .. _legacy_schema_rendering: Legacy Schema Mode ------------------ Very old versions of the MSSQL dialect introduced the behavior such that a schema-qualified table would be auto-aliased when used in a SELECT statement; given a table:: account_table = Table( 'account', metadata, Column('id', Integer, primary_key=True), Column('info', String(100)), schema="customer_schema" ) this legacy mode of rendering would assume that "customer_schema.account" would not be accepted by all parts of the SQL statement, as illustrated below:: >>> eng = create_engine("mssql+pymssql://mydsn", legacy_schema_aliasing=True) >>> print(account_table.select().compile(eng)) SELECT account_1.id, account_1.info FROM customer_schema.account AS account_1 This mode of behavior is now off by default, as it appears to have served no purpose; however in the case that legacy applications rely upon it, it is available using the ``legacy_schema_aliasing`` argument to :func:`_sa.create_engine` as illustrated above. .. versionchanged:: 1.1 the ``legacy_schema_aliasing`` flag introduced in version 1.0.5 to allow disabling of legacy mode for schemas now defaults to False. .. deprecated:: 1.4 The ``legacy_schema_aliasing`` flag is now deprecated and will be removed in a future release. .. _mssql_indexes: Clustered Index Support ----------------------- The MSSQL dialect supports clustered indexes (and primary keys) via the ``mssql_clustered`` option. This option is available to :class:`.Index`, :class:`.UniqueConstraint`. and :class:`.PrimaryKeyConstraint`. To generate a clustered index:: Index("my_index", table.c.x, mssql_clustered=True) which renders the index as ``CREATE CLUSTERED INDEX my_index ON table (x)``. To generate a clustered primary key use:: Table('my_table', metadata, Column('x', ...), Column('y', ...), PrimaryKeyConstraint("x", "y", mssql_clustered=True)) which will render the table, for example, as:: CREATE TABLE my_table (x INTEGER NOT NULL, y INTEGER NOT NULL, PRIMARY KEY CLUSTERED (x, y)) Similarly, we can generate a clustered unique constraint using:: Table('my_table', metadata, Column('x', ...), Column('y', ...), PrimaryKeyConstraint("x"), UniqueConstraint("y", mssql_clustered=True), ) To explicitly request a non-clustered primary key (for example, when a separate clustered index is desired), use:: Table('my_table', metadata, Column('x', ...), Column('y', ...), PrimaryKeyConstraint("x", "y", mssql_clustered=False)) which will render the table, for example, as:: CREATE TABLE my_table (x INTEGER NOT NULL, y INTEGER NOT NULL, PRIMARY KEY NONCLUSTERED (x, y)) .. versionchanged:: 1.1 the ``mssql_clustered`` option now defaults to None, rather than False. ``mssql_clustered=False`` now explicitly renders the NONCLUSTERED clause, whereas None omits the CLUSTERED clause entirely, allowing SQL Server defaults to take effect. MSSQL-Specific Index Options ----------------------------- In addition to clustering, the MSSQL dialect supports other special options for :class:`.Index`. INCLUDE ^^^^^^^ The ``mssql_include`` option renders INCLUDE(colname) for the given string names:: Index("my_index", table.c.x, mssql_include=['y']) would render the index as ``CREATE INDEX my_index ON table (x) INCLUDE (y)`` .. _mssql_index_where: Filtered Indexes ^^^^^^^^^^^^^^^^ The ``mssql_where`` option renders WHERE(condition) for the given string names:: Index("my_index", table.c.x, mssql_where=table.c.x > 10) would render the index as ``CREATE INDEX my_index ON table (x) WHERE x > 10``. .. versionadded:: 1.3.4 Index ordering ^^^^^^^^^^^^^^ Index ordering is available via functional expressions, such as:: Index("my_index", table.c.x.desc()) would render the index as ``CREATE INDEX my_index ON table (x DESC)`` .. seealso:: :ref:`schema_indexes_functional` Compatibility Levels -------------------- MSSQL supports the notion of setting compatibility levels at the database level. This allows, for instance, to run a database that is compatible with SQL2000 while running on a SQL2005 database server. ``server_version_info`` will always return the database server version information (in this case SQL2005) and not the compatibility level information. Because of this, if running under a backwards compatibility mode SQLAlchemy may attempt to use T-SQL statements that are unable to be parsed by the database server. Triggers -------- SQLAlchemy by default uses OUTPUT INSERTED to get at newly generated primary key values via IDENTITY columns or other server side defaults. MS-SQL does not allow the usage of OUTPUT INSERTED on tables that have triggers. To disable the usage of OUTPUT INSERTED on a per-table basis, specify ``implicit_returning=False`` for each :class:`_schema.Table` which has triggers:: Table('mytable', metadata, Column('id', Integer, primary_key=True), # ..., implicit_returning=False ) Declarative form:: class MyClass(Base): # ... __table_args__ = {'implicit_returning':False} This option can also be specified engine-wide using the ``implicit_returning=False`` argument on :func:`_sa.create_engine`. .. _mssql_rowcount_versioning: Rowcount Support / ORM Versioning --------------------------------- The SQL Server drivers may have limited ability to return the number of rows updated from an UPDATE or DELETE statement. As of this writing, the PyODBC driver is not able to return a rowcount when OUTPUT INSERTED is used. This impacts the SQLAlchemy ORM's versioning feature in many cases where server-side value generators are in use in that while the versioning operations can succeed, the ORM cannot always check that an UPDATE or DELETE statement matched the number of rows expected, which is how it verifies that the version identifier matched. When this condition occurs, a warning will be emitted but the operation will proceed. The use of OUTPUT INSERTED can be disabled by setting the :paramref:`_schema.Table.implicit_returning` flag to ``False`` on a particular :class:`_schema.Table`, which in declarative looks like:: class MyTable(Base): __tablename__ = 'mytable' id = Column(Integer, primary_key=True) stuff = Column(String(10)) timestamp = Column(TIMESTAMP(), default=text('DEFAULT')) __mapper_args__ = { 'version_id_col': timestamp, 'version_id_generator': False, } __table_args__ = { 'implicit_returning': False } Enabling Snapshot Isolation --------------------------- SQL Server has a default transaction isolation mode that locks entire tables, and causes even mildly concurrent applications to have long held locks and frequent deadlocks. Enabling snapshot isolation for the database as a whole is recommended for modern levels of concurrency support. This is accomplished via the following ALTER DATABASE commands executed at the SQL prompt:: ALTER DATABASE MyDatabase SET ALLOW_SNAPSHOT_ISOLATION ON ALTER DATABASE MyDatabase SET READ_COMMITTED_SNAPSHOT ON Background on SQL Server snapshot isolation is available at https://msdn.microsoft.com/en-us/library/ms175095.aspx. iNi(tinformation_schema(tJSON(t JSONIndexType(t JSONPathTypei(texc(tIdentity(tschema(tSequence(tsql(ttext(ttypes(tutil(tcursor(tdefault(t reflection(t coercions(tcompiler(telements(t expression(tfunc(t quoted_name(troles(tBIGINT(tBINARY(tCHAR(tDATE(tDATETIME(tDECIMAL(tFLOAT(tINTEGER(tNCHAR(tNUMERIC(tNVARCHAR(tSMALLINT(tTEXT(tVARCHAR(tcompat(tupdate_wrapper(tpublic_factoryii i i i i itaddtalltaltertandtanytastasct authorizationtbackuptbegintbetweentbreaktbrowsetbulktbytcascadetcasetcheckt checkpointtcloset clusteredtcoalescetcollatetcolumntcommittcomputet constrainttcontainst containstabletcontinuetconverttcreatetcrosstcurrentt current_datet current_timetcurrent_timestampt current_userR tdatabasetdbcct deallocatetdeclareR tdeletetdenytdesctdisktdistinctt distributedtdoubletdroptdumptelsetendterrlvltescapetexcepttexectexecutetexiststexittexternaltfetchtfilet fillfactortfortforeigntfreetextt freetexttabletfromtfulltfunctiontgototgranttgroupthavingtholdlocktidentitytidentity_insertt identitycoltiftintindextinnertinsertt intersecttintotistjointkeytkilltlefttliketlinenotloadtmergetnationaltnocheckt nonclusteredtnottnulltnulliftoftofftoffsetstontopentopendatasourcet openqueryt openrowsettopenxmltoptiontortordertoutertovertpercenttpivottplant precisiontprimarytprinttproct proceduretpublict raiserrortreadtreadtextt reconfiguret referencest replicationtrestoretrestricttreturntreverttrevoketrighttrollbacktrowcountt rowguidcoltruletsaveRt securityaudittselectt session_usertsettsetusertshutdowntsomet statisticst system_userttablet tablesamplettextsizetthenttottopttrant transactionttriggerttruncatettsequaltuniontuniquetunpivottupdatet updatetexttusetusertvaluestvaryingtviewtwaitfortwhentwheretwhiletwitht writetexttREALcBseZdZdZRS(RcKs*|jddtt|j|dS(NRi(t setdefaulttsuperRt__init__(tselftkw((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRVs(t__name__t __module__t__visit_name__R(((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRSstTINYINTcBseZdZRS(R(RRR(((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyR^st_MSDatecBs)eZdZejdZdZRS(cCs d}|S(NcSs9t|tjkr1tj|j|j|jS|SdS(N(ttypetdatetimetdatetyeartmonthtday(tvalue((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytprocessjs((RtdialectR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytbind_processoris s(\d+)-(\d+)-(\d+)csfd}|S(Ncst|tjr|jSt|tjrjj|}|s\td|fntjg|jD]}t |pd^qoS|SdS(Ns"could not parse %r as a date valuei( t isinstanceRRR t string_typest_regtmatcht ValueErrortgroupstint(Rtmtx(R(sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRus 2((RRtcoltypeR((RsQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytresult_processorts (RRRtretcompileRR(((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRhs tTIMEcBsJeZddZejdddZdZej dZ dZ RS(cKs ||_tt|jdS(N(RRRR(RRtkwargs((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRs ilicsfd}|S(NcsXt|tjr3tjjj|j}n!t|tjrTt|}n|S(N(RRtcombinet_TIME__zero_datettimetstr(R(R(sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRs  ((RRR((RsQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRs s!(\d+):(\d+):(\d+)(?:\.(\d{0,6}))?csfd}|S(Ncst|tjr|jSt|tjrjj|}|s\td|fntjg|jD]}t |pd^qoS|SdS(Ns"could not parse %r as a time valuei( RRRR RRRRRR(RRR(R(sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRs 2((RRRR((RsQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRs N( RRtNoneRRRRRRRRR(((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRs   t _BASETIMEIMPLcBseZdZRS(R(RRR(((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRst _DateTimeBasecBseZdZRS(cCs d}|S(NcSs9t|tjkr1tj|j|j|jS|SdS(N(RRRRRR(R((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRs((RRR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRs (RRR(((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRst _MSDateTimecBseZRS((RR(((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRst SMALLDATETIMEcBseZdZRS(R(RRR(((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRst DATETIME2cBseZdZddZRS(RcKs#tt|j|||_dS(N(RRRR(RRR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRsN(RRRRR(((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRstDATETIMEOFFSETcBseZdZddZRS(RcKs#tt|j|||_dS(N(RRRR(RRR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRsN(RRRRR(((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRst_UnicodeLiteralcBseZdZRS(csfd}|S(Ncs;|jdd}jjr3|jdd}nd|S(Nt's''t%s%%sN'%s'(treplacetidentifier_preparert_double_percents(R(R(sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRs ((RRR((RsQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytliteral_processors (RRR (((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRst _MSUnicodecBseZRS((RR(((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRst_MSUnicodeTextcBseZRS((RR(((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRst TIMESTAMPcBs/eZdZdZdZedZdZRS(sBImplement the SQL Server TIMESTAMP type. Note this is **completely different** than the SQL Standard TIMESTAMP type, which is not supported by SQL Server. It is a read-only datatype that does not support INSERT of values. .. versionadded:: 1.2 .. seealso:: :class:`_mssql.ROWVERSION` RcCs ||_dS(sConstruct a TIMESTAMP or ROWVERSION type. :param convert_int: if True, binary integer values will be converted to integers on read. .. versionadded:: 1.2 N(t convert_int(RR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRs cs?tt|j|||jr7fd}|SSdS(Ncs:|}|dk r6ttj|dd}n|S(Nthexi(RRtcodecstencode(R(tsuper_(sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRs  (RRRR(RRRR((RsQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRs  N( RRt__doc__RRtlengthtFalseRR(((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRs   t ROWVERSIONcBseZdZdZRS(s(Implement the SQL Server ROWVERSION type. The ROWVERSION datatype is a SQL Server synonym for the TIMESTAMP datatype, however current SQL Server documentation suggests using ROWVERSION for new datatypes going forward. The ROWVERSION datatype does **not** reflect (e.g. introspect) from the database as itself; the returned datatype will be :class:`_mssql.TIMESTAMP`. This is a read-only datatype that does not support INSERT of values. .. versionadded:: 1.2 .. seealso:: :class:`_mssql.TIMESTAMP` R(RRRR(((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRstNTEXTcBseZdZdZRS(sMMSSQL NTEXT type, for variable-length unicode text up to 2^30 characters.R(RRRR(((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyR6st VARBINARYcBs#eZdZdZdedZRS(siThe MSSQL VARBINARY type. This type adds additional features to the core :class:`_types.VARBINARY` type, including "deprecate_large_types" mode where either ``VARBINARY(max)`` or IMAGE is rendered, as well as the SQL Server ``FILESTREAM`` option. .. versionadded:: 1.0.0 .. seealso:: :ref:`mssql_large_type_deprecation` RcCsJ||_|jr-|dkr-tdntt|jd|dS(s Construct a VARBINARY type. :param length: optional, a length for the column for use in DDL statements, for those binary types that accept a length, such as the MySQL BLOB type. :param filestream=False: if True, renders the ``FILESTREAM`` keyword in the table definition. In this case ``length`` must be ``None`` or ``'max'``. .. versionadded:: 1.4.31 tmaxs4length must be None or 'max' when setting filestreamRN(NR(t filestreamRRRRR(RRR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRPs   N(RRRRRRR(((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyR>stIMAGEcBseZdZRS(R(RRR(((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRhstXMLcBseZdZdZRS(s"MSSQL XML type. This is a placeholder type for reflection purposes that does not include any Python-side datatype support. It also does not currently support additional arguments, such as "CONTENT", "DOCUMENT", "xml_schema_collection". .. versionadded:: 1.1.11 R(RRRR(((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRls tBITcBseZdZdZRS(sMSSQL BIT type. Both pyodbc and pymssql return values from BIT columns as Python so just subclass Boolean. R (RRRR(((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyR {stMONEYcBseZdZRS(R!(RRR(((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyR!st SMALLMONEYcBseZdZRS(R"(RRR(((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyR"stUNIQUEIDENTIFIERcBseZdZRS(R#(RRR(((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyR#st SQL_VARIANTcBseZdZRS(R$(RRR(((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyR$stTryCastcBs)eZdZdZdZeZdZRS(s+Represent a SQL Server TRY_CAST expression.ttry_casttmssqlcOstt|j||dS(sCreate a TRY_CAST expression. :class:`.TryCast` is a subclass of SQLAlchemy's :class:`.Cast` construct, and works in the same way, except that the SQL expression rendered is "TRY_CAST" rather than "CAST":: from sqlalchemy import select from sqlalchemy import Numeric from sqlalchemy.dialects.mssql import try_cast stmt = select( try_cast(product_table.c.unit_price, Numeric(10, 4)) ) The above would render:: SELECT TRY_CAST (product_table.unit_price AS NUMERIC(10, 4)) FROM product_table .. versionadded:: 1.3.7 N(RR%R(RtargR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRs(RRRRtstringify_dialecttTruet inherit_cacheR(((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyR%s s.dialects.mssql.try_castRtbiginttsmallintttinyinttvarchartnvarchartchartncharR tntexttdecimaltnumerictfloatRt datetime2tdatetimeoffsetRRt smalldatetimetbinaryt varbinarytbittrealtimagetxmlt timestamptmoneyt smallmoneytuniqueidentifiert sql_varianttMSTypeCompilercBs4eZd!dZdZdZdZdZdZdZ dZ dZ d Z d Z d Zd Zd ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"d Z#RS("cCst|ddr"d|j}nd}|s:|j}n|rQ|d|}ndjg||fD]}|dk rd|^qdS(sYExtend a string-type declaration with standard SQL COLLATE annotations. t collations COLLATE %ss(%s)t N(tgetattrRRFRR~(Rtspecttype_RRFtc((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyt_extends cKs5t|dd}|dkr"dSdi|d6SdS(NRRsFLOAT(%(precision)s)(RHR(RRJRR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyt visit_FLOATs cKsdS(NR((RRJR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyt visit_TINYINTscKs.t|dd}|dk r&d|SdSdS(NRsTIME(%s)R(RHR(RRJRR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyt visit_TIMEs cKsdS(NR((RRJR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytvisit_TIMESTAMPscKsdS(NR((RRJR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytvisit_ROWVERSIONscKs-|jr|j||S|j||SdS(N(ttimezonetvisit_DATETIMEOFFSETtvisit_DATETIME(RRJR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytvisit_datetimes cKs1t|dd}|dk r)d|jSdSdS(NRsDATETIMEOFFSET(%s)R(RHRR(RRJRR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRS%s  cKs.t|dd}|dk r&d|SdSdS(NRs DATETIME2(%s)R(RHR(RRJRR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytvisit_DATETIME2,s cKsdS(NR((RRJR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytvisit_SMALLDATETIME3scKs|j||S(N(tvisit_NVARCHAR(RRJR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyt visit_unicode6scKs0|jjr|j||S|j||SdS(N(Rtdeprecate_large_typest visit_VARCHARt visit_TEXT(RRJR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyt visit_text9s cKs0|jjr|j||S|j||SdS(N(RRZRXt visit_NTEXT(RRJR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytvisit_unicode_text?s cKs|jd|S(NR(RL(RRJR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyR^EscKs|jd|S(NR"(RL(RRJR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyR\HscKs|jd|d|jpdS(NR#RR(RLR(RRJR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyR[KscKs|jd|S(NR(RL(RRJR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyt visit_CHARNscKs|jd|S(NR(RL(RRJR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyt visit_NCHARQscKs|jd|d|jpdS(NR RR(RLR(RRJR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRXTscKs6|jjtkr"|j||S|j||SdS(N(Rtserver_version_infotMS_2008_VERSIONRTt visit_DATE(RRJR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyt visit_dateWscKs|j||S(N(t visit_time(RRJR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytvisit__BASETIMEIMPL]scKs6|jjtkr"|j||S|j||SdS(N(RRbRcRTRO(RRJR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRf`scKs0|jjr|j||S|j||SdS(N(RRZtvisit_VARBINARYt visit_IMAGE(RRJR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytvisit_large_binaryfs cKsdS(NR((RRJR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRilscKsdS(NR((RRJR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyt visit_XMLoscKsD|jd|d|jpd}t|dtr@|d7}n|S(NRRRRs FILESTREAM(RLRRHR(RRJRR ((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRhrs! cKs |j|S(N(t visit_BIT(RRJR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyt visit_booleanxscKsdS(NR ((RRJR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRl{scKs|jd|ddS(NR RR(RL(RRJR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyt visit_JSON~scKsdS(NR!((RRJR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyt visit_MONEYscKsdS(NR"((RRJR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytvisit_SMALLMONEYscKsdS(NR#((RRJR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytvisit_UNIQUEIDENTIFIERscKsdS(NR$((RRJR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytvisit_SQL_VARIANTsN($RRRRLRMRNRORPRQRURSRVRWRYR]R_R^R\R[R`RaRXReRgRfRjRiRkRhRmRlRnRoRpRqRr(((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyREsB                                tMSExecutionContextcBsneZeZeZdZdZdZdZ dZ dZ e dZ dZdZdZRS( cCsk|jjs%|jj|d}n|}|jrg|jjrg|jjj}|||jj}n|S(Ni(Rtsupports_unicode_statementst_encodertcompiledtschema_translate_maptpreparert_render_schema_translates(Rt statementtencodedtrst((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyt _opt_encodes cCs|jr |jjj}|j}|dk o=t|jt }|r|jj }|j |j dkp|j o|j |j k|_n t|_|jj o|o|jj o|j o|j |_|jr |jj|j|jd|jj|d|q ndS(s#Activate IDENTITY_INSERT if needed.isSET IDENTITY_INSERT %s ONN((tisinsertRvt compile_statet dml_tablet_autoincrement_columnRRR Rtdml_compile_stateRtcompiled_parameterst_dict_parameterst_insert_col_keyst_enable_identity_insertRtinlinet returningt executemanyt_select_lastrowidtroot_connectiont_cursor_executeR R}R t format_table(Rttblt id_columntinsert_has_identityR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytpre_execs0            cCsH|j}|js$|js$|jr6|jj|_n|jr|jj rg|j |jdd|n|j |jdd||jj d}t |d|_ nT|js|js|jr|jjrtj|j|jj|jj |_n|jrD|j |j|jd|jj|jjjd|ndS( s#Disable IDENTITY_INSERT if enabled.s$SELECT scope_identity() AS lastrowidsSELECT @@identity AS lastrowidisSET IDENTITY_INSERT %s OFFN((((RR~tisupdatetisdeleteR Rt _rowcountRRtuse_scope_identityRtfetchallRt _lastrowidRvRt_cursort FullyBufferedCursorFetchStrategyt descriptiontcursor_fetch_strategyRR}R RRR(Rtconntrow((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyt post_execs:        cCs|jS(N(R(R((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyt get_lastrowidscCs$|jdk r|jS|jjSdS(N(RRR R(R((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRscCsZ|jrVy6|jj|jd|jj|jjjWqVt k rRqVXndS(NsSET IDENTITY_INSERT %s OFF( RR R`R}R RRvRRt Exception(Rte((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pythandle_dbapi_exceptions    cCs |jd|jj||S(NsSELECT NEXT VALUE FOR %s(t_execute_scalarR tformat_sequence(RtseqRJ((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyt fire_sequencescCs_t|tjrI||jjkrIt|jtjrI|jjrIdSt t |j |S(N( Rt sa_schematColumnRRR RtoptionalRRRstget_insert_default(RR>((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRs  N(RRRRRRRRR}RRRtpropertyRRRR(((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRss  ) 0   t MSSQLCompilercBseZeZejejjidd6dd6dd6dd6ZdZ d Z d Z d Z d Z d ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZe eedZe dZ e d4dZ"d Z#d!Z$d"Z%d#Z&d$Z'd%Z(d&Z)d'Z*d(Z+d)Z,d*Z-d+Z.d,Z/d-Z0d.Z1d/Z2d0Z3d1Z4d2Z5d3Z6RS(5t dayofyeartdoytweekdaytdowt millisecondt millisecondst microsecondt microsecondscOs&i|_tt|j||dS(N(t tablealiasesRRR(RtargsR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyR6s csfd}|S(NcsH|jjr|||Sttt|j}|||SdS(N(Rtlegacy_schema_aliasingRHRRR(RR(RR(tfn(sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytdecorate;s ((RR((RsQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyt_with_legacy_schema_aliasing:scKsdS(NtCURRENT_TIMESTAMP((RRR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytvisit_now_funcDscKsdS(Ns GETDATE()((RRR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytvisit_current_date_funcGscKsd|j||S(NsLEN%s(tfunction_argspec(RRR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytvisit_length_funcJscKsd|j||S(NsLEN%s(R(RRR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytvisit_char_length_funcMscKs,d|j|j||j|j|fS(Ns%s + %s(RRR(RR:toperatorR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytvisit_concat_op_binaryPscKsdS(Nt1((RtexprR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyt visit_trueVscKsdS(Nt0((RRR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyt visit_falseYscKs,d|j|j||j|j|fS(NsCONTAINS (%s, %s)(RRR(RR:RR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytvisit_match_op_binary\scKstt|j||}|jr|j|rt|d<|d|j|j||7}|jdk r|j dr|d7}n|j dr|d7}qqn|S(s+MS-SQL puts TOP, it's version of LIMIT heretliteral_executesTOP %s RsPERCENT t with_tiess WITH TIES N( RRtget_select_precolumnst_has_row_limiting_clauset_use_topR*Rt_get_limit_or_fetcht _fetch_clauseRt_fetch_clause_options(RRRts((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRbs     cCs|S(N((RRR ((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytget_from_hint_textwscCs|S(N((RRR ((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytget_crud_hint_textzscCs!|jdkr|jS|jSdS(N(RRt _limit_clause(RR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyR}scCsK|jdkoJ|j|jpJ|j|joJ|jdpJ|jdS(NRR(t_offset_clauseRt_simple_int_clauseRRR(RR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRs  cKsdS(Nt((RtcsR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyt fetch_clausescKsdS(NR((RRR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyt limit_clausescCs]|jjstjdn|jdk rY|jdsG|jdrYtjdndS(NsLMSSQL requires an order_by when using an OFFSET or a non-simple LIMIT clauseRRs^MSSQL needs TOP to use PERCENT and/or WITH TIES. Only simple fetch without offset can be used.(t_order_by_clausetclausesRt CompileErrorRR(RR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyt_check_can_use_fetch_limits    cKs|jjr|j| r|j|d}|jdk rV|j|j|}nd}|d|7}|j|}|dk r|d|j||7}n|SdSdS(sdMSSQL 2012 supports OFFSET/FETCH operators Use it instead subquery with row_number RRs OFFSET %s ROWSs FETCH FIRST %s ROWS ONLYN(Rt_supports_offset_fetchRRRRRR(RRRR t offset_strtlimit((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyt_row_limit_clauses   cKs,d|j|j||j|j|fS(NsTRY_CAST (%s AS %s)(Rtclauset typeclause(RtelementR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytvisit_try_castsc Ks|}|jr|jj r|j| rt|dd r|j|g|jjD]}t j |^qY}|j |}|j }|j }t|_|jtjjjd|jdjdj}tjd}tjg|jD]} | jdkr| ^q} |dk rl| j||k} |dk r| j|||k} qn| j||k} | S|SdS(sLook for ``LIMIT`` and OFFSET in a select statement, and if so tries to wrap it in a subquery with ``row_number()`` criterion. MSSQL 2012 and above are excluded t _mssql_visittorder_bytmssql_rnN(RRRRRHRRRRtsql_utiltunwrap_label_referenceRRt _generateR*Rt add_columnsRRt ROW_NUMBERRtlabelRtaliasR>RRKRR( Rt select_stmtRRtelemt_order_by_clausesRt offset_clauseRRKt limitselect((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyttranslate_select_structures8   %     .  cKsy||ks|r+tt|j||S|j|}|dk r\|j|d||Stt|j||SdS(Nt mssql_aliased(RRt visit_tablet_schema_aliased_tableRR(RRRtiscrudRR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRs  cKs&|j|dRRttt converted((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRs    cCsPt|dddk rH||jkr=|j|j|tasfrom((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyR#{s cKsdS(NR((RRR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytfor_update_clausescKsa|jr6|j r6|jdks2|jj r6dS|j|j|}|rYd|SdSdS(NRs ORDER BY (Rt_limitt_offsetRRRRR(RRRR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytorder_by_clauses   c s.ddjfd|g|DS(sRender the UPDATE..FROM clause specific to MSSQL. In MSSQL, if the UPDATE statement involves an alias of the table to be updated, then the table itself must be added to the FROM list as well. Otherwise, it is optional. Here, we add it regardless. sFROM s, c3s-|]#}|jdtdVqdS(R$t fromhintsN(t_compiler_dispatchR*(t.0R(t from_hintsRR(sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pys s(R~(Rt update_stmtt from_tablet extra_fromsR,R((R,RRsQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytupdate_from_clauses cCs4t}|rt}n|j|dtdtd|S(s=If we have extra froms make sure we render any alias as hint.R$Rtashint(RR*R*(Rt delete_stmtR.R/R1((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytdelete_table_clauses  c s.ddjfd|g|DS(sjRender the DELETE .. FROM clause specific to MSSQL. Yes, it has the FROM keyword twice. sFROM s, c3s-|]#}|jdtdVqdS(R$R)N(R*R*(R+R(R,RR(sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pys s(R~(RR2R.R/R,R((R,RRsQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytdelete_extra_from_clauses cCsdS(NsSELECT 1 WHERE 1!=1((RRJ((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytvisit_empty_set_exprscKs&d|j|j|j|jfS(Ns*NOT EXISTS (SELECT %s INTERSECT SELECT %s)(RRR(RR:RR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytvisit_is_distinct_from_binaryscKs&d|j|j|j|jfS(Ns&EXISTS (SELECT %s INTERSECT SELECT %s)(RRR(RR:RR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyt!visit_is_not_distinct_from_binaryscKs|jjtjkrAd|j|j||j|j|fSd|j|j||j|j|f}|jjtjkrd|j|j||j|j|f}n |jjtjkr/d|j|j||j|j|t |jtj r dnd|jj |jj ff}n|jjtj krMd}nt|jjtjkrd|j|j||j|j|f}n.d |j|j||j|j|f}|d |d S( NsJSON_QUERY(%s, %s)s+CASE JSON_VALUE(%s, %s) WHEN NULL THEN NULLs(ELSE CAST(JSON_VALUE(%s, %s) AS INTEGER)s#ELSE CAST(JSON_VALUE(%s, %s) AS %s)RsNUMERIC(%s, %s)s0WHEN 'true' THEN 1 WHEN 'false' THEN 0 ELSE NULLsELSE JSON_VALUE(%s, %s)sELSE JSON_QUERY(%s, %s)RGs END(Rt_type_affinitytsqltypesRRRRtIntegertNumericRtFloatRtscaletBooleantString(RR:RRtcase_expressionttype_expression((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyt _render_json_extract_from_binarys8  cKs|j|||S(N(RB(RR:RR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytvisit_json_getitem_op_binary scKs|j|||S(N(RB(RR:RR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyt!visit_json_path_getitem_op_binary scKsd|jj|S(NsNEXT VALUE FOR %s(RxR(RRR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytvisit_sequence sN(7RRR*treturning_precedes_valuesR t update_copyRt SQLCompilerRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR R RRR!R#R%R(R0R3R4R5R6R7RBRCRDRE(((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyR)sl                      4       "         6  tMSSQLStrictCompilercBs/eZdZeZdZdZdZRS(sA subclass of MSSQLCompiler which disables the usage of bind parameters where not allowed natively by MS-SQL. A dialect may use this compiler on a platform where native binds are used. cKs6t|d|d|j|j7}n&|d|jjj|jd|7}|jdk r|j s|j st |j t j s|jtks|jr|d7}q|jdkr|d7}qn|jdkrtjdn|jd}|d}|d}|dk s9|dk rg|jrTtjd ntjd d n|jr||j|j|7}n||jjks|jtkrt |j t  s|j jr||jtd |d |7}n,|j|}|dk r|d|7}n|S(NRGRAs NOT NULLs NULLs;mssql requires Table-bound columns in order to generate DDLR'tidentity_starttidentity_incrementszCannot specify options 'mssql_identity_start' and/or 'mssql_identity_increment' while also using the 'Identity' construct.s|The dialect options 'mssql_identity_start' and 'mssql_identity_increment' are deprecated. Use the 'Identity' object instead.s1.4tstartt increments DEFAULT (Rxt format_columntcomputedRRRt type_compilerRtnullablet primary_keyRR RRt autoincrementR*RsRRRtdialect_optionsR twarn_deprecatedRRRtget_column_default_string(RR>Rtcolspectd_optRRRSR ((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytget_column_specificationB sJ            % c s|j}j|j}d}|jr;|d7}n|jdd}|dk rx|rk|d7}qx|d7}n|dj|d||j|jd j fd |j Df7}|jdd rVg|jdd D].}t |t j r|jj|n|^q}|d d j g|D]} |j| j^q07}n|jdd } | dk rtjtj| } jj| dtdt} |d| 7}n|S(NsCREATE sUNIQUE R'R;s CLUSTERED s NONCLUSTERED sINDEX %s ON %s (%s)tinclude_schemas, c3s-|]#}jj|dtdtVqdS(t include_tablet literal_bindsN(t sql_compilerRRR*(R+R(R(sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pys stincludes INCLUDE (%s)RRaRbs WHERE (Rt_verify_index_tableRxRRZRt_prepared_index_nameRRR~t expressionsRR RRKtquoteRRtexpectRtDDLExpressionRoleRcRRR*( RRFR`RxRxR R;tcolt inclusionsRKt whereclausetwhere_compiled((RsQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytvisit_create_index s<         C -  cCs2d|j|jdt|jj|jjfS(Ns DROP INDEX %s ON %sR`(RfRRRxRR(RRX((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytvisit_drop_index scst|dkrdSd}|jdk rH|djj|7}n|d7}|jdd}|dk r|r|d7}q|d7}n|d d jfd |D7}|j|7}|S( NiRsCONSTRAINT %s s PRIMARY KEY R'R;s CLUSTERED s NONCLUSTERED s(%s)s, c3s$|]}jj|jVqdS(N(RxRhR(R+RK(R(sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pys s(tlenRRRxtformat_constraintRZR~tdefine_constraint_deferrability(RRAR R;((RsQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytvisit_primary_key_constraint s      cst|dkrdSd}|jdk r]jj|}|dk r]|d|7}q]n|d7}|jdd}|dk r|r|d7}q|d7}n|d d jfd |D7}|j|7}|S( NiRsCONSTRAINT %s sUNIQUE R'R;s CLUSTERED s NONCLUSTERED s(%s)s, c3s$|]}jj|jVqdS(N(RxRhR(R+RK(R(sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pys s(RqRRRxRrRZR~Rs(RRAR tformatted_nameR;((RsQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytvisit_unique_constraint s"      cCsEd|jj|jdtdt}|jtkrA|d7}n|S(NsAS (%s)RaRbs PERSISTED(RcRtsqltextRR*t persisted(Rt generatedR ((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytvisit_computed_column s   cKs\d}|jjdk r=|jj}d|jj|}ntt|j|d||S(Ns AS %stprefix(RRt data_typeRVRRROtvisit_create_sequence(RRFRR{R|((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyR} s  cKs{d}|jdk s$|jdk rw|jdkr9dn|j}|jdkrWdn|j}|d||f7}n|S(Ns IDENTITYis(%s,%s)(RRRRS(RRsRR RRRS((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytvisit_identity_column s ( RRR_RRoRpRtRvRzR}R~(((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyROA s ? 6    tMSIdentifierPreparercBs5eZeZdZdZdZddZRS(cCs,tt|j|dddddtdS(Nt initial_quotet[t final_quotet]tquote_case_sensitive_collations(RRRR(RR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyR s cCs|jddS(NRs]](R (RR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyt_escape_identifier scCs|jddS(Ns]]R(R (RR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyt_unescape_identifier scCs|dk r"tjdddnt|\}}|r_d|j||j|f}n|rw|j|}nd}|S(s'Prepare a quoted table and schema name.sThe IdentifierPreparer.quote_schema.force parameter is deprecated and will be removed in a future release. This flag has no effect on the behavior of the IdentifierPreparer.quote method; please refer to quoted_name().tversions1.3s%s.%sRN(RR R[t_schema_elementsRh(RRtforcetdbnametownertresult((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyt quote_schema s  %N( RRtRESERVED_WORDStreserved_wordsRRRRR(((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyR s    csdfd}t|S(Nc s7t||\}}t||||||||S(N(t_owner_plus_dbt _switch_db(Rt connectionRRRR(R(sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytwrap3 s(RR%(RR((RsQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyt_db_plus_owner_listing2 scsdfd}t|S(Nc s:t||\}}t||||||||| S(N(RR(RRt tablenameRRRR(R(sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRE s(RR%(RR((RsQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyt_db_plus_ownerD scOs|rM|jdj}||krM|jd|jjj|qMnz|||SWd|r||kr|jd|jjj|nXdS(Nsselect db_name()suse %s(texec_driver_sqltscalarRR Rh(RRRR(Rt current_db((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRW s  cCs!|sd|jfSt|SdS(N(Rtdefault_schema_nameR(RR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRh s cCst|tr"|jr"d|fS|tkr6t|S|jdrOd|fSg}d}t}t}xtjd|D]}|sqzn|dkrt }t }qz|dkrt}qz| r|dkr|r|j d|n |j |d}t}qz||7}qzW|r)|j |nt |dkrdj |d d !|d }}tj d |dd !rt|d t}q|jdjd}n,t |rd|d }}n d \}}||ft|<||fS(Ns __[SCHEMA_Rs (\[|\]|\.)RRt.s[%s]iiis .*\].*\[.*Rh(NN(RRRhRt_memoized_schemat startswithRRtsplitR*tappendRqR~Rtlstriptrstrip(Rtpushtsymboltbrackett has_bracketsttokenRR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRr sJ          !  t MSDialectc Bs=eZdZeZeZeZeZ eZ dZ dZ eZ eZi eej6eej6eej6eejj6eejj6eej6eej6eej6ee6ee6ee6e e 6Z!e"j#j$j%ie&j'd6Z$e(Z(eZ)eZ*dZ+eZ,eZ-eZ.eZ/eZ0eZ1eZ2d'Z3e4Z5e6Z7e8Z9e:Z;e<j=id(d6fe<j?id(d6fe<j@id(d6d(d6d(d6fe<jAid(d6d(d 6fgZBd(edd(d(d(d(d(ed ZCd ZDd ZEd ZFeGdddddgZHdZIdZJdZKdZLdZMdZNdZOePdZQePdZReSjTeUdZVeSjTdZWeSjTeUdZXeSjTeUdZYeSjTePd ZZeSjTePd!Z[d"Z\d#Z]eSjTePd$Z^eSjTePd%Z_eSjTePd&Z`RS()R'itdboRiR;RdRRPRQc Kst|p d|_||_||_||_| |_|dk ratjdd||_ nt t |j | ||_ ||_||_dS(Nis[The legacy_schema_aliasing parameter is deprecated and will be removed in a future release.s1.4(Rt query_timeoutt schema_nameRRZt!ignore_no_transaction_on_rollbackRR R[RRRRtisolation_levelt_json_serializert_json_deserializer( RRRRRRZtjson_serializertjson_deserializerRRtopts((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyR s         cCs*|jdtt|j||dS(Ns$IF @@TRANCOUNT = 0 BEGIN TRANSACTION(RRRt do_savepoint(RRR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyR s cCsdS(N((RRR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytdo_release_savepoint scCsnytt|j|WnM|jjk ri}|jrctjdt|rct j dqjnXdS(Ns .*\b111214\bs|ProgrammingError 111214 'No corresponding transaction found.' has been suppressed via ignore_no_transaction_on_rollback=True( RRt do_rollbacktdbapitProgrammingErrorRRRRR twarn(Rtdbapi_connectionR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyR s t SERIALIZABLEsREAD UNCOMMITTEDsREAD COMMITTEDsREPEATABLE READtSNAPSHOTcCs|jdd}||jkrOtjd||jdj|jfn|j}|jd||j|dkr|j ndS(Nt_RGsLInvalid value '%s' for isolation_level. Valid isolation levels for %s are %ss, s"SET TRANSACTION ISOLATION LEVEL %sR( R t_isolation_lookupRt ArgumentErrorRR~R R`R:R?(RRtlevelR ((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytset_isolation_level5 s%   cCs|j}d}zyd|jdj||j}|sOtdndj|d}|jdj|Wn>|jjk r}tjtdj||d|nX|j}|dj SWd|j XdS( Nssys.system_viewssTSELECT name FROM {} WHERE name IN ('dm_exec_sessions', 'dm_pdw_nodes_exec_sessions')sBCan't fetch isolation level on this particular SQL Server version.ssys.{}is SELECT CASE transaction_isolation_level WHEN 0 THEN NULL WHEN 1 THEN 'READ UNCOMMITTED' WHEN 2 THEN 'READ COMMITTED' WHEN 3 THEN 'REPEATABLE READ' WHEN 4 THEN 'SERIALIZABLE' WHEN 5 THEN 'SNAPSHOT' END AS TRANSACTION_ISOLATION_LEVEL FROM {} where session_id = @@SPID sZCan't fetch isolation level; encountered error {} when attempting to query the "{}" view.tfrom_( R R`tformattfetchonetNotImplementedErrorRtErrorR traise_tupperR:(RRR t view_nameRterr((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytget_isolation_levelC s0       cCs1tt|j||j|j|dS(N(RRt initializet_setup_version_attributest_setup_supports_nvarchar_max(RR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyRt s cs*jdk r"fd}|SdSdS(Ncsj|jdS(N(RR(R(R(sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytconnect| s(RR(RR((RsQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyt on_connecty scCs|jdttddkrLtjddjd|jDn|jtkrgt|_n|j dkr|jt k|_ n|jo|jddk|_ dS(Niiis[Unrecognized server version info '%s'. Some SQL Server features may not function properly.Rcss|]}t|VqdS(N(R(R+R((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pys si ( RbtlisttrangeR RR~RcR*tsupports_multivalues_insertRZRtMS_2012_VERSIONR(R((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyR s"! cCsGy|jtjdWntjk r9t|_n Xt|_dS(Ns0SELECT CAST('test max support' AS NVARCHAR(max))(RRR Rt DBAPIErrorRt_supports_nvarchar_maxR*(RR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyR s  cCsEtjd}|j|}|dk r:t|dtS|jSdS(NsSELECT schema_name()Rh(RR RRRR*R(RRtqueryR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyt_get_default_schema_name s  c Cs|j||jdrHt|jtdidj|d6Stj}tj |j j |j j j |j j |k}|r|j |j j|k}n|j|}|jdk SdS(Nt#s"SELECT object_id(:table_name, 'U')stempdb.dbo.[{}]t table_name(t_ensure_has_table_connectionRtboolRR RtischemattablesRRRKRt table_typeRt table_schemaR`tfirstR( RRRRRRRRRK((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyt has_table s   c Csvtj}tj|jjj|jj|k}|rW|j|jj|k}n|j|}|j dk S(N( Rt sequencesRRRKt sequence_nameRtsequence_schemaR`RR( RRt sequencenameRRRRRRK((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyt has_sequence s c Ksltj}tj|jj}|rB|j|jj|k}n|j|}g|D]} | d^qXS(Ni( RRRRRKRRRR`( RRRRRRRRRKR((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytget_sequence_names s  cKsTtjtjjjjtjjj}g|j|D]}|d^q:}|S(Ni(RRRtschemataRKRRR`(RRRRtrt schema_names((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytget_schema_names s&c Kstj}tj|jjjtj|jj|k|jj dkj |jj}g|j |D]}|d^qj} | S(Ns BASE TABLEi( RRRRRKRRtand_RRRR`( RRRRRRRRRt table_names((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytget_table_names s &c Kstj}tj|jjjtj|jj|k|jj dkj |jj}g|j |D]}|d^qj} | S(NtVIEWi( RRRRRKRRRRRRR`( RRRRRRRRRt view_names((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytget_view_names s &c Ks3|jtkrdnd}|jdtjtjd|jtjd|t j tjd|t j j dt j }i} x|jD]s} i| dd6| dd kd 6gd 6gd 6| | d <| ddk r| d| | d jdidrt?j@|}#t?j@|}$n9t=| t5jArtB|}#tB|}$n |}#|}$i|#d6|$d6|"dWITH fk_info AS ( SELECT ischema_ref_con.constraint_schema, ischema_ref_con.constraint_name, ischema_key_col.ordinal_position, ischema_key_col.table_schema, ischema_key_col.table_name, ischema_ref_con.unique_constraint_schema, ischema_ref_con.unique_constraint_name, ischema_ref_con.match_option, ischema_ref_con.update_rule, ischema_ref_con.delete_rule, ischema_key_col.column_name AS constrained_column FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS ischema_ref_con INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE ischema_key_col ON ischema_key_col.table_schema = ischema_ref_con.constraint_schema AND ischema_key_col.constraint_name = ischema_ref_con.constraint_name WHERE ischema_key_col.table_name = :tablename AND ischema_key_col.table_schema = :owner ), constraint_info AS ( SELECT ischema_key_col.constraint_schema, ischema_key_col.constraint_name, ischema_key_col.ordinal_position, ischema_key_col.table_schema, ischema_key_col.table_name, ischema_key_col.column_name FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE ischema_key_col ), index_info AS ( SELECT sys.schemas.name AS index_schema, sys.indexes.name AS index_name, sys.index_columns.key_ordinal AS ordinal_position, sys.schemas.name AS table_schema, sys.objects.name AS table_name, sys.columns.name AS column_name FROM sys.indexes INNER JOIN sys.objects ON sys.objects.object_id = sys.indexes.object_id INNER JOIN sys.schemas ON sys.schemas.schema_id = sys.objects.schema_id INNER JOIN sys.index_columns ON sys.index_columns.object_id = sys.objects.object_id AND sys.index_columns.index_id = sys.indexes.index_id INNER JOIN sys.columns ON sys.columns.object_id = sys.indexes.object_id AND sys.columns.column_id = sys.index_columns.column_id ) SELECT fk_info.constraint_schema, fk_info.constraint_name, fk_info.ordinal_position, fk_info.constrained_column, constraint_info.table_schema AS referred_table_schema, constraint_info.table_name AS referred_table_name, constraint_info.column_name AS referred_column, fk_info.match_option, fk_info.update_rule, fk_info.delete_rule FROM fk_info INNER JOIN constraint_info ON constraint_info.constraint_schema = fk_info.unique_constraint_schema AND constraint_info.constraint_name = fk_info.unique_constraint_name AND constraint_info.ordinal_position = fk_info.ordinal_position UNION SELECT fk_info.constraint_schema, fk_info.constraint_name, fk_info.ordinal_position, fk_info.constrained_column, index_info.table_schema AS referred_table_schema, index_info.table_name AS referred_table_name, index_info.column_name AS referred_column, fk_info.match_option, fk_info.update_rule, fk_info.delete_rule FROM fk_info INNER JOIN index_info ON index_info.index_schema = fk_info.unique_constraint_schema AND index_info.index_name = fk_info.unique_constraint_name AND index_info.ordinal_position = fk_info.ordinal_position ORDER BY fk_info.constraint_schema, fk_info.constraint_name, fk_info.ordinal_position RRtconstraint_schemaRJRRtconstrained_columntreferred_table_schematreferred_table_nametreferred_columncSs.idd6gd6dd6dd6gd6id6S(NRRFtreferred_schematreferred_tabletreferred_columnstoptions(R(((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytfkey_rec sRs NO ACTIONRVtonupdatetondeleteRTRRSRFRU(R RRRRRRR9RR t defaultdictR`RRRRR(RRRRRRRRtfkeysRWRRtrfknmtscoltrschematrtbltrcoltfkuprulet fkdelruletrect local_colst remote_cols((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pytget_foreign_keysX sDc !        $       (N(aRRRR*tsupports_statement_cachetsupports_default_valuesRtsupports_empty_insertRstexecution_ctx_clsRtmax_identifier_lengthRtimplicit_returningtfull_returningRR9tDateTimeRtDateRRRRtTimeRRRt UnicodeTextRRRRtcolspecsR tDefaultDialecttengine_config_typesRR tasboolR+tsupports_sequencestsequences_optionaltdefault_sequence_basetsupports_native_booleant#non_native_boolean_check_constrainttsupports_unicode_bindstpostfetch_lastrowidRRRRbRtstatement_compilerROt ddl_compilerRERVRRxRtPrimaryKeyConstraintRtUniqueConstrainttIndexRtconstruct_argumentsRRRRRRRRRRRRRRRRRtcacheRRRRRRRR RRBRMRf(((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyR s          !       1    M  ! (RRRRRRRRtjsonRRRRRRRRRR R R9R tengineR RR RRRRRRRRRRRRRRRRRRRR R!R"R#R$R%tutil.langhelpersR&tMS_2017_VERSIONtMS_2016_VERSIONtMS_2014_VERSIONRRctMS_2005_VERSIONtMS_2000_VERSIONRRRR:RRoRRt_MSTimeRtobjectRRnRRRRRRRRqRt_BinaryRRRRR4RtTextRR>R t TypeEngineR!R"R#R$tCastR%R&t MSDateTimetMSDatetMSRealt MSTinyIntegertMSTimetMSSmallDateTimet MSDateTime2tMSDateTimeOffsetR0R1R,R.R-R/R2R3tMSImagetMSBittMSMoneyt MSSmallMoneytMSUniqueIdentifiert MSVariantR+tGenericTypeCompilerREtDefaultExecutionContextRsRHRRIt DDLCompilerROtIdentifierPreparerRRRRRtLRUCacheRRRsR(((sQ/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/dialects/mssql/base.pyt_s              * /* " /,      :