On Nov 30, 7:57 am, Stef Mientki <[email protected]> wrote:
> hello,
>
> I'm trying to build some (not trivial) queries and encounter a number of
> problems
> my first problem is that a space makes a huge difference,
> is that to be expected ?
>
> this *works* as (I) expected
> Select = "Name, Test_Count"
> Rows = DB ( Query ).select ( Select )
it is select(*fields, **attributes)
where fields is a alist and attributes is a dictionary
(according to python not web2py)
> print Rows[0]
> <Row {'_extra': <Row {'Test_Count': 1000, 'Name': u'breath_algvm'}>}>
here you are just lucky that the internal processing builds something
similar to what is required for the real DB query, you can see it
using:
DB(Query)._select(Select) # note the underscore
> but removing the space from the string, gives me an *unexpected result*
> Select = "Name,Test_Count" ### <-- space removed
> Rows = DB ( Query ).select ( Select )
> print Rows[0]
> <Row {'_extra': <Row {'Name,Test_Count': u'breath_algvm'}>}>
>
> The second problem, has to do with what's the preferred substitution, string
> or objects ?
>
> this *works* :
> Select = DB.VraagList.Name
> Rows = DB ( Query ).select ( Select )
> print Rows[0]
>
> This *doesn't work*
> Select = DB.VraagList.Name, DB.VraagList.id
python (not web2py) creates a tuple with both fields
which is usable as explained below
> Rows = DB ( Query ).select ( Select )
the correct call (python's rules) would be:
Rows = DB ( Query ).select( *Select )
> print Rows[0]
>
> for the record, this is the Query in all the above
> PID = 1018
> Query = ( DB.VraagList.id == DB.Opnamen.VLID ) & \
> ( DB.Opnamen.PID == PID )
>
> thanks,
> Stef Mientki