1 #ifndef cetlib_sqlite_Ntuple_h 2 #define cetlib_sqlite_Ntuple_h 120 template <
typename... Args>
126 template <
typename T>
128 std::unique_ptr<typename sqlite::permissive_column<T>::element_type>;
129 using row_t = std::tuple<element_t<Args>...>;
130 static constexpr
auto nColumns = std::tuple_size_v<row_t>;
138 bool overwriteContents = false,
139 std::
size_t bufsize = 1000ull);
149 void insert(Args
const...);
153 static constexpr
auto iSequence = std::make_index_sequence<nColumns>();
156 template <std::size_t...
I>
160 bool overwriteContents,
162 std::index_sequence<I...>);
177 template <
typename... Args>
178 template <std::size_t...
I>
182 bool const overwriteContents,
183 std::size_t
const bufsize,
184 std::index_sequence<I...>)
187 std::lock_guard sentry{
mutex_};
196 for (std::size_t i = 1; i <
nColumns; ++i) {
200 int const rc{sqlite3_prepare_v2(
202 if (
rc != SQLITE_OK) {
205 <<
"Failed to prepare insertion statement.\n" 206 <<
"Return code: " << ec <<
'\n';
211 template <
typename... Args>
215 bool const overwriteContents,
216 std::size_t
const bufsize)
220 template <
typename... Args>
224 std::cerr <<
"SQLite step failure while flushing.\n";
229 template <
typename... Args>
233 std::lock_guard sentry{
mutex_};
237 buffer_.emplace_back(std::make_unique<Args>(args)...);
240 template <
typename... Args>
246 std::lock_guard sentry{
mutex_};
249 if (
rc != SQLITE_DONE) {
256 template <
typename... Args>
263 <<
"SQLite step failure while flushing.";
void insert(Args const ...)
void createTableIfNeeded(sqlite3 *db, bool const delete_contents, std::string const &tablename, permissive_column< Args > const &...cols)
std::recursive_mutex mutex_
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
struct sqlite3_stmt sqlite3_stmt
std::string const & name() const
static constexpr auto iSequence
sqlite::name_array< nColumns > name_array
std::vector< row_t > buffer_
Ntuple(Connection &connection, std::string const &name, name_array const &columns, bool overwriteContents=false, std::size_t bufsize=1000ull)
static constexpr auto nColumns
std::unique_ptr< typename sqlite::permissive_column< T >::element_type > element_t
sqlite3_stmt * insert_statement_
std::tuple< element_t< Args >... > row_t
int flush_no_throw(std::vector< Row > const &buffer, sqlite3_stmt *&insertStmt)
std::array< std::string, N > name_array