Same thing...

print db(db.contadores.id>0)._count()   -  it respond a sql (with or 
without argument)
print db.contadores._count()  - it does not work

Traceback (most recent call last):
  File "C:\web2py\gluon\restricted.py", line 205, in restricted
    exec ccode in environment
  File "C:/web2py/applications/OPM/controllers/default.py" 
<http://127.0.0.1:8000/admin/default/edit/OPM/controllers/default.py>, line 
614, in <module>
  File "C:\web2py\gluon\globals.py", line 173, in <lambda>
    self._caller = lambda f: f()
  File "C:\web2py\gluon\tools.py", line 2575, in f
    return action(*a, **b)
  File "C:\web2py\gluon\tools.py", line 2575, in f
    return action(*a, **b)
  File "C:/web2py/applications/OPM/controllers/default.py" 
<http://127.0.0.1:8000/admin/default/edit/OPM/controllers/default.py>, line 
529, in timeline_opm
    count = db.contadores._count()
  File "C:\web2py\gluon\dal.py", line 6774, in __getattr__
    return self[key]
  File "C:\web2py\gluon\dal.py", line 6714, in __getitem__
    return dict.__getitem__(self, str(key))
KeyError: '_count'


Em sexta-feira, 9 de março de 2012 12h31min01s UTC-3, Fabiano Faver 
escreveu:
>
> I'm using version 1.99.4.
> I will test it in 1.99.7 to see if it stop giving this error
>
> Em sexta-feira, 9 de março de 2012 12h21min22s UTC-3, Niphlod escreveu:
>>
>> last version is working ok (1.99.7), what web2py version are you using ?
>>
>> if db.contadores is a table, then it definitely has a "_count" method...
>>
>>
>>
>> Il giorno venerdì 9 marzo 2012 15:55:42 UTC+1, Fabiano Faver ha scritto:
>>>
>>> Niphlod, this is what i got, using distinct argument or not:
>>>
>>> Traceback (most recent call last):
>>>   File "C:\web2py\gluon\restricted.py", line 204, in restricted
>>>     exec ccode in environment
>>>   File "C:/web2py/applications/OPM/controllers/default.py" 
>>> <http://127.0.0.1:8000/admin/default/edit/OPM/controllers/default.py>, line 
>>> 613, in <module>
>>>   File "C:\web2py\gluon\globals.py", line 172, in <lambda>
>>>     self._caller = lambda f: f()
>>>   File "C:\web2py\gluon\tools.py", line 2533, in f
>>>     return action(*a, **b)
>>>   File "C:\web2py\gluon\tools.py", line 2533, in f
>>>     return action(*a, **b)
>>>   File "C:/web2py/applications/OPM/controllers/default.py" 
>>> <http://127.0.0.1:8000/admin/default/edit/OPM/controllers/default.py>, line 
>>> 528, in timeline_opm
>>>     print db.contadores._count(distinct=db.contadores.id_impressora)
>>>   File "C:\web2py\gluon\dal.py", line 5542, in __getattr__
>>>     return self[key]
>>>   File "C:\web2py\gluon\dal.py", line 5482, in __getitem__
>>>     return dict.__getitem__(self, str(key))
>>> KeyError: '_count'
>>>
>>>
>>>
>>> @Bruno
>>> While I can`t get all grouped records at once I am query them 
>>> individually one by one using argument distinct
>>>
>>> for dias in range(loop_back):
>>>         d = timedelta(days=dias)
>>>         dias_passado = dia_hoje - d
>>>         header.append(TH(dias_passado.strftime("%d/%m"),_width='60px'))
>>>         contador_no_dia     = db((db.contadores.id
>>> >0)&(db.contadores.data==dias_passado)).count(distinct=db.contadores.id_impressora)
>>>
>>> Em sexta-feira, 9 de março de 2012 10h54min59s UTC-3, Niphlod escreveu:
>>>>
>>>> ooops, sorry, the _count method is on the table, not the field
>>>> try with
>>>>
>>>> db.contadores._count(distinct=db.contadores.id_impressora)
>>>>
>>>>
>>>>
>>>> Il giorno venerdì 9 marzo 2012 13:37:16 UTC+1, Fabiano Faver ha scritto:
>>>>>
>>>>> I have phpmyadmin to test it but I didn`t manage to get the generated 
>>>>> sql using underline.
>>>>>
>>>>> with or without distinct argument it gives 
>>>>>
>>>>> Traceback (most recent call last):
>>>>>   File "C:\web2py\gluon\restricted.py", line 204, in restricted
>>>>>     exec ccode in environment
>>>>>   File "C:/web2py/applications/OPM/controllers/default.py" 
>>>>> <http://127.0.0.1:8000/admin/default/edit/OPM/controllers/default.py>, 
>>>>> line 610, in <module>
>>>>>   File "C:\web2py\gluon\globals.py", line 172, in <lambda>
>>>>>     self._caller = lambda f: f()
>>>>>   File "C:\web2py\gluon\tools.py", line 2533, in f
>>>>>     return action(*a, **b)
>>>>>   File "C:\web2py\gluon\tools.py", line 2533, in f
>>>>>     return action(*a, **b)
>>>>>   File "C:/web2py/applications/OPM/controllers/default.py" 
>>>>> <http://127.0.0.1:8000/admin/default/edit/OPM/controllers/default.py>, 
>>>>> line 529, in timeline_opm
>>>>>     print 
>>>>> db.contadores.id_impressora._count(distinct=db.contadores.id_impressora)
>>>>> AttributeError: 'Field' object has no attribute '_count'
>>>>>
>>>>>
>>>>> Em sexta-feira, 9 de março de 2012 09h13min01s UTC-3, Niphlod escreveu:
>>>>>>
>>>>>> ok, can you print here what is the result of :
>>>>>>
>>>>>>
>>>>>> db.contadores.id_impressora._count(distinct=db.contadores.id_impressora)
>>>>>>
>>>>>> (mind the _ before count.)
>>>>>>
>>>>>> If you can fire off queries on your db using another tool than web2py 
>>>>>> (let's say, phpmyadmin), try to copy the resulting string into that and 
>>>>>> watch if the query raises an error.
>>>>>>
>>>>>> Il giorno venerdì 9 marzo 2012 13:02:49 UTC+1, Fabiano Faver ha 
>>>>>> scritto:
>>>>>>>
>>>>>>> MySQL
>>>>>>>
>>>>>>> Em sexta-feira, 9 de março de 2012 08h59min46s UTC-3, Niphlod 
>>>>>>> escreveu:
>>>>>>>>
>>>>>>>> what db are you using ?
>>>>>>>>
>>>>>>>>
>>>>>>>> Il giorno giovedì 8 marzo 2012 15:20:17 UTC+1, Fabiano Faver ha 
>>>>>>>> scritto:
>>>>>>>>>
>>>>>>>>> I`m trying to select distinct printers used in each day but i`m 
>>>>>>>>> not managing to use the distinct argument
>>>>>>>>>
>>>>>>>>> count = db.contadores.id_impressora.count()
>>>>>>>>> for row in db((db.contadores.id
>>>>>>>>> >0)&(db.contadores.data<=today)).select(db.contadores.data,count,groupby=db.contadores.data):
>>>>>>>>>         print row.contadores.data, row[count]
>>>>>>>>>
>>>>>>>>> if I use something like
>>>>>>>>>     
>>>>>>>>>   
>>>>>>>>> db.contadores.id_impressora.count(distinct=db.contadores.id_impressora)
>>>>>>>>>
>>>>>>>>> it gives:
>>>>>>>>>
>>>>>>>>> Traceback (most recent call last):
>>>>>>>>>   File "C:\web2py\gluon\restricted.py", line 204, in restricted
>>>>>>>>>     exec ccode in environment
>>>>>>>>>   File "C:/web2py/applications/OPM/controllers/default.py" 
>>>>>>>>> <http://127.0.0.1:8000/admin/default/edit/OPM/controllers/default.py>,
>>>>>>>>>  line 581, in <module>
>>>>>>>>>   File "C:\web2py\gluon\globals.py", line 172, in <lambda>
>>>>>>>>>     self._caller = lambda f: f()
>>>>>>>>>   File "C:/web2py/applications/OPM/controllers/default.py" 
>>>>>>>>> <http://127.0.0.1:8000/admin/default/edit/OPM/controllers/default.py>,
>>>>>>>>>  line 516, in timeline_opm
>>>>>>>>>     count = 
>>>>>>>>> db.contadores.id_impressora.count(distinct=('id_impressora'))
>>>>>>>>> TypeError: count() got an unexpected keyword argument 'distinct' 
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> How can I use distinct count here?
>>>>>>>>>
>>>>>>>>

Reply via email to