Skip to content

Commit

Permalink
#362 reproduced and fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Nov 5, 2023
1 parent faa0437 commit 1a1f3d6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
Empty file added src/main/aspect/.gitkeep
Empty file.
1 change: 0 additions & 1 deletion src/main/aspect/README.txt

This file was deleted.

14 changes: 9 additions & 5 deletions src/main/java/com/jcabi/dynamo/mock/H2Data.java
Expand Up @@ -56,6 +56,7 @@
import java.util.LinkedList;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;
import javax.sql.DataSource;
import lombok.EqualsAndHashCode;
import lombok.ToString;
Expand Down Expand Up @@ -118,7 +119,7 @@ private Attributes fetch(final ResultSet rset) throws SQLException {
* Where clause.
*/
private static final Function<String, String> WHERE =
key -> String.format("%s = ?", key);
key -> String.format("`%s` = ?", key);

/**
* Select WHERE.
Expand Down Expand Up @@ -146,21 +147,21 @@ private Attributes fetch(final ResultSet rset) throws SQLException {
);
}
return String.format(
"%s %s ?", cnd.getKey(), opr
"`%s` %s ?", cnd.getKey(), opr
);
};

/**
* Create primary key.
*/
private static final Function<String, String> CREATE_KEY =
key -> String.format("%s VARCHAR PRIMARY KEY", key);
key -> String.format("`%s` VARCHAR PRIMARY KEY", key);

/**
* Create attr.
*/
private static final Function<String, String> CREATE_ATTR =
key -> String.format("%s CLOB", key);
key -> String.format("`%s` CLOB", key);

/**
* WHERE clauses are joined with this.
Expand Down Expand Up @@ -250,7 +251,10 @@ public void put(final String table, final Attributes attrs)
String.format(
"INSERT INTO %s (%s) VALUES (%s)",
H2Data.encodeTableName(table),
Joiner.on(',').join(attrs.keySet()),
attrs.keySet()
.stream()
.map((a) -> String.format("`%s`", a))
.collect(Collectors.joining(", ")),
Joiner.on(',').join(Collections.nCopies(attrs.size(), "?"))
)
);
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/com/jcabi/dynamo/mock/H2DataTest.java
Expand Up @@ -56,9 +56,9 @@ final class H2DataTest {
@Test
void storesAndReadsAttributes() throws Exception {
final String table = "users";
final String key = "id";
final String key = "user";
final int number = 43;
final String attr = "desc";
final String attr = "user.name";
final String value = "some\n\t\u20ac text";
final MkData data = new H2Data().with(
table, new String[] {key},
Expand All @@ -81,7 +81,7 @@ table, new Conditions().with(key, Conditions.equalTo(number))
void storesToFile(@TempDir final Path temp) throws Exception {
final File file = temp.resolve("foo.txt").toFile();
final String table = "tbl";
final String key = "key1";
final String key = "user";
final MkData data = new H2Data(file).with(
table, new String[] {key}
);
Expand All @@ -93,7 +93,7 @@ void storesToFile(@TempDir final Path temp) throws Exception {
@Test
void createsManyTables() throws Exception {
new H2Data()
.with("firsttable", new String[] {"firstid"})
.with("firsttable", new String[] {"firstid"}, "test")
.with("secondtable", new String[]{"secondid"});
}

Expand Down

0 comments on commit 1a1f3d6

Please sign in to comment.