Reputation: 313
I am writing a simple web2py application and can't seem to figure out how to run comparison checks on variables from db.select statements. Code is posted below:
form = FORM('Enter Member ID: ', INPUT(_type='text', _name='name'),
INPUT(_type='submit', _value='submit'))
if form.accepts(request, session):
member_id= form.vars.name
measure_1 = db(db.Detailed_Info.MEMBER_NBR==form.vars.name).select(db.Detailed_Info.MEASURE_1)
measure_2 = db(db.Detailed_Info.MEMBER_NBR==form.vars.name).select(db.Detailed_Info.MEASURE_2)
response.flash = 'Form Accepted'
if measure_1=='DBD':
test = 'IT WORKED'
else:
test = 'IT DIDNT WORK'
return dict(form=form, test=test)
My question is, I am able to see that the value from the first select statement (that defines variable measure_1) is in fact 'DBD'. But the if statement conditional at the bottom isn't working. I feel it's because the result of the select statement is a "row" object. Is there a way to extract the actual value?
Thank you!
Upvotes: 0
Views: 826
Reputation: 4964
Citing the web2py manual:
DAL Rows is the object returned by a database select. It can be thought of as a list of Row rows:
rows = db(db.mytable.myfield!=None).select()
Row contains field values.
for row in rows:
print row.myfield
I suppose you can also do for example for the first row,
result = rows[0].myfield
Edit: Again from the docs, the indexing should work: Given one row
row = rows[0]
you can extract its values using multiple equivalent expressions:
>>> row.name
Alex
>>> row['name']
Alex
>>> row('person.name')
Alex
Upvotes: 2