mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-06 21:00:22 +00:00
5907: Update legacy modules
- Removed getConnectionMetadata() api and added columnExists() & tableExists()
This commit is contained in:
parent
e6e83682fe
commit
0ef999ade2
@ -21,7 +21,6 @@ package org.sleuthkit.autopsy.coreutils;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
@ -288,13 +287,92 @@ public final class AppSQLiteDB {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns connection meta data.
|
||||
* Checks if a column exists in a table.
|
||||
*
|
||||
* @return DatabaseMetaData
|
||||
* @throws SQLException
|
||||
* @param tableName name of the table
|
||||
* @param columnName column name to check
|
||||
*
|
||||
* @return true if the column exists, false otherwise
|
||||
* @throws TskCoreException
|
||||
*/
|
||||
public DatabaseMetaData getConnectionMetadata() throws SQLException {
|
||||
return connection.getMetaData();
|
||||
public boolean columnExists(String tableName, String columnName) throws TskCoreException {
|
||||
|
||||
boolean columnExists = false;
|
||||
Statement colExistsStatement = null;
|
||||
ResultSet resultSet = null;
|
||||
try {
|
||||
colExistsStatement = connection.createStatement();
|
||||
String tableInfoQuery = "PRAGMA table_info(%s)"; //NON-NLS
|
||||
resultSet = colExistsStatement.executeQuery(String.format(tableInfoQuery, tableName));
|
||||
while (resultSet.next()) {
|
||||
if (resultSet.getString("name").equalsIgnoreCase(columnName)) {
|
||||
columnExists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
throw new TskCoreException("Error checking if column " + columnName + "exists ", ex);
|
||||
} finally {
|
||||
if (resultSet != null) {
|
||||
try {
|
||||
resultSet.close();
|
||||
} catch (SQLException ex2) {
|
||||
logger.log(Level.WARNING, "Failed to close resultset after checking column", ex2);
|
||||
}
|
||||
}
|
||||
if (colExistsStatement != null) {
|
||||
try {
|
||||
colExistsStatement.close();
|
||||
} catch (SQLException ex2) {
|
||||
logger.log(Level.SEVERE, "Error closing Statement", ex2); //NON-NLS
|
||||
}
|
||||
}
|
||||
}
|
||||
return columnExists;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a table exists in the case database.
|
||||
*
|
||||
* @param tableName name of the table to check
|
||||
*
|
||||
* @return true if the table exists, false otherwise
|
||||
* @throws TskCoreException
|
||||
*/
|
||||
public boolean tableExists(String tableName) throws TskCoreException {
|
||||
|
||||
boolean tableExists = false;
|
||||
Statement tableExistsStatement = null;
|
||||
ResultSet resultSet = null;
|
||||
try {
|
||||
|
||||
tableExistsStatement = connection.createStatement();
|
||||
resultSet = tableExistsStatement.executeQuery("SELECT name FROM sqlite_master WHERE type='table'"); //NON-NLS
|
||||
while (resultSet.next()) {
|
||||
if (resultSet.getString("name").equalsIgnoreCase(tableName)) { //NON-NLS
|
||||
tableExists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
throw new TskCoreException("Error checking if table " + tableName + "exists ", ex);
|
||||
} finally {
|
||||
if (resultSet != null) {
|
||||
try {
|
||||
resultSet.close();
|
||||
} catch (SQLException ex2) {
|
||||
logger.log(Level.WARNING, "Failed to close resultset after checking table", ex2);
|
||||
}
|
||||
}
|
||||
if (tableExistsStatement != null) {
|
||||
try {
|
||||
tableExistsStatement.close();
|
||||
} catch (SQLException ex2) {
|
||||
logger.log(Level.SEVERE, "Error closing Statement", ex2); //NON-NLS
|
||||
}
|
||||
}
|
||||
}
|
||||
return tableExists;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -92,6 +92,8 @@ class CallLogAnalyzer(general.AndroidComponentAnalyzer):
|
||||
|
||||
for tableName in CallLogAnalyzer._tableNames:
|
||||
try:
|
||||
tableFound = callLogDb.tableExists(tableName)
|
||||
if tableFound:
|
||||
resultSet = callLogDb.runQuery("SELECT number, date, duration, type, name FROM " + tableName + " ORDER BY date DESC;")
|
||||
self._logger.log(Level.INFO, "Reading call log from table {0} in db {1}", [tableName, callLogDb.getDBFile().getName()])
|
||||
if resultSet is not None:
|
||||
|
@ -102,13 +102,7 @@ class ContactAnalyzer(general.AndroidComponentAnalyzer):
|
||||
# get display_name, mimetype(email or phone number) and data1 (phonenumber or email address depending on mimetype)
|
||||
# sorted by name, so phonenumber/email would be consecutive for a person if they exist.
|
||||
# check if contacts.name_raw_contact_id exists. Modify the query accordingly.
|
||||
columnFound = False
|
||||
metadata = contactDb.getConnectionMetadata()
|
||||
columnListResultSet = metadata.getColumns(None, None, "contacts", None)
|
||||
while columnListResultSet.next():
|
||||
if columnListResultSet.getString("COLUMN_NAME") == "name_raw_contact_id":
|
||||
columnFound = True
|
||||
break
|
||||
columnFound = contactDb.columnExists("contacts", "name_raw_contact_id")
|
||||
if columnFound:
|
||||
resultSet = contactDb.runQuery(
|
||||
"SELECT mimetype, data1, name_raw_contact.display_name AS display_name \n"
|
||||
|
Loading…
x
Reference in New Issue
Block a user