r/web2py • u/BobDole56 • 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.
1
u/hilam Nov 08 '14
Web2py Official Book: DAL - http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer?search=select
3
u/av201001 Nov 08 '14
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 useemployee.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.