Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
cet::sqlite::Connection Class Reference

#include <Connection.h>

Public Member Functions

 ~Connection () noexcept
 
 Connection ()=default
 
 Connection (Connection const &)=delete
 
 Connection (Connection &&)=delete
 
Connectionoperator= (Connection const &)=delete
 
Connectionoperator= (Connection &&)=delete
 
sqlite3get () const
 
 operator sqlite3 * ()
 
template<std::size_t NColumns, typename Row >
int flush_no_throw (std::vector< Row > const &buffer, sqlite3_stmt *&insertStmt)
 

Private Member Functions

template<typename DatabaseOpenPolicy >
 Connection (std::string const &filename, std::shared_ptr< std::recursive_mutex >, DatabaseOpenPolicy)
 

Private Attributes

sqlite3db_ {nullptr}
 
std::shared_ptr< std::recursive_mutex > mutex_ {nullptr}
 

Friends

class ConnectionFactory
 

Detailed Description

Definition at line 31 of file Connection.h.

Constructor & Destructor Documentation

Connection::~Connection ( )
noexcept

Definition at line 8 of file Connection.cc.

9 {
10  // It is safe to call sqlite3_close on a null db_.
11  sqlite3_close(db_);
12 }
cet::sqlite::Connection::Connection ( )
explicitdefault
cet::sqlite::Connection::Connection ( Connection const &  )
delete
cet::sqlite::Connection::Connection ( Connection &&  )
delete
template<typename DatabaseOpenPolicy >
cet::sqlite::Connection::Connection ( std::string const &  filename,
std::shared_ptr< std::recursive_mutex >  spmutex,
DatabaseOpenPolicy  policy 
)
explicitprivate

Definition at line 70 of file Connection.h.

73  : mutex_{spmutex}
74  {
75  // No lock necessary since the c'tor is called in a protected
76  // environment.
77  db_ = policy.open(filename);
78  }
std::shared_ptr< std::recursive_mutex > mutex_
Definition: Connection.h:66
string filename
Definition: train.py:213

Member Function Documentation

template<std::size_t NColumns, typename Row >
int cet::sqlite::Connection::flush_no_throw ( std::vector< Row > const &  buffer,
sqlite3_stmt *&  insertStmt 
)

Definition at line 82 of file Connection.h.

84  {
85  // Guard against concurrent updates to the same database.
86  std::lock_guard sentry{*mutex_};
87  sqlite::Transaction txn{db_};
88  for (auto const& r : buffer) {
90  int const rc{sqlite3_step(insertStmt)};
91  if (rc != SQLITE_DONE) {
92  return rc;
93  }
94  sqlite3_reset(insertStmt);
95  }
96  txn.commit();
97  return SQLITE_DONE;
98  }
std::shared_ptr< std::recursive_mutex > mutex_
Definition: Connection.h:66
static void bind(sqlite3_stmt *s, TUP const &t)
sqlite3* cet::sqlite::Connection::get ( ) const
inline

Definition at line 48 of file Connection.h.

49  {
50  return db_;
51  }
cet::sqlite::Connection::operator sqlite3 * ( )
inline

Definition at line 52 of file Connection.h.

52 { return db_; }
Connection& cet::sqlite::Connection::operator= ( Connection const &  )
delete
Connection& cet::sqlite::Connection::operator= ( Connection &&  )
delete

Friends And Related Function Documentation

friend class ConnectionFactory
friend

Definition at line 32 of file Connection.h.

Member Data Documentation

sqlite3* cet::sqlite::Connection::db_ {nullptr}
private

Definition at line 64 of file Connection.h.

std::shared_ptr<std::recursive_mutex> cet::sqlite::Connection::mutex_ {nullptr}
private

Definition at line 66 of file Connection.h.


The documentation for this class was generated from the following files: