-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconfig.py
43 lines (39 loc) · 2.19 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import sqlite3
from sqlite3.dbapi2 import Cursor
from models.models_sql_queries import *
################################## DB Connection Configurations ####################################
#===================================================================================================
# Function: open_connection
# Input: <sting:db_name> => the relative path of required database to be connected with
# Output: <(Sqlite3::Connection):connection> => An object of class connection from sqlite3 module
# Prerequistes: None
# Description: Open connection with the required database
#===================================================================================================
def open_connection(db_name):
connection = sqlite3.connect(db_name , check_same_thread=False)
return connection
#===================================================================================================
# Function: get_cursor
# Input: <(Sqlite3::Connection):connection> => An object of class connection from sqlite3 module
# Output: <(Sqlite3::Connection::Cursor):cursor> => An object of class cursor from class connection
# which is from sqlite3 module
# Prerequistes: The passed connection is already opened
# Description: Get a cursor to connected database's data and return the cursor
#===================================================================================================
def get_cursor(connection):
return connection.cursor()
# Function used to close the given connection
#===================================================================================================
# Function: close_connection
# Input: <(Sqlite3::Connection):connection> => An object of class connection from sqlite3 module
# Output: None
# Prerequistes: The passed connection is already opened
# Description: Close the given connection
#===================================================================================================
def close_connection(connection):
connection.commit()
connection.close()
####################################################################################################
def Database_Setup(cursor):
for table in HOSPITAL_DB_TABLES:
cursor.execute(table)