Skip to content
Snippets Groups Projects
Commit 391e9e4f authored by Marco Biasini's avatar Marco Biasini
Browse files

sqlite3 is very picky about date formats

Make sure, our dates have the correct format:

  2012-05-21 works, but 2012-5-12 does not.

Haven't I already fixed this one a few months ago?
parent f79af27f
No related branches found
No related tags found
No related merge requests found
......@@ -52,11 +52,11 @@ struct Date {
static Date FromString(const StringRef& str)
{
assert(str[4]=='-');
assert(str[7]=='-');
std::pair<bool, int> year=str.substr(0,4).to_int();
std::pair<bool, int> month=str.substr(5,2).to_int();
std::pair<bool, int> day=str.substr(8, 2).to_int();
std::vector<StringRef> parts=str.split('-');
assert(parts.size()==3);
std::pair<bool, int> year=parts[0].to_int();
std::pair<bool, int> month=parts[1].to_int();
std::pair<bool, int> day=parts[2].to_int();
assert(year.first); assert(month.first); assert(day.first);
return Date(year.second, month.second, day.second);
}
......
......@@ -116,14 +116,22 @@ void CompoundLib::AddCompound(const CompoundPtr& compound)
sqlite3_bind_text(stmt, 6, compound->GetFormula().c_str(),
compound->GetFormula().length(), NULL);
std::stringstream ss;
ss << compound->GetCreationDate().year << "-"
<< compound->GetCreationDate().month << "-"
<< compound->GetCreationDate().day;
ss << compound->GetCreationDate().year << "-";
ss.fill('0');
ss.width(2);
ss << compound->GetCreationDate().month << "-";
ss.fill('0');
ss.width(2);
ss << compound->GetCreationDate().day;
String date=ss.str();
ss.str("");
ss << compound->GetModificationDate().year << "-"
<< compound->GetModificationDate().month << "-"
<< compound->GetModificationDate().day;
ss << compound->GetModificationDate().year << "-";
ss.fill('0');
ss.width(2);
ss << compound->GetModificationDate().month << "-";
ss.fill('0');
ss.width(2);
ss << compound->GetModificationDate().day;
sqlite3_bind_text(stmt, 7, date.c_str(), date.length(), NULL);
date=ss.str();
sqlite3_bind_text(stmt, 8, date.c_str(), date.length(), NULL);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment