-
Notifications
You must be signed in to change notification settings - Fork 521
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(", "); | ||
} | ||
} | ||
|
@@ -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--; | ||
continue; | ||
} | ||
update.append(formatKey(key)); | ||
update.append("=?"); | ||
if (++i != size) { | ||
if (i++ > 0) { | ||
update.append(", "); | ||
} | ||
update.append(formatKey(key)); | ||
update.append("=?"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could add a uri example to diff the logic There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SQL example: |
||
} | ||
|
||
WhereBuilder where = this.newWhereBuilder(); | ||
|
There was a problem hiding this comment.
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