问题
I have this mysql query which works fine for me
select * from mc,mcex
where instr(mcex.example,mc.element)
I have written following code in web2py for this as given below:
rows=db(db.mcex.example.contains(db.mc.element)).select()
Its not working. Please help.
回答1:
Using the web2py DAL, the query (which generates the SQL WHERE
clause) can simply be a string of SQL code, so you can do:
rows = db('instr(mcex.example, mc.element)').select(db.mcex.ALL, db.mc.ALL)
UPDATE:
If you need a conjunction of conditions for the query, you can do so by chaining Set
object calls:
rows = db(query1)(query2)('instr(mcex.example, mc.element)').select(
db.mcex.ALL, db.mc.ALL)
来源:https://stackoverflow.com/questions/25426031/web2pys-contains-function-for-instr-function-of-mysql