LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
SQLite3Wrapper.h
Go to the documentation of this file.
1 #ifndef art_Framework_IO_Root_RootDB_SQLite3Wrapper_h
2 #define art_Framework_IO_Root_RootDB_SQLite3Wrapper_h
3 
4 // Sentry-like entity to manage the lifetime of an SQL database handle.
5 #include <string>
6 
7 extern "C" {
8 #include "sqlite3.h"
9 }
10 
11 namespace art {
12  class SQLite3Wrapper;
13 }
14 
15 #include "TFile.h"
16 
18 public:
19  SQLite3Wrapper(SQLite3Wrapper const&) = delete;
20  SQLite3Wrapper& operator=(SQLite3Wrapper const&) = delete;
21 
22  typedef int (*callback_t)(void*, int, char**, char**);
23 
24  // A default constructed wrapper is not associated with an SQLite database.
26 
27  // Create a database connected to the file named by 'key';
28  explicit SQLite3Wrapper(std::string const& key,
29  int flags = SQLITE_OPEN_READONLY);
30 
31  SQLite3Wrapper(TFile* tfile,
32  std::string const& key,
33  int flags = SQLITE_OPEN_READWRITE);
34 
35  std::string const&
36  key() const
37  {
38  return key_;
39  }
40 
41  operator sqlite3*() { return db_; }
42 
43  // Query the environment variable ART_DEBUG_SQL to determine whether or
44  // not we should do tracing of SQLite interface calls.
45  static bool wantTracing();
46 
47  void reset();
48 
49  void reset(std::string const& key, int flags = SQLITE_OPEN_READONLY);
50 
51  void reset(TFile* tfile,
52  std::string const& key,
53  int flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_TRANSIENT_DB);
54 
56 
57  void swap(SQLite3Wrapper& other);
58 
59 private:
60  void initDB(int flags, TFile* tfile = 0);
61 
62  void maybeTrace() const;
63 
64  sqlite3* db_;
65  std::string key_;
66 };
67 #endif /* art_Framework_IO_Root_RootDB_SQLite3Wrapper_h */
68 
69 // Local Variables:
70 // mode: c++
71 // End:
int(* callback_t)(void *, int, char **, char **)
void swap(SQLite3Wrapper &other)
static bool wantTracing()
void initDB(int flags, TFile *tfile=0)
SQLite3Wrapper & operator=(SQLite3Wrapper const &)=delete
std::string const & key() const
HLT enums.
void maybeTrace() const