Web2py's 'contains' function for 'instr' function of mysql

余生长醉 提交于 2019-12-25 03:19:39

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!