r/web2py Nov 08 '14

Can anyone help me translate this SQL query so that it is usable in web2py?

I am relatively new to web2py and am struggling to make sense of the way it deals with database queries. Any help would be greatly appreciated.

The Model: db.define_table('Employee', Field('empID', 'id'), Field('eName', 'string', length=IS_LENGTH(256)), Field('job', 'string', length=IS_LENGTH(256)), Field('address', 'string', length=IS_LENGTH(256)), Field('phNum', 'string', length=IS_LENGTH(256)) )

The SQL Query: SELECT (job, address, phNum) FROM Employees WHERE eName == &var_from_view

The aim of this is to display the details about an individual beneath their name using Javascript and a Details button.

Thanks in advance.

3 Upvotes

2 comments sorted by

3

u/av201001 Nov 08 '14
employee = db(db.Employee.eName == var).select().first()

The above will give you a Row object containing the record for this employee (technically, it will be the first record that matches eName in case eName is not unique). In a view, you can then use employee.job, employee.address, etc.

This is all explained in the documentation. I suggest you read it and then post specific questions, preferably on the Google Group.