<commit_before># -*- coding: utf-8 -*-
"""
Management of SQLite3 databases
===============================

:depends:   - SQLite3 Python Module
:configuration: See :py:mod:`salt.modules.sqlite3` for setup instructions
.. versionadded:: 2016.3.0

The sqlite3 module is used to create and manage sqlite3 databases
and execute queries

Here is an example of creating a table using sql statements:

  .. code-block:: yaml

    users:
      sqlite3.table_present:
        - db: /var/www/data/app.sqlite
        - schema: CREATE TABLE `users` (`username` TEXT COLLATE NOCASE UNIQUE NOT NULL, `password` BLOB NOT NULL, `salt` BLOB NOT NULL, `last_login` INT)


Here is an example of creating a table using yaml/jinja instead of sql:

  .. code-block:: yaml

    users:
      sqlite3.table_present:
        - db: /var/www/app.sqlite
        - schema:
          - email TEXT COLLATE NOCASE UNIQUE NOT NULL
          - firstname TEXT NOT NULL
          - lastname TEXT NOT NULL
          - company TEXT NOT NULL
          - password BLOB NOT NULL
          - salt BLOB NOT NULL


Here is an example of making sure a table is absent:

  .. code-block:: yaml

    badservers:
      sqlite3.table_absent:
        - db: /var/www/data/users.sqlite


Sometimes you would to have specific data in tables to be used by other services
Here is an example of making sure rows with specific data exist:

  .. code-block:: yaml

    user_john_doe_xyz:
      sqlite3.row_present:
        - db: /var/www/app.sqlite
        - table: users
        - where_sql: email='<EMAIL>'
        - data:
            email: <EMAIL>
            lastname: doe
            firstname: john
            company: companyxyz.com
            password: <PASSWORD>
            salt: <PASSWORD>
        - require:
          - sqlite3: users


Here is an example of removing a row from a table:

  .. code-block:: yaml

    user_john_doe_abc:
      sqlite3.row_absent:
        - db: /var/www/app.sqlite
        - table: users
        - where_sql: email="<EMAIL>"
        - require:
          - sqlite3: users
"""

# Import Python libs
from __future__ import absolute_import

# Import Salt libs
import salt.ext.six as six

try:
    import sqlite3

    HAS_SQLITE3 = True
except ImportError:
    HAS_SQLITE3 = False


def __virtual__():
    """
    Only load if the sqlite3 module is available
    """
    return HAS_SQLITE3


def row_absent(name, db, table, where_sql, where_args=None):
    """
    Makes sure the specified row is absent in db.  If multiple rows<commit_msg>Added a hint how to run random sqlite queries<commit_after># -*- coding: utf-8 -*-
"""
Management of SQLite3 databases
===============================

:depends:   - SQLite3 Python Module
:configuration: See :py:mod:`salt.modules.sqlite3` for setup instructions
.. versionadded:: 2016.3.0

The sqlite3 module is used to create and manage sqlite3 databases
and execute queries

Here is an example of creating a table using sql statements:

  .. code-block:: yaml

    users:
      sqlite3.table_present:
        - db: /var/www/data/app.sqlite
        - schema: CREATE TABLE `users` (`username` TEXT COLLATE NOCASE UNIQUE NOT NULL, `password` BLOB NOT NULL, `salt` BLOB NOT NULL, `last_login` INT)


Here is an example of creating a table using yaml/jinja instead of sql:

  .. code-block:: yaml

    users:
      sqlite3.table_present:
        - db: /var/www/app.sqlite
        - schema:
          - email TEXT COLLATE NOCASE UNIQUE NOT NULL
          - firstname TEXT NOT NULL
          - lastname TEXT NOT NULL
          - company TEXT NOT NULL
          - password BLOB NOT NULL
          - salt BLOB NOT NULL


Here is an example of making sure a table is absent:

  .. code-block:: yaml

    badservers:
      sqlite3.table_absent:
        - db: /var/www/data/users.sqlite


Sometimes you would to have specific data in tables to be used by other services
Here is an example of making sure rows with specific data exist:

  .. code-block:: yaml

    user_john_doe_xyz:
      sqlite3.row_present:
        - db: /var/www/app.sqlite
        - table: users
        - where_sql: email='<EMAIL>'
        - data:
            email: <EMAIL>
            lastname: doe
            firstname: john
            company: companyxyz.com
            password: <PASSWORD>
            salt: abcdef012934125
        - require:
          - sqlite3: users


Here is an example of removing a row from a table:

  .. code-block:: yaml

    user_john_doe_abc:
      sqlite3.row_absent:
        - db: /var/www/app.sqlite
        - table: users
        - where_sql: email="<EMAIL>"
        - require:
          - sqlite3: users
          
Note that there is no explicit state to perform random queries, however, this 
can be approximated sqlite3's module functions and module.run:

  .. code-block:: yaml
  
    zone-delete:
      module.run:
        - name: sqlite3.modify
        - db: {{ db }}
        - sql: "DELETE FROM records WHERE id > {{ count[0] }} AND domain_id = {{ domain_id }}"
        - watch:
          - sqlite3: zone-insert-12
"""

# Import Python libs
from __future__ import absolute_import

# Import Salt libs
import salt.ext.six as six

try:
    import sqlite3

    HAS_SQLITE3 = True
except ImportError:
    HAS_SQLITE3 = False


def __virtual__():
    """
    Only load if the sqlite3 module is available
    """
    return HAS_SQLITE3


def row_absent(name, db, table, where_sql, where_args=None):
    """
    Makes sure the specified row is absent in db.  If multiple rows
{'fraction_non_alphanumeric': 0.09512550018188431, 'fraction_numerical': 0.011458712259003273, 'mean_word_length': 2.2252199413489735, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 10, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '476877', 'n_tokens_mistral': 1735, 'n_tokens_neox': 1635, 'n_words': 579}