-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path042123_Project_AJAX_v2.py
66 lines (58 loc) · 1.88 KB
/
042123_Project_AJAX_v2.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
#!/usr/bin/env python
# coding: utf-8
import pymysql
import cgi
import cgitb
import json
cgitb.enable()
form = cgi.FieldStorage()
print("Content-type: text/html\n")
def executeQuery(query):
connection = pymysql.connect(
host='bioed.bu.edu',
user="soueryw",
password="soueryw",
db="Team_G",
port = 4253)
cursor = connection.cursor()
try:
cursor.execute(query)
except pymysql.Error as e:
print(e)
results = cursor.fetchall()
connection.commit()
return(results)
if form:
query = form.getvalue("query","")
if (query == "wholePatientSearch"):
opt = form.getvalue("opt","")
if (opt == "ETHN_GRP_CAT_TXT"):
INPUT = 1 # UPDATE
query1 = """
select * from Persons
"""
multiOut = executeQuery(query1)
if (len(multiOut) == 0):
print(json.dumps({'error': 1, 'message': "There was no data for your input: %s" % (opt)}))
else:
print(json.dumps({'error': 0,'table_data':multiOut}))
elif (opt == "PERSON_GENDER"):
INPUT = 2 # UPDATE
query2 = """
select * from Persons
"""
multiOut = executeQuery(query2)
if (len(multiOut) == 0):
print(json.dumps({'error': 1, 'message': "There was no data for your input: %s" % (opt)}))
else:
print(json.dumps({'error': 0,'table_data':multiOut}))
else:
INPUT = 3 # UPDATE
query3 = """
select * from Persons
"""
multiOut = executeQuery(query3)
if (len(multiOut) == 0):
print(json.dumps({'error': 1, 'message': "There was no data for your input: %s" % (opt)}))
else:
print(json.dumps({'error': 0,'table_data':multiOut}))