def save_to_db(records, bin_file): try: conn = db_operation.connect_to_db_simple() #conn = db_operation.connect_to_db('172.18.100.125', 'lp_crawler', '_lp_crawler', '_launchpad_crawler') for (function_addr, symbol_type, function_name, source_file, source_lineno) in records: db_operation.add_ImageMagick_compile_src2bin( conn, str(function_addr), str(symbol_type), str(function_name), str(source_file), int(source_lineno), bin_file) conn.close() return True except Exception, e: print 'save to db [Exception]', e return False
def open_if_connection_closed(self): try: if self.db is None: return False if self.db.open == 0: self.db = db_operation.connect_to_db_simple() if self.db is None: return False return True except Exception, e: print e return False
def query_src2bin(function_name, filename, commit): try: conn = db_operation.connect_to_db_simple() sql = "select B.local_url,A.function_address from S_ImageMagick_Src2Bin as A, S_ImageMagick_Bin as B where A.function_name like '%s' and \ A.debug_file = B.id and B.tag like '%s' and A.source_file like '%%%s' and A.source_file not like '%%./.libs/%%';"%(function_name, commit, filename) #print sql cursor = conn.cursor() cursor.execute(sql) result = cursor.fetchall() conn.close() if len(result) > 0: return result return [] except Exception as e: print e return []