Some optimizations on empty wxString comparison and on Search (Database)

This commit is contained in:
2010-08-21 09:54:04 +02:00
parent 3802460429
commit d12e00c6fb
7 changed files with 49 additions and 47 deletions

View File

@@ -1030,6 +1030,23 @@ std::vector<Operation>* Database::Search(User* user, wxString* description, wxDa
std::vector<wxString>::iterator it;
std::vector<Account>::iterator accountIt;
std::vector<Operation>* res = new std::vector<Operation>;
wxString dayFrom, monthFrom, yearFrom;
wxString dayTo, monthTo, yearTo;
if (dateFrom)
{
dayFrom = wxString::Format(wxT("%d"), dateFrom->GetDay()-1);
monthFrom = wxString::Format(wxT("%d"), dateFrom->GetMonth());
yearFrom = wxString::Format(wxT("%d"), dateFrom->GetYear());
}
if (dateTo)
{
dayTo = wxString::Format(wxT("%d"), dateTo->GetDay()-1);
monthTo = wxString::Format(wxT("%d"), dateTo->GetMonth());
yearTo = wxString::Format(wxT("%d"), dateTo->GetYear());
}
req = wxT("SELECT * from operation WHERE ");
@@ -1043,9 +1060,8 @@ std::vector<Operation>* Database::Search(User* user, wxString* description, wxDa
{
if (firstCond) req += wxT(" AND ") ; else firstCond = true;
req += wxT("(");
req += wxT(" year >= '") + wxString::Format(wxT("%d"), dateFrom->GetYear()) + wxT("'");
//req += wxT(" AND month >= '") + wxString::Format(wxT("%d"), dateFrom->GetMonth()) + wxT("'");
// req += wxT(" AND day >= '") + wxString::Format(wxT("%d"), dateFrom->GetDay()) + wxT("'");
req += wxT("year >= ") + yearFrom ;
req += wxT(" AND (month > '") + monthFrom + wxT("' OR (month == '") + monthFrom + wxT("' AND day >= '") + dayFrom + wxT("'))");
req += wxT(")");
}
@@ -1053,9 +1069,8 @@ std::vector<Operation>* Database::Search(User* user, wxString* description, wxDa
{
if (firstCond) req += wxT(" AND ") ; else firstCond = true;
req += wxT("(");
req += wxT(" year <= '") + wxString::Format(wxT("%d"), dateTo->GetYear()) + wxT("'");
//req += wxT(" AND month <= '") + wxString::Format(wxT("%d"), dateTo->GetMonth()) + wxT("'");
// req += wxT(" AND day <= '") + wxString::Format(wxT("%d"), dateTo->GetDay()) + wxT("'");
req += wxT("year <= ") + yearTo ;
req += wxT(" AND (month < '") + monthTo + wxT("' OR (month == '") + monthTo + wxT("' AND day <= '") + dayTo + wxT("'))");
req += wxT(")");
}
@@ -1134,19 +1149,6 @@ std::vector<Operation>* Database::Search(User* user, wxString* description, wxDa
op.category = set.GetAsString(wxT("category"));
op.fix_cost = set.GetBool(wxT("fix_cost"));
op.checked = set.GetBool(wxT("checked"));
if (dateFrom &&
(int)op.year == dateFrom->GetYear() &&
(int)op.month <= dateFrom->GetMonth() &&
(int)op.day < dateFrom->GetDay()-1)
continue;
if (dateTo &&
(int)op.year == dateTo->GetYear() &&
(int)op.month >= dateTo->GetMonth() &&
(int)op.day > dateTo->GetDay()-1)
continue;
res->push_back(op);
}

View File

@@ -110,7 +110,7 @@ wxLanguage User::GetLanguage()
wxString res = _preferences[wxT("language")];
long val;
if (res == wxT(""))
if (!res.Length())
return wxLANGUAGE_ENGLISH ;
res.ToLong(&val);