HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/sdb/__pycache__/sqlite3.cpython-310.pyc
o

�N�g0�@s�dZddlZddlZddlZzddlZdZWney!dZYnwdZe�	e
�ZddiZdd	�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_�setcCstsdSdS)z,
    Only load if sqlite3 is available.
    FT)�HAS_SQLITE3�rr�D/opt/saltstack/salt/lib/python3.10/site-packages/salt/sdb/sqlite3.py�__virtual__Asr�strictcCsn|�d|��d�}|�d�}|dkr-td|||dd�}t�|�}||�\}}|�d|�}d|�dd�dS)	Nzutf-8�rzNUL-terminated utf-8�zNUL not allowed�"z"")�encode�decode�find�UnicodeEncodeError�codecs�lookup_error�replace)�s�errorsZ	encodableZ	nul_index�errorZ
error_handlerZreplacement�_rrr�_quoteJs
�
rcCs�|d}d}t�|�}|��}|�d�}|�dt�}t|d�}t|�}z*|r2|D]}|�|�q)n|�dd�rM|�d|�d��|�d	|�d
|�d��Wn
tjyXYnw|||fS)NZdatabaseZcreate_statements�tableZ_idxZcreate_tableTz
CREATE TABLE z (key text, value blob)zCREATE UNIQUE INDEX z ON z (key))�sqlite3�connectZcursor�get�
DEFAULT_TABLEr�executeZOperationalError)�profileZdbr�conn�curZstmts�idxZsqlrrr�_connect^s*

���
r"cCsZ|sdSt|�\}}}ttjj�|��}|�dd|�d��}|�|||d��|��dS)z)
    Set a key/value pair in sqlite3
    FZ	set_queryzINSERT OR REPLACE INTO z VALUES (:key, :value))�key�valueT)	r"�
memoryview�salt�utils�msgpackZpackbrrZcommit)r#r$rrr r�qrrrrus
�cCs`|sdSt|�\}}}|�dd|�d��}|�|d|i�}|��}|s%dStjjj|ddd�S)	z"
    Get a value from sqlite3
    NZ	get_queryzSELECT value FROM z WHERE key=:keyr#rF)�raw)r"rrZfetchoner&r'r(Zunpackb)r#rrr rr)�resrrrr�sr)r)N)�__doc__r�loggingZsalt.utils.msgpackr&rr�ImportErrorr�	getLogger�__name__�logZ__func_alias__rrr"rrrrrr�<module>s$,�