Exemplo n.º 1
0
    def connect(self, host, port=30015, **kwargs):
        """
        Connect to the SAP HANA database

        # TODO: Add option to connect using the key
        # TODO: Add encryption options

        Args:
            host (str): Host where the database is running
            port (int): Database port (3{inst_number}15 by default)
            user (str): Existing username in the database
            password (str): User password
        """
        self._logger.info('connecting to SAP HANA database at %s:%s', host,
                          port)
        try:
            self._connection = pyhdb.connect(
                host=host,
                port=port,
                user=kwargs.get('user'),
                password=kwargs.get('password'),
            )
        except socket.error as err:
            raise base_connector.ConnectionError(
                'connection failed: {}'.format(err))
        self._logger.info('connected successfully')
Exemplo n.º 2
0
    def connect(self, host, port=30015, **kwargs):
        """
        Connect to the SAP HANA database

        # TODO: Add option to connect using the key
        # TODO: Add encryption options

        Args:
            host (str): Host where the database is running
            port (int): Database port (3{inst_number}15 by default)
            user (str): Existing username in the database
            password (str): User password
            properties : Additional properties can be used with named parameters. More info at:
                https://help.sap.com/viewer/0eec0d68141541d1b07893a39944924e/2.0.02/en-US/ee592e89dcce4480a99571a4ae7a702f.html

        Example:
            To avoid automatic reconnection set RECONNECT='FALSE' as parameter
        """
        self._logger.info('connecting to SAP HANA database at %s:%s', host,
                          port)
        self.__properties = kwargs
        try:
            self._connection = dbapi.connect(
                address=host,
                port=port,
                #user=kwargs.get('user'),
                #password=kwargs.get('password'),
                **self.__properties)
        except dbapi.Error as err:
            raise base_connector.ConnectionError(
                'connection failed: {}'.format(err))
        self._logger.info('connected successfully')
Exemplo n.º 3
0
 def reconnect(self):
     """
     Reconnect to the previously connected SAP HANA database if the connection is lost
     """
     if not self._connection:
         raise base_connector.ConnectionError(
             'connect method must be used first to reconnect')
     if not self.isconnected():
         # Initialize the socket connection parameters as a new connection will be created
         self._connection.session_id = -1
         self._connection.packet_count = -1
         try:
             self._logger.info('reconnecting...')
             self._connection.connect()
         except (socket.error, pyhdb.exceptions.DatabaseError) as err:
             raise base_connector.ConnectionError(
                 'connection failed: {}'.format(err))
     else:
         self._logger.info('connection already created')
Exemplo n.º 4
0
    def reconnect(self):
        """
        Reconnect to the previously connected SAP HANA database if the connection is lost

        The dbapi object str result example:
        <dbapi.Connection Connection object : 10.10.10.10,30015,SYSTEM,Qwerty1234,True>

        """
        if not self._connection:
            raise base_connector.ConnectionError(
                'connect method must be used first to reconnect')
        if not self.isconnected():
            connection_data = str(
                self._connection).split(':')[-1].strip()[:-1].split(',')
            host = connection_data[0]
            port = int(connection_data[1])
            #user = connection_data[2]
            #password = connection_data[3]
            #self.connect(host, port, user=user, password=password, **self._properties)
            self._logger.info('reconnecting...')
            self.connect(host, port, **self.__properties)
        else:
            self._logger.info('connection already created')