check for table before checking for column to avoid "query doesn't return ResultSet"error

This commit is contained in:
millmanorama 2018-09-27 14:32:34 +02:00
parent ba72865298
commit a341eee92a

View File

@ -379,15 +379,28 @@ public final class DrawableDB {
} }
private static boolean hasDataSourceObjIdColumn(Path dbPath) throws TskCoreException { private static boolean hasDataSourceObjIdColumn(Path dbPath) throws TskCoreException {
String sql = "PRAGMA table_info('drawable_files')"; //NON-NLS
try (Connection con = DriverManager.getConnection("jdbc:sqlite:" + dbPath.toString()); //NON-NLS try (Connection con = DriverManager.getConnection("jdbc:sqlite:" + dbPath.toString()); //NON-NLS
Statement stmt = con.createStatement(); Statement stmt = con.createStatement();) {
ResultSet results = stmt.executeQuery(sql);) { boolean tableExists = false;
try (ResultSet results = stmt.executeQuery("SELECT name FROM sqlite_master WHERE type='table'");) {//NON-NLS
while (results.next()) {
if ("drawable_files".equals(results.getString("name"))) {
tableExists = true;
break;
}
}
}
if (false == tableExists) {
return false;
} else {
try (ResultSet results = stmt.executeQuery("PRAGMA table_info('drawable_files')");) { //NON-NLS
while (results.next()) { while (results.next()) {
if ("data_source_obj_id".equals(results.getString("name"))) { if ("data_source_obj_id".equals(results.getString("name"))) {
return true; return true;
} }
} }
}
}
} catch (SQLException ex) { } catch (SQLException ex) {
throw new TskCoreException("SQL error checking database compatibility", ex); //NON-NLS throw new TskCoreException("SQL error checking database compatibility", ex); //NON-NLS