Skip to content

Commit 5241039

Browse files
authored
Added update_demographics.py which updates the country_code every 5 seconds (#21)
1 parent b751cad commit 5241039

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

oracle/update_demographics.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import oracledb
2+
import config
3+
from time import sleep
4+
5+
def update_country_code(connection: oracledb.Connection, country_code: str = "US") -> None:
6+
7+
# First retrieve all rows that have "US" as country_code
8+
cursor = connection.cursor()
9+
statement = """
10+
SELECT *
11+
FROM ADMIN.DEMOGRAPHICS demographics
12+
WHERE demographics.COUNTRY_CODE = :1
13+
"""
14+
cursor.execute(statement, [country_code])
15+
results = cursor.fetchall()
16+
17+
# Update country_codes for all customers from US to USA
18+
19+
for result in results:
20+
statement = """
21+
UPDATE ADMIN.DEMOGRAPHICS demographics
22+
SET demographics.COUNTRY_CODE = 'USA'
23+
WHERE demographics.ID = :1
24+
"""
25+
cursor.execute(statement, [result[0]])
26+
connection.commit()
27+
print("Updated country code for customer id: "+result[0])
28+
sleep(5)
29+
cursor.close()
30+
31+
if __name__=="__main__":
32+
33+
with oracledb.connect(
34+
user=config.username,
35+
password=config.password,
36+
dsn=config.dsn,
37+
port=config.port) as connection:
38+
39+
update_country_code(connection)

0 commit comments

Comments
 (0)