Skip to content

Commit 96a5692

Browse files
Update dbtools.py
1 parent 6c3b46d commit 96a5692

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

app/dbtools.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,20 @@ def run_latency_test(
3636
ts = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
3737
try:
3838
if dbtype == "oracle":
39-
conn = oracledb.connect(user=username, password=password, dsn=host)
40-
cursor = conn.cursor()
41-
sql = custom_sql if custom_sql else "select 1 from dual"
42-
cursor.execute(sql)
43-
cursor.fetchall()
44-
cursor.close()
45-
conn.close()
39+
conn = None
40+
try:
41+
if port and database:
42+
cp = oracledb.ConnectParams(host=host, port=int(port), service_name=database)
43+
conn = oracledb.connect(user=username, password=password, params=cp)
44+
else:
45+
conn = oracledb.connect(user=username, password=password, dsn=host)
46+
with conn.cursor() as cursor:
47+
sql = custom_sql if custom_sql else "select 1 from dual"
48+
cursor.execute(sql)
49+
cursor.fetchall()
50+
finally:
51+
if conn:
52+
conn.close()
4653
elif dbtype == "postgresql":
4754
conn = psycopg2.connect(host=host, port=port, dbname=database, user=username, password=password)
4855
cursor = conn.cursor()

0 commit comments

Comments
 (0)