Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import db_config
- import sqlite3
- from sqlite3 import Error
- def create_connection(db_file):
- """ create a database connection to the SQLite database
- specified by the db_file
- :param db_file: database file
- :return: Connection object or None
- """
- conn = None
- try:
- conn = sqlite3.connect(db_file)
- except Error as e:
- print(e)
- return conn
- def select_all_sample1(conn):
- """
- Query all rows in the tasks table
- :param conn: the Connection object
- :return:
- """
- cur = conn.cursor()
- cur.execute("SELECT * FROM sample1")
- rows = cur.fetchall()
- names = [description[0]
- for description in cur.description] # to extract the table headers
- data = {} # bank dictonary
- for row in rows:
- # print(row)
- for i in range(0, len(names)):
- data['app'] = 'DSL' # adding custom flags for splunk
- data['app-category'] = 'IL' # adding custom flags for splunk
- data['Environment'] = 'DEV' # adding custom flags for splunk
- data[names[i]] = row[i]
- print(data)
- def select_task_by_priority(conn, priority):
- """
- Query tasks by priority
- :param conn: the Connection object
- :param priority:
- :return:
- """
- cur = conn.cursor()
- cur.execute("SELECT * FROM tasks WHERE priority=?", (priority,))
- rows = cur.fetchall()
- for row in rows:
- print(row)
- def main():
- database = r"/home/alamin/allianz/testDB"
- # create a database connection
- conn = create_connection(database)
- with conn:
- #print("1. Query task by priority:")
- #select_task_by_priority(conn, 1)
- print("connected")
- print("1. Query all sample1")
- select_all_sample1(conn)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement