If the query only has that one condition, then you can do:

s.query.second

A Set object has a "query" attribute, which is a Query object, and a Query 
object has "op", "first", and "second" attributes. So, s.query gets the 
Query object of the Set, and s.query.second gets the second operand of the 
"==" operator. If instead you have multiple conditions in the query, keep 
in mind that the operands of the "&" operator are themselves Query objects. 
So, if you have:

set = db((db.person.id > 10) & (db.person.name.startswith('A')))

you can extract the 10 from the first part of the query via:

set.query.first.second

In that case, set.query.first itself returns a Query (i.e., db.person.id > 
10), so set.query.first.second gives you the 10.

Keep in mind that these properties of Set and Query are internal and not 
part of the API, so this isn't guaranteed to remain backward compatible.

Another option is to pass the Set to the str() function, which generates a 
string that contains the SQL produced by the query. You could then do some 
parsing of that string to get what you want. For example, in this case you 
get:

>>> str(db(db.person.id == 1))
'<Set (person.id = 1)>'

You can use a regex to get the 1 from that string.

Anthony

On Wednesday, May 8, 2013 6:10:05 PM UTC-4, Jurgis Pralgauskis wrote:
>
> Hi, 
>
> I look at example:
> http://www.web2py.com/book/default/chapter/06#before-and-after-callbacks
>
> how can I find out what is the value of person.id from the set without 
> select?
> (<Set (person.id = 1)>,)
>
> as I tried:
> s.select(..)[0]   # it worked for update
> but got 
>
> Traceback (most recent call last):
>   File "/home/nijole/Downloads/EasyVet/web2py/gluon/restricted.py", line 212, 
> in restricted
>     exec ccode in environment
>   File 
> "/home/nijole/Downloads/EasyVet/web2py/applications/apskaitele/controllers/appadmin.py"
>  
> <http://localhost:8000/admin/default/edit/apskaitele/controllers/appadmin.py>,
>  line 569, in <module>
>   File "/home/nijole/Downloads/EasyVet/web2py/gluon/globals.py", line 194, in 
> <lambda>
>     self._caller = lambda f: f()
>   File 
> "/home/nijole/Downloads/EasyVet/web2py/applications/apskaitele/controllers/appadmin.py"
>  
> <http://localhost:8000/admin/default/edit/apskaitele/controllers/appadmin.py>,
>  line 304, in update
>     if form.accepts(request.vars, session):
>   File "/home/nijole/Downloads/EasyVet/web2py/gluon/sqlhtml.py", line 1398, 
> in accepts
>     self.table._db(qry).delete()
>   File "/home/nijole/Downloads/EasyVet/web2py/gluon/dal.py", line 9821, in 
> delete
>     ret and [f(self) for f in table._after_delete]
>   File 
> "/home/nijole/Downloads/EasyVet/web2py/applications/apskaitele/models/db.py" 
> <http://localhost:8000/admin/default/edit/apskaitele/models/db.py>, line 329, 
> in <lambda>
>     db.Pardavimai._after_delete.append( lambda s: 
> update_SandelioProduktai_likutis_from_Pardavimai(s.select(db.Pardavimai.sandelio_produktas)[0])
>  )
>   File "/home/nijole/Downloads/EasyVet/web2py/gluon/dal.py", line 10075, in 
> __getitem__
>     row = self.records[i]
> IndexError: list index out of range
>
>
>
>

-- 

--- 
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.


Reply via email to