Beispiel #1
0
    def connect(self):
        s = self.connstr + " user="******" password="******"Could not connect to the server: %s" %
                e.args[0].split('\n')[0],
                source=e)

        return True
Beispiel #2
0
    def __init__(self, connstr, dbuser, dbpass):
        self.connstr = connstr
        self.dbuser = dbuser
        self.dbpass = dbpass

        name = "psycopg2"
        try:
            self.driver = __import__(name, fromlist=[''])
        except Exception as e:
            raise DbProfilerException.DriverError(
                u"Could not load the driver module: %s" % name, source=e)
Beispiel #3
0
 def connect(self):
     try:
         self.conn = self.driver.connect(host=self.host,
                                         db=self.dbname,
                                         user=self.dbuser,
                                         passwd=self.dbpass)
     except Exception as e:
         raise DbProfilerException.DriverError(
             u"Could not connect to the server: %s" %
             e.args[1].split('\n')[0],
             source=e)
     return True
Beispiel #4
0
    def connect(self):
        try:
            self.conn = self.driver.connect(self.host, self.dbuser,
                                            self.dbpass, self.dbname)
        except Exception as e:
            # assuming OperationalError
            msg = to_unicode(e[0][1]).replace('\n', ' ')
            msg = re.sub(r'DB-Lib.*', '', msg)
            raise DbProfilerException.DriverError(
                u"Could not connect to the server: %s" % msg, source=e)

        return True
Beispiel #5
0
    def __init__(self, host, dbname, dbuser, dbpass):
        self.host = host
        self.dbname = dbname
        self.dbuser = dbuser
        self.dbpass = dbpass

        name = "pymssql"
        try:
            self.driver = __import__(name, fromlist=[''])
        except Exception as e:
            raise DbProfilerException.DriverError(
                u"Could not load the driver module: %s" % name, source=e)
Beispiel #6
0
    def disconnect(self):
        if self.conn is None:
            return False

        try:
            self.conn.close()
        except Exception as e:
            raise DbProfilerException.DriverError(
                u"Could not disconnect from the server: %s" % to_unicode(e),
                source=e)
        self.conn = None
        return True
Beispiel #7
0
    def disconnect(self):
        if self.conn is None:
            return False

        try:
            self.conn.close()
        except Exception as e:
            msg = (u"Could not disconnect from the server: %s" %
                   unicode(e).split('\n')[0])
            raise DbProfilerException.DriverError(msg, source=e)
        self.conn = None
        return True
Beispiel #8
0
    def __init__(self, host, port, dbname, dbuser, dbpass):
        self.host = host
        self.port = port
        self.dbname = dbname
        self.dbuser = dbuser
        self.dbpass = dbpass

        name = "cx_Oracle"
        try:
            self.driver = __import__(name, fromlist=[''])
        except Exception as e:
            msg = u"Could not load the driver module: %s" % name
            raise DbProfilerException.DriverError(msg, source=e)
Beispiel #9
0
    def connect(self):
        try:
            if self.host is not None and self.port is not None:
                # use host name and port number
                dsn_tns = self.driver.makedsn(self.host, self.port,
                                              self.dbname)
            else:
                # use tns name
                dsn_tns = self.dbname
            log.trace("dsn_tns: %s" % dsn_tns)
            self.conn = self.driver.connect(self.dbuser, self.dbpass, dsn_tns)
        except Exception as e:
            msg = (u"Could not connect to the server: %s" %
                   unicode(e).split('\n')[0])
            raise DbProfilerException.DriverError(msg, source=e)

        return True
Beispiel #10
0
    def validate(self, dbdriver):
        if dbdriver is None:
            raise DbProfilerException.DriverError(
                _("Database driver not found."))

        try:
            res = dbdriver.q2rs(self.query)
        except DbProfilerException.QueryError as e:
            raise DbProfilerException.ValidationError(_("SQL error: ") +
                                                      "`%s'" % self.query,
                                                      self.label,
                                                      source=e)

        assert res
        assert len(res.column_names) == len(res.resultset[0])
        assert len(res.resultset) == 1

        kv = {}
        for k, v in zip(res.column_names, res.resultset[0]):
            kv[k] = v

        return validate_eval(kv, self.rule[2])