LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
art::SQLite3Wrapper Class Reference

#include "SQLite3Wrapper.h"

Public Types

typedef int(* callback_t) (void *, int, char **, char **)
 

Public Member Functions

 SQLite3Wrapper (SQLite3Wrapper const &)=delete
 
SQLite3Wrapperoperator= (SQLite3Wrapper const &)=delete
 
 SQLite3Wrapper ()
 
 SQLite3Wrapper (std::string const &key, int flags=SQLITE_OPEN_READONLY)
 
 SQLite3Wrapper (TFile *tfile, std::string const &key, int flags=SQLITE_OPEN_READWRITE)
 
std::string const & key () const
 
 operator sqlite3 * ()
 
void reset ()
 
void reset (std::string const &key, int flags=SQLITE_OPEN_READONLY)
 
void reset (TFile *tfile, std::string const &key, int flags=SQLITE_OPEN_READWRITE|SQLITE_OPEN_TRANSIENT_DB)
 
 ~SQLite3Wrapper ()
 
void swap (SQLite3Wrapper &other)
 

Static Public Member Functions

static bool wantTracing ()
 

Private Member Functions

void initDB (int flags, TFile *tfile=0)
 
void maybeTrace () const
 

Private Attributes

sqlite3 * db_
 
std::string key_
 

Detailed Description

Definition at line 17 of file SQLite3Wrapper.h.

Member Typedef Documentation

typedef int(* art::SQLite3Wrapper::callback_t) (void *, int, char **, char **)

Definition at line 22 of file SQLite3Wrapper.h.

Constructor & Destructor Documentation

art::SQLite3Wrapper::SQLite3Wrapper ( SQLite3Wrapper const &  )
delete
art::SQLite3Wrapper::SQLite3Wrapper ( )

Definition at line 49 of file SQLite3Wrapper.cc.

49 : db_(0), key_() {}
art::SQLite3Wrapper::SQLite3Wrapper ( std::string const &  key,
int  flags = SQLITE_OPEN_READONLY 
)
explicit

Definition at line 51 of file SQLite3Wrapper.cc.

References initDB().

52  : db_(0), key_(key)
53 {
54  initDB(flags);
55 }
void initDB(int flags, TFile *tfile=0)
std::string const & key() const
art::SQLite3Wrapper::SQLite3Wrapper ( TFile *  tfile,
std::string const &  key,
int  flags = SQLITE_OPEN_READWRITE 
)

Definition at line 57 of file SQLite3Wrapper.cc.

References initDB().

60  : db_(0), key_(key)
61 {
62  initDB(flags, tfile);
63 }
void initDB(int flags, TFile *tfile=0)
std::string const & key() const
art::SQLite3Wrapper::~SQLite3Wrapper ( )

Definition at line 93 of file SQLite3Wrapper.cc.

References db_.

Referenced by operator sqlite3 *().

94 {
95  if (db_) {
96  sqlite3_close(db_);
97  }
98 }

Member Function Documentation

void art::SQLite3Wrapper::initDB ( int  flags,
TFile *  tfile = 0 
)
private

Definition at line 109 of file SQLite3Wrapper.cc.

References db_, art::errors::FileOpenError, key_, maybeTrace(), and tkeyvfs_open_v2().

Referenced by operator sqlite3 *(), and SQLite3Wrapper().

110 {
111  int err = 0;
112  DBTYPE type = tfile ? SQLITE3_TKEYDB :
113  key_.size() ?
114  (key_ == ":memory:" ? SQLITE3_MEMDB : SQLITE3_FILEDB) :
115  SQLITE3_TMPDB;
116  switch (type) {
117  case SQLITE3_TKEYDB:
118  if (!key_.size()) {
120  << "Failed to open TKEYVFS DB due to empty key spec.\n";
121  }
122  err = tkeyvfs_open_v2(key_.c_str(), &db_, flags, tfile);
123  break;
124  case SQLITE3_MEMDB:
125  err = sqlite3_open(key_.c_str(), &db_);
126  break;
127  case SQLITE3_FILEDB:
128  err = sqlite3_open_v2(key_.c_str(), &db_, flags, nullptr);
129  break;
130  case SQLITE3_TMPDB:
131  err = sqlite3_open(key_.c_str(), &db_);
132  break;
133  }
134  if (err) {
136  << "Failed to open requested DB, \"" << key_ << "\" of type, \""
137  << dbTypeAsString(type) << "\" -- " << sqlite3_errmsg(db_) << "\n";
138  }
139  maybeTrace();
140 }
DBTYPE
int tkeyvfs_open_v2(const char *filename, sqlite3 **ppDb, int flags, TFile *rootFile )
Definition: tkeyvfs.cc:1837
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
void maybeTrace() const
std::string const& art::SQLite3Wrapper::key ( ) const
inline

Definition at line 36 of file SQLite3Wrapper.h.

References key_.

Referenced by operator sqlite3 *(), and reset().

37  {
38  return key_;
39  }
void art::SQLite3Wrapper::maybeTrace ( ) const
private

Definition at line 143 of file SQLite3Wrapper.cc.

References db_, key_, and wantTracing().

Referenced by initDB(), and operator sqlite3 *().

144 {
145  if (wantTracing()) {
146  // Cast away constness for C interface.
147  sqlite3_trace(db_, traceit, const_cast<std::string*>(&key_));
148  }
149 }
static bool wantTracing()
art::SQLite3Wrapper::operator sqlite3 * ( )
inline

Definition at line 41 of file SQLite3Wrapper.h.

References db_, initDB(), key(), maybeTrace(), fhicl::other, reset(), swap(), wantTracing(), and ~SQLite3Wrapper().

41 { return db_; }
SQLite3Wrapper& art::SQLite3Wrapper::operator= ( SQLite3Wrapper const &  )
delete
void art::SQLite3Wrapper::reset ( void  )

Definition at line 73 of file SQLite3Wrapper.cc.

References swap(), and tmp.

Referenced by operator sqlite3 *().

74 {
76  swap(tmp);
77 }
void swap(SQLite3Wrapper &other)
Float_t tmp
Definition: plot.C:37
void art::SQLite3Wrapper::reset ( std::string const &  key,
int  flags = SQLITE_OPEN_READONLY 
)

Definition at line 80 of file SQLite3Wrapper.cc.

References key(), swap(), and tmp.

81 {
82  SQLite3Wrapper tmp{key, flags};
83  swap(tmp);
84 }
void swap(SQLite3Wrapper &other)
Float_t tmp
Definition: plot.C:37
std::string const & key() const
void art::SQLite3Wrapper::reset ( TFile *  tfile,
std::string const &  key,
int  flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_TRANSIENT_DB 
)

Definition at line 87 of file SQLite3Wrapper.cc.

References key(), swap(), and tmp.

88 {
89  SQLite3Wrapper tmp{tfile, key, flags};
90  swap(tmp);
91 }
void swap(SQLite3Wrapper &other)
Float_t tmp
Definition: plot.C:37
std::string const & key() const
void art::SQLite3Wrapper::swap ( SQLite3Wrapper other)

Definition at line 101 of file SQLite3Wrapper.cc.

References db_, and key_.

Referenced by operator sqlite3 *(), and reset().

102 {
103  using std::swap;
104  swap(db_, other.db_);
105  swap(key_, other.key_);
106 }
void swap(SQLite3Wrapper &other)
void swap(art::HLTGlobalStatus &lhs, art::HLTGlobalStatus &rhs)
bool art::SQLite3Wrapper::wantTracing ( )
static

Definition at line 66 of file SQLite3Wrapper.cc.

Referenced by maybeTrace(), and operator sqlite3 *().

67 {
68  static char const* s_debug = getenv("ART_DEBUG_SQL");
69  return s_debug;
70 }

Member Data Documentation

sqlite3* art::SQLite3Wrapper::db_
private

Definition at line 64 of file SQLite3Wrapper.h.

Referenced by initDB(), maybeTrace(), operator sqlite3 *(), swap(), and ~SQLite3Wrapper().

std::string art::SQLite3Wrapper::key_
private

Definition at line 65 of file SQLite3Wrapper.h.

Referenced by initDB(), key(), maybeTrace(), and swap().


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