File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/sdb/__pycache__/sqlite3.cpython-310.pyc
o
�N�g0 � @ s� d Z ddlZddlZddlZzddlZdZW n ey! dZY nw dZe� e
�ZddiZdd � Z
ddd�Zd
d� Zddd�Zddd�ZdS )a�
SQLite sdb Module
:maintainer: SaltStack
:maturity: New
:platform: all
This module allows access to sqlite3 using an ``sdb://`` URI
Like all sdb modules, the sqlite3 module requires a configuration profile to
be configured in either the minion or master configuration file. This profile
requires very little. For example:
.. code-block:: yaml
mysqlite:
driver: sqlite3
database: /tmp/sdb.sqlite
table: sdb
create_table: True
The ``driver`` refers to the sqlite3 module, ``database`` refers to the sqlite3
database file. ``table`` is the table within the db that will hold keys and
values (defaults to ``sdb``). The database and table will be created if they
do not exist.
Advanced Usage:
===============
Instead of a table name, it is possible to provide custom SQL statements to
create the table(s) and get and set values.
.. code-block:: yaml
myadvanced
driver: sqlite3
database: /tmp/sdb-advanced.sqlite
create_statements:
- "CREATE TABLE advanced (a text, b text, c blob, d blob)"
- "CREATE INDEX myidx ON advanced (a)"
get_query: "SELECT d FROM advanced WHERE a=:key"
set_query: "INSERT OR REPLACE INTO advanced (a, d) VALUES (:key, :value)"
� NTFZsdb�set_�setc C s t sdS dS )z,
Only load if sqlite3 is available.
FT)�HAS_SQLITE3� r r �D/opt/saltstack/salt/lib/python3.10/site-packages/salt/sdb/sqlite3.py�__virtual__A s r �strictc C sn | � d|��d�}|�d�}|dkr-td|||d d�}t�|�}||�\}}|�d|�}d|�dd� d S ) Nzutf-8� r zNUL-terminated utf-8� zNUL not allowed�"z"")�encode�decode�find�UnicodeEncodeError�codecs�lookup_error�replace)�s�errorsZ encodableZ nul_index�errorZ
error_handlerZreplacement�_r r r �_quoteJ s
�
r c C s� | d }d }t �|�}|�� }| �d�}| �dt�}t|d �}t|�}z*|r2|D ]}|�|� q)n| �dd�rM|�d|� d�� |�d |� d
|� d�� W n
t jyX Y nw |||fS )NZdatabaseZcreate_statements�tableZ_idxZcreate_tableTz
CREATE TABLE z (key text, value blob)zCREATE UNIQUE INDEX z ON z (key))�sqlite3�connectZcursor�get�
DEFAULT_TABLEr �executeZOperationalError)�profileZdbr �conn�curZstmts�idxZsqlr r r �_connect^ s*
���
r"