Skip to content
Snippets Groups Projects
Commit eae52b4b authored by apriestman's avatar apriestman
Browse files

Add update prepared statement to CaseDbAccessManager

parent 387c05c7
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment