Merge pull request #1362 from karlmortensen/fix_sql

Fix sql
This commit is contained in:
Richard Cordovano 2015-06-12 16:23:11 -04:00
commit 302fd6b83d
4 changed files with 44 additions and 26 deletions

View File

@ -47,6 +47,7 @@ FileSearchPanel.search.results.msg=File Search\: {0} matches found
FileSearchPanel.search.results.details=Large number of matches may impact performance on some operations
FileSearchPanel.search.exception.noFilterSelected.msg=At least one filter must be selected.
FileSearchPanel.search.validationErr.msg=Validation Error\: {0}
FileSearchPanel.emptyWhereClause.text=Invalid options, nothing to show.
KnownStatusSearchFilter.noneSelectedMsg.text=At least one known status must be selected\!
NameSearchFilter.emptyNameMsg.text=Must enter something for name search.
SearchNode.getName.text=Search Result

View File

@ -72,9 +72,9 @@ class DateSearchFilter extends AbstractFileSearchFilter<DateSearchPanel> {
@Override
public String getPredicate() throws FilterValidationException {
String addQuery = "1";
String query = "NULL";
DateSearchPanel panel = this.getComponent();
// first, get the selected timeZone from the dropdown list
String tz = this.getComponent().getTimeZoneComboBox().getSelectedItem().toString();
String tzID = tz.substring(tz.indexOf(" ") + 1); // 1 index after the space is the ID
@ -92,7 +92,7 @@ class DateSearchFilter extends AbstractFileSearchFilter<DateSearchPanel> {
startDate = Calendar.getInstance(new SimpleTimeZone(0, "GMT")); //NON-NLS
startDate.setTime(temp); // convert to GMT
} catch (ParseException ex) {
// for now, no need to show the error message to the user her
// for now, no need to show the error message to the user here
}
if (!startDateValue.equals("")) {
if (startDate != null) {
@ -120,6 +120,13 @@ class DateSearchFilter extends AbstractFileSearchFilter<DateSearchPanel> {
}
}
// If they put the dates in backwards, help them out.
if (fromDate > toDate) {
long temp = toDate;
toDate = fromDate;
fromDate = temp;
}
final boolean modifiedChecked = panel.getModifiedCheckBox().isSelected();
final boolean changedChecked = panel.getChangedCheckBox().isSelected();
final boolean accessedChecked = panel.getAccessedCheckBox().isSelected();
@ -127,30 +134,27 @@ class DateSearchFilter extends AbstractFileSearchFilter<DateSearchPanel> {
if (modifiedChecked || changedChecked || accessedChecked || createdChecked) {
String subQuery = "0";
if (modifiedChecked) {
subQuery += " or mtime between " + fromDate + " and " + toDate; //NON-NLS
query += " OR (mtime BETWEEN " + fromDate + " AND " + toDate + ")"; //NON-NLS
}
if (changedChecked) {
subQuery += " or ctime between " + fromDate + " and " + toDate; //NON-NLS
query += " OR (ctime BETWEEN " + fromDate + " AND " + toDate + ")"; //NON-NLS
}
if (accessedChecked) {
subQuery += " or atime between " + fromDate + " and " + toDate; //NON-NLS
query += " OR (atime BETWEEN " + fromDate + " AND " + toDate + ")"; //NON-NLS
}
if (createdChecked) {
subQuery += " or crtime between " + fromDate + " and " + toDate; //NON-NLS
query += " OR (crtime BETWEEN " + fromDate + " AND " + toDate + ")"; //NON-NLS
}
addQuery += " and (" + subQuery + ")"; //NON-NLS
} else {
throw new FilterValidationException(NONE_SELECTED_MESSAGE);
}
return addQuery;
return query;
}

View File

@ -63,7 +63,8 @@ import org.sleuthkit.datamodel.TskCoreException;
private List<FilterArea> filterAreas = new ArrayList<FilterArea>();
private JButton searchButton;
private static int resultWindowCount = 0; //keep track of result windows so they get unique names
private static final String EMPTY_WHERE_CLAUSE = NbBundle.getMessage(DateSearchFilter.class, "FileSearchPanel.emptyWhereClause.text");
/**
* Creates new form FileSearchPanel
*/
@ -202,17 +203,29 @@ import org.sleuthkit.datamodel.TskCoreException;
* org.sleuthkit.autopsy.filesearch.FileSearchFilter.FilterValidationException
* if an enabled filter is in an invalid state
*/
private String getQuery() throws FilterValidationException {
private String getQuery() throws FilterValidationException {
//String query = "SELECT " + tempQuery + " FROM tsk_files WHERE 1";
String query = " 1";
//String query = "SELECT " + tempQuery + " FROM tsk_files WHERE ";
String query = "";
int i=0;
for (FileSearchFilter f : this.getEnabledFilters()) {
String result = f.getPredicate();
if (!result.isEmpty()) {
if(i>0) {
query += " AND (" + result + ")"; //NON-NLS
}
else {
query += " (" + result + ")"; //NON-NLS
}
++i;
}
}
for (FileSearchFilter f : this.getEnabledFilters()) {
query += " AND (" + f.getPredicate() + ")"; //NON-NLS
}
return query;
}
if (query.isEmpty()) {
throw new FilterValidationException(EMPTY_WHERE_CLAUSE);
}
return query;
}
private Collection<FileSearchFilter> getFilters() {
Collection<FileSearchFilter> filters = new ArrayList<FileSearchFilter>();

View File

@ -56,15 +56,15 @@ class KnownStatusSearchFilter extends AbstractFileSearchFilter<KnownStatusSearch
throw new FilterValidationException(NONE_SELECTED_MESSAGE);
}
String expr = "0";
String expr = "NULL";
if (unknown) {
expr += " or " + predicateHelper(FileKnown.UNKNOWN); //NON-NLS
expr += " OR " + predicateHelper(FileKnown.UNKNOWN); //NON-NLS
}
if (known) {
expr += " or " + predicateHelper(FileKnown.KNOWN); //NON-NLS
expr += " OR " + predicateHelper(FileKnown.KNOWN); //NON-NLS
}
if (knownBad) {
expr += " or " + predicateHelper(FileKnown.BAD); //NON-NLS
expr += " OR " + predicateHelper(FileKnown.BAD); //NON-NLS
}
return expr;
}
@ -75,7 +75,7 @@ class KnownStatusSearchFilter extends AbstractFileSearchFilter<KnownStatusSearch
* @return un-padded SQL boolean expression
*/
private String predicateHelper(FileKnown knownStatus) {
return "known is " + knownStatus.getFileKnownValue(); //NON-NLS
return "known = " + knownStatus.getFileKnownValue(); //NON-NLS
}
@Override