rischi_della_mansione = "GROUP_CONCAT(rischio, ', ')"
l = [db.RISCHI_MANSIONE.on(
(db.RISCHI_MANSIONE.mansione_ID==db.MANSIONE.id)),
db.RISCHI.on(
(db.RISCHI.id==db.RISCHI_MANSIONE.rischio_ID))
]
mansioni = db((db.MANSIONE.id>0)).select(db.MANSIONE.mansione,
rischi_della_mansione,
left=l,
groupby=db.MANSIONE.id
)
fattori_rischio = SQLTABLE(mansioni,
truncate=None,
_id="rischi",
headers={'MANSIONE.mansione':'MANSIONE',
rischi_della_mansione:'FATTORI DI RISCHIO'
},
columns=['MANSIONE.mansione',
rischi_della_mansione
]
)
The relevant code that generates the issue is:
from pydal.objects import Expression
dialect = db._adapter.dialect
rischi_della_mansione =
Expression(db, group_concat,
db.RISCHI.id
,
', ', 'string')
We need to define that the proper way to put custom SQL mixed with DAL code is using Expression and document how to use it. SQL in strings isn't acceptable, for that you use executesql.I'm going to say it outright I don't think this should be supported.
I don't think this should be considered a backwards compatibility problem, because you're not using the DAL API you're just sending SQL in a string.
from pydal.objects import Expression
dialect = db._adapter.dialect
def group_concat(first, second, query_env={}):
return "GROUP_CONCAT(%s, '%s')" % (dialect.expand(first, query_env), second)rischi_della_mansione =
Expression(db, group_concat,
db.RISCHI.id
,We need to define that the proper way to put custom SQL mixed with DAL code is using Expression and document how to use it. SQL in strings isn't acceptable, for that you use executesql.
', ', 'string')
'''GROUP_CONCAT("RISCHI"."rischio", \', \')'''
tablemap = dict(((f.tablename, f.table) if isinstance(f, Field) else (f._table._tablename, f._table) for f in fieldmap.values()))