what's the prefered way to retreive only a single answer from the db?

41 views
Skip to first unread message

berry

unread,
May 21, 2012, 9:44:29 AM5/21/12
to buzhug
now i'm using

rs = db.select( ['field'], field=5 )
answer = rs[0].field

is it the correct way? the most elegant way>?

Pierre Quentel

unread,
May 22, 2012, 3:22:07 AM5/22/12
to buz...@googlegroups.com

This is explained on the documentation page at http://buzhug.sourceforge.net/ : you can select a record

. with its record id if you know it : record = db[record_id]
. by a list comprehension : [ r.field for r in db if r.field==5 ]
. by a call : db(field=5)
. by select()

In your example, the most natural is

answer = db(field=5)[0].field

- Pierre

yalla balagan

unread,
May 23, 2012, 3:38:13 AM5/23/12
to buz...@googlegroups.com
the last solution will raise an exception if no record is found for this criteria.
thanks anyway.


--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes buzhug.
Cette discussion peut être lue sur le Web à l'adresse https://groups.google.com/d/msg/buzhug/-/NOkOf-c3gOcJ.

Pour envoyer un message à ce groupe, adressez un e-mail à buz...@googlegroups.com.
Pour vous désabonner de ce groupe, envoyez un e-mail à l'adresse buzhug+un...@googlegroups.com.
Pour plus d'options, consultez la page de ce groupe : http://groups.google.com/group/buzhug?hl=fr



--
יאללה בלגאן!!!


Reply all
Reply to author
Forward
0 new messages