当前使用版本(必须填写清楚,否则不予处理)
mp version: 3.3.0 ms sql server: 2012
该问题是怎么引起的?(最新版上已修复的会直接close掉)
获取表信息的时候,使用了sql server 不支持的语法
重现步骤
class: com.baomidou.mybatisplus.generator.config.builder
method: private List
拼接完成的sql中,where 条件中的 TABLE_NAME 是 select as TABLE_NAME,而sql server 不支持此语法 拼接完的sql如下: select cast(so.name as varchar(500)) as TABLE_NAME, cast(sep.value as varchar(500)) as COMMENTS from sysobjects so left JOIN sys.extended_properties sep on sep.major_id = so.id and sep.minor_id = 0 where (xtype = 'U' or xtype = 'v') AND TABLE_NAME IN ('xxx');
报错信息
com.microsoft.sqlserver.jdbc.SQLServerException: 列名 'TABLE_NAME' 无效。
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:262)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1624)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:594)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:524)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7194)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:2979)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:248)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:223)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(SQLServerPreparedStatement.java:446)
at com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder.getTablesInfo(ConfigBuilder.java:477)
at com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder.handlerStrategy(ConfigBuilder.java:289)
at com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder.
Comment From: liukeshao
sql server 语法 where 不支持使用as 字段 https://stackoverflow.com/questions/3096301/sql-server-as-statement-aliased-column-within-where-statement
Comment From: nieqiurong
这好像是数据库兼容性问题,低版本的sqlserver好像是能支持的,缺少数据库环境,没法一个个去适配.
Comment From: nieqiurong
想起以前是表名是内存过滤的,所以暂时按全部生成使用试试把。
Comment From: liukeshao
对的,3.2 是没有这个问题的,我比较过3.2和3.3的代码,3.2是使用java 过滤的,3.3使用sql过滤的,我觉得生成表的时候,表的数量应该不会有太多,使用java 内存过滤应该没问题
Comment From: nieqiurong
3.3.1 后增加了一个开关,默认激活的,你需要手动将此设置为false,如果你能改进一下的话,可以PR给我们。 new StrategyConfig().setEnableSqlFilter(false)
Comment From: nieqiurong
尝试使用3.3.1.8-SNAPSHOT,快照使用方式参考:https://mp.baomidou.com/guide/install.html
Comment From: nieqiurong