Improve sqlite3 connection creation
This commit is contained in:
parent
76b2dd4408
commit
2dbc6945a2
1 changed files with 12 additions and 16 deletions
|
@ -2,23 +2,19 @@ import sqlite3
|
||||||
|
|
||||||
|
|
||||||
def create_database(name):
|
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)
|
||||||
|
|
||||||
|
return conn
|
||||||
# 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
|
|
||||||
|
|
||||||
|
|
||||||
def create_tables(db):
|
def create_tables(db):
|
||||||
|
|
Loading…
Reference in a new issue