def new_api_module(self, module_name, module_prefix, module_desc, module_part, module_env): module_name = module_name.strip(" ") if check_chinese_en(module_name, 1, 35) is False: return False, "Bad module_name." if check_path(module_prefix, 1, 35) is False: return False, "Bad module_prefix" if check_int(module_part, max_v=9999) is False: return False, "Bad module_part" if type(module_env) != list: return False, "Bad module_env" if len(module_env) not in range(1, 6): print(module_env) return False, "Bad module_env." module_desc = check_sql_character(module_desc)[:240] module_env_s = "" for env_no in module_env: if type(env_no) != int: return False, "Bad env_no" module_env_s += "%s|" % env_no insert_sql = "INSERT INTO %s (module_name,module_prefix,module_desc,module_part,module_env) " \ "VALUES ('%s','%s','%s',%s,'%s');" \ % (self.api_module, module_name, module_prefix, module_desc, module_part, module_env_s[:-1]) result = self.db.execute(insert_sql) if result != 1: return False, "sql execute result is %s " % result return True, "success"
def insert_function_module(self, service_id, function_title, function_desc): if check_chinese_en(function_title) is False: return False, "Bad function_title" if check_special_character(function_desc) is False: return False, "Bad function_desc" select_sql = "SELECT MAX(function_id) FROM %s WHERE service_id=%s;" % (self.function_module, service_id) result = self.db.execute(select_sql) if result == 0: function_id = 0 else: db_result = self.db.fetchone()[0] if db_result is None: function_id = 0 else: function_id = db_result + 1 insert_sql = "INSERT INTO %s (service_id,function_id,function_title,function_desc) VALUES (%s,%s,'%s','%s');" \ % (self.function_module, service_id, function_id, function_title, function_desc) self.db.execute(insert_sql) return True, {"function_id": fill_zero(function_id, 2), "function_title": function_title, "function_desc": function_desc}
def update_api_module(self, module_no, module_name, module_prefix, module_desc, module_part, module_env): if check_chinese_en(module_name, 0, 35) is False: return False, "Bad module_name." if check_path(module_prefix, 0, 35) is False: return False, "Bad module_prefix" if check_int(module_part, max_v=9999) is False: return False, "Bad module_part" if type(module_env) != list: return False, "Bad module_env" if len(module_env) not in range(1, 6): print(module_env) return False, "Bad module_env." module_desc = check_sql_character(module_desc)[:240] module_env_s = "" for env_no in module_env: if type(env_no) != int: return False, "Bad env_no" module_env_s += "%s|" % env_no update_sql = "UPDATE %s SET module_name='%s',module_prefix='%s',module_desc='%s',module_part=%s,module_env='%s' " \ "WHERE module_no=%s;" \ % (self.api_module, module_name, module_prefix, module_desc, module_part, module_env_s[:-1], module_no) result = self.db.execute(update_sql) return True, "success"