Skip to content

Commit 9559824

Browse files
Merge pull request #43 from indrasuthar07/database-connection
feat: Ensure database connection and cursor are properly closed
2 parents ef8bb7b + acdd065 commit 9559824

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

app/etl/load.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def load(df: pd.DataFrame, db_path: str = "etl_data.db", table_name: str = "proc
2727
if db_dir and not os.path.exists(db_dir):
2828
os.makedirs(db_dir)
2929
conn = None
30+
cursor = None
3031
try:
3132
# Connect to database
3233
conn = sqlite3.connect(db_path)
@@ -63,5 +64,9 @@ def load(df: pd.DataFrame, db_path: str = "etl_data.db", table_name: str = "proc
6364
if conn:
6465
conn.rollback()
6566
finally:
67+
# Ensure cursor is closed
68+
if cursor:
69+
cursor.close()
70+
# Ensure database connection is properly closed
6671
if conn:
6772
conn.close()

0 commit comments

Comments
 (0)