Skip to content

Commit

Permalink
Fixed process of creation update query
Browse files Browse the repository at this point in the history
  • Loading branch information
timsixth committed Jun 17, 2023
1 parent bff3919 commit 19aeec1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>pl.timsixth</groupId>
<artifactId>T-DataBasesAPI</artifactId>
<version>1.7</version>
<version>1.7.1</version>

<repositories>
<repository>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,23 @@ public QueryBuilder update(String table, Map<String, Object> data) {
query.append("UPDATE ").append(table);

data.forEach((key, value) -> {
if (value instanceof String)
query.append(" SET ").append(key)
.append(" = ").append("'").append(value).append("'").append(",");
else query.append(" SET ").append(key)
.append(" = ").append(value).append(",");
if (value instanceof String) {
if (!query.toString().contains("SET")) {
query.append(" SET ").append(key)
.append(" = ").append("'").append(value).append("'").append(",");
} else {
query.append(key)
.append(" = ").append("'").append(value).append("'").append(",");
}
} else {
if (!query.toString().contains("SET")) {
query.append(" SET ").append(key)
.append(" = ").append(value).append(",");
} else {
query.append(key)
.append(" = ").append(value).append(",");
}
}
});

query.deleteCharAt(query.lastIndexOf(","));
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: T-DatabasesApi
main: pl.timsixth.databasesapi.DatabasesApiPlugin
version: '1.7'
version: '1.7.1'
author: timsixth
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void shouldGenerateUpdateQuery() {

String query = queryBuilder.update("users", data).build();

assertEquals("UPDATE users SET age = 12, SET username = 'test'", query);
assertEquals("UPDATE users SET age = 12,username = 'test'", query);
}

@Test
Expand Down

0 comments on commit 19aeec1

Please sign in to comment.