diff --git a/bindings/java/src/org/sleuthkit/datamodel/CaseDbAccessManager.java b/bindings/java/src/org/sleuthkit/datamodel/CaseDbAccessManager.java index 8e417fdf39c81a99bf83d0cc593153db0626925a..ddfdd88f17c6177151f9e30cedc6fff49c0ff6b0 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/CaseDbAccessManager.java +++ b/bindings/java/src/org/sleuthkit/datamodel/CaseDbAccessManager.java @@ -522,6 +522,54 @@ public long insertOrUpdate(final String tableName, final String sql, final CaseD return rowId; } + /** + * Creates a prepared statement object for the purposes of running an update + * statement. The given SQL should not include the starting "UPDATE" + * or the name of the table. + * + * @param tableName The name of the table being updated. + * @param sql The insert statement without the starting "UPDATE (table name)" part. + * @param trans The open transaction. + * + * @return The prepared statement object. + * + * @throws TskCoreException + */ + @Beta + public CaseDbPreparedStatement prepareUpdate(String tableName, String sql, CaseDbTransaction trans) throws TskCoreException { + validateTableName(tableName); + validateSQL(sql); + + String updateSQL = "UPDATE " + tableName + " " + sql; // NON-NLS + + try { + return new CaseDbPreparedStatement(StatementType.UPDATE, updateSQL, trans); + } catch (SQLException ex) { + throw new TskCoreException("Error creating update prepared statement for query:\n" + updateSQL, ex); + } + } + + /** + * Performs an update statement query with the given case prepared statement. + * + * @param preparedStatement The case prepared statement. + * + * @throws TskCoreException + */ + @Beta + public void update(CaseDbPreparedStatement preparedStatement) throws TskCoreException { + + if (!preparedStatement.getType().equals(StatementType.UPDATE)) { + throw new TskCoreException("CaseDbPreparedStatement has incorrect type for update operation"); + } + + try { + preparedStatement.getStatement().executeUpdate(); + } catch (SQLException ex) { + throw new TskCoreException("Error updating row in table " + "" + " with sql = "+ "", ex); + } + } + /** * Updates row(s) in the specified table. * @@ -798,7 +846,8 @@ private enum LockType { */ private enum StatementType { SELECT, - INSERT; + INSERT, + UPDATE; } /**