From 51a58a0b0b9afe16ee316438281aeee36fa34b05 Mon Sep 17 00:00:00 2001 From: Xavier Robin <xavier.robin@unibas.ch> Date: Tue, 23 Jul 2024 10:45:43 +0200 Subject: [PATCH] fix: skip missing creation/modification dates Dates can be NULL in the current database schema. We never use them anyways (ie they are not read back from the database when compounds are loaded) so it is safe to skip them if they are missing. --- modules/conop/src/compound_lib.cc | 22 ++++++++++++++++------ modules/io/src/mol/chemdict_parser.cc | 18 ++++++++++++------ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/modules/conop/src/compound_lib.cc b/modules/conop/src/compound_lib.cc index c84b0e9b7..6782828f3 100644 --- a/modules/conop/src/compound_lib.cc +++ b/modules/conop/src/compound_lib.cc @@ -264,13 +264,23 @@ void CompoundLib::AddCompound(const CompoundPtr& compound) sqlite3_bind_text(stmt, 6, compound->GetFormula().c_str(), compound->GetFormula().length(), NULL); Date crea_date=compound->GetCreationDate(); + if (crea_date == Date()) { + sqlite3_bind_null(stmt, 7); + } + else { + crea_date_str=crea_date.ToString(); + sqlite3_bind_text(stmt, 7, crea_date_str.c_str(), crea_date_str.length(), + NULL); + } 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); + if (modi_date == Date()) { + sqlite3_bind_null(stmt, 8); + } + else { + modi_date_str=modi_date.ToString(); + sqlite3_bind_text(stmt, 8, modi_date_str.c_str(), modi_date_str.length(), + NULL); + } sqlite3_bind_text(stmt, 9, compound->GetName().c_str(), compound->GetName().length(), NULL); sqlite3_bind_text(stmt, 10, compound->GetInchi().c_str(), diff --git a/modules/io/src/mol/chemdict_parser.cc b/modules/io/src/mol/chemdict_parser.cc index 382a983af..3f97a49b5 100644 --- a/modules/io/src/mol/chemdict_parser.cc +++ b/modules/io/src/mol/chemdict_parser.cc @@ -155,18 +155,24 @@ void ChemdictParser::OnDataItem(const StarDataItem& item) compound_->SetObsolete(true); } } else if (item.GetName()==StringRef("pdbx_replaced_by", 16)) { - String replaced_by = item.GetValue().str(); - if (replaced_by != "?") { - compound_->SetReplacedBy(replaced_by); + StringRef replaced_by = item.GetValue(); + if (! IsUndefined(replaced_by)) { + compound_->SetReplacedBy(replaced_by.str()); } } else if (item.GetName()==StringRef("one_letter_code", 15)) { if (item.GetValue().length()==1) { compound_->SetOneLetterCode(item.GetValue()[0]); } - } else if (item.GetName()==StringRef("pdbx_initial_date", 17)) { - compound_->SetCreationDate(Date::FromString(item.GetValue())); + } else if (item.GetName()==StringRef("pdbx_initial_date", 17)) { + StringRef pdbx_initial_date = item.GetValue(); + if (! IsUndefined(pdbx_initial_date)) { + compound_->SetCreationDate(Date::FromString(pdbx_initial_date)); + } } else if (item.GetName()==StringRef("pdbx_modified_date", 18)) { - compound_->SetModificationDate(Date::FromString(item.GetValue())); + StringRef pdbx_modified_date = item.GetValue(); + if (! IsUndefined(pdbx_modified_date)) { + compound_->SetModificationDate(Date::FromString(pdbx_modified_date)); + } } } else if (item.GetName()==StringRef("atom_id", 7)) { atom_.name=item.GetValue().str(); -- GitLab