Skip to content
Snippets Groups Projects
Unverified Commit 5c86a73b authored by Ann Priestman's avatar Ann Priestman Committed by GitHub
Browse files

Merge pull request #2761 from APriestman/6024_updatePreparedStatement

6024 Add update prepared statement to CaseDbAccessManager
parents e122f2bd eae52b4b
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 ...@@ -522,6 +522,54 @@ public long insertOrUpdate(final String tableName, final String sql, final CaseD
return rowId; 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. * Updates row(s) in the specified table.
* *
...@@ -798,7 +846,8 @@ private enum LockType { ...@@ -798,7 +846,8 @@ private enum LockType {
*/ */
private enum StatementType { private enum StatementType {
SELECT, 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