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

work around scoping problem

The problem manifested for a very small number of compounds,
but could be reproducibly triggered with the MallocScribble
option.
parent 9c10f9da
No related branches found
No related tags found
No related merge requests found
...@@ -36,4 +36,16 @@ int Compound::GetAtomSpecIndex(const String& name) const { ...@@ -36,4 +36,16 @@ int Compound::GetAtomSpecIndex(const String& name) const {
} }
return -1; return -1;
} }
String Date::ToString() const
{
std::stringstream ss;
ss << year << "-";
ss.fill('0');
ss.width(2);
ss << month << "-";
ss.fill('0');
ss.width(2);
ss << day;
return ss.str();
}
}} }}
...@@ -61,6 +61,8 @@ struct Date { ...@@ -61,6 +61,8 @@ struct Date {
return Date(year.second, month.second, day.second); return Date(year.second, month.second, day.second);
} }
String ToString() const;
int year; int year;
int month; int month;
int day; int day;
......
...@@ -102,6 +102,7 @@ void CompoundLib::AddCompound(const CompoundPtr& compound) ...@@ -102,6 +102,7 @@ void CompoundLib::AddCompound(const CompoundPtr& compound)
sqlite3_stmt* stmt=NULL; sqlite3_stmt* stmt=NULL;
int retval=sqlite3_prepare_v2(conn_, INSERT_COMPOUND_STATEMENT, int retval=sqlite3_prepare_v2(conn_, INSERT_COMPOUND_STATEMENT,
strlen(INSERT_COMPOUND_STATEMENT), &stmt, NULL); strlen(INSERT_COMPOUND_STATEMENT), &stmt, NULL);
String crea_date_str, modi_date_str;
if (SQLITE_OK==retval) { if (SQLITE_OK==retval) {
sqlite3_bind_text(stmt, 1, compound->GetID().c_str(), sqlite3_bind_text(stmt, 1, compound->GetID().c_str(),
compound->GetID().length(), NULL); compound->GetID().length(), NULL);
...@@ -115,29 +116,16 @@ void CompoundLib::AddCompound(const CompoundPtr& compound) ...@@ -115,29 +116,16 @@ void CompoundLib::AddCompound(const CompoundPtr& compound)
sqlite3_bind_text(stmt, 5, &chem_type, 1, NULL); sqlite3_bind_text(stmt, 5, &chem_type, 1, NULL);
sqlite3_bind_text(stmt, 6, compound->GetFormula().c_str(), sqlite3_bind_text(stmt, 6, compound->GetFormula().c_str(),
compound->GetFormula().length(), NULL); compound->GetFormula().length(), NULL);
std::stringstream ss;
ss << compound->GetCreationDate().year << "-"; Date crea_date=compound->GetCreationDate();
ss.fill('0'); Date modi_date=compound->GetModificationDate();
ss.width(2); crea_date_str=crea_date.ToString();
ss << compound->GetCreationDate().month << "-"; modi_date_str=modi_date.ToString();
ss.fill('0'); sqlite3_bind_text(stmt, 7, crea_date_str.c_str(), crea_date_str.length(), NULL);
ss.width(2); sqlite3_bind_text(stmt, 8, modi_date_str.c_str(), modi_date_str.length(), NULL);
ss << compound->GetCreationDate().day;
String date=ss.str();
ss.str("");
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);
} else { } else {
LOG_ERROR(sqlite3_errmsg(conn_)); LOG_ERROR(sqlite3_errmsg(conn_));
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
return; return;
} }
retval=sqlite3_step(stmt); retval=sqlite3_step(stmt);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment