Hi Manuele,
I don't need to build the entire query, just the filters for the itemgroup
column. Let me try and explain this a bit differently. I have a list of 10
items a user can select from. If the user selects 4 items, I need to have
four 'OR' statements (itemgroup=='a' or itemgroup=='b' or itemgroup=='c' or
itemgroup=='d')
It would be even better if I could just say itemgroup isin
['a','b','c','d'] but I know that probably isn't available.
Thanks
Simon
On Friday, 24 May 2013 12:31:50 UTC+1, Manuele wrote:
>
> Il 24/05/13 13:21, Simon Carr ha scritto:
>
> By the way I am using Gluon in a standalone Python script, so if the code
> does not look quite that might be the reason.
>
> I currently have some values hard coded in my SQL but I now want users to
> have a choice. Here is the current code.
>
> RS_Data = db(
> (db.weekly_data.week == weekno)&
> ((db.weekly_data.itemgroup == 'BOTDTO')|
> (db.weekly_data.itemgroup == 'C&FOTO')|
> (db.weekly_data.itemgroup == 'PROPTO')|
> (db.weekly_data.itemgroup == 'STRSTO'))&
> (db.weekly_data.days <= bin_group['high'])&
> (db.weekly_data.days >= bin_group['low'])
> ).select(db.weekly_data.item,
> orderby=db.weekly_data.item,
> groupby=db.weekly_data.item
> )
>
> Below is what I am trying to do but getting an error. As you can see I am
> trying to build up my selection criteria based on the values a users has
> selected from a list. It would be great I could just pass in a Python List.
> If I cant just pass in a list what would you suggest is the best way to
> solve this problem?
>
> If I correctly understood you need a way to build a queryparametrically...
> I would try something like this:
>
> def build_my_query(v):
> q = (db.weekly_data.itemgroup == v)
> return (db.weekly_data.week == weekno)&q&(db.weekly_data.days <=
> bin_group['high'])&(db.weekly_data.days >= bin_group['low'])
>
> personally I don't like code that write code...
>
> I hope it could be of any help
>
> bye
>
> M.
>
>
> buildCommod = "("
> for commodity in commodityList:
> buildCommod += "(db.weekly_data.itemgroup == '" +
> commodity + "')|"
> buildCommod = buildCommod[:-1] + ")"
>
> RS_Data = db(
> (db.weekly_data.week == weekno)& buildCommod &
> (db.weekly_data.days <= bin_group['high'])&
> (db.weekly_data.days >= bin_group['low'])
> ).select(db.weekly_data.item,
> orderby=db.weekly_data.item,
> groupby=db.weekly_data.item
> )
>
>
> The error I am getting is
>
> File "D:\Data\BAAN\summary.py", line 1052, in AOL_AllUpAllUpToExcel
> groupby=db.weekly_data.item
> File "D:\Python27_5\gluon\dal.py", line 9860, in select
> return adapter.select(self.query,fields,attributes)
> File "D:\Python27_5\gluon\dal.py", line 1690, in select
> return self._select_aux(sql,fields,attributes)
> File "D:\Python27_5\gluon\dal.py", line 1655, in _select_aux
> self.execute(sql)
> File "D:\Python27_5\gluon\dal.py", line 1768, in execute
> return self.log_execute(*a, **b)
> File "D:\Python27_5\gluon\dal.py", line 1762, in log_execute
> ret = self.cursor.execute(*a, **b)
> File "D:\Python27_5\gluon\contrib\pg8000\dbapi.py", line 246, in _fn
> return fn(self, *args, **kwargs)
> File "D:\Python27_5\gluon\contrib\pg8000\dbapi.py", line 317, in execute
> self._execute(operation, args)
> File "D:\Python27_5\gluon\contrib\pg8000\dbapi.py", line 322, in _execute
> self.cursor.execute(new_query, *new_args)
> File "D:\Python27_5\gluon\contrib\pg8000\interface.py", line 398, in
> execute
> self._stmt = PreparedStatement(self.connection, query,
> statement_name="", *[{"type": type(x), "value": x} for x in args])
> File "D:\Python27_5\gluon\contrib\pg8000\interface.py", line 138, in
> __init__
> self._parse_row_desc = self.c.parse(self._statement_name, statement,
> types)
> File "D:\Python27_5\gluon\contrib\pg8000\protocol.py", line 943, in _fn
> return fn(self, *args, **kwargs)
> File "D:\Python27_5\gluon\contrib\pg8000\protocol.py", line 1104, in
> parse
> return reader.handle_messages()
> File "D:\Python27_5\gluon\contrib\pg8000\protocol.py", line 929, in
> handle_messages
> raise exc
> gluon.contrib.pg8000.errors.ProgrammingError: ('ERROR', '3F000', 'schema
> "db" does not exist')
>
>
>
> --
>
> ---
> 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] <javascript:>.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
>
>
--
---
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.