db.mytable(name=s) 

is shortcut for

db(db.mytable.name==s).select(limitby=(0,1)).first()


On Monday, 21 November 2016 09:58:01 UTC-6, Ramos wrote:
>
> I used this compact way and i noticed it only returns one record.
>
> for example 
>
> table db.badass
> id   name   value
> 1    trump   10
> 2    trump   20
> 3    hilary    30
>
> db.badass(name="trump")
> only returns record with id =1
>
> Regards
> António
>
> 2016-11-21 15:47 GMT+00:00 Massimo Di Pierro <[email protected]>:
>
>> It depends
>>
>> a query is always field==value so you can do
>>
>>    query = db.table.field ==  value
>>    row = db(query).select(limitby=(0,10)).first()
>>
>> or
>>
>>    row = db.table(query)
>>
>> (they are equivalent)
>>
>> But db.table(...) can take an "implicit query"
>>
>>    db.table(fieldname=value)
>>
>> which is a more compact way to do
>>
>>    db.table(db.table.field==value)
>>
>> The most common way to use db.table(...) is this
>>
>>    db.table(id)
>>
>> or
>>
>>    db.table(id, fieldname=value) # returns the record only of the 
>> fieldname==value
>>
>> or 
>>
>>    db.table(id, query) # returns the record only if the query is true.
>>
>>
>>
>> On Sunday, 20 November 2016 09:08:38 UTC-6, Meinolf wrote:
>>>
>>> Hi Massimo
>>>
>>> Just came across this post and got a bit alarmed, so when i check if a 
>>> record exists i don't have to use the usual '==' but instead '=' ?
>>>
>>> On Monday, October 10, 2011 at 3:55:27 PM UTC+2, Massimo Di Pierro wrote:
>>>>
>>>> row = db.postcode_cache(postcode=postcode) 
>>>> if not row: 
>>>> db.postcode_cache.insert(postcode=postcode,nearset=nearest) 
>>>> elif not row.nearest: row.update_record(nearset=nearest) 
>>>> else: pass # do nothing 
>>>>
>>>> On Oct 10, 8:22 am, Chris Rowson <[email protected]> wrote: 
>>>> > Hi list, 
>>>> > 
>>>> > I have a database table which looks like this: 
>>>> > 
>>>> > postcode_cache 
>>>> > ------------------------ 
>>>> > postcode (UNIQUE) 
>>>> > lat 
>>>> > lon 
>>>> > nearest 
>>>> > 
>>>> > I want to test first whether or not a record exists for 'postcode' 
>>>> and 
>>>> > if a record does exist, I want to check whether the 'nearest' field 
>>>> > contains any data. 
>>>> > 
>>>> > I've tried this: 
>>>> > 
>>>> > if db(db.postcode_cache.postcode==postcode).select().first()==None: 
>>>> >     create_a_new_postcode_record() 
>>>> > 
>>>> > elif 
>>>> db(db.postcode_cache.postcode==postcode).select(db.postcode_cache.nearest)=
>>>>  
>>>> =None: 
>>>> >     populate_the_nearest_field() 
>>>> > 
>>>> > else: 
>>>> >     nothing_to_do() 
>>>> > 
>>>> > And while the check to establish whether or not a record exists seems 
>>>> > to work, the check to see whether or not the 'nearest' field within 
>>>> > the record is populated doesn't seem to work. 
>>>> > 
>>>> > Can anyone tell me what I'm doing wrong please? 
>>>> > 
>>>> > Thank you, 
>>>> > 
>>>> > Chris
>>>
>>> -- 
>> Resources:
>> - http://web2py.com
>> - http://web2py.com/book (Documentation)
>> - http://github.com/web2py/web2py (Source code)
>> - https://code.google.com/p/web2py/issues/list (Report Issues)
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "web2py-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected].
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to