Commit 1fca6f74 authored by Huihui, Jonathan's avatar Huihui, Jonathan
Browse files

add modify connection statements

parent a7e7745c
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -11,6 +11,13 @@ class MSSQLMixin():
    """Provides a convenient API-like interface to Microsoft SQL databases.
    The database object is the interface to the database.
    """
    DEFAULT_DB = ce('DATABASE_DB_MS', 'CommonDB')
    DEFAULT_USER = ce('DATABASE_USER_MS', 'sa')
    DEFAULT_PW = ce('DATABASE_PW_MS', '5nowDog5')
    DEFAULT_HOST = ce('DATABASE_HOST_MS', "mssql")
    DEFAULT_PORT = int(ce('DATABASE_PORT_MS', 1433))
    DEFAULT_SCHEMA = ce('DATABASE_SCHEMA_MS', 'public')
    
    def __del__(self):
        """ Close the connection to database.
        Ensure function call is superior to Database i.e:
@@ -21,6 +28,14 @@ class MSSQLMixin():
        """Open the connection to the database.
        :return: True if connection established, else false"""
        self.logger.debug('Opening Database Object')
        
        self.modify_connection_info('dbName', MSSQLMixin.DEFAULT_DB)
        self.modify_connection_info('dbUser', MSSQLMixin.DEFAULT_USER)
        self.modify_connection_info('dbPassword', MSSQLMixin.DEFAULT_PW)
        self.modify_connection_info('dbHost', MSSQLMixin.DEFAULT_HOST)
        self.modify_connection_info('dbPort', MSSQLMixin.DEFAULT_PORT)
        #self.modify_connection_info('dbTimeout', MSSQLMixin.DEFAULT_TIMEOUT)
        
        try:
            msg = "\nConnecting information\n" + \
                  f"Database: {self.connection_info['dbName']}\n" + \
+7 −2
Original line number Diff line number Diff line
@@ -4,7 +4,6 @@
import psycopg2
from common.env import check_environment as ce


class PostgresMixin():
    """Serve common connection method for postgres.

@@ -31,9 +30,15 @@ class PostgresMixin():
        """ Explicitly open the database connection

        :param search_path: the search path to default to

        :return: True if connection established, else false
        """
        self.modify_connection_info('dbName', PostgresMixin.DEFAULT_DB)
        self.modify_connection_info('dbUser', PostgresMixin.DEFAULT_USER)
        self.modify_connection_info('dbPassword', PostgresMixin.DEFAULT_PW)
        self.modify_connection_info('dbHost', PostgresMixin.DEFAULT_HOST)
        self.modify_connection_info('dbPort', PostgresMixin.DEFAULT_PORT)
        self.modify_connection_info('dbTimeout', PostgresMixin.DEFAULT_TIMEOUT)

        self.logger.debug('Opening Database Connection and creating Cursor')
        try:
            self.connection = psycopg2.connect(