db(q1&q2).select().first() will return None if no records are returned, so
you should be able to do:
if selected_record:
[code to execute when a record is returned]
If that's not working, let's see some more code.
Anthony
On Tuesday, June 4, 2013 7:43:27 PM UTC-4, Jordan Ladora wrote:
>
> Hi,
>
> If I set up a query like so,
>
> q1 = auth.accessible_query('read', db.stuff)
> q2 = db.stuff.id==3
> selected_record = db(q1&q2).select().first() # how to check if
> this successfully got db record?
> selected_records = db(q1&q2).select() # how to check if
> this successfully got db records?
>
> ...I want to check if my select() or select().first() was successful and
> contains record(s) before executing more code.
>
> These are some ways I thought of doing it, but they have all created
> problems in one way or another.
>
> 1) if selected_record in locals(): # if query successful,
> returns FALSE
> 2) if selected_record: # code below still
> executes even if 'selected_record' does not exist
> 3) if len(selected_record): # throws row object
> has no len attribute error
>
>
> Thanks for help,
> -JL
>
--
---
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/groups/opt_out.