How to use the pymapd.exceptions._translate_exception function in pymapd

To help you get started, we’ve selected a few pymapd examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github omnisci / pymapd / tests / test_exceptions.py View on Github external
def test_nonexistant_table_raises(self, nonexistant_table):
        result = _translate_exception(nonexistant_table)
        assert isinstance(result, DatabaseError)
        assert "Exception occurred: Table" in result.args[0]
github omnisci / pymapd / tests / test_exceptions.py View on Github external
def test_invalid_sql_raises(self, invalid_sql):
        result = _translate_exception(invalid_sql)
        assert isinstance(result, ProgrammingError)
        assert 'Validate failed: From line 1,' in result.args[0]
github omnisci / pymapd / pymapd / connection.py View on Github external
if e.NOT_OPEN:
                err = OperationalError("Could not connect to database")
                raise err from e
            else:
                raise
        self._client = Client(proto)
        try:
            # If a sessionid was passed, we should validate it
            if sessionid:
                self._session = sessionid
                self.get_tables()
                self.sessionid = sessionid
            else:
                self._session = self._client.connect(user, password, dbname)
        except TMapDException as e:
            raise _translate_exception(e) from e
        except TTransportException:
            raise ValueError(f"Connection failed with port {port} and "
                             f"protocol '{protocol}'. Try port 6274 for "
                             "protocol == binary or 6273, 6278 or 443 for "
                             "http[s]"
                             )

        # if OmniSci version <4.6, raise RuntimeError, as data import can be
        # incorrect for columnar date loads
        # Caused by https://github.com/omnisci/pymapd/pull/188
        semver = self._client.get_version()
        if Version(semver.split("-")[0]) < Version("4.6"):
            raise RuntimeError(f"Version {semver} of OmniSci detected. "
                               "Please use pymapd <0.11. See release notes "
github omnisci / pymapd / pymapd / cursor.py View on Github external
[('RHAT', 100.0), ('IBM', 500.0)]
        """

        # https://github.com/omnisci/pymapd/issues/263
        operation = operation.strip()

        if parameters is not None:
            operation = str(_bind_parameters(operation, parameters))
        self.rowcount = -1
        try:
            result = self.connection._client.sql_execute(
                self.connection._session, operation,
                column_format=True,
                nonce=None, first_n=-1, at_most_n=-1)
        except T.TMapDException as e:
            raise _translate_exception(e) from e
        self._description = _extract_description(result.row_set.row_desc)

        try:
            self.rowcount = len(result.row_set.columns[0].nulls)
        except IndexError:
            pass

        self._result_set = make_row_results_set(result)
        self._result = result
        return self