diff --git a/src/main/java/xyz/vallat/louis/database/LanguageManager.java b/src/main/java/xyz/vallat/louis/database/LanguageManager.java index fc958e2..ab3da2c 100644 --- a/src/main/java/xyz/vallat/louis/database/LanguageManager.java +++ b/src/main/java/xyz/vallat/louis/database/LanguageManager.java @@ -29,7 +29,7 @@ public final class LanguageManager { } public static void importLanguageIfNeeded(Connection connection) { - String storedHash = ""; + String storedHash = null; try { logger.debug("Checking if we need to import languages again."); storedHash = getPropertyValue(HASH_KEY); @@ -37,12 +37,12 @@ public final class LanguageManager { String actualHash = getActualHash(); logger.debug("Actual hash is '{}'.", actualHash); logger.info("Importing new language file."); - if (!storedHash.equals(actualHash)) importLanguageFile(connection); + if (storedHash == null || !storedHash.equals(actualHash)) importLanguageFile(connection); logger.debug("Saving new hash in database."); saveProperty(HASH_KEY, actualHash); } catch (SQLException | IOException | NoSuchAlgorithmException e) { logger.error("Cannot update the languages right now. Reason: {}", e.getMessage()); - if (storedHash.isEmpty()) System.exit(7); + if (storedHash == null || storedHash.isEmpty()) System.exit(7); logger.warn("Using language already in database. Please contact this bot's administrator to fix this issue."); } } @@ -103,8 +103,8 @@ public final class LanguageManager { String insert = "INSERT INTO languages(alpha3_b, alpha3_t, alpha2, english, french) VALUES(?, ?, ?, ?, ?);"; try (PreparedStatement stmt = connection.prepareStatement(insert)) { stmt.setString(1, alpha3b); - stmt.setString(2, alpha3t); - stmt.setString(3, alpha2b); + stmt.setString(2, alpha3t.isBlank() ? null : alpha3t); + stmt.setString(3, alpha2b.isBlank() ? null : alpha2b); stmt.setString(4, english); stmt.setString(5, french); stmt.executeUpdate();