Beispiel #1
0
    def __run(self):

        # # check connection
        # # conn_info = getjson('sqlrun-dblist', self.dbname)
        # conn_info = env('daemon_instances').get(self.dbname, None)
        # if conn_info is None:
        #     raise Exception(u'null db object')

        # check unicode
        _chku = lambda x: isinstance(x, unicode)
        assert _chku(self.code)

        # connect
        try:
            # db = dbconn(conn_info['dbconn_str'])
            db = dbconn(self.dbname)
        except Exception as e:
            logging.critical('failed to connect to ' + self.dbname)
            raise Exception('failed to connect to ' + self.dbname)

        # run
        try:
            # db = dbconn(conn_info['dbconn_id'], conn_info['dbconn_pw'], conn_info['dbconn_ip'], conn_info['dbconn_port'], conn_info['dbconn_db'], conn_info['dbconn_encoding'])
            self.start_time = time.time()
            self.result = db.proc_exec(self.code)
            self.end_time = time.time()
        except Exception as e:
            self.error = True
            # logging.critical('sqlrun failed.')#, exc_info=True)
            msg = unicode(e.message, db.getEncoding()).strip()
            raise Exception(msg)

        self.error = True
        self.run = True
        self.elapsed = str(float(self.end_time-self.start_time))
Beispiel #2
0
    def __run(self):

        logging.debug('__run init..')

        # check connection
        # conn_info = getjson('sqlrun-dblist', self.dbname)
        # conn_info = env('daemon_instances').get(self.dbname, None)
        # if conn_info is None:
        #     raise Exception(u'null db object')

        # check bindvars
        binds2chk = []
        for key in self.params:
            self.params[key] = str(self.params[key])
            if len(str(self.params[key]).strip()) == 0:
                binds2chk.append(key)
        if len(binds2chk)>0:
            raise SqlRuntimeError(u'Check bind variables. -> ' + ','.join(binds2chk))

        # check unicode
        _chku = lambda x: isinstance(x, unicode)
        assert _chku(self.query)
        assert all(map(_chku, self.params))

        # connect
        try:
            logging.debug('connect to ' + self.dbname)
            db = dbconn(self.dbname)
        except Exception as e:
            logging.critical('failed to connect to ' + self.dbname)
            raise SqlRuntimeError('failed to connect to ' + self.dbname)

        # run
        try:
            # db = dbconn(conn_info['dbconn_id'], conn_info['dbconn_pw'], conn_info['dbconn_ip'], conn_info['dbconn_port'], conn_info['dbconn_db'], conn_info['dbconn_encoding'])
            self.start_time = time.time()
            self.columns, self.rows = db.select(self.query, self.params)
            self.end_time = time.time()
            self.error = False
        except Exception as e:
            self.error = True
            self.error_msg = str(e.message)
            logging.critical('sqlrun failed.', exc_info=True)
            # print dir(e.args)
            # print dir(e.message)
            # try:
            #     msg = unicode(e.message, self.getEncoding.strip()
            # except:
            #     # msg = 'ora-%d' % e.message.code
            #     msg = e.message
            # raise Exception(e)
            raise SqlRuntimeError(str(e.message))

        self.run = True
        self.elapsed = str(float(self.end_time-self.start_time))
        self.rowcnt = len(self.rows)