-
Notifications
You must be signed in to change notification settings - Fork 0
/
edc_sqlite.py
67 lines (53 loc) · 2.32 KB
/
edc_sqlite.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import sqlite3 as lite
__author__ = 'Marcin Pieczyński'
class SQliteEdit:
"""
The Class containing methods for reading and saving profiles in Profile_database.db file.
"""
def __init__(self):
"""
Init method of SQliteEdit class.
"""
self.con = lite.connect('Profile_database.db') # Opening of database file
self.cursor = self.con.cursor()
self.profiles_name_list = []
self.output_zakladki = []
self.output_leki = []
self.output_leki_cegly = []
self.output_lista_cegiel = []
def get_tables_from_db(self):
"""
The method for reading tables names from db.
"""
self.cursor.execute("SELECT name FROM sqlite_master WHERE type = 'table';")
# Return list of tuples with the names of tables --> names of profiles.
self.profiles_name_list = [elem[0] for elem in self.cursor.fetchall()]
self.profiles_name_list = tuple(self.profiles_name_list)
def get_data_from_profile(self, profile_to_use):
"""
The methods for reading data from profile
"""
self.cursor.execute("SELECT * FROM " + profile_to_use)
for row in self.cursor.fetchall():
if row[0] == "PvNa_UNITS":
self.output_zakladki.append(row[1])
a = [elem.strip() for elem in row[2].split(",")]
self.output_leki.append(a)
elif row[0] == "CEGLY":
self.output_leki_cegly = [elem.strip() for elem in row[2].split(",")]
elif row[0] == "lista_cegiel":
self.output_lista_cegiel = [elem.strip() for elem in row[2].split(",")]
def sqsave_profile(self, nazwa, final_profile):
"""
The methods for saving prifile in db file
"""
self.cursor.execute("DROP TABLE IF EXISTS " + nazwa)
self.cursor.execute("CREATE TABLE " + nazwa + "(Typ TEXT, Id_Grupy TEXT, lek TEXT)")
self.cursor.executemany("INSERT INTO " + nazwa + " VALUES(?, ?, ?)", final_profile)
def sqdel_profile(self, profile_to_del):
"""
The methods for deleting profile.
"""
self.cursor.execute("DROP TABLE IF EXISTS " + profile_to_del)