-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqlite_functions.py
More file actions
123 lines (99 loc) · 3.59 KB
/
sqlite_functions.py
File metadata and controls
123 lines (99 loc) · 3.59 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# -*- coding: utf-8 -*-
"""
sqlite_functions.py
created by: Ferdinand Feoli
developer's profile: https://sites.google.com/view/ferdsprofile/
coded using Python 3.7 syntax
built using Python 3.6 and pyinstaller 3.3
This module contains the functions for interaction with the database.
The database creation comes implicit in all the functions of this module.
Available functions:
- db_drop_table()
- db_create_table()
- db_table_sort()
- db_insert()
- db_get_top50()
"""
# External modules needed - - - - - - -
import sqlite3 as sql3
# - - - - - - - - - - - - - - - - - - - -
def db_drop_table(path):
"""
Drops REGEDITINFO table if exists.
args:
path=
(string) the directory where the database should be stored
"""
conn = sql3.connect(path+"STORAGE.db")
cur = conn.cursor()
cur.execute("DROP TABLE IF EXISTS REGEDITINFO")
conn.commit()
conn.close()
def db_create_table(path):
"""
Creates REGEDITINFO table and its columns:
- KEY: (String) Column to store the registry key/subkey name.
- NUM_DATE: (Float) Column to store the value in seconds of the
key/subkey's last modification date time.
- NUM_DATE: (DateTime) Column to store the value of the
key/subkey's last modification date time
in the following format: A,B d,Y H:M:S
args:
path=
(string) the directory where the database should be stored
"""
conn = sql3.connect(path+"STORAGE.db")
cur = conn.cursor()
cur.execute("CREATE TABLE REGEDITINFO (KEY TEXT, NUM_DATE REAL, LAST_MODIFIED DATETIME)")
conn.commit()
conn.close()
def db_table_sort(path):
"""
Sorts REGEDITINFO table by descending NUM_DATE.
args:
path=
(string) the directory where the database should be stored
"""
conn = sql3.connect(path+"STORAGE.db")
cur = conn.cursor()
cur.execute("DROP TABLE IF EXISTS TEMP")
cur.execute("CREATE TABLE TEMP AS SELECT * FROM REGEDITINFO ORDER BY NUM_DATE DESC")
cur.execute("DROP TABLE REGEDITINFO")
cur.execute("ALTER TABLE TEMP RENAME TO REGEDITINFO")
conn.commit()
conn.close()
def db_insert(path, key, num_date, last_modified):
"""
Stores key/subkey information passed as arguments by
store_key_info() function from backend module in REGEDITINFO table.
args:
path=
(string) the directory where the database should be stored
key=
(string) contains the name of the key/subkey.
num_date=
(float) contains the value in seconds of the
key/subkey's last modification date time.
last_modified=
(datetime) (DateTime) contains the value of the
key/subkey's last modification date time
in the following format: A,B d,Y H:M:S
"""
conn = sql3.connect(path+"STORAGE.db")
cur = conn.cursor()
cur.execute("INSERT INTO REGEDITINFO VALUES (?,?,?)", (key, num_date, last_modified))
conn.commit()
conn.close()
def db_get_top50(path):
"""
Executes a query taht gets the top50 results stored in the database.
args:
path=
(string) the directory where the database should be stored
"""
conn = sql3.connect(path+"STORAGE.db")
cur = conn.cursor()
cur.execute("SELECT KEY, LAST_MODIFIED FROM REGEDITINFO LIMIT 51")
lst = cur.fetchall()
conn.close()
return lst