fix: SQL中order by关键字处理

This commit is contained in:
junjun 2023-10-27 11:27:09 +08:00
parent ef2489a5eb
commit 073c13ca41
3 changed files with 14 additions and 3 deletions

View File

@ -47,6 +47,8 @@ public class SQLConstants {
public static final String FIELD_NAME = "%s.`%s`";
public static final String FIELD_DOT = "`%s`";
public static final String UNIX_TIMESTAMP = "UNIX_TIMESTAMP(%s)";
public static final String DATE_FORMAT = "DATE_FORMAT(%s,'%s')";

View File

@ -56,7 +56,10 @@ public class SQLProvider {
if (ObjectUtils.isNotEmpty(xFields)) {
xOrders = new ArrayList<>();
SQLObj sqlObj = xFields.get(0);
SQLObj result = SQLObj.builder().orderField(sqlObj.getFieldAlias()).orderAlias(sqlObj.getFieldAlias()).orderDirection("ASC").build();
SQLObj result = SQLObj.builder()
.orderField(String.format(SQLConstants.FIELD_DOT, sqlObj.getFieldAlias()))
.orderAlias(String.format(SQLConstants.FIELD_DOT, sqlObj.getFieldAlias()))
.orderDirection("ASC").build();
xOrders.add(result);
}
}
@ -115,7 +118,10 @@ public class SQLProvider {
if (needOrder && ObjectUtils.isEmpty(orders)) {
if (ObjectUtils.isNotEmpty(xFields) || ObjectUtils.isNotEmpty(yFields)) {
SQLObj sqlObj = ObjectUtils.isNotEmpty(xFields) ? xFields.get(0) : yFields.get(0);
SQLObj result = SQLObj.builder().orderField(sqlObj.getFieldAlias()).orderAlias(sqlObj.getFieldAlias()).orderDirection("ASC").build();
SQLObj result = SQLObj.builder()
.orderField(String.format(SQLConstants.FIELD_DOT, sqlObj.getFieldAlias()))
.orderAlias(String.format(SQLConstants.FIELD_DOT, sqlObj.getFieldAlias()))
.orderDirection("ASC").build();
orders.add(result);
}
}

View File

@ -78,7 +78,10 @@ public class Order2SQLObj {
fieldName = originField;
}
}
SQLObj result = SQLObj.builder().orderField(originField).orderAlias(originField).orderDirection(f.getOrderDirection()).build();
SQLObj result = SQLObj.builder()
.orderField(String.format(SQLConstants.FIELD_DOT, originField))
.orderAlias(String.format(SQLConstants.FIELD_DOT, originField))
.orderDirection(f.getOrderDirection()).build();
return result;
}