-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathfetchData.py
More file actions
39 lines (27 loc) · 966 Bytes
/
fetchData.py
File metadata and controls
39 lines (27 loc) · 966 Bytes
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
from mysql import connector
def fetchUserData(userEmail,
dbConnection
):
cursor = dbConnection.cursor()
query = ("SELECT FirstName, LastName, Age, Phone FROM users "
"WHERE Email EQUALS %(emailVal)s") # fetch user data
queryData = {
'emailVal': userEmail
} # user primary key
try:
cursor.execute(query, queryData) # execute the changes
except:
return 2 #errorval
returnMap = {}
for (FirstName, LastName, Age, Phone,) in cursor:
# iterate through a set of tuples
# the tuples are the rows, but we only fetched one
returnMap = {
'FirstNameVal': FirstName,
'LastNameVal': LastName,
'AgeVal': Age,
'PhoneVal': Phone
} # make a return map for the row
cursor.close() # close cursor
dbConnection.close() # close connection
return returnMap #return the map