From 2dbc6945a21c17def214a7d23db3e1c74b06d914 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Mon, 6 Dec 2021 16:37:04 +0100 Subject: [PATCH] Improve sqlite3 connection creation --- habitmove/schema.py | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/habitmove/schema.py b/habitmove/schema.py index 0c3d56c..e5e8404 100644 --- a/habitmove/schema.py +++ b/habitmove/schema.py @@ -2,23 +2,19 @@ import sqlite3 def create_database(name): - return sqlite3.connect(name) + """create a database connection to the SQLite database + specified by db_file + :param db_file: database file + :return: Connection object or None + """ + conn = None + try: + conn = sqlite3.connect(name) + return conn + except sqlite3.Error as e: + print(e) - -# TODO better way to do the above -# def create_connection(db_file): -# """create a database connection to the SQLite database -# specified by db_file -# :param db_file: database file -# :return: Connection object or None -# """ -# conn = None -# try: -# conn = sqlite3.connect(db_file) -# return conn -# except Error as e: -# print(e) -# return conn + return conn def create_tables(db):