Exemplo n.º 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))
Exemplo n.º 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))
Exemplo n.º 3
0
def script_mysql_task(host, username, password, sql, file_name, user):
    file_path = os.path.join(SQL_DIRS, file_name)
    cmd = "php %s/saplatform/scripts/SchemaTool.php %s %s %s %s" % (
        BASE_DIR, host, username, password, file_path)
    result = local_cmd(cmd)
    r = SQLResult(sql_name=file_name, content=sql, result=result, user=user)
    r.save()
Exemplo n.º 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()
Exemplo n.º 5
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()
Exemplo n.º 6
0
def script_mysql_task(host, username, password, sql, file_name, user):
    file_path = os.path.join(SQL_DIRS, file_name)
    cmd = "php %s/saplatform/scripts/SchemaTool.php %s %s %s %s" % (BASE_DIR, host, username, password, file_path)
    result = local_cmd(cmd)
    r = SQLResult(sql_name=file_name, content=sql, result=result, user=user)
    r.save()