from cx_Oracle import connect, makedsn

from use_cx_oracle.ResultBag import ResultBag


class OracleDb:
    def execute_query(self, user, password, host, port, sid, query, args):
        results = []
        try:
            with connect(user, password, makedsn(host, port, sid)) as db:
                cursor = db.cursor()
                cursor.execute(query, args)
                # col_names = [row[0] for row in cursor.description]
                # results.append(col_names)
                for row in cursor:
                    results.append(row)
            return ResultBag(status="success", results=results, error=None)
        except Exception as ex:
            return ResultBag(status="failure", results=results, error=ex)
