diff --git a/headers/os/storage/Query.h b/headers/os/storage/Query.h index 143a3d6eea..cb07dcd921 100644 --- a/headers/os/storage/Query.h +++ b/headers/os/storage/Query.h @@ -99,6 +99,7 @@ private: bool deleteOnError); status_t _SetPredicate(const char* expression); status_t _EvaluateStack(); + void _ParseDates(BString& parsedPredicate); // FBC virtual void _QwertyQuery1(); diff --git a/src/kits/storage/Query.cpp b/src/kits/storage/Query.cpp index 6170c13331..ea65e5fe67 100644 --- a/src/kits/storage/Query.cpp +++ b/src/kits/storage/Query.cpp @@ -518,8 +518,11 @@ BQuery::Fetch() if (!fPredicate || fDevice < 0) return B_NO_INIT; - fQueryFd = _kern_open_query(fDevice, fPredicate, strlen(fPredicate), - fLive ? B_LIVE_QUERY : 0, fPort, fToken); + BString parsedPredicate; + _ParseDates(parsedPredicate); + + fQueryFd = _kern_open_query(fDevice, parsedPredicate.String(), + parsedPredicate.Length(), fLive ? B_LIVE_QUERY : 0, fPort, fToken); if (fQueryFd < 0) return fQueryFd; @@ -761,6 +764,41 @@ BQuery::_EvaluateStack() } +void +BQuery::_ParseDates(BString& parsedPredicate) +{ + const char* start = fPredicate; + const char* pos = start; + bool quotes = false; + + while (pos[0]) { + if (pos[0] == '\\') { + pos++; + continue; + } + if (pos[0] == '"') + quotes = !quotes; + else if (!quotes && pos[0] == '%') { + const char* end = strchr(pos + 1, '%'); + if (end == NULL) + continue; + + parsedPredicate.Append(start, pos - start); + start = end + 1; + + // We have a date string + BString date(pos + 1, start - 1 - pos); + parsedPredicate << parsedate(date.String(), time(NULL)); + + pos = end; + } + pos++; + } + + parsedPredicate.Append(start, pos - start); +} + + // FBC void BQuery::_QwertyQuery1() {} void BQuery::_QwertyQuery2() {}