From a662eab22d2d3342b74420a700106f24aeab8c31 Mon Sep 17 00:00:00 2001 From: Raman Arora Date: Fri, 17 Jul 2020 13:54:44 -0400 Subject: [PATCH] 6624: Incorrect SQL for inserting accounts in SQLite CentralRepo --- .../datamodel/RdbmsCentralRepo.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/RdbmsCentralRepo.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/RdbmsCentralRepo.java index 2a68f1e1d9..b48797e3fc 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/RdbmsCentralRepo.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/RdbmsCentralRepo.java @@ -1085,8 +1085,19 @@ abstract class RdbmsCentralRepo implements CentralRepository { // Get the account fom the accounts table String normalizedAccountID = CentralRepoAccount.normalizeAccountIdentifier(crAccountType, accountUniqueID); - String insertSQL = "INSERT INTO accounts (account_type_id, account_unique_identifier) " - + "VALUES (?, ?) " + getConflictClause(); + // insert the account. If there is a conflict, ignore it. + String insertSQL; + switch (CentralRepoDbManager.getSavedDbChoice().getDbPlatform()) { + case POSTGRESQL: + insertSQL = "INSERT INTO accounts (account_type_id, account_unique_identifier) VALUES (?, ?) " + getConflictClause(); //NON-NLS + break; + case SQLITE: + insertSQL = "INSERT OR IGNORE INTO accounts (account_type_id, account_unique_identifier) VALUES (?, ?) "; //NON-NLS + break; + default: + throw new CentralRepoException(String.format("Cannot add account to currently selected CR database platform %s", CentralRepoDbManager.getSavedDbChoice().getDbPlatform())); //NON-NLS + } + try (Connection connection = connect(); PreparedStatement preparedStatement = connection.prepareStatement(insertSQL);) {