修改字段时,在表达式中不能使用sql的函数?
万物皆对象 发布于104月前 2答/3789阅

我想实现xx功能:在用户表中查询出性别字段来填充下拉框


过程中遇到的问题:设置字段表示后,列表查询报错,异常信息为:

Sql: select count(*) from sctcus_user 

Sql: select * from sctcus_user order by id desc limit 0, 15

Sql: select sex, if(com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr@a82a0423, '女', '男') from sctcus_user where 1 = 1 and sex in('0','1')

04-27 17:07:15[ERROR]/grid/query/user-sctcus_account_manage

com.jfinal.plugin.activerecord.ActiveRecordException: java.sql.SQLException: sql injection violation, syntax error: syntax error, expect RPAREN, actual VARIANT @a82a0423 : select sex, if(com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr@a82a0423, '女', '男') from sctcus_user where 1 = 1 and sex in('0','1')

at com.jfinal.plugin.activerecord.DbPro.find(DbPro.java:318)

at com.jfinal.plugin.activerecord.DbPro.find(DbPro.java:329)

at com.eova.widget.WidgetManager.convertValueByExp(WidgetManager.java:259)

at com.eova.widget.grid.GridController.query(GridController.java:137)

at sun.reflect.GeneratedMethodAccessor55.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:483)

at com.jfinal.aop.Invocation.invoke(Invocation.java:73)

at com.eova.interceptor.LoginInterceptor.intercept(LoginInterceptor.java:50)

at com.jfinal.aop.Invocation.invoke(Invocation.java:67)

at com.jfinal.core.ActionHandler.handle(ActionHandler.java:74)

at com.jfinal.plugin.druid.DruidStatViewHandler.handle(DruidStatViewHandler.java:75)

at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:72)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)

at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)

at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:617)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)

at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)

at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)

at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1527)

at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1484)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

at java.lang.Thread.run(Thread.java:745)

Caused by: java.sql.SQLException: sql injection violation, syntax error: syntax error, expect RPAREN, actual VARIANT @a82a0423 : select sex, if(com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr@a82a0423, '女', '男') from sctcus_user where 1 = 1 and sex in('0','1')

at com.alibaba.druid.wall.WallFilter.check(WallFilter.java:711)

at com.alibaba.druid.wall.WallFilter.connection_prepareStatement(WallFilter.java:240)

at com.alibaba.druid.filter.FilterChainImpl.connection_prepareStatement(FilterChainImpl.java:448)

at com.alibaba.druid.filter.FilterAdapter.connection_prepareStatement(FilterAdapter.java:928)

at com.alibaba.druid.filter.FilterEventAdapter.connection_prepareStatement(FilterEventAdapter.java:122)

at com.alibaba.druid.filter.FilterChainImpl.connection_prepareStatement(FilterChainImpl.java:448)

at com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl.prepareStatement(ConnectionProxyImpl.java:342)

at com.alibaba.druid.pool.DruidPooledConnection.prepareStatement(DruidPooledConnection.java:318)

at sun.reflect.GeneratedMethodAccessor45.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:483)

at com.jfinal.plugin.activerecord.SqlReporter.invoke(SqlReporter.java:58)

at com.sun.proxy.$Proxy3.prepareStatement(Unknown Source)

at com.jfinal.plugin.activerecord.DbPro.find(DbPro.java:301)

at com.jfinal.plugin.activerecord.DbPro.find(DbPro.java:316)

... 30 more

Caused by: com.alibaba.druid.sql.parser.ParserException: syntax error, expect RPAREN, actual VARIANT @a82a0423

at com.alibaba.druid.sql.parser.SQLExprParser.accept(SQLExprParser.java:1449)

at com.alibaba.druid.sql.parser.SQLExprParser.methodRest(SQLExprParser.java:686)

at com.alibaba.druid.sql.parser.SQLExprParser.primaryRest(SQLExprParser.java:651)

at com.alibaba.druid.sql.dialect.mysql.parser.MySqlExprParser.primaryRest(MySqlExprParser.java:480)

at com.alibaba.druid.sql.parser.SQLExprParser.primary(SQLExprParser.java:548)

at com.alibaba.druid.sql.dialect.mysql.parser.MySqlExprParser.primary(MySqlExprParser.java:166)

at com.alibaba.druid.sql.parser.SQLExprParser.expr(SQLExprParser.java:118)

at com.alibaba.druid.sql.parser.SQLSelectParser.expr(SQLSelectParser.java:457)

at com.alibaba.druid.sql.parser.SQLSelectParser.parseSelectItem(SQLSelectParser.java:302)

at com.alibaba.druid.sql.parser.SQLSelectParser.parseSelectList(SQLSelectParser.java:275)

at com.alibaba.druid.sql.dialect.mysql.parser.MySqlSelectParser.query(MySqlSelectParser.java:127)

at com.alibaba.druid.sql.parser.SQLSelectParser.select(SQLSelectParser.java:60)

at com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser.parseSelect(MySqlStatementParser.java:195)

at com.alibaba.druid.sql.parser.SQLStatementParser.parseStatementList(SQLStatementParser.java:145)

at com.alibaba.druid.sql.parser.SQLStatementParser.parseStatementList(SQLStatementParser.java:121)

at com.alibaba.druid.wall.WallProvider.checkInternal(WallProvider.java:620)

at com.alibaba.druid.wall.WallProvider.check(WallProvider.java:574)

at com.alibaba.druid.wall.WallFilter.check(WallFilter.java:699)

... 44 more




我的分析过程如下:在元数据管理里面对性别sex字段进行写入表达式,表达式为:

select sex ID,IF(sex=0,"女","男") CN  from  sctcus_user  where 1=1 GROUP BY sex




[沙发] Jieven
表达式不是原生SQL,是伪SQL,所以不支持复杂语法和函数,所有下拉建议都是通过字典的方式实现!
最佳
[地板] 遗忘之静静
这个问题算是解决还是没解决?
没解决:
9.1 元字段表达式
9.1.1 下拉框表达式
select id ID,name 公会 from gms_guild where 1=1;ds=main
语法:select 值 ID,名 CN from 表名 where 条件;ds=数据源

---重点---PS:别名必须叫 ID 和 CN,否则无法识别,无条件写 1=1

举例:
select value ID,name CN from `dict` where `class` = 'game' and field = 'type';ds=main

9.1.2 查找框表达式

语法:select 值列 as 显示别名,名称列 as 显示别名 from game;ds=数据源

---已经解决请做个标注。
有问题可以先去在线文档和新手引导( http://note.youdao.com/share/?id=df8de9adaf8bf6d13646812a12f2e17f&type=note#/ )里面找找有没有解决的方法,然后在问
提交评论