Hacked By AnonymousFox

Current Path : /opt/cloudlinux/venv/lib/python3.11/site-packages/sqlalchemy/dialects/sqlite/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib/python3.11/site-packages/sqlalchemy/dialects/sqlite/__pycache__/base.cpython-311.pyc

�

�܋f�%����dZddlZddlZddlZddlmZddlmZddlmZddlm	Z	dd	lm
Z
dd
lmZddlm
Z
ddlmZdd
lmZddlmZddlmZddl
mZddl
mZdd
l
mZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!Gd�de��Z"Gd �d!e#��Z$Gd"�d#e$ej%��Z&Gd$�d%e$ej'��Z(Gd&�d'e$ej)��Z*ej'e(ej%e&eje"ejjeejjeej)e*iZ+id(ej,�d)ej�d*ej�d+ej�d,ej�d%ej(�d-ej(�d#ej&�d.ej&�d/ej�d0ej�d1ej�d2ej�d3ej�d4e�d5ej�d6ej�ejejej*ej*ej ej!ej-ej.d7��Z/Gd8�d9ej0��Z1Gd:�d;ej2��Z3Gd<�d=ej4��Z5Gd>�d?ej6��Z7Gd@�dAej8��Z9GdB�dCej:��Z;dS)DacU
.. dialect:: sqlite
    :name: SQLite

.. _sqlite_datetime:

Date and Time Types
-------------------

SQLite does not have built-in DATE, TIME, or DATETIME types, and pysqlite does
not provide out of the box functionality for translating values between Python
`datetime` objects and a SQLite-supported format. SQLAlchemy's own
:class:`~sqlalchemy.types.DateTime` and related types provide date formatting
and parsing functionality when SQLite is used. The implementation classes are
:class:`_sqlite.DATETIME`, :class:`_sqlite.DATE` and :class:`_sqlite.TIME`.
These types represent dates and times as ISO formatted strings, which also
nicely support ordering. There's no reliance on typical "libc" internals for
these functions so historical dates are fully supported.

Ensuring Text affinity
^^^^^^^^^^^^^^^^^^^^^^

The DDL rendered for these types is the standard ``DATE``, ``TIME``
and ``DATETIME`` indicators.    However, custom storage formats can also be
applied to these types.   When the
storage format is detected as containing no alpha characters, the DDL for
these types is rendered as ``DATE_CHAR``, ``TIME_CHAR``, and ``DATETIME_CHAR``,
so that the column continues to have textual affinity.

.. seealso::

    `Type Affinity <http://www.sqlite.org/datatype3.html#affinity>`_ -
    in the SQLite documentation

.. _sqlite_autoincrement:

SQLite Auto Incrementing Behavior
----------------------------------

Background on SQLite's autoincrement is at: http://sqlite.org/autoinc.html

Key concepts:

* SQLite has an implicit "auto increment" feature that takes place for any
  non-composite primary-key column that is specifically created using
  "INTEGER PRIMARY KEY" for the type + primary key.

* SQLite also has an explicit "AUTOINCREMENT" keyword, that is **not**
  equivalent to the implicit autoincrement feature; this keyword is not
  recommended for general use.  SQLAlchemy does not render this keyword
  unless a special SQLite-specific directive is used (see below).  However,
  it still requires that the column's type is named "INTEGER".

Using the AUTOINCREMENT Keyword
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

To specifically render the AUTOINCREMENT keyword on the primary key column
when rendering DDL, add the flag ``sqlite_autoincrement=True`` to the Table
construct::

    Table('sometable', metadata,
            Column('id', Integer, primary_key=True),
            sqlite_autoincrement=True)

Allowing autoincrement behavior SQLAlchemy types other than Integer/INTEGER
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

SQLite's typing model is based on naming conventions.  Among other things, this
means that any type name which contains the substring ``"INT"`` will be
determined to be of "integer affinity".  A type named ``"BIGINT"``,
``"SPECIAL_INT"`` or even ``"XYZINTQPR"``, will be considered by SQLite to be
of "integer" affinity.  However, **the SQLite autoincrement feature, whether
implicitly or explicitly enabled, requires that the name of the column's type
is exactly the string "INTEGER"**.  Therefore, if an application uses a type
like :class:`.BigInteger` for a primary key, on SQLite this type will need to
be rendered as the name ``"INTEGER"`` when emitting the initial ``CREATE
TABLE`` statement in order for the autoincrement behavior to be available.

One approach to achieve this is to use :class:`.Integer` on SQLite
only using :meth:`.TypeEngine.with_variant`::

    table = Table(
        "my_table", metadata,
        Column("id", BigInteger().with_variant(Integer, "sqlite"), primary_key=True)
    )

Another is to use a subclass of :class:`.BigInteger` that overrides its DDL
name to be ``INTEGER`` when compiled against SQLite::

    from sqlalchemy import BigInteger
    from sqlalchemy.ext.compiler import compiles

    class SLBigInteger(BigInteger):
        pass

    @compiles(SLBigInteger, 'sqlite')
    def bi_c(element, compiler, **kw):
        return "INTEGER"

    @compiles(SLBigInteger)
    def bi_c(element, compiler, **kw):
        return compiler.visit_BIGINT(element, **kw)


    table = Table(
        "my_table", metadata,
        Column("id", SLBigInteger(), primary_key=True)
    )

.. seealso::

    :meth:`.TypeEngine.with_variant`

    :ref:`sqlalchemy.ext.compiler_toplevel`

    `Datatypes In SQLite Version 3 <http://sqlite.org/datatype3.html>`_

.. _sqlite_concurrency:

Database Locking Behavior / Concurrency
---------------------------------------

SQLite is not designed for a high level of write concurrency. The database
itself, being a file, is locked completely during write operations within
transactions, meaning exactly one "connection" (in reality a file handle)
has exclusive access to the database during this period - all other
"connections" will be blocked during this time.

The Python DBAPI specification also calls for a connection model that is
always in a transaction; there is no ``connection.begin()`` method,
only ``connection.commit()`` and ``connection.rollback()``, upon which a
new transaction is to be begun immediately.  This may seem to imply
that the SQLite driver would in theory allow only a single filehandle on a
particular database file at any time; however, there are several
factors both within SQLite itself as well as within the pysqlite driver
which loosen this restriction significantly.

However, no matter what locking modes are used, SQLite will still always
lock the database file once a transaction is started and DML (e.g. INSERT,
UPDATE, DELETE) has at least been emitted, and this will block
other transactions at least at the point that they also attempt to emit DML.
By default, the length of time on this block is very short before it times out
with an error.

This behavior becomes more critical when used in conjunction with the
SQLAlchemy ORM.  SQLAlchemy's :class:`.Session` object by default runs
within a transaction, and with its autoflush model, may emit DML preceding
any SELECT statement.   This may lead to a SQLite database that locks
more quickly than is expected.   The locking mode of SQLite and the pysqlite
driver can be manipulated to some degree, however it should be noted that
achieving a high degree of write-concurrency with SQLite is a losing battle.

For more information on SQLite's lack of write concurrency by design, please
see
`Situations Where Another RDBMS May Work Better - High Concurrency
<http://www.sqlite.org/whentouse.html>`_ near the bottom of the page.

The following subsections introduce areas that are impacted by SQLite's
file-based architecture and additionally will usually require workarounds to
work when using the pysqlite driver.

.. _sqlite_isolation_level:

Transaction Isolation Level / Autocommit
----------------------------------------

SQLite supports "transaction isolation" in a non-standard way, along two
axes.  One is that of the
`PRAGMA read_uncommitted <http://www.sqlite.org/pragma.html#pragma_read_uncommitted>`_
instruction.   This setting can essentially switch SQLite between its
default mode of ``SERIALIZABLE`` isolation, and a "dirty read" isolation
mode normally referred to as ``READ UNCOMMITTED``.

SQLAlchemy ties into this PRAGMA statement using the
:paramref:`_sa.create_engine.isolation_level` parameter of
:func:`_sa.create_engine`.
Valid values for this parameter when used with SQLite are ``"SERIALIZABLE"``
and ``"READ UNCOMMITTED"`` corresponding to a value of 0 and 1, respectively.
SQLite defaults to ``SERIALIZABLE``, however its behavior is impacted by
the pysqlite driver's default behavior.

When using the pysqlite driver, the ``"AUTOCOMMIT"`` isolation level is also
available, which will alter the pysqlite connection using the ``.isolation_level``
attribute on the DBAPI connection and set it to None for the duration
of the setting.

.. versionadded:: 1.3.16 added support for SQLite AUTOCOMMIT isolation level
   when using the pysqlite / sqlite3 SQLite driver.


The other axis along which SQLite's transactional locking is impacted is
via the nature of the ``BEGIN`` statement used.   The three varieties
are "deferred", "immediate", and "exclusive", as described at
`BEGIN TRANSACTION <http://sqlite.org/lang_transaction.html>`_.   A straight
``BEGIN`` statement uses the "deferred" mode, where the database file is
not locked until the first read or write operation, and read access remains
open to other transactions until the first write operation.  But again,
it is critical to note that the pysqlite driver interferes with this behavior
by *not even emitting BEGIN* until the first write operation.

.. warning::

    SQLite's transactional scope is impacted by unresolved
    issues in the pysqlite driver, which defers BEGIN statements to a greater
    degree than is often feasible. See the section :ref:`pysqlite_serializable`
    for techniques to work around this behavior.

.. seealso::

    :ref:`dbapi_autocommit`

SAVEPOINT Support
----------------------------

SQLite supports SAVEPOINTs, which only function once a transaction is
begun.   SQLAlchemy's SAVEPOINT support is available using the
:meth:`_engine.Connection.begin_nested` method at the Core level, and
:meth:`.Session.begin_nested` at the ORM level.   However, SAVEPOINTs
won't work at all with pysqlite unless workarounds are taken.

.. warning::

    SQLite's SAVEPOINT feature is impacted by unresolved
    issues in the pysqlite driver, which defers BEGIN statements to a greater
    degree than is often feasible. See the section :ref:`pysqlite_serializable`
    for techniques to work around this behavior.

Transactional DDL
----------------------------

The SQLite database supports transactional :term:`DDL` as well.
In this case, the pysqlite driver is not only failing to start transactions,
it also is ending any existing transaction when DDL is detected, so again,
workarounds are required.

.. warning::

    SQLite's transactional DDL is impacted by unresolved issues
    in the pysqlite driver, which fails to emit BEGIN and additionally
    forces a COMMIT to cancel any transaction when DDL is encountered.
    See the section :ref:`pysqlite_serializable`
    for techniques to work around this behavior.

.. _sqlite_foreign_keys:

Foreign Key Support
-------------------

SQLite supports FOREIGN KEY syntax when emitting CREATE statements for tables,
however by default these constraints have no effect on the operation of the
table.

Constraint checking on SQLite has three prerequisites:

* At least version 3.6.19 of SQLite must be in use
* The SQLite library must be compiled *without* the SQLITE_OMIT_FOREIGN_KEY
  or SQLITE_OMIT_TRIGGER symbols enabled.
* The ``PRAGMA foreign_keys = ON`` statement must be emitted on all
  connections before use.

SQLAlchemy allows for the ``PRAGMA`` statement to be emitted automatically for
new connections through the usage of events::

    from sqlalchemy.engine import Engine
    from sqlalchemy import event

    @event.listens_for(Engine, "connect")
    def set_sqlite_pragma(dbapi_connection, connection_record):
        cursor = dbapi_connection.cursor()
        cursor.execute("PRAGMA foreign_keys=ON")
        cursor.close()

.. warning::

    When SQLite foreign keys are enabled, it is **not possible**
    to emit CREATE or DROP statements for tables that contain
    mutually-dependent foreign key constraints;
    to emit the DDL for these tables requires that ALTER TABLE be used to
    create or drop these constraints separately, for which SQLite has
    no support.

.. seealso::

    `SQLite Foreign Key Support <http://www.sqlite.org/foreignkeys.html>`_
    - on the SQLite web site.

    :ref:`event_toplevel` - SQLAlchemy event API.

    :ref:`use_alter` - more information on SQLAlchemy's facilities for handling
     mutually-dependent foreign key constraints.

.. _sqlite_on_conflict_ddl:

ON CONFLICT support for constraints
-----------------------------------

SQLite supports a non-standard clause known as ON CONFLICT which can be applied
to primary key, unique, check, and not null constraints.   In DDL, it is
rendered either within the "CONSTRAINT" clause or within the column definition
itself depending on the location of the target constraint.    To render this
clause within DDL, the extension parameter ``sqlite_on_conflict`` can be
specified with a string conflict resolution algorithm within the
:class:`.PrimaryKeyConstraint`, :class:`.UniqueConstraint`,
:class:`.CheckConstraint` objects.  Within the :class:`_schema.Column` object,
there
are individual parameters ``sqlite_on_conflict_not_null``,
``sqlite_on_conflict_primary_key``, ``sqlite_on_conflict_unique`` which each
correspond to the three types of relevant constraint types that can be
indicated from a :class:`_schema.Column` object.

.. seealso::

    `ON CONFLICT <https://www.sqlite.org/lang_conflict.html>`_ - in the SQLite
    documentation

.. versionadded:: 1.3


The ``sqlite_on_conflict`` parameters accept a  string argument which is just
the resolution name to be chosen, which on SQLite can be one of ROLLBACK,
ABORT, FAIL, IGNORE, and REPLACE.   For example, to add a UNIQUE constraint
that specifies the IGNORE algorithm::

    some_table = Table(
        'some_table', metadata,
        Column('id', Integer, primary_key=True),
        Column('data', Integer),
        UniqueConstraint('id', 'data', sqlite_on_conflict='IGNORE')
    )

The above renders CREATE TABLE DDL as::

    CREATE TABLE some_table (
        id INTEGER NOT NULL,
        data INTEGER,
        PRIMARY KEY (id),
        UNIQUE (id, data) ON CONFLICT IGNORE
    )


When using the :paramref:`_schema.Column.unique`
flag to add a UNIQUE constraint
to a single column, the ``sqlite_on_conflict_unique`` parameter can
be added to the :class:`_schema.Column` as well, which will be added to the
UNIQUE constraint in the DDL::

    some_table = Table(
        'some_table', metadata,
        Column('id', Integer, primary_key=True),
        Column('data', Integer, unique=True,
               sqlite_on_conflict_unique='IGNORE')
    )

rendering::

    CREATE TABLE some_table (
        id INTEGER NOT NULL,
        data INTEGER,
        PRIMARY KEY (id),
        UNIQUE (data) ON CONFLICT IGNORE
    )

To apply the FAIL algorithm for a NOT NULL constraint,
``sqlite_on_conflict_not_null`` is used::

    some_table = Table(
        'some_table', metadata,
        Column('id', Integer, primary_key=True),
        Column('data', Integer, nullable=False,
               sqlite_on_conflict_not_null='FAIL')
    )

this renders the column inline ON CONFLICT phrase::

    CREATE TABLE some_table (
        id INTEGER NOT NULL,
        data INTEGER NOT NULL ON CONFLICT FAIL,
        PRIMARY KEY (id)
    )


Similarly, for an inline primary key, use ``sqlite_on_conflict_primary_key``::

    some_table = Table(
        'some_table', metadata,
        Column('id', Integer, primary_key=True,
               sqlite_on_conflict_primary_key='FAIL')
    )

SQLAlchemy renders the PRIMARY KEY constraint separately, so the conflict
resolution algorithm is applied to the constraint itself::

    CREATE TABLE some_table (
        id INTEGER NOT NULL,
        PRIMARY KEY (id) ON CONFLICT FAIL
    )

.. _sqlite_type_reflection:

Type Reflection
---------------

SQLite types are unlike those of most other database backends, in that
the string name of the type usually does not correspond to a "type" in a
one-to-one fashion.  Instead, SQLite links per-column typing behavior
to one of five so-called "type affinities" based on a string matching
pattern for the type.

SQLAlchemy's reflection process, when inspecting types, uses a simple
lookup table to link the keywords returned to provided SQLAlchemy types.
This lookup table is present within the SQLite dialect as it is for all
other dialects.  However, the SQLite dialect has a different "fallback"
routine for when a particular type name is not located in the lookup map;
it instead implements the SQLite "type affinity" scheme located at
http://www.sqlite.org/datatype3.html section 2.1.

The provided typemap will make direct associations from an exact string
name match for the following types:

:class:`_types.BIGINT`, :class:`_types.BLOB`,
:class:`_types.BOOLEAN`, :class:`_types.BOOLEAN`,
:class:`_types.CHAR`, :class:`_types.DATE`,
:class:`_types.DATETIME`, :class:`_types.FLOAT`,
:class:`_types.DECIMAL`, :class:`_types.FLOAT`,
:class:`_types.INTEGER`, :class:`_types.INTEGER`,
:class:`_types.NUMERIC`, :class:`_types.REAL`,
:class:`_types.SMALLINT`, :class:`_types.TEXT`,
:class:`_types.TIME`, :class:`_types.TIMESTAMP`,
:class:`_types.VARCHAR`, :class:`_types.NVARCHAR`,
:class:`_types.NCHAR`

When a type name does not match one of the above types, the "type affinity"
lookup is used instead:

* :class:`_types.INTEGER` is returned if the type name includes the
  string ``INT``
* :class:`_types.TEXT` is returned if the type name includes the
  string ``CHAR``, ``CLOB`` or ``TEXT``
* :class:`_types.NullType` is returned if the type name includes the
  string ``BLOB``
* :class:`_types.REAL` is returned if the type name includes the string
  ``REAL``, ``FLOA`` or ``DOUB``.
* Otherwise, the :class:`_types.NUMERIC` type is used.

.. versionadded:: 0.9.3 Support for SQLite type affinity rules when reflecting
   columns.


.. _sqlite_partial_index:

Partial Indexes
---------------

A partial index, e.g. one which uses a WHERE clause, can be specified
with the DDL system using the argument ``sqlite_where``::

    tbl = Table('testtbl', m, Column('data', Integer))
    idx = Index('test_idx1', tbl.c.data,
                sqlite_where=and_(tbl.c.data > 5, tbl.c.data < 10))

The index will be rendered at create time as::

    CREATE INDEX test_idx1 ON testtbl (data)
    WHERE data > 5 AND data < 10

.. versionadded:: 0.9.9

.. _sqlite_dotted_column_names:

Dotted Column Names
-------------------

Using table or column names that explicitly have periods in them is
**not recommended**.   While this is generally a bad idea for relational
databases in general, as the dot is a syntactically significant character,
the SQLite driver up until version **3.10.0** of SQLite has a bug which
requires that SQLAlchemy filter out these dots in result sets.

.. versionchanged:: 1.1

    The following SQLite issue has been resolved as of version 3.10.0
    of SQLite.  SQLAlchemy as of **1.1** automatically disables its internal
    workarounds based on detection of this version.

The bug, entirely outside of SQLAlchemy, can be illustrated thusly::

    import sqlite3

    assert sqlite3.sqlite_version_info < (3, 10, 0), "bug is fixed in this version"

    conn = sqlite3.connect(":memory:")
    cursor = conn.cursor()

    cursor.execute("create table x (a integer, b integer)")
    cursor.execute("insert into x (a, b) values (1, 1)")
    cursor.execute("insert into x (a, b) values (2, 2)")

    cursor.execute("select x.a, x.b from x")
    assert [c[0] for c in cursor.description] == ['a', 'b']

    cursor.execute('''
        select x.a, x.b from x where a=1
        union
        select x.a, x.b from x where a=2
    ''')
    assert [c[0] for c in cursor.description] == ['a', 'b'], \
        [c[0] for c in cursor.description]

The second assertion fails::

    Traceback (most recent call last):
      File "test.py", line 19, in <module>
        [c[0] for c in cursor.description]
    AssertionError: ['x.a', 'x.b']

Where above, the driver incorrectly reports the names of the columns
including the name of the table, which is entirely inconsistent vs.
when the UNION is not present.

SQLAlchemy relies upon column names being predictable in how they match
to the original statement, so the SQLAlchemy dialect has no choice but
to filter these out::


    from sqlalchemy import create_engine

    eng = create_engine("sqlite://")
    conn = eng.connect()

    conn.execute("create table x (a integer, b integer)")
    conn.execute("insert into x (a, b) values (1, 1)")
    conn.execute("insert into x (a, b) values (2, 2)")

    result = conn.execute("select x.a, x.b from x")
    assert result.keys() == ["a", "b"]

    result = conn.execute('''
        select x.a, x.b from x where a=1
        union
        select x.a, x.b from x where a=2
    ''')
    assert result.keys() == ["a", "b"]

Note that above, even though SQLAlchemy filters out the dots, *both
names are still addressable*::

    >>> row = result.first()
    >>> row["a"]
    1
    >>> row["x.a"]
    1
    >>> row["b"]
    1
    >>> row["x.b"]
    1

Therefore, the workaround applied by SQLAlchemy only impacts
:meth:`_engine.ResultProxy.keys` and :meth:`.RowProxy.keys()`
in the public API. In
the very specific case where an application is forced to use column names that
contain dots, and the functionality of :meth:`_engine.ResultProxy.keys` and
:meth:`.RowProxy.keys()` is required to return these dotted names unmodified,
the ``sqlite_raw_colnames`` execution option may be provided, either on a
per-:class:`_engine.Connection` basis::

    result = conn.execution_options(sqlite_raw_colnames=True).execute('''
        select x.a, x.b from x where a=1
        union
        select x.a, x.b from x where a=2
    ''')
    assert result.keys() == ["x.a", "x.b"]

or on a per-:class:`_engine.Engine` basis::

    engine = create_engine("sqlite://", execution_options={"sqlite_raw_colnames": True})

When using the per-:class:`_engine.Engine` execution option, note that
**Core and ORM queries that use UNION may not function properly**.

SQLite-specific table options
-----------------------------

One option for CREATE TABLE is supported directly by the SQLite
dialect in conjunction with the :class:`_schema.Table` construct:

* ``WITHOUT ROWID``::

    Table("some_table", metadata, ..., sqlite_with_rowid=False)

.. seealso::

    `SQLite CREATE TABLE options
    <https://www.sqlite.org/lang_createtable.html>`_

�N�)�JSON)�
JSONIndexType)�JSONPathType�)�exc)�
processors��schema)�sql)�types)�util)�default)�
reflection)�
ColumnElement)�compiler)�BLOB)�BOOLEAN)�CHAR)�DECIMAL)�FLOAT)�INTEGER)�NUMERIC)�REAL)�SMALLINT)�TEXT)�	TIMESTAMP)�VARCHARc���eZdZ�fd�Z�xZS)�_SQliteJsonc�f���tt|���||����fd�}|S)Nc�v��	�|��S#t$r t|tj��r|cYS�wxYw�N)�	TypeError�
isinstance�numbers�Number)�value�default_processors ��V/opt/cloudlinux/venv/lib64/python3.11/site-packages/sqlalchemy/dialects/sqlite/base.py�processz-_SQliteJson.result_processor.<locals>.process�sT���
�(�(��/�/�/���
�
�
��e�W�^�4�4�� �L�L�L��	
���s�
�&8�8)�superr �result_processor)�self�dialect�coltyper+r)�	__class__s    @�r*r-z_SQliteJson.result_processor}sI����!�+�t�4�4�E�E��W�
�
��	�	�	�	�	���)�__name__�
__module__�__qualname__r-�
__classcell__�r1s@r*r r |s8���������������r2r c�N��eZdZdZdZd�fd�	Zed���Z�fd�Zd�Z	�xZ
S)�_DateTimeMixinNc���tt|��jdi|��|�tj|��|_|�	||_dSdS)N�)r,r9�__init__�re�compile�_reg�_storage_format)r.�storage_format�regexp�kwr1s    �r*r<z_DateTimeMixin.__init__�sY���,��n�d�#�#�,�2�2�r�2�2�2����
�6�*�*�D�I��%�#1�D� � � �&�%r2c	�j�|jdddddddd�z}ttjd|����S)a`return True if the storage format will automatically imply
        a TEXT affinity.

        If the storage format contains no non-numeric characters,
        it will imply a NUMERIC storage format on SQLite; in this case,
        the type will generate its DDL as DATE_CHAR, DATETIME_CHAR,
        TIME_CHAR.

        .. versionadded:: 1.0.0

        r��year�month�day�hour�minute�second�microsecondz[^0-9])r@�boolr=�search)r.�specs  r*�format_is_text_affinityz&_DateTimeMixin.format_is_text_affinity�sL���#��������'
�'
�
���B�I�i��.�.�/�/�/r2c���t|t��r"|jr
|j|d<|jr
|j|d<t	t|��j|fi|��S)NrArB)�
issubclassr9r@r?r,�adapt)r.�clsrCr1s   �r*rSz_DateTimeMixin.adapt�sh����c�>�*�*�	)��#�
<�'+�';��#�$��y�
)�#�y��8��0�u�^�T�*�*�0��;�;��;�;�;r2c�<��|�|����fd�}|S)Nc� ��d�|��zS)Nz'%s'r;)r(�bps �r*r+z1_DateTimeMixin.literal_processor.<locals>.process�s����B�B�u�I�I�%�%r2)�bind_processor)r.r/r+rWs   @r*�literal_processorz _DateTimeMixin.literal_processor�s6���
�
 �
 ��
)�
)��	&�	&�	&�	&�	&��r2)NN)r3r4r5r?r@r<�propertyrPrSrYr6r7s@r*r9r9�s���������D��O�2�2�2�2�2�2��0�0��X�0�.<�<�<�<�<�������r2r9c�2��eZdZdZdZ�fd�Zd�Zd�Z�xZS)�DATETIMEa�Represent a Python datetime object in SQLite using a string.

    The default string storage format is::

        "%(year)04d-%(month)02d-%(day)02d %(hour)02d:%(minute)02d:%(second)02d.%(microsecond)06d"

    e.g.::

        2011-03-15 12:05:57.10558

    The storage format can be customized to some degree using the
    ``storage_format`` and ``regexp`` parameters, such as::

        import re
        from sqlalchemy.dialects.sqlite import DATETIME

        dt = DATETIME(storage_format="%(year)04d/%(month)02d/%(day)02d "
                                     "%(hour)02d:%(minute)02d:%(second)02d",
                      regexp=r"(\d+)/(\d+)/(\d+) (\d+)-(\d+)-(\d+)"
        )

    :param storage_format: format string which will be applied to the dict
     with keys year, month, day, hour, minute, second, and microsecond.

    :param regexp: regular expression which will be applied to incoming result
     rows. If the regexp contains named groups, the resulting match dict is
     applied to the Python datetime() constructor as keyword arguments.
     Otherwise, if positional groups are used, the datetime() constructor
     is called with positional arguments via
     ``*map(int, match_obj.groups(0))``.

    zW%(year)04d-%(month)02d-%(day)02d %(hour)02d:%(minute)02d:%(second)02d.%(microsecond)06dc����|�dd��}tt|��j|i|��|r%d|vs
Jd���d|vs
Jd���d|_dSdS)N�truncate_microsecondsFrA�DYou can specify only one of truncate_microseconds or storage_format.rB�<You can specify only one of truncate_microseconds or regexp.zE%(year)04d-%(month)02d-%(day)02d %(hour)02d:%(minute)02d:%(second)02d)�popr,r\r<r@�r.�args�kwargsr^r1s    �r*r<zDATETIME.__init__�s���� &�
�
�+B�E� J� J��&��h����&��7��7�7�7� �	�#�6�1�1�1�B�2�1�1��6�)�)�)�3�*�)�)�
7�
� � � �	�	r2c�X����tj�tj�|j����fd�}|S)Nc	���|�dSt|���r0�|j|j|j|j|j|j|jd�zSt|���r�|j|j|jddddd�zStd���)NrErzLSQLite DateTime type only accepts Python datetime and date objects as input.)	r%rFrGrHrIrJrKrLr$)r(�
datetime_date�datetime_datetime�format_s ���r*r+z(DATETIME.bind_processor.<locals>.process�s�����}��t��E�#4�5�5�
��!�J�"�[� �9�!�J�#�l�#�l�#(�#4�"�"����E�=�1�1�
��!�J�"�[� �9����#$�"�"��� �:���r2��datetime�dater@)r.r/r+rgrhris   @@@r*rXzDATETIME.bind_processor�sG�����$�-�� �
�
��&��	�	�	�	�	�	�	�:�r2c�p�|jr$tj|jtj��StjSr#)r?r	�!str_to_datetime_processor_factoryrk�str_to_datetime�r.r/r0s   r*r-zDATETIME.result_processors6���9�	.��?��	�8�,���
��-�-r2�	r3r4r5�__doc__r@r<rXr-r6r7s@r*r\r\�sm���������D	A��
�����""�"�"�H.�.�.�.�.�.�.r2r\c�"�eZdZdZdZd�Zd�ZdS)�DATEaRepresent a Python date object in SQLite using a string.

    The default string storage format is::

        "%(year)04d-%(month)02d-%(day)02d"

    e.g.::

        2011-03-15

    The storage format can be customized to some degree using the
    ``storage_format`` and ``regexp`` parameters, such as::

        import re
        from sqlalchemy.dialects.sqlite import DATE

        d = DATE(
                storage_format="%(month)02d/%(day)02d/%(year)04d",
                regexp=re.compile("(?P<month>\d+)/(?P<day>\d+)/(?P<year>\d+)")
            )

    :param storage_format: format string which will be applied to the
     dict with keys year, month, and day.

    :param regexp: regular expression which will be applied to
     incoming result rows. If the regexp contains named groups, the
     resulting match dict is applied to the Python date() constructor
     as keyword arguments. Otherwise, if positional groups are used, the
     date() constructor is called with positional arguments via
     ``*map(int, match_obj.groups(0))``.
    z %(year)04d-%(month)02d-%(day)02dc�<���tj�|j���fd�}|S)Nc�z��|�dSt|���r�|j|j|jd�zSt	d���)N)rFrGrHz;SQLite Date type only accepts Python date objects as input.)r%rFrGrHr$)r(rgris ��r*r+z$DATE.bind_processor.<locals>.processNs^����}��t��E�=�1�1�

��!�J�"�[� �9�"�"��� �-���r2rj)r.r/r+rgris   @@r*rXzDATE.bind_processorJs8���� �
�
��&��
	�
	�
	�
	�
	�
	��r2c�p�|jr$tj|jtj��StjSr#)r?r	rnrkrl�str_to_daterps   r*r-zDATE.result_processor_�5���9�	*��?��	�8�=���
��)�)r2N)r3r4r5rrr@rXr-r;r2r*rtrt'sD��������@9�O����**�*�*�*�*r2rtc�2��eZdZdZdZ�fd�Zd�Zd�Z�xZS)�TIMEaZRepresent a Python time object in SQLite using a string.

    The default string storage format is::

        "%(hour)02d:%(minute)02d:%(second)02d.%(microsecond)06d"

    e.g.::

        12:05:57.10558

    The storage format can be customized to some degree using the
    ``storage_format`` and ``regexp`` parameters, such as::

        import re
        from sqlalchemy.dialects.sqlite import TIME

        t = TIME(storage_format="%(hour)02d-%(minute)02d-"
                                "%(second)02d-%(microsecond)06d",
                 regexp=re.compile("(\d+)-(\d+)-(\d+)-(?:-(\d+))?")
        )

    :param storage_format: format string which will be applied to the dict
     with keys hour, minute, second, and microsecond.

    :param regexp: regular expression which will be applied to incoming result
     rows. If the regexp contains named groups, the resulting match dict is
     applied to the Python time() constructor as keyword arguments. Otherwise,
     if positional groups are used, the time() constructor is called with
     positional arguments via ``*map(int, match_obj.groups(0))``.
    z6%(hour)02d:%(minute)02d:%(second)02d.%(microsecond)06dc����|�dd��}tt|��j|i|��|r%d|vs
Jd���d|vs
Jd���d|_dSdS)Nr^FrAr_rBr`z$%(hour)02d:%(minute)02d:%(second)02d)rar,r{r<r@rbs    �r*r<z
TIME.__init__�s���� &�
�
�+B�E� J� J��"��d�D���"�D�3�F�3�3�3� �		J�#�6�1�1�1�B�2�1�1��6�)�)�)�3�*�)�)�$J�D� � � �		J�		Jr2c�<���tj�|j���fd�}|S)Nc���|�dSt|���r�|j|j|j|jd�zStd���)N)rIrJrKrLz;SQLite Time type only accepts Python time objects as input.)r%rIrJrKrLr$)r(�
datetime_timeris ��r*r+z$TIME.bind_processor.<locals>.process�sd����}��t��E�=�1�1�
��!�J�#�l�#�l�#(�#4�	"�"��� �-���r2)rk�timer@)r.r/r+rris   @@r*rXzTIME.bind_processor�s8���� �
�
��&��	�	�	�	�	�	� �r2c�p�|jr$tj|jtj��StjSr#)r?r	rnrkr��str_to_timerps   r*r-zTIME.result_processor�ryr2rqr7s@r*r{r{hsm���������>O�O�J�J�J�J�J����,*�*�*�*�*�*�*r2r{�BIGINTr�BOOLrr�	DATE_CHAR�
DATETIME_CHAR�DOUBLErr�INTrrrr)rrr{�	TIME_CHARrr�NVARCHAR�NCHARc���eZdZejejjddddddddd	d
d�
��Zd�Zd
�Z	d�Z
d�Zd�Z�fd�Z
d�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z�xZS)�SQLiteCompilerz%mz%dz%Yz%Sz%Hz%jz%Mz%sz%wz%W)
rGrHrFrKrI�doyrJ�epoch�dow�weekc��dS)N�CURRENT_TIMESTAMPr;�r.�fnrCs   r*�visit_now_funczSQLiteCompiler.visit_now_func�s��"�"r2c��dS)Nz(DATETIME(CURRENT_TIMESTAMP, "localtime")r;)r.�funcrCs   r*�visit_localtimestamp_funcz(SQLiteCompiler.visit_localtimestamp_func�s��9�9r2c��dS)N�1r;�r.�exprrCs   r*�
visit_truezSQLiteCompiler.visit_true�����sr2c��dS)N�0r;r�s   r*�visit_falsezSQLiteCompiler.visit_false�r�r2c�2�d|�|��zS)Nzlength%s)�function_argspecr�s   r*�visit_char_length_funcz%SQLiteCompiler.visit_char_length_func�s���D�1�1�"�5�5�5�5r2c���|jjr!tt|��j|fi|��S|j|jfi|��Sr#)r/�
supports_castr,r��
visit_castr+�clause)r.�castrdr1s   �r*r�zSQLiteCompiler.visit_cast�sQ����<�%�	7�9�5���.�.�9�$�I�I�&�I�I�I��4�<���6�6�v�6�6�6r2c���d|j|j�d|j|jfi|���d�S#t$r;}tjtjd|jz��|���Yd}~dSd}~wwxYw)NzCAST(STRFTIME('z', z
) AS INTEGER)z#%s is not a valid extract argument.��replace_context)	�extract_map�fieldr+r��KeyErrorr�raise_r�CompileError)r.�extractrC�errs    r*�
visit_extractzSQLiteCompiler.visit_extracts���	�� ���/�/�/����W�\�0�0�R�0�0�0�0��
���	�	�	��K�� �9�G�M�I���!$�	
�
�
�
�
�
�
�
�
�
�����	���s�)+�
A0�0A+�+A0c�@�d}|j�|d|j|jfi|��zz
}|j�N|j�-|d|�tjd����zz
}|d|j|jfi|��zz
}n&|d|jtjd��fi|��zz
}|S)N�z
 LIMIT ���z OFFSET r)�
_limit_clauser+�_offset_clauser�literal)r.�selectrC�texts    r*�limit_clausezSQLiteCompiler.limit_clauses�������+��K�,�$�,�v�/C�"J�"J�r�"J�"J�J�J�D�� �,��#�+���d�l�l�3�;�r�?�?�&C�&C�C�C���J����f�.C�!J�!J�r�!J�!J�J�J�D�D��J����c�k�!�n�n�!C�!C��!C�!C�C�C�D��r2c��dS)Nr�r;)r.r�rCs   r*�for_update_clausez SQLiteCompiler.for_update_clauses���rr2c�p�|�|j���d|�|j����S)Nz IS NOT �r+�left�right�r.�binary�operatorrCs    r*�visit_is_distinct_from_binaryz,SQLiteCompiler.visit_is_distinct_from_binary!�7���L�L���%�%�%�%��L�L���&�&�&�
�	
r2c�p�|�|j���d|�|j����S)Nz IS r�r�s    r*� visit_isnot_distinct_from_binaryz/SQLiteCompiler.visit_isnot_distinct_from_binary'r�r2c��|jjtjurd}nd}||j|jfi|��|j|jfi|��fzS�Nz JSON_QUOTE(JSON_EXTRACT(%s, %s))zJSON_EXTRACT(%s, %s)��type�_type_affinity�sqltypesrr+r�r��r.r�r�rCr�s     r*�visit_json_getitem_op_binaryz+SQLiteCompiler.visit_json_getitem_op_binary-�d���;�%���6�6�5�D�D�)�D���D�L���+�+��+�+��D�L���,�,��,�,�
�
�	
r2c��|jjtjurd}nd}||j|jfi|��|j|jfi|��fzSr�r�r�s     r*�!visit_json_path_getitem_op_binaryz0SQLiteCompiler.visit_json_path_getitem_op_binary8r�r2c���dd�d�|pt��gD�����dd�d�|pt��gD�����d�S)NzSELECT �, c3�K�|]}dV��dS�r�Nr;��.0�type_s  r*�	<genexpr>z6SQLiteCompiler.visit_empty_set_expr.<locals>.<genexpr>E�"����D�D�e�c�D�D�D�D�D�Dr2z FROM (SELECT c3�K�|]}dV��dSr�r;r�s  r*r�z6SQLiteCompiler.visit_empty_set_expr.<locals>.<genexpr>Fr�r2z) WHERE 1!=1)�joinr)r.�
element_typess  r*�visit_empty_set_exprz#SQLiteCompiler.visit_empty_set_exprCsl����I�I�D�D�}�'C�����D�D�D�D�D�D�D��I�I�D�D�}�'C�����D�D�D�D�D�D�D�
�	
r2)r3r4r5r�update_copyr�SQLCompilerr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r6r7s@r*r�r��s@�������"�$�"���(�����������	
�	
���K� #�#�#�:�:�:�������6�6�6�7�7�7�7�7����
�
�
����
�
�
�
�
�
�	
�	
�	
�	
�	
�	
�
�
�
�
�
�
�
r2r�c�b��eZdZd�Z�fd�Z�fd�Z�fd�Z�fd�Z�fd�Zd�Z		dd
�Z
d�Z�xZS)
�SQLiteDDLCompilerc�b�|jj�|j|���}|j�|��dz|z}|�|��}|�/t|jj	t��rd|zdz}|d|zz
}|js"|dz
}|jdd}|�|d	|zz
}|j
r�|jd
ur6t|jj
j��dkrt%jd���|jjdd
rtt|jj
j��dkrRt)|jjt,j��r.|js'|dz
}|jdd}|�|d	|zz
}|dz
}|j� |d|�|j��zz
}|S)N)�type_expression� �(�)z	 DEFAULT z	 NOT NULL�sqlite�on_conflict_not_null�
 ON CONFLICT Trz@SQLite does not support autoincrement for composite primary keys�
autoincrementz PRIMARY KEY�on_conflict_primary_keyz AUTOINCREMENT)r/�
type_compilerr+r��preparer�
format_column�get_column_default_stringr%�server_default�argr�nullable�dialect_options�primary_keyr��len�table�columnsrr�rRr�r��Integer�foreign_keys�computed)r.�columnrdr0�colspecr�on_conflict_clauses       r*�get_column_specificationz*SQLiteDDLCompiler.get_column_specificationKs����,�,�4�4��K��5�
�
���-�-�-�f�5�5��;�g�E���0�0��8�8�����&�/�3�]�C�C�
.���-�#�-���{�W�,�,�G���	@��{�"�G�!'�!7��!A�&�"��"�-��?�-?�?�?����	,��$��,�,����0�8�9�9�Q�>�>��&�-������,�X�6��G�
,����0�8�9�9�Q�>�>��v�{�9�8�;K�L�L�?��+�?��>�)��%+�%;�H�%E�-�&�"�&�1���1C�C�C�G��+�+���?�&��s�T�\�\�&�/�:�:�:�:�G��r2c���t|j��dkrat|��d}|jrE|jjddr-t
|jjtj
��r	|jsdStt|���|��}|jdd}|�>t|j��dkr&t|��djdd}|�|d|zz
}|S)Nrrr�r��on_conflictr�r�)r�r��listr�r�r�rRr�r�r�r�r�r,r��visit_primary_key_constraint)r.�
constraint�cr�rr1s     �r*rz.SQLiteDDLCompiler.visit_primary_key_constraints����z�!�"�"�a�'�'��Z� � ��#�A��
�
��G�+�H�5�o�F�
��q�v�4�h�6F�G�G�
���	
��t��&��-�-�J�J��
�
��(�7��A��
���%�#�j�.@�*A�*A�Q�*F�*F�!%�j�!1�!1�!�!4�!D�X�!N�)�"���)��O�&8�8�8�D��r2c�p��tt|���|��}|jdd}|�mt	|j��dkrUt
|��d}t|tj	��r&t
|��djdd}|�|d|zz
}|S)Nr�rrr�on_conflict_uniquer�)
r,r��visit_unique_constraintr�r�r�rr%r�
SchemaItem)r.r	r�r�col1r1s     �r*r
z)SQLiteDDLCompiler.visit_unique_constraint�s�����&��-�-�E�E��
�
��(�7��A��
���%�#�j�.@�*A�*A�Q�*F�*F��
�#�#�A�&�D��$�� 1�2�2�
(�%)�*�%5�%5�a�%8�%H��&�&�&(�"��)��O�&8�8�8�D��r2c���tt|���|��}|jdd}|�|d|zz
}|S)Nr�rr�)r,r��visit_check_constraintr�)r.r	r�rr1s    �r*rz(SQLiteDDLCompiler.visit_check_constraint�s[����&��-�-�D�D��
�
��(�7��A��
���)��O�&8�8�8�D��r2c���tt|���|��}|jdd�t	jd���|S)Nr�rzFSQLite does not support on conflict clause for column check constraint)r,r��visit_column_check_constraintr�rr�)r.r	r�r1s   �r*rz/SQLiteDDLCompiler.visit_column_check_constraint�s\����&��-�-�K�K��
�
���%�h�/�
�>�J��"�*���
�
�r2c����|jdjj}|jdjj}|j|jkrdStt|���|��S)Nr)�elements�parentr�rrr,r��visit_foreign_key_constraint)r.r	�local_table�remote_tabler1s    �r*rz.SQLiteDDLCompiler.visit_foreign_key_constraint�se��� �)�!�,�3�9��!�*�1�-�4�:�����!4�4�4��4��*�D�1�1�N�N����
r2c�0�|�|d���S)z=Format the remote table clause of a CREATE CONSTRAINT clause.F��
use_schema)�format_table)r.r	r�r�s    r*�define_constraint_remote_tablez0SQLiteDDLCompiler.define_constraint_remote_table�s���$�$�U�u�$�=�=�=r2FTc
���|j}��|���j}d}|jr|dz
}|d��|d����d|�|jd����d	d
��fd�|jD�����d�z
}|j	d
d}|�%�j
�|dd���}|d|zz
}|S)NzCREATE zUNIQUE zINDEX T)�include_schemaz ON Frz (r�c3�R�K�|]!}�j�|dd���V��"dS)FT��
include_table�
literal_bindsN)�sql_compilerr+)r�r�r.s  �r*r�z7SQLiteDDLCompiler.visit_create_index.<locals>.<genexpr>�sX���������!�)�)���T�*��������r2r�r��wherer"z WHERE )�element�_verify_index_tabler��unique�_prepared_index_namerr�r��expressionsr�r%r+)	r.�creater �include_table_schema�indexr�r��whereclause�where_compileds	`        r*�visit_create_indexz$SQLiteDDLCompiler.visit_create_index�s%������� � ��'�'�'��=�����<�	��I��D����%�%�e�D�%�A�A�A�A��!�!�%�+�%�!�@�@�@�@��I�I�����"�-�	���
�
�
�
�	
�		
���+�H�5�g�>���"�!�.�6�6��5��7���N�
�I��.�.�D��r2c�4�|jdddurdSdS)Nr��
with_rowidFz
 WITHOUT ROWIDr�)r�)r.r�s  r*�post_create_tablez#SQLiteDDLCompiler.post_create_table�s%��� ��*�<�8�E�A�A�%�%��rr2)FT)
r3r4r5rrr
rrrrr1r4r6r7s@r*r�r�Js��������2�2�2�h�����>�����(����������
�
�
�
�
�>�>�>�BF�����:������r2r�c�>��eZdZd�Z�fd�Z�fd�Z�fd�Zd�Z�xZS)�SQLiteTypeCompilerc�,�|�|��Sr#)�
visit_BLOB�r.r�rCs   r*�visit_large_binaryz%SQLiteTypeCompiler.visit_large_binarys�����u�%�%�%r2c���t|t��r|jr(tt|���|��SdS)Nr�)r%r9rPr,r6�visit_DATETIME�r.r�rCr1s   �r*r<z!SQLiteTypeCompiler.visit_DATETIMEsF����5�.�1�1�	#��,�	#��+�T�2�2�A�A�%�H�H�H�"�?r2c���t|t��r|jr(tt|���|��SdS)Nr�)r%r9rPr,r6�
visit_DATEr=s   �r*r?zSQLiteTypeCompiler.visit_DATE�F����5�.�1�1�	��,�	��+�T�2�2�=�=�e�D�D�D��;r2c���t|t��r|jr(tt|���|��SdS)Nr�)r%r9rPr,r6�
visit_TIMEr=s   �r*rBzSQLiteTypeCompiler.visit_TIMEr@r2c��dS)Nrr;r9s   r*�
visit_JSONzSQLiteTypeCompiler.visit_JSON s	���vr2)	r3r4r5r:r<r?rBrDr6r7s@r*r6r6s��������&�&�&�#�#�#�#�#�����������������r2r6c�(�eZdZegd���ZdS)�SQLiteIdentifierPreparer)u�add�after�all�alter�analyze�and�as�asc�attachr��before�begin�between�by�cascade�caser��check�collater�commit�conflictr	r,�cross�current_date�current_time�current_timestamp�databaser�
deferrable�deferred�delete�desc�detach�distinct�drop�each�else�end�escape�except�	exclusive�exists�explain�false�fail�for�foreign�from�full�glob�group�having�if�ignore�	immediate�inr.�indexed�	initially�inner�insert�instead�	intersect�into�is�isnullr��keyr��like�limit�match�natural�not�notnull�null�of�offset�on�or�order�outer�plan�pragma�primary�query�raise�
references�reindex�rename�replace�restrictr��rollback�rowr��setr��temp�	temporary�then�to�transaction�trigger�true�unionr)�update�using�vacuum�values�view�virtual�whenr&N)r3r4r5r��reserved_wordsr;r2r*rFrF's3�������S�v	
�v	
�v	
�x�x�N�N�Nr2rFc�4�eZdZejd���Zd�ZdS)�SQLiteExecutionContextc�R�|jjp|j�dd��S)N�sqlite_raw_colnamesF)r/�_broken_dotted_colnames�execution_options�get)r.s r*�_preserve_raw_colnamesz-SQLiteExecutionContext._preserve_raw_colnames�s1����4�4�
H��%�)�)�*?��G�G�	
r2c�Z�|js!d|vr|�d��d|fS|dfS)N�.r�)r��split)r.�colnames  r*�_translate_colnamez)SQLiteExecutionContext._translate_colname�s=���*�	!�s�g�~�~��=�=��%�%�b�)�7�2�2��D�=� r2N)r3r4r5r�memoized_propertyr�r�r;r2r*r�r��s@������	��
�
���
�!�!�!�!�!r2r�c���eZdZdZdZdZdZdZdZdZ	dZ
dZdZe
ZeZeZeZeZeZeZdZejddd�fejddifejdddd�fejd	difgZdZ dZ!e"j#d
d���						d&d
���Z$ddd�Z%d�Z&d�Z'd�Z(e)j*d���Z+e)j*d'd���Z,e)j*d���Z-e)j*d���Z.d'd�Z/e)j*d'd���Z0e)j*d'd���Z1e)j*d'd���Z2d�Z3d�Z4e)j*d'd���Z5e)j*d'd���Z6d �Z7e)j*	d'd!���Z8e)j*d'd"���Z9e)j*d'd#���Z:e)j*d'd$���Z;d'd%�Z<dS)(�
SQLiteDialectr�FT�qmarkN)r�r3r&)r�r�rr)�1.3.7z�The _json_serializer argument to the SQLite dialect has been renamed to the correct name of json_serializer.  The old argument name will be removed in a future release.)r�z�The _json_deserializer argument to the SQLite dialect has been renamed to the correct name of json_deserializer.  The old argument name will be removed in a future release.)�_json_serializer�_json_deserializerc��tjj|fi|��||_|r|}|r|}||_||_||_|j��|jjdk|_	|jjdk|_
|jjdk|_|jjdk|_|jjdk|_
|jjdk|_dSdS)N)r��)r�
r)rr�)r�r)rr��)r��)r�DefaultDialectr<�isolation_levelr�r��native_datetime�dbapi�sqlite_version_info�supports_right_nested_joinsr��supports_default_valuesr��supports_multivalues_insert�_broken_fk_pragma_quotes)r.r�r��json_serializer�json_deserializerr�r�rds        r*r<zSQLiteDialect.__init__�s��0	��'��7�7��7�7�7�.����	/�.�O��	3� 2�� /���"3��� /����:�!��
�.�*�<�
�,�,0�:�+I�M�,�D�(�
,0�:�+I�N�,�D�(�
"&��!?�9�!L�D���
�.���
�,�-1�J�,J�N�-�D�)�)�)�-"�!r2rr)�READ UNCOMMITTED�SERIALIZABLEc
��	|j|�dd��}ne#t$rX}tjtjd|�d|j�dd�|j������|���Yd}~nd}~wwxYw|�	��}|�
d|z��|���dS)	N�_r�zInvalid value 'z2' for isolation_level. Valid isolation levels for z are r�r�zPRAGMA read_uncommitted = %d)�_isolation_lookupr�r�rr�r�
ArgumentError�namer��cursor�execute�close)r.�
connection�levelr�r�r�s      r*�set_isolation_levelz!SQLiteDialect.set_isolation_level+s���
	�"�4�U�]�]�3��5L�5L�M�O�O���	�	�	��K��!�!��u�u�d�i�i�i����4�3I�)J�)J�)J�L���
!$�

�
�
�
�
�
�
�
�
�����	�����"�"�$�$�����5��G�H�H�H��������s�!$�
B�AB�Bc��|���}|�d��|���}|r	|d}nd}|���|dkrdS|dkrdSJd|z���)NzPRAGMA read_uncommittedrr�rr�FzUnknown isolation level %s)r�r��fetchoner�)r.r�r��resr(s     r*�get_isolation_levelz!SQLiteDialect.get_isolation_level;s����"�"�$�$�����0�1�1�1��o�o�����		���F�E�E��E��������A�:�:�!�>�
�a�Z�Z�%�%�>�6��>�>�>�5r2c�$���j��fd�}|SdS)Nc�>����|�j��dSr#)r�r�)�connr.s �r*�connectz)SQLiteDialect.on_connect.<locals>.connectTs"����(�(��t�/C�D�D�D�D�Dr2)r�)r.r�s` r*�
on_connectzSQLiteDialect.on_connectQs6�����+�
E�
E�
E�
E�
E��N��4r2c�H�d}|�|��}d�|D��S)NzPRAGMA database_listc�6�g|]}|ddk�|d��S)rr�r;)r��dbs  r*�
<listcomp>z2SQLiteDialect.get_schema_names.<locals>.<listcomp>`s%��6�6�6�"�b��e�v�o�o��1��o�o�or2�r�)r.r�rC�s�dls     r*�get_schema_nameszSQLiteDialect.get_schema_names[s.��"��
�
�
��
"�
"��6�6��6�6�6�6r2c��|� |j�|��}d|z}nd}d|�d�}|�|��}d�|D��S)N�%s.sqlite_master�
sqlite_master�SELECT name FROM z! WHERE type='table' ORDER BY namec��g|]
}|d��S�rr;�r�r�s  r*r�z1SQLiteDialect.get_table_names.<locals>.<listcomp>m���%�%�%�3��A��%�%�%r2��identifier_preparer�quote_identifierr��r.r�rrC�qschema�masterr��rss        r*�get_table_nameszSQLiteDialect.get_table_namesbsg�����.�?�?��G�G�G�'�'�1�F�F�$�F���F�F�
���
�
��
"�
"��%�%�"�%�%�%�%r2c�H�d}|�|��}d�|D��S)NzESELECT name FROM sqlite_temp_master WHERE type='table' ORDER BY name c��g|]
}|d��Sr�r;r�s  r*r�z6SQLiteDialect.get_temp_table_names.<locals>.<listcomp>wr�r2r��r.r�rCr�rs     r*�get_temp_table_namesz"SQLiteDialect.get_temp_table_namesos5��
0�	
��
�
��
"�
"��%�%�"�%�%�%�%r2c�H�d}|�|��}d�|D��S)NzDSELECT name FROM sqlite_temp_master WHERE type='view' ORDER BY name c��g|]
}|d��Sr�r;r�s  r*r�z5SQLiteDialect.get_temp_view_names.<locals>.<listcomp>�r�r2r�rs     r*�get_temp_view_namesz!SQLiteDialect.get_temp_view_namesys5��
/�	
��
�
��
"�
"��%�%�"�%�%�%�%r2c�R�|�|d||���}t|��S)N�
table_infor
)�_get_table_pragmarM)r.r��
table_namer�infos     r*�	has_tablezSQLiteDialect.has_table�s3���%�%���j��&�
�
���D�z�z�r2c��|� |j�|��}d|z}nd}d|�d�}|�|��}d�|D��S)Nr�r�r�z  WHERE type='view' ORDER BY namec��g|]
}|d��Sr�r;r�s  r*r�z0SQLiteDialect.get_view_names.<locals>.<listcomp>�r�r2r�rs        r*�get_view_nameszSQLiteDialect.get_view_names�sg�����.�?�?��G�G�G�'�'�1�F�F�$�F���F�F�
���
�
��
"�
"��%�%�"�%�%�%�%r2c�\�|�=|j�|��}d|z}d|�d�}|�||f��}nI	d}|�||f��}n.#tj$rd}|�||f��}YnwxYw|���}	|	r
|	djSdS)Nr�zSELECT sql FROM z WHERE name = ? AND type='view'zzSELECT sql FROM  (SELECT * FROM sqlite_master UNION ALL   SELECT * FROM sqlite_temp_master) WHERE name = ? AND type='view'z<SELECT sql FROM sqlite_master WHERE name = ? AND type='view'r)r�r�r�r�
DBAPIError�fetchallr)
r.r��	view_namerrCrrr�r�results
          r*�get_view_definitionz!SQLiteDialect.get_view_definition�s������.�?�?��G�G�G�'�'�1�F�F�����A��#�#�A�	�|�4�4�B�B�
9�&�� �'�'��I�<�8�8�����>�
9�
9�
9�&�� �'�'��I�<�8�8����
9�����������	!��!�9�=� �	!�	!s�A�(B�Bc
��d}|jdkrd}|�||||���}g}d}|D]�}	|	d}
|	d���}|	d}|	d}
|	d	}|dkr|	d
nd}|dkr�Tt|��}|dk}|�|r|j|||fi|��}|�|�|
|||
||||������|S)Nr
)r��table_xinfor
rr�r��r�r)�server_version_infor�upperrM�_get_table_sql�append�_get_column_info)r.r�rrrCr�rr��tablesqlr�r�r�r�rr��hidden�	generated�	persisteds                  r*�get_columnszSQLiteDialect.get_columns�sJ�����#�w�.�.�"�F��%�%���
�6�&�
�
�������!	�!	�C��q�6�D���F�L�L�N�N�E��q�6�z�H��!�f�G��a�&�K�%��6�6�S��V�V�A�F�
��{�{���V���I��!��I���I��.�4�.��
�F���68����
�N�N��%�%���������	�	�
�
�
�
��r2c	���|rVtjdd|tj���}tjdd|tj������}|�|��}	|�tj|��}||	||d|d�}
|rZd}|rNd}tjtj|��|z|tj��}
|
r|
�	d��}||d	�|
d
<|
S)Nr'r�)�flags�always�auto)r�r�r�rr�r�z.[^,]*\s+AS\s+\(([^,]*)\)\s*(?:virtual|stored)?r)�sqltextr(r)
r=�sub�
IGNORECASE�strip�_resolve_type_affinityr�	text_typerNriru)r.r�r�r�rr�r'r(r%r0rr.�patternr�s              r*r$zSQLiteDialect._get_column_info�s���	M��F�;��E���G�G�G�E��F�8�R��b�m�D�D�D�J�J�L�L�E��-�-�e�4�4�����n�W�-�-�G��� ��#�&�

�
���		O��G��
-�K���	��I�d�O�O�g�-�x�������-�#�k�k�!�n�n�G�.5�I�"N�"N�G�J���r2c�R�tjd|��}|r+|�d��}|�d��}nd}d}||jvr|j|}nbd|vr
tj}nQd|vsd|vsd|vr
tj}n8d	|vs|s
tj}n%d
|vsd|vsd|vr
tj}ntj	}|�[tj
d|��}	|d�|D���}n?#t$r(tj
d|�d|�d���|��}YnwxYw|��}|S)aZReturn a data type from a reflected column, using affinity tules.

        SQLite's goal for universal compatibility introduces some complexity
        during reflection, as a column's defined type might not actually be a
        type that SQLite understands - or indeed, my not be defined *at all*.
        Internally, SQLite handles this with a 'data type affinity' for each
        column definition, mapping to one of 'TEXT', 'NUMERIC', 'INTEGER',
        'REAL', or 'NONE' (raw bits). The algorithm that determines this is
        listed in http://www.sqlite.org/datatype3.html section 2.1.

        This method allows SQLAlchemy to support that algorithm, while still
        providing access to smarter reflection utilities by regcognizing
        column definitions that SQLite only supports through affinity (like
        DATE and DOUBLE).

        z([\w ]+)(\(.*?\))?rr�r�r�r�CLOBrrr�FLOA�DOUBNz(\d+)c�,�g|]}t|����Sr;)�int)r��as  r*r�z8SQLiteDialect._resolve_type_affinity.<locals>.<listcomp>8s��#9�#9�#9�q�C��F�F�#9�#9�#9r2zCould not instantiate type z with reflected arguments z; using no arguments.)r=r�ru�
ischema_namesr�rr�NullTyperr�findallr$r�warn)r.r�r�r0rcs     r*r2z$SQLiteDialect._resolve_type_affinitys���"��.��6�6���	��k�k�!�n�n�G��;�;�q�>�>�D�D��G��D��d�(�(�(��(��1�G�G�
�g�
�
��&�G�G�
�w�
�
�&�G�"3�"3�v��7H�7H��m�G�G�
�w�
�
�g�
��'�G�G�
�w�
�
�&�G�"3�"3�v��7H�7H��m�G�G��&�G����:�h��-�-�D�
$�!�'�#9�#9�D�#9�#9�#9�:�����
$�
$�
$��	�	��w�w����&����
"�'�)�)����

$�����g�i�i�G��s�C(�(/D�Dc�\�d}|�|||���}|r;d}tj||tj��}|r|�d��nd}|j|||fi|��}	|	�d����g}
|	D]%}|dr|
�|d���&|
|d�S)	Nr
zCONSTRAINT (\w+) PRIMARY KEYrc�,�|�d��S)Nr�)r�)�cols r*�<lambda>z1SQLiteDialect.get_pk_constraint.<locals>.<lambda>Os��#�'�'�-�"8�"8�r2)r�r�r�)�constrained_columnsr�)r"r=rN�Irur)�sortr#)r.r�rrrC�constraint_name�
table_data�
PK_PATTERNr�cols�pkeysrBs            r*�get_pk_constraintzSQLiteDialect.get_pk_constraintEs������(�(��Z��(�O�O�
��	B�8�J��Y�z�:�r�t�<�<�F�17�A�f�l�l�1�o�o�o�T�O��t��
�J��E�E�"�E�E���	�	�8�8�	�9�9�9����	*�	*�C��=�!�
*����S��[�)�)�)��',�o�F�F�Fr2c�������|d||���}i}|D]�}|d|d|d|df\}}	}
}|s�j||	fd|i|��}|d}
ng}
�jrtjd	d
|	��}	||vr	||}ndg||	|
id�x}||<|||<|d�|
��|r|d�|����d
��t
�fd�|���D����}��|||������gS��fd�}g}|��D]h\}}}}
}�|||
��}||vrtj
d|�d|�����4|�|��}||d<||d<|�|���i|�|�����|S)N�foreign_key_listr
rr�rrrrDz^[\"\[`\']|[\"\]`\']$r�)r�rD�referred_schema�referred_table�referred_columns�optionsrQc�H�t|��|fzt|��zSr#)�tuple)rDrPrQs   r*�fk_sigz.SQLiteDialect.get_foreign_keys.<locals>.fk_sig�s/���)�*�*�!�#�$��(�)�)�*�
r2c3�Z�K�|]%}�|d|d|d��|fV��&dS)rDrPrQNr;)r��fkrUs  �r*r�z1SQLiteDialect.get_foreign_keys.<locals>.<genexpr>�sj�����
!
�
!
�����,�-��'�(��)�*���
�

�
!
�
!
�
!
�
!
�
!
�
!
r2c	3�r�K�d}tj|�tj��D�]}|�dddddd��\}}}}}}t	�
�|����}|s|}n"t	�
�|����}|p|}i}tjd|�����D]k}	|	�d	��r |	dd��	��|d
<�7|	�d��r|	dd��	��|d<�l|||||fV���dS)
Nz�(?:CONSTRAINT (\w+) +)?FOREIGN KEY *\( *(.+?) *\) +REFERENCES +(?:(?:"(.+?)")|([a-z0-9_]+)) *\((.+?)\) *((?:ON (?:DELETE|UPDATE) (?:SET NULL|SET DEFAULT|CASCADE|RESTRICT|NO ACTION) *)*)rr�rrrr�z
 *\bON\b *�DELETE�ondelete�UPDATE�onupdate)
r=�finditerrErur�_find_cols_in_sigr�r!�
startswithr1)�
FK_PATTERNr�rGrD�referred_quoted_name�
referred_namerQ�onupdatedeleterR�tokenr.rHs          ��r*�	parse_fksz1SQLiteDialect.get_foreign_keys.<locals>.parse_fks�s������L�
���Z��R�T�B�B� 
� 
���K�K��1�a��A�q�1�1��#�'�(�!�$�"�&*��*�*�+>�?�?�'�'�#�(��':�$�$�'+��.�.�/?�@�@�(�(�$�!5� E�
�
����X�m�^�5I�5I�5K�5K�L�L�@�@�E��'�'��1�1�@�.3�A�B�B�i�o�o�.?�.?��
�+�+��)�)�(�3�3�@�.3�A�B�B�i�o�o�.?�.?��
�+��#�'�!�$�������5 
� 
r2z,WARNING: SQL-parsed foreign key constraint 'z8' could not be located in PRAGMA foreign_keys for table r�rR)
rrLr�r=r/r#�dictr�r"rr?ra�extend)r.r�rrrC�
pragma_fks�fksr��numerical_id�rtbl�lcol�rcol�referred_pkrQrW�keys_by_signaturere�fkeysrGrDrbrR�sigr�rUrHs`                       @@r*�get_foreign_keyszSQLiteDialect.get_foreign_keysWs�������+�+��*�J�v�,�
�
�
����'	4�'	4�C�03�A���A���A���A��/O�,�\�4��t��
&�
5�d�4�����-3��79����
$/�/D�#E� � �
$&� ��,�
B��v�6��D�A�A���s�"�"���&���!�+-�'-�&*�(8�!�
*�*���S��&�%'��L�!��$�%�,�,�T�2�2�2��
4��%�&�-�-�d�3�3�3��	�	�	�!�
!
�
!
�
!
�
!
��j�j�l�l�
!
�
!
�
!
�

�

���(�(��Z��(�O�O�
����I�(	�(	�(	�(	�(	�(	�T���Y�[�[�
	�	�
�������&�,�m�=M�N�N�C��+�+�+��	�	�47�3�3�
�
�D����
�#�'�'��,�,�C�)�C��K�$�C�	�N��L�L������	���&�-�-�/�/�0�0�0��r2c#�K�tjd|tj��D].}|�d��p|�d��V��/dS)Nz(?:"(.+?)")|([a-z0-9_]+)rr�)r=r]rEru)r.rqr�s   r*r^zSQLiteDialect._find_cols_in_sig�sX�����[�!<�c�2�4�H�H�	3�	3�E��+�+�a�.�.�2�E�K�K��N�N�2�2�2�2�	3�	3r2c���
�i}�j||f|dd�|��D]8}|d�d��s�t|d��}|||<�9�j||fd|i|���
�
sgSg}��
fd�}	|	��D]G\}
}t|��}||vr/|�|��|
|d�}|�|���H|S)	NT)r�include_auto_indexesr��sqlite_autoindex�column_namesrc3��K�d}d}tj|�tj��D]A}|�dd��\}}|t	��|����fV��Btj|�tj��D]R}t	��|�d��p|�d������}d|fV��SdS)Nz,(?:CONSTRAINT "?(.+?)"? +)?UNIQUE *\((.+?)\)z-(?:(".+?")|([a-z0-9]+)) +[a-z0-9_ ]+? +UNIQUErr�)r=r]rErurr^)�UNIQUE_PATTERN�INLINE_UNIQUE_PATTERNr�r�rJr.rHs     ��r*�	parse_uqsz7SQLiteDialect.get_unique_constraints.<locals>.parse_uqs	s������L�N�D�
"���^�Z���F�F�
?�
?��"�[�[��A�.�.�
��d��D��!7�!7��!=�!=�>�>�>�>�>�>�>�
��%:�J���M�M�
!�
!����*�*�5�;�;�q�>�>�+K�U�[�[��^�^�L�L�����D�j� � � � �	
!�
!r2)r�rw)�get_indexesr_rTr"rar#)r.r�rrrC�auto_index_by_sig�idxrq�unique_constraintsr{r�rJ�parsed_constraintrHs`            @r*�get_unique_constraintsz$SQLiteDialect.get_unique_constraints�s_����
��#�4�#���
��!%�	
�
�
�
�
�
	)�
	)�C��v�;�)�)�*<�=�=�
����N�+�,�,�C�%(��c�"�"�(�T�(��
�
�
�+1�
�57�
�
�
��	��I���	!�	!�	!�	!�	!�	!�&$�)�+�+�	=�	=�J�D�$���+�+�C��'�'�'�!�%�%�c�*�*�*�-1�4�$H�$H�!�"�)�)�*;�<�<�<��"�!r2c��|j||fd|i|��}|sgSd}g}tj||tj��D]@}|�|�d��|�d��d����A|S)Nrz.(?:CONSTRAINT (\w+) +)?CHECK *\( *(.+) *\),? *r�r)r.r�)r"r=r]rEr#ru)	r.r�rrrCrH�
CHECK_PATTERN�check_constraintsr�s	         r*�get_check_constraintsz#SQLiteDialect.get_check_constraints&s���(�T�(��
�
�
�+1�
�57�
�
�
��	��I�M�
����[��
�B�D�A�A�	�	�E��$�$�!�K�K��N�N�E�K�K��N�N�C�C�
�
�
�
�!� r2c	�2�|�|d||���}g}|�dd��}|D]Q}|s|d�d��r� |�t	|dg|d������Rt|��D]�}	|�|d	|	d
��}
|
D]_}|d�4t
jd|	d
z��|�|	��n"|	d�|d���`��|S)
N�
index_listr
ruFrrvr�)r�rwr)�
index_infor�z;Skipped unsupported reflection of expression-based index %srw)	rrar_r#rfrrr?�remove)r.r�rrrC�pragma_indexes�indexesrur�r~�pragma_indexs           r*r|zSQLiteDialect.get_indexes<sa���/�/���j��0�
�
����!�v�v�&<�e�D�D��!�	N�	N�C�(�
�C��F�,=�,=�"�-�-�
���N�N�4�S��V�"�S��V�L�L�L�M�M�M�M���=�=�	7�	7�C��1�1��L�#�f�+���L�$�	
7�	
7���q�6�>��I�4�69�&�k�B�����N�N�3�'�'�'��E���'�.�.�s�1�v�6�6�6�6���r2c��|rd|j�|��z}nd}	dd|iz}|�||f��}n3#tj$r!dd|iz}|�||f��}YnwxYw|���S)Nz%s.r�z�SELECT sql FROM  (SELECT * FROM %(schema)ssqlite_master UNION ALL   SELECT * FROM %(schema)ssqlite_temp_master) WHERE name = ? AND type = 'table'rzISELECT sql FROM %(schema)ssqlite_master WHERE name = ? AND type = 'table')r�r�r�rr�scalar)r.r�rrrC�schema_exprr�rs        r*r"zSQLiteDialect._get_table_sql_s����	���(�9�9�&�A�A��K�K��K�	6�%�)1�+�'>�	?�
��#�#�A�
�}�5�5�B�B���~�	6�	6�	6�%�(0�+�'>�?�
�
�#�#�A�
�}�5�5�B�B�B�
	6�����y�y�{�{�s�A�-A3�2A3c���|jj}|�d||��zg}nddg}||��}|D]E}|�|�d|�d�}|�|��}	|	js|	���}
ng}
|
r|
cS�FgS)Nz
PRAGMA %s.zPRAGMA main.zPRAGMA temp.r�r�)r�r�r��_soft_closedr)r.r�r�rr�quote�
statements�qtable�	statementr�rs           r*rzSQLiteDialect._get_table_pragmays����(�9����&���v���6�7�J�J�)�.�9�J���z�"�"��#�
	�
	�I�&/�i�������@�I��'�'�	�2�2�F��&�
� ���*�*������
��
�
�
�
��Ir2)NFNNNNr#)=r3r4r5r��supports_alter�supports_unicode_statements�supports_unicode_bindsr��supports_empty_insertr�r��tuple_in_values�default_paramstyler��execution_ctx_clsr��statement_compilerr��ddl_compilerr6r�rFr�r<�colspecsr��	sa_schema�Table�Index�Column�
Constraint�construct_argumentsr�r�r�deprecated_paramsr<r�r�r�r�r�cacher�rrrrrrr)r$r2rLrrr^r�r�r|r"rr;r2r*r�r��s��������D��N�"&��!��"��!���M�"&���O� ��.��'��$�L�&�M�'�H�!�M��H��O�
�O�!&�"�
�
�	
�
��7�D�/�*���+/�(,�&*�
�
�	
�
�	�
�t�4�5�#��( %��#���T��
�
�
�
�
� ������4�4�4�
�
�4�l./��B�B����� ?�?�?�,�����7�7���7���
&�
&�
&���
&���&�&���&���&�&���&�������&�&�&���&���!�!�!���!�:��,�,�,���,�\)�)�)�V4�4�4�l��G�G�G���G�"��Q�Q�Q���Q�f3�3�3���-1�4"�4"�4"���4"�l��!�!�!���!�*�� � � ��� �D��������2�����r2r�)<rrrkr&r=�jsonrrrr�rr	rr�rr
r�r�enginerrrrrrrrrrrrrrrrr �objectr9�DateTimer\�Datert�Timer{r�r�r�r�r<r�r��DDLCompilerr��GenericTypeCompilerr6�IdentifierPreparerrF�DefaultExecutionContextr�r�r�r;r2r*�<module>r�s���R	�R	�h��������	�	�	�	�������������������������������#�#�#�#�#�#�������!�!�!�!�!�!������������� � � � � � � � � � � � ������������������������������������������������������������������������������������������$����$1�1�1�1�1�V�1�1�1�hb.�b.�b.�b.�b.�~�x�0�b.�b.�b.�J>*�>*�>*�>*�>*�>�8�=�>*�>*�>*�BL*�L*�L*�L*�L*�>�8�=�L*�L*�L*�`
�M�4���x��M�;��M����M����M�4�
����h�o��
�H�M���H����x��	�
�H�M���H�M�
�������!���X�&��
�h�n���x����X�^��
�8����x����D�� �x��!�"�H�M�#�$�!��M��M����#����!�
�^�3���
�:j
�j
�j
�j
�j
�X�)�j
�j
�j
�Zt�t�t�t�t��,�t�t�t�n#�#�#�#�#��5�#�#�#�Ly�y�y�y�y�x�:�y�y�y�x!�!�!�!�!�W�<�!�!�!�,Y�Y�Y�Y�Y�G�*�Y�Y�Y�Y�Yr2

Hacked By AnonymousFox1.0, Coded By AnonymousFox