# -*- coding: utf-8 -*-
'''
Created on 8 окт. 2015 г.

@author: despair
'''
from django.http import JsonResponse
from game.models import unit,player
from django.db import connection

def send_units_list(request):
    cursor=connection.cursor()
    j={}
    p=player.objects.get(user=request.user)
    #print p.user.pk
    try:
        cursor.execute('begin')
        cursor.execute('LOCK TABLE game_unit in access share mode')
        cursor.execute("""select max(a1) from (
        select count(*) as a1 from game_unit 
        where user_id=%s and in_move is null group by x_pos,y_pos) as foo;""",
        [p.user.pk])
        #print "bfg", cursor.fetchone()[0]
        j["max"]=cursor.fetchone()[0]
        cursor.execute("""select x_pos,y_pos,count(*) from game_unit
        where user_id=%s and in_move is null group by x_pos,y_pos;""",[p.user.pk])
        #print "bfg2"#,cursor.fetchall()
        #for i in connection.queries:
        #    print i
        j["own"]=cursor.fetchall()
        cursor.execute("""select id,x_pos,y_pos from game_unit
        where user_id=%s and in_move is null order by id;""",[p.user.pk])
        j["own_units_pos"]=cursor.fetchall()
        #print j["own_units_pos"]
        """"q=unit.objects.filter(user=p.user.pk)
        for i in q:
            print i"""
    finally:
        cursor.execute('commit')
    return JsonResponse(j)

63fa606b986780ee85894b399026fd75271061f7
<mask token>

<mask token>


def send_units_list(request):
    cursor = connection.cursor()
    j = {}
    p = player.objects.get(user=request.user)
    try:
        cursor.execute('begin')
        cursor.execute('LOCK TABLE game_unit in access share mode')
        cursor.execute(
            """select max(a1) from (
        select count(*) as a1 from game_unit 
        where user_id=%s and in_move is null group by x_pos,y_pos) as foo;"""
            , [p.user.pk])
        j['max'] = cursor.fetchone()[0]
        cursor.execute(
            """select x_pos,y_pos,count(*) from game_unit
        where user_id=%s and in_move is null group by x_pos,y_pos;"""
            , [p.user.pk])
        j['own'] = cursor.fetchall()
        cursor.execute(
            """select id,x_pos,y_pos from game_unit
        where user_id=%s and in_move is null order by id;"""
            , [p.user.pk])
        j['own_units_pos'] = cursor.fetchall()
        """"q=unit.objects.filter(user=p.user.pk)
        for i in q:
            print i"""
    finally:
        cursor.execute('commit')
    return JsonResponse(j)

<mask token>
from django.http import JsonResponse
from game.models import unit, player
from django.db import connection


def send_units_list(request):
    cursor = connection.cursor()
    j = {}
    p = player.objects.get(user=request.user)
    try:
        cursor.execute('begin')
        cursor.execute('LOCK TABLE game_unit in access share mode')
        cursor.execute(
            """select max(a1) from (
        select count(*) as a1 from game_unit 
        where user_id=%s and in_move is null group by x_pos,y_pos) as foo;"""
            , [p.user.pk])
        j['max'] = cursor.fetchone()[0]
        cursor.execute(
            """select x_pos,y_pos,count(*) from game_unit
        where user_id=%s and in_move is null group by x_pos,y_pos;"""
            , [p.user.pk])
        j['own'] = cursor.fetchall()
        cursor.execute(
            """select id,x_pos,y_pos from game_unit
        where user_id=%s and in_move is null order by id;"""
            , [p.user.pk])
        j['own_units_pos'] = cursor.fetchall()
        """"q=unit.objects.filter(user=p.user.pk)
        for i in q:
            print i"""
    finally:
        cursor.execute('commit')
    return JsonResponse(j)

# -*- coding: utf-8 -*-
'''
Created on 8 окт. 2015 г.

@author: despair
'''
from django.http import JsonResponse
from game.models import unit,player
from django.db import connection

def send_units_list(request):
    cursor=connection.cursor()
    j={}
    p=player.objects.get(user=request.user)
    #print p.user.pk
    try:
        cursor.execute('begin')
        cursor.execute('LOCK TABLE game_unit in access share mode')
        cursor.execute("""select max(a1) from (
        select count(*) as a1 from game_unit 
        where user_id=%s and in_move is null group by x_pos,y_pos) as foo;""",
        [p.user.pk])
        #print "bfg", cursor.fetchone()[0]
        j["max"]=cursor.fetchone()[0]
        cursor.execute("""select x_pos,y_pos,count(*) from game_unit
        where user_id=%s and in_move is null group by x_pos,y_pos;""",[p.user.pk])
        #print "bfg2"#,cursor.fetchall()
        #for i in connection.queries:
        #    print i
        j["own"]=cursor.fetchall()
        cursor.execute("""select id,x_pos,y_pos from game_unit
        where user_id=%s and in_move is null order by id;""",[p.user.pk])
        j["own_units_pos"]=cursor.fetchall()
        #print j["own_units_pos"]
        """"q=unit.objects.filter(user=p.user.pk)
        for i in q:
            print i"""
    finally:
        cursor.execute('commit')
    return JsonResponse(j)
