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,13 +379,26 @@ 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;
while (results.next()) { try (ResultSet results = stmt.executeQuery("SELECT name FROM sqlite_master WHERE type='table'");) {//NON-NLS
if ("data_source_obj_id".equals(results.getString("name"))) { while (results.next()) {
return true; 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()) {
if ("data_source_obj_id".equals(results.getString("name"))) {
return true;
}
}
} }
} }