| 5106 | */ |
| 5107 | |
| 5108 | datum::EngineeringDatumNNPtr |
| 5109 | AuthorityFactory::createEngineeringDatum(const std::string &code) const { |
| 5110 | auto res = d->runWithCodeParam( |
| 5111 | "SELECT name, publication_date, " |
| 5112 | "anchor, anchor_epoch, deprecated FROM " |
| 5113 | "engineering_datum WHERE auth_name = ? AND code = ?", |
| 5114 | code); |
| 5115 | if (res.empty()) { |
| 5116 | throw NoSuchAuthorityCodeException("engineering datum not found", |
| 5117 | d->authority(), code); |
| 5118 | } |
| 5119 | try { |
| 5120 | const auto &row = res.front(); |
| 5121 | const auto &name = row[0]; |
| 5122 | const auto &publication_date = row[1]; |
| 5123 | const auto &anchor = row[2]; |
| 5124 | const auto &anchor_epoch = row[3]; |
| 5125 | const bool deprecated = row[4] == "1"; |
| 5126 | auto props = d->createPropertiesSearchUsages("engineering_datum", code, |
| 5127 | name, deprecated); |
| 5128 | |
| 5129 | if (!publication_date.empty()) { |
| 5130 | props.set("PUBLICATION_DATE", publication_date); |
| 5131 | } |
| 5132 | if (!anchor_epoch.empty()) { |
| 5133 | props.set("ANCHOR_EPOCH", anchor_epoch); |
| 5134 | } |
| 5135 | auto anchorOpt = util::optional<std::string>(); |
| 5136 | if (!anchor.empty()) |
| 5137 | anchorOpt = anchor; |
| 5138 | return datum::EngineeringDatum::create(props, anchorOpt); |
| 5139 | } catch (const std::exception &ex) { |
| 5140 | throw buildFactoryException("engineering datum", d->authority(), code, |
| 5141 | ex); |
| 5142 | } |
| 5143 | } |
| 5144 | |
| 5145 | // --------------------------------------------------------------------------- |
| 5146 | |