Пример #1
0
def sql_input(request):
    db_configs = DbConfig.objects.all()
    # if request.method == "GET":
    #     pass
    try:
        sql = request.GET["context"]
        ID = request.GET["db_config"]
        the_db_config = DbConfig.objects.get(id=ID)
        the_auth = Auth.objects.get(id=the_db_config.auth)
        sql = "%s %s %s" % ("select", sql, "limit 100;")
        # print sql
        # mysql_cmd_task.delay(the_db_config.address,
        #                      the_auth.username,
        #                      the_auth.password,
        #                      sql,
        #                      request.user.username,
        #                      u'SQL语句执行')
        result = mysql_cmd(the_db_config.address, the_auth.username,
                           the_auth.password, sql)
        if not result:
            result = ({'result': 'success'}, )
        r = SQLResult(content=sql,
                      result=str(result),
                      user=request.user.username,
                      sql_name=u'SQL语句')
        r.save()
        return http_success(request, u'操作成功,请等待执行结果,在SQL执行结果查看.')
    except:
        return render_to_response('database/sql_input.html', locals(),
                                  RequestContext(request))
Пример #2
0
def sql_input(request):
    db_configs = DbConfig.objects.all()
    # if request.method == "GET":
    #     pass
    try:
        sql = request.GET["context"]
        ID = request.GET["db_config"]
        the_db_config = DbConfig.objects.get(id=ID)
        the_auth = Auth.objects.get(id=the_db_config.auth)
        sql = "%s %s %s" % ("select", sql, "limit 100;")
        # print sql
        # mysql_cmd_task.delay(the_db_config.address,
        #                      the_auth.username,
        #                      the_auth.password,
        #                      sql,
        #                      request.user.username,
        #                      u'SQL语句执行')
        result = mysql_cmd(the_db_config.address, the_auth.username, the_auth.password, sql)
        if not result:
            result = ({'result': 'success'},)
        r = SQLResult(content=sql, result=str(result), user=request.user.username, sql_name=u'SQL语句')
        r.save()
        return http_success(request, u'操作成功,请等待执行结果,在SQL执行结果查看.')
    except:
        return render_to_response('database/sql_input.html', locals(), RequestContext(request))
Пример #3
0
def mysql_cmd_task(host, username, password, sql, user, sql_name):
    # return mysql_cmd(host, username, password, sql)
    result = mysql_cmd(host, username, password, sql)
    if not result:
        result = ({'result': 'success'},)
    r = SQLResult(content=sql, result=str(result), user=user, sql_name=sql_name)
    r.save()
Пример #4
0
def mysql_cmd_task(host, username, password, sql, user, sql_name):
    # return mysql_cmd(host, username, password, sql)
    result = mysql_cmd(host, username, password, sql)
    if not result:
        result = ({'result': 'success'}, )
    r = SQLResult(content=sql,
                  result=str(result),
                  user=user,
                  sql_name=sql_name)
    r.save()