Skip to content

Commit

Permalink
fix: 修复nativeSQL进行嵌套查询驼峰字段可能错误问题
Browse files Browse the repository at this point in the history
  • Loading branch information
zhou-hao committed Aug 3, 2023
1 parent 04963ff commit d6513d7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ private Map<String, Column> getColumnMappings() {
Column col = new Column(column.getName(), column.getAlias(), select.table.alias, column.metadata);
columnMappings.put(entry.getKey(), col);
columnMappings.put(select.table.alias + "." + entry.getKey(), col);

if (!(column instanceof ExpressionColumn) && column.metadata != null) {
columnMappings.put(column.metadata.getName(), col);
columnMappings.put(select.table.alias + "." + column.metadata.getName(), col);
}
}

for (Column column : select.getColumnList()) {
Expand Down Expand Up @@ -191,7 +196,7 @@ private static SelectBody parse(String sql) {
}

private String parsePlainName(String name) {
if (name == null || name.length() == 0) {
if (name == null || name.isEmpty()) {
return null;
}
char firstChar = name.charAt(0);
Expand Down Expand Up @@ -524,10 +529,11 @@ public SqlFragments createTermFragments(QueryAnalyzerImpl impl, Term term) {
if (col.metadata == null) {
metadata = table.metadata;
}
String colName = col.metadata != null ? col.metadata.getName() : col.name;
return metadata
.findFeature(createFeatureId(term.getTermType()))
.map(feature -> feature.createFragments(
table.alias + "." + dialect.quote(col.name, col.metadata != null), col.metadata, term))
table.alias + "." + dialect.quote(colName, col.metadata != null), col.metadata, term))
.orElse(EmptySqlFragments.INSTANCE);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,17 @@ public void testInner() {
.insert("s_test")
.value("id", "inner-test")
.value("name", "inner")
.value("testName","inner")
.value("age", 31)
.execute()
.sync();


helper.select("select age,count(1) c from ( select name,age from s_test ) a group by age ", 0)
helper.select("select age,count(1) c from ( select *,'1' as x from s_test ) a group by age ", 0)
.where(dsl -> dsl
.is("a.name", "inner")
.is("x", "1")
.is("name", "inner")
.is("a.testName", "inner")
.is("age", 31))
.fetchPaged(0, 10)
.doOnNext(v -> System.out.println(JSON.toJSONString(v, SerializerFeature.PrettyFormat)))
Expand Down

0 comments on commit d6513d7

Please sign in to comment.