-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuery.py
More file actions
84 lines (76 loc) · 2.86 KB
/
Query.py
File metadata and controls
84 lines (76 loc) · 2.86 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
import sqlite3
def output_table(s, i):
# Conect to database
conn = sqlite3.connect('Notes.db')
# Open coursor
cursor=conn.cursor()
# Get section from database
if(s == 'Job'):
cursor.execute("SELECT * FROM Job WHERE generated_id = ?",(i,) )
elif(s == 'FaF'):
cursor.execute("SELECT * FROM FaF WHERE generated_id = ?",(i,) )
elif(s == 'School'):
cursor.execute("SELECT * FROM School WHERE generated_id = ?",(i,) )
elif(s == 'Travel'):
cursor.execute("SELECT * FROM Travel WHERE generated_id = ?",(i,) )
elif(s == 'Extracurricular'):
cursor.execute("SELECT * FROM Extracurricular WHERE generated_id = ?",(i,) )
elif(s == 'Passwords'):
cursor.execute("SELECT * FROM Passwords WHERE generated_id = ?",(i,) )
elif(s == 'House'):
cursor.execute("SELECT * FROM House WHERE generated_id = ?",(i,) )
elif(s == 'Expences'):
cursor.execute("SELECT * FROM Expences WHERE generated_id = ?",(i,) )
# Get rows from database
rows=cursor.fetchall()
# Close database
conn.close()
# Return rows
return rows
# Get last selected row
def get_row(section, list_box, indexes_list):
# Get indexes of currently selected items
index = list_box.curselection()
# If there are no selected items set i_prev=-1
i_prev = -1
# Go through indexes of database
for i in index:
# Convert index in database to index in listbox
i_prev = indexes_list[i]
# If some item is selected
if(i_prev >= 0):
# Get rows from database
rows = output_table(section, i_prev)
# Get the last selected row
s = rows[0]
return s
else:
return []
def select_name(s):
# Connect to database
conn = sqlite3.connect('Notes.db')
# Open cursor
cursor = conn.cursor()
# Find rows of name and indes from section
if(s == 'Job'):
cursor.execute("SELECT generated_id,name FROM Job")
elif(s == 'FaF'):
cursor.execute("SELECT generated_id,name FROM FaF")
elif(s == 'School'):
cursor.execute("SELECT generated_id,name FROM School")
elif(s == 'Travel'):
cursor.execute("SELECT generated_id,name FROM Travel")
elif(s == 'Extracurricular'):
cursor.execute("SELECT generated_id,name FROM Extracurricular")
elif(s == 'Passwords'):
cursor.execute("SELECT generated_id,name FROM Passwords")
elif(s == 'House'):
cursor.execute("SELECT generated_id,name FROM House")
elif(s == 'Expences'):
cursor.execute("SELECT generated_id, date FROM Expences")
# Get rows
rows = cursor.fetchall()
# Close database
conn.close()
# Return rows
return rows