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

#include <Transaction.h>

Public Member Functions

 Transaction (sqlite3 *db) noexcept(false)
 
 ~Transaction () noexcept
 
void commit () noexcept(false)
 
 Transaction (Transaction const &)=delete
 
 Transaction (Transaction &&)=delete
 
Transactionoperator= (Transaction const &)=delete
 
Transactionoperator= (Transaction &&)=delete
 

Private Attributes

sqlite3db_
 

Detailed Description

Definition at line 24 of file Transaction.h.

Constructor & Destructor Documentation

cet::sqlite::Transaction::Transaction ( sqlite3 db)
explicitnoexcept

Definition at line 20 of file Transaction.cc.

20  : db_{db}
21 {
22  assert(db_);
23  int const rc{sqlite3_exec(db_, "BEGIN;", nullptr, nullptr, nullptr)};
24  if (rc != SQLITE_OK) {
26  << "Failed to start SQLite transaction due to status code " << rc << ":\n"
27  << sqlite3_errmsg(db_) << '\n';
28  }
29 }
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:27
cet::sqlite::Transaction::~Transaction ( )
noexcept

Definition at line 31 of file Transaction.cc.

32 {
33  // We can't throw an exception from our destructor, so we just emit
34  // an error message.
35  if (db_) {
36  sqlite3_exec(db_, "ROLLBACK;", nullptr, nullptr, nullptr);
37  std::cerr << "Transaction d'tor called before commit was called.\n";
38  }
39 }
cet::sqlite::Transaction::Transaction ( Transaction const &  )
delete
cet::sqlite::Transaction::Transaction ( Transaction &&  )
delete

Member Function Documentation

void cet::sqlite::Transaction::commit ( )
noexcept

Definition at line 42 of file Transaction.cc.

43 {
44  assert(db_);
45  set_to_null_when_done sentry{db_};
46  int const rc{sqlite3_exec(db_, "COMMIT;", nullptr, nullptr, nullptr)};
47  if (rc != SQLITE_OK) {
49  << "Failed to commit SQLite transaction due to status code " << rc
50  << ":\n"
51  << sqlite3_errmsg(db_) << '\n';
52  }
53 }
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:27
Transaction& cet::sqlite::Transaction::operator= ( Transaction const &  )
delete
Transaction& cet::sqlite::Transaction::operator= ( Transaction &&  )
delete

Member Data Documentation

sqlite3* cet::sqlite::Transaction::db_
private

Definition at line 38 of file Transaction.h.


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