mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Beginnings of SQLite3 support for Salt
This commit is contained in:
parent
a1cdc63072
commit
0a9a9d2e83
57
salt/modules/sqlite3.py
Normal file
57
salt/modules/sqlite3.py
Normal file
@ -0,0 +1,57 @@
|
||||
'''
|
||||
Support for SQLite3
|
||||
'''
|
||||
|
||||
import sqlite3
|
||||
|
||||
def version():
|
||||
'''
|
||||
Return version of pysqlite
|
||||
|
||||
CLI Example::
|
||||
|
||||
salt '*' sqlite3.version
|
||||
'''
|
||||
return sqlite3.version
|
||||
|
||||
def sqlite_version():
|
||||
'''
|
||||
Return version of sqlite
|
||||
|
||||
CLI Example::
|
||||
|
||||
salt '*' sqlite3.sqlite_version
|
||||
'''
|
||||
return sqlite3.sqlite_version
|
||||
|
||||
def query(db=None, sql=None):
|
||||
'''
|
||||
Issue an SQL query to sqlite3 (with no return data)
|
||||
|
||||
CLI Example::
|
||||
|
||||
salt '*' sqlite3.query /root/test.db 'CREATE TABLE test(id INT, testdata TEXT);'
|
||||
'''
|
||||
if db == None:
|
||||
return False
|
||||
|
||||
con = sqlite3.connect(db)
|
||||
cur = con.cursor()
|
||||
cur.execute(sql)
|
||||
|
||||
def select(db=None, sql=None):
|
||||
'''
|
||||
SELECT data from an sqlite3 db (returns all rows, be careful!)
|
||||
|
||||
CLI Example::
|
||||
|
||||
salt '*' sqlite3.select /root/test.db 'SELECT * FROM test;'
|
||||
'''
|
||||
if db == None:
|
||||
return False
|
||||
|
||||
con = sqlite3.connect(db)
|
||||
cur = con.cursor()
|
||||
cur.execute(sql)
|
||||
rows = cur.fetchall()
|
||||
return rows
|
Loading…
Reference in New Issue
Block a user