sql=request.POST.get('sql'),port=dbServer.db_port) if status == 0: return JsonResponse({'msg':"获取SQL优化数据成功","code":200,'data':result,'tag':2}) else: return JsonResponse({'msg':"获取SQL优化数据失败","code":500,'data':result,'tag':2}) else:return JsonResponse({'msg':"获取SQL优化数据失败","code":500,'data':[],'tag':2}) elif request.method == "POST" and request.POST.get('opsTag') == '3':#执行DQL if re.match(r"^(\s*)?select(\S+)?(.*)", request.POST.get('sql').lower()): try: dbServer = DataBase_Server_Config.objects.get(id=int(request.POST.get('dbId'))) except Exception, ex: dbServer = None if dbServer: mysql = MySQLPool(host=dbServer.db_host,port=dbServer.db_port,user=dbServer.db_user,passwd=dbServer.db_passwd,dbName=dbServer.db_name) result = mysql.queryMany(sql=request.POST.get('sql'),num=1000) if isinstance(result,str): recordSQL.delay(exe_user=str(request.user),exe_db=dbServer,exe_sql=request.POST.get('sql'),exec_status=0,exe_result=str) return JsonResponse({'msg':"数据查询失败","code":500,'data':result,'tag':3}) recordSQL.delay(exe_user=str(request.user),exe_db=dbServer,exe_sql=request.POST.get('sql'),exec_status=1,exe_result=None) return JsonResponse({'msg':"数据查询成功","code":200,'data':{"colName":result[2],"dataList":result[1]},'count':result[0],'tag':3}) else:return JsonResponse({'msg':"数据查询失败","code":500,'data':"不是DQL类型语句",'tag':3}) elif request.method == "POST" and request.POST.get('opsTag') == '4' and request.user.is_superuser:#执行原生SQL try: dbServer = DataBase_Server_Config.objects.get(id=int(request.POST.get('dbId'))) except Exception, ex: dbServer = None if dbServer: mysql = MySQLPool(host=dbServer.db_host,port=dbServer.db_port,user=dbServer.db_user,passwd=dbServer.db_passwd,dbName=dbServer.db_name) result = mysql.execute(sql=request.POST.get('sql'),num=1000)
elif request.method == "POST" and request.POST.get( 'opsTag') == '3': #执行DQL if re.match(r"^(\s*)?select(\S+)?(.*)", request.POST.get('sql').lower()): try: dbServer = DataBase_Server_Config.objects.get( id=int(request.POST.get('dbId'))) except Exception, ex: dbServer = None if dbServer: mysql = MySQLPool(host=dbServer.db_host, port=dbServer.db_port, user=dbServer.db_user, passwd=dbServer.db_passwd, dbName=dbServer.db_name) result = mysql.queryMany(sql=request.POST.get('sql'), num=1000) if isinstance(result, str): recordSQL.delay(exe_user=str(request.user), exe_db=dbServer, exe_sql=request.POST.get('sql'), exec_status=0, exe_result=str) return JsonResponse({ 'msg': "数据查询失败", "code": 500, 'data': result, 'tag': 3 }) recordSQL.delay(exe_user=str(request.user), exe_db=dbServer, exe_sql=request.POST.get('sql'),