관리-도구
편집 파일: aiosqlite.cpython-38.pyc
U -?�f90 � @ s� d Z ddlZddlmZ ddlmZ ddlmZ ddlm Z dd l mZ dd l mZ ddl mZ ddlmZ dd lmZ G dd� d�ZG dd� de�ZG dd� de�ZG dd� de�ZG dd� d�ZG dd� de�ZG dd� de �ZeZdS )aZ .. dialect:: sqlite+aiosqlite :name: aiosqlite :dbapi: aiosqlite :connectstring: sqlite+aiosqlite:///file_path :url: https://pypi.org/project/aiosqlite/ The aiosqlite dialect provides support for the SQLAlchemy asyncio interface running on top of pysqlite. aiosqlite is a wrapper around pysqlite that uses a background thread for each connection. It does not actually use non-blocking IO, as SQLite databases are not socket-based. However it does provide a working asyncio interface that's useful for testing and prototyping purposes. Using a special asyncio mediation layer, the aiosqlite dialect is usable as the backend for the :ref:`SQLAlchemy asyncio <asyncio_toplevel>` extension package. This dialect should normally be used only with the :func:`_asyncio.create_async_engine` engine creation function:: from sqlalchemy.ext.asyncio import create_async_engine engine = create_async_engine("sqlite+aiosqlite:///filename") The URL passes through all arguments to the ``pysqlite`` driver, so all connection arguments are the same as they are for that of :ref:`pysqlite`. .. _aiosqlite_udfs: User-Defined Functions ---------------------- aiosqlite extends pysqlite to support async, so we can create our own user-defined functions (UDFs) in Python and use them directly in SQLite queries as described here: :ref:`pysqlite_udfs`. .. _aiosqlite_serializable: Serializable isolation / Savepoints / Transactional DDL (asyncio version) ------------------------------------------------------------------------- Similarly to pysqlite, aiosqlite does not support SAVEPOINT feature. The solution is similar to :ref:`pysqlite_serializable`. This is achieved by the event listeners in async:: from sqlalchemy import create_engine, event from sqlalchemy.ext.asyncio import create_async_engine engine = create_async_engine("sqlite+aiosqlite:///myfile.db") @event.listens_for(engine.sync_engine, "connect") def do_connect(dbapi_connection, connection_record): # disable aiosqlite's emitting of the BEGIN statement entirely. # also stops it from emitting COMMIT before any DDL. dbapi_connection.isolation_level = None @event.listens_for(engine.sync_engine, "begin") def do_begin(conn): # emit our own BEGIN conn.exec_driver_sql("BEGIN") .. warning:: When using the above recipe, it is advised to not use the :paramref:`.Connection.execution_options.isolation_level` setting on :class:`_engine.Connection` and :func:`_sa.create_engine` with the SQLite driver, as this function necessarily will also alter the ".isolation_level" setting. � N)�deque)�partial� )�SQLiteExecutionContext)�SQLiteDialect_pysqlite� )�pool)�util)�AdaptedConnection)�await_fallback)� await_onlyc @ s` e Zd ZdZdZdd� Zdd� Zddd �Zd d� Zdd � Z dd� Z dd� Zddd�Zdd� Z dS )�AsyncAdapt_aiosqlite_cursor)�_adapt_connection�_connection�description�await_�_rows� arraysize�rowcount� lastrowidFc C s4 || _ |j| _|j| _d| _d| _d | _t� | _d S )Nr ���)r r r r r r r r )�selfZadapt_connection� r �T/opt/hc_python/lib64/python3.8/site-packages/sqlalchemy/dialects/sqlite/aiosqlite.py�__init__n s z$AsyncAdapt_aiosqlite_cursor.__init__c C s | j �� d S �N)r �clear�r r r r �closew s z!AsyncAdapt_aiosqlite_cursor.closeNc C s� z�| � | j�� �}|d kr,| � |�|�� n| � |�||�� |jrt|j| _d | _| _| js�t| � |� � ��| _ nd | _|j| _|j| _| js�| � |�� � n|| _W n. t k r� } z| j�|� W 5 d }~X Y nX d S )Nr )r r �cursor�executer r r �server_sider �fetchallr r �_cursor� Exceptionr �_handle_exception)r � operation� parametersr# �errorr r r r z s$ z#AsyncAdapt_aiosqlite_cursor.executec C s~ zJ| � | j�� �}| � |�||�� d | _|j| _|j| _| � |�� � W n. tk rx } z| j � |� W 5 d }~X Y nX d S r )r r r �executemanyr r r r r$ r r% )r r&