Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TrimSqlNode should add an extra space when concatenating its contents like MixedSqlNode does #3422

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public FilteredDynamicContext(DynamicContext delegate) {
public void applyAll() {
sqlBuffer = new StringBuilder(sqlBuffer.toString().trim());
String trimmedUppercaseSql = sqlBuffer.toString().toUpperCase(Locale.ENGLISH);
if (trimmedUppercaseSql.length() > 0) {
if (!trimmedUppercaseSql.isEmpty()) {
applyPrefix(sqlBuffer, trimmedUppercaseSql);
applySuffix(sqlBuffer, trimmedUppercaseSql);
}
Expand All @@ -99,6 +99,9 @@ public void applyAll() {

@Override
public void appendSql(String sql) {
if (sqlBuffer.length() > 0) {
sqlBuffer.append(" ");
}
sqlBuffer.append(sql);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ void shouldTrimWHEREInsteadOfORForSecondCondition() throws Exception {

@Test
void shouldTrimWHEREInsteadOfANDForBothConditions() throws Exception {
final String expected = "SELECT * FROM BLOG WHERE ID = ? OR NAME = ?";
final String expected = "SELECT * FROM BLOG WHERE ID = ? OR NAME = ?";
DynamicSqlSource source = createDynamicSqlSource(new TextSqlNode("SELECT * FROM BLOG"),
new WhereSqlNode(new Configuration(),
mixedContents(new IfSqlNode(mixedContents(new TextSqlNode(" and ID = ? ")), "true"),
Expand All @@ -236,7 +236,7 @@ void shouldTrimNoWhereClause() throws Exception {

@Test
void shouldTrimSETInsteadOfCOMMAForBothConditions() throws Exception {
final String expected = "UPDATE BLOG SET ID = ?, NAME = ?";
final String expected = "UPDATE BLOG SET ID = ?, NAME = ?";
DynamicSqlSource source = createDynamicSqlSource(new TextSqlNode("UPDATE BLOG"),
new SetSqlNode(new Configuration(),
mixedContents(new IfSqlNode(mixedContents(new TextSqlNode(" ID = ?, ")), "true"),
Expand Down