%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/states/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/states/sqlite3.pyc

�
���^c@@s�dZddlmZmZmZddlmZyddlZeZ	Wne
k
raeZ	nXd�Zdd�Zded�Zd�Zed	�Zdd
�Zd�Zd�ZdS(
u�	
Management of SQLite3 databases
===============================

.. versionadded:: 2016.3.0

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

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='john.doe@companyxyz.com'
        - data:
            email: john.doe@companyxyz.com
            lastname: doe
            firstname: john
            company: companyxyz.com
            password: abcdef012934125
            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="john.doe@companyabc.com"
        - require:
          - sqlite3: users

Note that there is no explicit state to perform random queries, however, this
can be approximated with 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
i(tabsolute_importtunicode_literalstprint_function(tsixNcC@stS(u6
    Only load if the sqlite3 module is available
    (tHAS_SQLITE3(((s7/usr/lib/python2.7/site-packages/salt/states/sqlite3.pyt__virtual__nsc
C@si|d6id6dd6dd6}d}z�y�tj|dtj�}t|_d}|dkrt|d|d|�}nt|d|d||�}t|�d	kr�t|d<d
|d<n�t|�d	kr�t	drt
|d<d||d<|d
|dd<q�|dkr9|jd|d|�}n|jd|d||�}|j�|j
d	kr�t
|d<d|d<|d
|dd<q�t|d<d|d<nt
|d<d|d<Wn0tk
r�}	t|d<tj|	�|d<nXWd|r|j�nX|S(ux
    Makes sure the specified row is absent in db.  If multiple rows
    match where_sql, then the state will fail.

    name
        Only used as the unique ID

    db
        The database file name

    table
        The table name to check

    where_sql
        The sql to select the row to check

    where_args
        The list parameters to substitute in where_sql
    unameuchangesuresultuucommenttdetect_typesuSELECT * FROM `u` WHERE iu-More than one row matched the specified queryutestuRow will be removed in iuoldu
DELETE FROM `uRow removeduUnable to remove rowu
Row is absentN(tNonetsqlite3tconnecttPARSE_DECLTYPESt
_dict_factorytrow_factoryt_querytlentFalset__opts__tTruetexecutetcommittrowcountt	ExceptionRt	text_typetclose(
tnametdbttablet	where_sqlt
where_argstchangestconntrowstcursorte((s7/usr/lib/python2.7/site-packages/salt/states/sqlite3.pyt
row_absentusZ

		



	






cC@s2i|d6id6d#d6dd6}d#}z�y�tj|dtj�}t|_d#}	|d#krt|d|d|�}	nt|d|d||�}	t|	�d	kr�t|d<d
|d<nt|	�d	kr�x�t	j
|�D]�\}
}|
|	dkr�|	d|
|kr�|rXtdrCt|d<d
||d<qqg}g}
x?t	j
|�D].\}
}|j
d|
d�|
j
|�q_W|d#k	r�|
|7}
nd|d}|dj|�7}|d7}||7}|j||
�}|j�|jd	krAt|d<d|d<|	d|dd<||dd<qqt|d<d|d<qtt|d<dd|d<Pq�q�W|dd#kr�t|d<d|d<q�n@tdr�t|d<||dd<d||d<n
g}g}g}xLt	j
|�D];\}
}|j
d�|j
|�|j
d|
d�q�Wd|d}|dj|�7}|d7}|dj|�7}|d 7}|j||�}|j�|jd	kr�t|d<||dd<d!|d<nt|d<d"|d<Wn0tk
r}t|d<t	j|�|d<nXWd#|r-|j�nX|S($u�
    Checks to make sure the given row exists. If row exists and update is True
    then row will be updated with data. Otherwise it will leave existing
    row unmodified and check it against data. If the existing data
    doesn't match data_check the state will fail.  If the row doesn't
    exist then it will insert data into the table. If more than one
    row matches, then the state will fail.

    name
        Only used as the unique ID

    db
        The database file name

    table
        The table name to check the data

    data
        The dictionary of key/value pairs to check against if
        row exists, insert into the table if it doesn't

    where_sql
        The sql to select the row to check

    where_args
        The list parameters to substitute in where_sql

    update
        True will replace the existing row with data
        When False and the row exists and data does not equal
        the row data then the state will fail
    unameuchangesuresultuucommentRuSELECT * FROM `u` WHERE iu-More than one row matched the specified queryiutestuRow will be update in u`u`=?uUPDATE `u` SET u,u WHERE uRow updateduoldunewuRow update faileduExisting data doesunot match desired stateu
Row existsuRow will be inserted into u?u
INSERT INTO `u` (u
) VALUES (u)uInserted rowuUnable to insert dataN(RRR	R
RRR
RRRt	iteritemsRRtappendtjoinRRRRRR(RRRtdataRRtupdateRRRtkeytvaluetcolumnstparamstsqlR t
value_stmttvaluesR!((s7/usr/lib/python2.7/site-packages/salt/states/sqlite3.pytrow_present�s�'

		

$






















cC@s�i|d6id6dd6dd6}d}zDy
tj|dtj�}t|dd|g�}t|�d	kr�td
r�t|d<d|d|d<q7|jd
|�|j	�|dd|dd<t|d<d|d|d<nMt|�dkrt|d<d|d|d<nt
|d<d|d|d<Wn0tk
rj}t
|d<tj
|�|d<nXWd|r�|j�nX|S(u�
    Make sure the specified table does not exist

    name
        The name of the table

    db
        The name of the database file
    unameuchangesuresultuucommentRuSELECT sql FROM sqlite_master u WHERE type='table' AND name=?iutestu'u' will be droppeduDROP TABLE iuoldu
' was droppedu' is already absentu$Multiple tables with the same name='N(RRR	R
R
RRRRRRRRRR(RRRRttablesR!((s7/usr/lib/python2.7/site-packages/salt/states/sqlite3.pyttable_absentNs<


	






c	C@s�i|d6id6dd6dd6}d}z�yrtj|dtj�}t|dd|g�}t|�d	kr�d}t|tj�r�|j	�}nt
||�}||d
d
kr�|r}tdrt|d<|d
d
|dd<||dd
<d|d|d<q�|j
d|d�|j
|�|j�t|d<|d
d
|dd<||dd
<d|d|d<q�t|d<d|d|d
d
|d<q�t|d<d|d|d<n�t|�d
kr�d}t|tj�r�|}nt
||�}tdr@t|d<||dd
<d|d|d<q�|j
|�|j�t|d<||dd
<d|d|d<nt|d<d||d<Wn-tk
r�}t|d<t|�|d<nXWd|r�|j�nX|S(u�
    Make sure the specified table exists with the specified schema

    name
        The name of the table

    db
        The name of the database file

    schema
        The dictionary containing the schema information

    force
        If the name of the table exists and force is set to False,
        the state will fail.  If force is set to True, the existing
        table will be replaced with the new table
    unameuchangesuresultuucommentRuSELECT sql FROM sqlite_master uWHERE type='table' AND name=?iiutestuoldunewu'u' will be replaceduDROP TABLE `u`u
Replaced 'uExpected schema=u
actual schema=u' exists with matching schemau' will be createduCreated table 'u#Multiple tables with the same name=N(RRR	R
R
Rt
isinstanceRtstring_typeststript_get_sql_from_schemaRRRRRRtstrR(	RRtschematforceRRR0R,R!((s7/usr/lib/python2.7/site-packages/salt/states/sqlite3.pyt
table_presentsr







!
	






cC@s@d}|dkr$|j|�}n|j||�}|j�S(N(RRtfetchall(RR,t
parametersR ((s7/usr/lib/python2.7/site-packages/salt/states/sqlite3.pyR
�s
cC@sd|ddj|�dS(NuCREATE TABLE `u` (u,u)(R%(RR7((s7/usr/lib/python2.7/site-packages/salt/states/sqlite3.pyR5�scC@s<i}x/t|j�D]\}}||||d<qW|S(Ni(t	enumeratetdescription(R trowtdtidxtcol((s7/usr/lib/python2.7/site-packages/salt/states/sqlite3.pyR�s(t__doc__t
__future__RRRtsalt.extRRRRtImportErrorRRRR"R/R1R9R
R5R(((s7/usr/lib/python2.7/site-packages/salt/states/sqlite3.pyt<module>^s 


	R�	1[		

Zerion Mini Shell 1.0