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 possible extra comma before where statement in MySQL backend #1924

Merged
merged 3 commits into from
Jul 19, 2022
Merged
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 @@ -235,18 +235,18 @@ protected String buildInsertKeys(StringBuilder insert,
insert.append(" (");

int i = 0;
int n = entry.columns().size();
int size = entry.columns().size();
for (HugeKeys key : entry.columns().keySet()) {
insert.append(formatKey(key));
if (++i != n) {
if (++i != size) {
insert.append(", ");
}
}
insert.append(") VALUES (");
// Fill with '?' as a placeholder
for (i = 0; i < n; i++) {
for (i = 0; i < size; i++) {
insert.append("?");
if (i != n - 1) {
if (i != size - 1) {
insert.append(", ");
}
}
Expand Down Expand Up @@ -286,25 +286,22 @@ protected List<Object> buildColumnsParams(MysqlBackendEntry.Row entry,
}

protected String buildUpdateIfPresentTemplate(MysqlBackendEntry.Row entry) {

StringBuilder update = new StringBuilder();
update.append("UPDATE ").append(this.table());
update.append(" SET ");

List<HugeKeys> idNames = this.idColumnName();

int i = 0;
int size = entry.columns().size();
for (HugeKeys key : entry.columns().keySet()) {
if (idNames.contains(key)) {
size--;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: the id key may be the last key

continue;
}
update.append(formatKey(key));
update.append("=?");
if (++i != size) {
if (i++ > 0) {
update.append(", ");
}
update.append(formatKey(key));
update.append("=?");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could add a uri example to diff the logic

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SQL example:
UPDATE il SET INDEX_TYPE=21, FIELDS='[76]', STATUS=4, USER_DATA='xx', BASE_VALUE=16, NAME='personByAge', BASE_TYPE=1, WHERE ID=1
=>
UPDATE il SET INDEX_TYPE=21, FIELDS='[76]', STATUS=4, USER_DATA='xx', BASE_VALUE=16, NAME='personByAge', BASE_TYPE=1 WHERE ID=1

}

WhereBuilder where = this.newWhereBuilder();
Expand Down