Note, this is all covered in the online documentation -- I suggest you skim through the chapter on the DAL: http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer
A select returns a Rows object. You must then extract an individual Row from it, and then the individual field value from the Row. In your case, you want: X[0].X Anthony On Wednesday, April 29, 2015 at 2:38:05 PM UTC-4, Aydin S wrote: > > Thanks Anthony, This works fine, I also added the field name because I > want to get only the value of X, so I used: > db(db.Table1).select(db.Table1.X, orderby=~db.Table1.id, limitby=(0, 1)) > However, this does not return the value, I used: > def index(): > form = SQLFORM(db.Temp).process() > X = db(db.Table1).select(db.Table1.X, orderby=~db.Table1.id, limitby=(0, 1 > )) > return (form=form,X=X) > Then I printed X in the view using {{=X}} which returns: > > Table1.X > 10 > > As you see this is a column, what I want is the number 10 only. Sorry if > this is so basic issue. > > > > On Wednesday, 29 April 2015 10:17:57 UTC-4, Anthony wrote: >> >> db.Table1.X is just a field object and doesn't refer to any record in the >> database. To retrieve a record, you must create a query. In most databases, >> you can just take the record with the largest ID: >> >> db(db.Table1).select(orderby=~db.Table1.id, limitby=(0, 1)) >> >> That sorts in reverse order based on ID and takes the first record. >> Alternatively, you could include a record creation timestamp and sort based >> on that. >> >> Anthony >> >> On Wednesday, April 29, 2015 at 9:31:50 AM UTC-4, Aydin S wrote: >>> >>> Thank you, you are right, right now I have: >>> def index(): >>> form = SQLFORM(db.X).process() >>> return dict(form=form) >>> >>> and I see the database getting updated with new records. >>> One last question, I use db.Table1.X to refer to the last entered >>> record. However, this does not work. How can I make it use the last entered >>> row? >>> >>> On Wednesday, 29 April 2015 08:27:22 UTC-4, Anthony wrote: >>>> >>>> See answer on SO: http://stackoverflow.com/a/29932995/440323 >>>> >>>> On Tuesday, April 28, 2015 at 9:35:31 PM UTC-4, Aydin S wrote: >>>>> >>>>> It looks like the scheduler which is a model file does not see >>>>> variable X in the database! >>>>> >>>>> On Tuesday, 28 April 2015 21:19:14 UTC-4, Aydin S wrote: >>>>>> >>>>>> No, the value of the form gets processed every time the scheduler >>>>>> runs. >>>>>> >>>>>> On Tuesday, 28 April 2015 21:07:42 UTC-4, Dave S wrote: >>>>>>> >>>>>>> >>>>>>> >>>>>>> On Tuesday, April 28, 2015 at 6:01:04 PM UTC-7, Aydin S wrote: >>>>>>>> >>>>>>>> This is probably very simple, sorry in advance! >>>>>>>> I have a form defined in a model file: >>>>>>>> db.define_table('table1', >>>>>>>> Field('X', 'integer')) >>>>>>>> I have a controller that is also defined as: >>>>>>>> def index(): >>>>>>>> form = SQLFORM(db.X) >>>>>>>> return dict(form=form) >>>>>>>> >>>>>>>> >>>>>>> In my index view file I have: >>>>>>>> >>>>>>>> <h2>Input form</h2> >>>>>>>> {{=form}} >>>>>>>> >>>>>>>> I want to use value X in a scheduler defined as a model like: >>>>>>>> >>>>>>>> A = X+2 >>>>>>>> >>>>>>>> The form shows up as expected. I enter a value in it and submit it. >>>>>>>> The scheduler is running as expected. However it looks like the value >>>>>>>> X >>>>>>>> never gets set to what I enter. >>>>>>>> Any idea? >>>>>>>> >>>>>>>> >>>>>>> Do you process the form once the user has entered the input? >>>>>>> >>>>>>> /dps >>>>>>> >>>>>>> >>>>>> -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.