Skip to content

Commit

Permalink
fix: duplicate key error
Browse files Browse the repository at this point in the history
  • Loading branch information
zyxxoo committed May 30, 2022
1 parent 3e332b4 commit c8781e8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ public Meta(Map<String, String> typesMapping) {
}

public void writeVersion(Session session, String driverVersion) {
String insert = String.format("INSERT INTO %s VALUES ('%s', '%s')",
this.table(),
formatKey(HugeKeys.VERSION),
driverVersion);
String versionColumn = formatKey(HugeKeys.VERSION);
String insert = String.format("INSERT IGNORE INTO %s VALUES " +
"('%s', '%s')", this.table(),
versionColumn, driverVersion);
try {
session.execute(insert);
} catch (SQLException throwables) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,17 @@ public Meta() {
}

public void writeVersion(Session session, String version) {
MysqlTables.Meta table = (MysqlTables.Meta) this.template;
table.writeVersion(session, version);
String versionColumn = formatKey(HugeKeys.VERSION);
String insert = String.format("INSERT INTO %s VALUES ('%s', '%s') " +
"ON CONFLICT(%s) DO NOTHING;",
this.table(), versionColumn, version,
versionColumn);
try {
session.execute(insert);
} catch (SQLException throwables) {
throw new BackendException("Failed to insert driver version " +
"with '%s'", insert);
}
}

public String readVersion(Session session) {
Expand Down

0 comments on commit c8781e8

Please sign in to comment.