From 62fa66944b1d0592ba1d7e498213e7f3c607b771 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, 23 insertions(+), 21 deletions(-) diff --git a/modules/conop/src/compound.cc b/modules/conop/src/compound.cc index b6ccaef83..dc6ff57c8 100644 --- a/modules/conop/src/compound.cc +++ b/modules/conop/src/compound.cc @@ -36,4 +36,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 975664a14..3ea9b71ec 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 76efe4ac7..e8a3388d0 100644 --- a/modules/conop/src/compound_lib.cc +++ b/modules/conop/src/compound_lib.cc @@ -102,6 +102,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); @@ -115,29 +116,16 @@ 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); + + 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