From 59057aec1049d5de10b832d5294d9a9b0f06204a Mon Sep 17 00:00:00 2001 From: Marco Biasini <marco.biasini@unibas.ch> Date: Fri, 15 Jun 2012 11:46:33 +0200 Subject: [PATCH] work around scoping problem The problem manifested for a very small number of compounds, but could be reproducibly triggered with the MallocScribble option. --- modules/conop/src/compound.cc | 12 ++++++++++++ modules/conop/src/compound.hh | 2 ++ modules/conop/src/compound_lib.cc | 30 ++++++++---------------------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/modules/conop/src/compound.cc b/modules/conop/src/compound.cc index dfa1a69f9..4e4500969 100644 --- a/modules/conop/src/compound.cc +++ b/modules/conop/src/compound.cc @@ -29,4 +29,16 @@ int Compound::GetAtomSpecIndex(const String& name) const { } 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(); +} }} diff --git a/modules/conop/src/compound.hh b/modules/conop/src/compound.hh index 45466a1cc..baca26eb7 100644 --- a/modules/conop/src/compound.hh +++ b/modules/conop/src/compound.hh @@ -61,6 +61,8 @@ struct Date { return Date(year.second, month.second, day.second); } + String ToString() const; + int year; int month; int day; diff --git a/modules/conop/src/compound_lib.cc b/modules/conop/src/compound_lib.cc index 020c3468c..61c8fc11a 100644 --- a/modules/conop/src/compound_lib.cc +++ b/modules/conop/src/compound_lib.cc @@ -103,6 +103,7 @@ void CompoundLib::AddCompound(const CompoundPtr& compound) sqlite3_stmt* stmt=NULL; int retval=sqlite3_prepare_v2(conn_, INSERT_COMPOUND_STATEMENT, strlen(INSERT_COMPOUND_STATEMENT), &stmt, NULL); + String crea_date_str, modi_date_str; if (SQLITE_OK==retval) { sqlite3_bind_text(stmt, 1, compound->GetID().c_str(), compound->GetID().length(), NULL); @@ -116,30 +117,15 @@ void CompoundLib::AddCompound(const CompoundPtr& compound) sqlite3_bind_text(stmt, 5, &chem_type, 1, NULL); sqlite3_bind_text(stmt, 6, compound->GetFormula().c_str(), compound->GetFormula().length(), NULL); - std::stringstream ss; - 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 << "-"; - 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); - sqlite3_bind_text(stmt, 9, compound->GetName().c_str(), compound->GetName().length(), NULL); + Date crea_date=compound->GetCreationDate(); + Date modi_date=compound->GetModificationDate(); + crea_date_str=crea_date.ToString(); + modi_date_str=modi_date.ToString(); + sqlite3_bind_text(stmt, 7, crea_date_str.c_str(), crea_date_str.length(), NULL); + sqlite3_bind_text(stmt, 8, modi_date_str.c_str(), modi_date_str.length(), NULL); } else { LOG_ERROR(sqlite3_errmsg(conn_)); - sqlite3_finalize(stmt); + sqlite3_finalize(stmt); return; } retval=sqlite3_step(stmt); -- GitLab