-
Notifications
You must be signed in to change notification settings - Fork 0
/
course_sql.py
95 lines (78 loc) · 2.95 KB
/
course_sql.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
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
import mysql.connector as mys
def fetch(id):
connection = mys.connect(user="root", passwd="root", host="localhost", database='SUMA')
cursor = connection.cursor()
cursor.execute(f'select * from course_master natural join course_details where course_id={id}')
s = cursor.fetchone()
return s
def get_sujects(courseid):
connection = mys.connect(user="root", passwd="root", host="localhost", database='SUMA')
cursor = connection.cursor()
cursor.execute('select subject from course_details where course_id = ' + str(courseid))
result = cursor.fetchall()
return result
def fetch_m(id):
connection = mys.connect(user="root", passwd="root", host="localhost", database='SUMA')
cursor = connection.cursor()
cursor.execute(f'select * from course_master where course_id={id}')
s = cursor.fetchone()
return s
def fetch_all():
connection = mys.connect(user="root", passwd="root", host="localhost", database='SUMA')
cursor = connection.cursor()
cursor.execute(f'select * from course_master natural join course_details')
s = cursor.fetchall()
return s
def fetch_m_all():
connection = mys.connect(user="root", passwd="root", host="localhost", database='SUMA')
cursor = connection.cursor()
cursor.execute(f'select * from course_master')
s = cursor.fetchall()
return s
def fetch_d_all():
connection = mys.connect(user="root", passwd="root", host="localhost", database='SUMA')
cursor = connection.cursor()
cursor.execute(f'select * from course_details')
s = cursor.fetchall()
return s
def update_master(s):
id, name = s
connection = mys.connect(user="root", passwd="root", host="localhost", database='SUMA')
cursor = connection.cursor()
q="select * from course_master where course_id={}".format(id)
cursor.execute(q)
data=cursor.fetchone()
if data==None:
print("record not found")
return False
else:
q="update course_master where course_id = {} set course_Name='{}'".format(id,name)
cursor.execute(q)
connection.commit()
print(cursor.rowcount,"Record updated")
def update_details(s):
pass
def add_master(s):
id, name = s
connection = mys.connect(user="root", passwd="root", host="localhost", database='SUMA')
cursor = connection.cursor()
course = fetch(id)
if course!= None:
print('Course already exists')
return "Exists"
q="insert into course_master values({},'{}')".format(id, name)
cursor.execute(q)
connection.commit()
return "Created"
def add_details(s):
id, sub = s
connection = mys.connect(user="root", passwd="root", host="localhost", database='SUMA')
cursor = connection.cursor()
course = fetch(id)
if course!= None:
print('Course detail already exists')
return "Exists"
q="insert into course_details values({},'{}')".format(id, sub)
cursor.execute(q)
connection.commit()
return "Created"