This commit is contained in:
黎明伟 2020-10-21 19:51:39 +08:00
parent 3cecd33e19
commit 50b7639b73
3 changed files with 13 additions and 3 deletions

View File

@ -79,6 +79,7 @@ public abstract class AbstractSqlStatementParser implements SqlStatementParser {
return jdbcStatement; return jdbcStatement;
} catch (Throwable e) { } catch (Throwable e) {
log.error("#76 sql parse error, cause=" + e + ", sql=" + sql + ", this=" + this, e); log.error("#76 sql parse error, cause=" + e + ", sql=" + sql + ", this=" + this, e);
throw new SQLException("#77 sql parse error, cause=" + e + ", sql=" + sql + ", this=" + this, e); throw new SQLException("#77 sql parse error, cause=" + e + ", sql=" + sql + ", this=" + this, e);
} }
} }

View File

@ -376,6 +376,9 @@ public class JSqlParserMongoStatementParser extends AbstractJSqlParserMongoState
} }
private JdbcStatement findStatement(String sql, Select select, PlainSelect plainSelect) { private JdbcStatement findStatement(String sql, Select select, PlainSelect plainSelect) {
Table fromTable = MongoJSqlParserUtil.getFromTable(select);
String collectionName = MongoJSqlParserUtil.getTableName(fromTable);
Map<String, Object> statementDocument = new HashMap<String, Object>(); Map<String, Object> statementDocument = new HashMap<String, Object>();
Map<String, Object> where = this.whereDocument(plainSelect.getWhere()); Map<String, Object> where = this.whereDocument(plainSelect.getWhere());
@ -388,8 +391,6 @@ public class JSqlParserMongoStatementParser extends AbstractJSqlParserMongoState
MongoFindStatement findStatement = new MongoFindStatement(); MongoFindStatement findStatement = new MongoFindStatement();
findStatement.setStatementJson(statementJson); findStatement.setStatementJson(statementJson);
Table fromTable = MongoJSqlParserUtil.getFromTable(select);
String collectionName = MongoJSqlParserUtil.getTableName(fromTable);
findStatement.setCollectionName(collectionName); findStatement.setCollectionName(collectionName);
String[] selectColumnNames = MongoJSqlParserUtil.getSelectColumnNames(select); String[] selectColumnNames = MongoJSqlParserUtil.getSelectColumnNames(select);

View File

@ -54,6 +54,10 @@ public class MongoJSqlParserUtil {
} }
protected static String getTableName(Table table) { protected static String getTableName(Table table) {
if (null == table) {
return null;
}
String tableName = table.getName(); String tableName = table.getName();
int len = tableName.length(); int len = tableName.length();
if (tableName.charAt(0) == '`' && tableName.charAt(len - 1) == '`') { if (tableName.charAt(0) == '`' && tableName.charAt(len - 1) == '`') {
@ -205,6 +209,10 @@ public class MongoJSqlParserUtil {
if (selectBody instanceof PlainSelect) { if (selectBody instanceof PlainSelect) {
PlainSelect plainSelect = (PlainSelect) selectBody; PlainSelect plainSelect = (PlainSelect) selectBody;
FromItem fromItem = plainSelect.getFromItem(); FromItem fromItem = plainSelect.getFromItem();
if (null == fromItem) {
return null;
}
if (fromItem instanceof Table) { if (fromItem instanceof Table) {
return (Table) fromItem; return (Table) fromItem;
} }
@ -215,7 +223,7 @@ public class MongoJSqlParserUtil {
} }
} }
throw new BudoJdbcDriverNotSupportedException("#185 statement=" + statement + ", type=" + statement); throw new BudoJdbcDriverNotSupportedException("#185 statement=" + statement + ", type=" + statement.getClass());
} }
protected static boolean isFindStatement(PlainSelect plainSelect) { protected static boolean isFindStatement(PlainSelect plainSelect) {