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

Fix SQL queries #348

Merged
merged 1 commit into from
Jun 25, 2024
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
- ![IO] Fix parsing of .ods files [#309](https://github.com/jdemetra/jdplus-main/issues/309)
- ![IO] Fix grid parsing when some headers are null [#328](https://github.com/jdemetra/jdplus-main/issues/328)
- ![IO] Fix reading v2 legacy WS when some user defined calendars have fixed and non-fixed coefficients [#183](https://github.com/jdemetra/jdplus-main/issues/183)
- ![IO] Fix SQL queries [#347](https://github.com/jdemetra/jdplus-main/issues/347)
- ![UI] Fix default toolbar and menu [#311](https://github.com/jdemetra/jdplus-main/issues/311)
- ![UI] Fix slow dialog box when opening a file [#313](https://github.com/jdemetra/jdplus-main/issues/313)
- ![UI] Fix option show-provider-nodes cannot be reset between sessions [#292](https://github.com/jdemetra/jdplus-main/issues/292)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
/*
* Copyright 2013 National Bank of Belgium
*
* Licensed under the EUPL, Version 1.1 or – as soon they will be approved
* Licensed under the EUPL, Version 1.1 or – as soon they will be approved
* by the European Commission - subsequent versions of the EUPL (the "Licence");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://ec.europa.eu/idabc/eupl
*
* Unless required by applicable law or agreed to in writing, software
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
package internal.sql.base.api;

import lombok.NonNull;
import nbbrd.design.BuilderPattern;
import nbbrd.sql.jdbc.SqlIdentifierQuoter;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import nbbrd.sql.jdbc.SqlIdentifierQuoter;
import lombok.NonNull;

/**
*
* @author Philippe Charles
*/
@lombok.RequiredArgsConstructor(staticName = "from")
Expand Down Expand Up @@ -89,7 +89,7 @@ private void appendOrderBy(StringBuilder result) {
private void appendWhere(StringBuilder result) {
if (!filter.isEmpty()) {
result.append(" WHERE ");
result.append(filter.stream().map(identifierQuoter::quote).collect(WHERE_JOINER));
result.append(filter.stream().map(identifierQuoter::quote).map(column -> column + "=?").collect(WHERE_JOINER));
}
}

Expand All @@ -102,7 +102,11 @@ private void appendSelect(StringBuilder result) {
if (distinct) {
result.append("DISTINCT ");
}
result.append(select.stream().map(identifierQuoter::quote).collect(COMMA_JOINER));
if (select.isEmpty()) {
result.append("*");
} else {
result.append(select.stream().map(identifierQuoter::quote).collect(COMMA_JOINER));
}
}

@NonNull
Expand All @@ -116,5 +120,5 @@ private SelectBuilder addIfNotNullOrEmpty(@NonNull List<String> list, @NonNull S
}

private static final Collector<CharSequence, ?, String> COMMA_JOINER = Collectors.joining(",");
private static final Collector<CharSequence, ?, String> WHERE_JOINER = Collectors.joining(" AND ", "", "=?");
private static final Collector<CharSequence, ?, String> WHERE_JOINER = Collectors.joining(" AND ");
}
Loading
Loading