Esempio n. 1
0
    def execute(self, sql, values=None, sqlhole=True):
        """
        @brief      execute sql commands, return result if it has
        @param      sql  String
        @param      value  Tuple
        @return     result  Array
        """
        c = self.conn.cursor()
        self.lock.acquire()
        hasReturn = sql.lstrip().upper().startswith("SELECT")

        result = []
        print values
        try:
            if values and not sqlhole:
                c.executemany(sql, values)
            else:
                c.execute(sql, values)
            # c.execute(sql,values)
            if hasReturn:
                result = c.fetchall()

        except Exception, e:
            Log.error(traceback.format_exc())
            self.conn.rollback()
Esempio n. 2
0
def ret_run(str, func, *args):
    t = time.time()
    r = False
    try:
        r = func(*args)
        return r + 1
    except:
        Log.error(str + ":" + traceback.format_exc())
        return False
Esempio n. 3
0
 def run(self, str, func, *args):
     t = time.time()
     # echo(str)
     r = False
     try:
         r = func(*args)
     except:
         Log.error(traceback.format_exc())
     if r:
         totalTime = int(time.time() - t)
         # echo(Constant.RUN_RESULT_SUCCESS % totalTime)
     else:
         pass
Esempio n. 4
0
    def insertmany(self, table, values):
        """
        @brief      Insert many rows in table
        @param      table  String
        @param      values  Array of tuple
        """
        c = self.conn.cursor()
        self.lock.acquire()
        n = len(values[0])
        sql = ("INSERT INTO %s VALUES (" + ",".join(['?'] * n) + ");") % table
        Log.debug('DB -> %s' % sql)

        try:
            c.executemany(sql, values)
        except Exception, e:
            Log.error(traceback.format_exc())