-
Notifications
You must be signed in to change notification settings - Fork 0
/
Regions.py
55 lines (43 loc) · 1.48 KB
/
Regions.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
from Database import db
from mysql.connector import Error
from Log import Log
def FetchById( id ):
"""
Fetches an individual region record from the database using the specified identifier.
Args:
id: int, the unique identifier of the region.
Returns:
A dict containing all the region fields: id, parent_id, code, name
"""
result = None
try:
Log.info(('REGIONS-Fetch-Id:', 'Trying to grab data from table using Id'))
query = "SELECT * FROM region WHERE id = %s;"
db.cursor.execute( query, ( id, ) )
result = db.cursor.fetchone()
Log.info(('REGIONS-Fetch-Id:', 'Successfully grabbed data'))
except Error as e:
Log.error(('REGIONS-Fetch-Id:', e))
Log.info(('REGIONS-Fetch-Id:Query:', query))
Log.info(('REGIONS-Fetch-Id:', 'Failed to grab data'))
return result
def FetchByCode( code ):
"""
Fetches an individual region record from the database using the specified region code.
Args:
code: string, the region's code.
Returns:
A dict containing all the region fields: id, parent_id, code, name
"""
result = None
try:
Log.info(('REGIONS-Fetch-Code', 'Trying to grab data from table using Code'))
query = "SELECT * FROM region WHERE code = %s;"
db.cursor.execute( query, ( code, ) )
result = db.cursor.fetchone()
Log.info((('REGIONS-Fetch-Code', 'Successfully grabbed data')))
except Error as e:
Log.info(('REGIONS-Fetch-Code', e))
Log.info(('REGIONS-Fetch-Code:Query:', query))
Log.info(('REGIONS-Fetch-Code:', 'Failed to grab data'))
return result