27 sqlite3_open(
":memory:", &result);
45 if (errcode != SQLITE_OK) {
49 << sqlite3_errstr(errcode) <<
" (" << errcode <<
')' 50 << (msgString.empty() ?
"" : (
std::string(
": ") + msgString));
61 auto const errcode = sqlite3_errcode(db);
67 sqlite3_finalize(stmt_);
72 std::cerr << e.what() <<
'\n';
78 retcode = sqlite3_close(primaryDB_);
79 }
while (retcode == SQLITE_BUSY);
86 std::lock_guard sentry{mutex_};
91 sqlite3* primaryDB = instance_().primaryDB_;
96 "INSERT OR IGNORE INTO ParameterSets(ID, PSetBlob) VALUES(?, ?);",
104 inputPSes <<
select(
"*").from(db,
"ParameterSets");
106 for (
auto const& [idString, psBlob] : inputPSes) {
108 oStmt, 1, idString.c_str(), idString.size() + 1, SQLITE_STATIC);
111 oStmt, 2, psBlob.c_str(), psBlob.size() + 1, SQLITE_STATIC);
113 switch (sqlite3_step(oStmt)) {
119 sqlite3_reset(oStmt);
122 sqlite3_finalize(oStmt);
130 std::lock_guard sentry{mutex_};
134 "DROP TABLE IF EXISTS ParameterSets;" 135 "CREATE TABLE ParameterSets(ID PRIMARY KEY, PSetBlob);");
141 "INSERT OR IGNORE INTO ParameterSets(ID, PSetBlob) VALUES(?, ?);",
146 for (
auto const&
p : instance_().registry_) {
149 sqlite3_bind_text(oStmt, 1,
id.c_str(),
id.
size() + 1, SQLITE_STATIC);
152 oStmt, 2, psBlob.c_str(), psBlob.size() + 1, SQLITE_STATIC);
154 switch (sqlite3_step(oStmt)) {
156 sqlite3_reset(oStmt);
164 sqlite3*
const primaryDB{instance_().primaryDB_};
167 regPSes <<
select(
"*").from(primaryDB,
"ParameterSets");
169 for (
auto const& [idString, psBlob] : regPSes) {
171 oStmt, 1, idString.c_str(), idString.size() + 1, SQLITE_STATIC);
174 oStmt, 2, psBlob.c_str(), psBlob.size() + 1, SQLITE_STATIC);
176 switch (sqlite3_step(oStmt)) {
178 sqlite3_reset(oStmt);
185 sqlite3_finalize(oStmt);
192 std::lock_guard sentry{mutex_};
194 sqlite3* primaryDB = instance_().primaryDB_;
195 auto& registry = instance_().registry_;
198 entriesToStageIn <<
select(
"*").from(primaryDB,
"ParameterSets");
201 std::inserter(registry,
std::begin(registry)),
202 [](
auto const&
row) {
203 auto const& [idString, psBlob] =
row;
210 : primaryDB_{openPrimaryDB()}
220 if (
stmt_ ==
nullptr) {
222 "SELECT PSetBlob FROM ParameterSets WHERE ID = ?;",
228 auto idString =
id.to_string();
229 auto result = sqlite3_bind_text(
230 stmt_, 1, idString.c_str(), idString.size() + 1, SQLITE_STATIC);
232 result = sqlite3_step(
stmt_);
237 reinterpret_cast<char const*>(sqlite3_column_text(
stmt_, 0)));
246 sqlite3_reset(
stmt_);
void msg(const char *fmt,...)
static ParameterSet make(intermediate_table const &tbl)
struct sqlite3_stmt sqlite3_stmt
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
void create_table(sqlite3 *const db, std::string const &tablename, Cols const &...cols)
auto transform_all(Container &, OutputIt, UnaryOp)
collection_type registry_
auto select(T const &...t)
static std::recursive_mutex mutex_
typename collection_type::const_iterator const_iterator
void throwOnSQLiteFailure(int rc, char *msg=nullptr)
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
const_iterator find_(ParameterSetID const &id)
void exec(sqlite3 *db, std::string const &ddl)
cet::coded_exception< error, detail::translate > exception
static void exportTo(sqlite3 *db)
static void importFrom(sqlite3 *db)