IBR-DTNSuite  0.10
SQLiteConfigure.cpp
Go to the documentation of this file.
1 /*
2  * SQLiteConfigure.cpp
3  *
4  * Copyright (C) 2011 IBR, TU Braunschweig
5  *
6  * Written-by: Johannes Morgenroth <morgenroth@ibr.cs.tu-bs.de>
7  * Written-by: Matthias Myrtus
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  */
23 #include <sqlite3.h>
24 #include <iostream>
26 #include <ibrcommon/Logger.h>
27 
28 namespace dtn
29 {
30  namespace storage
31  {
32  ibrcommon::Mutex SQLiteConfigure::_mutex;
33  bool SQLiteConfigure::_isSet = false;
34 
36  {
37  //Configure SQLite Library
39 
40  if (!_isSet)
41  {
42  int err = sqlite3_config(SQLITE_CONFIG_SERIALIZED);
43 
44  if (err != SQLITE_OK)
45  {
46  IBRCOMMON_LOGGER_TAG("SQLiteConfigure", error) << "SQLite configure failed: " << err << IBRCOMMON_LOGGER_ENDL;
47  throw ibrcommon::Exception("unable to set serialized sqlite configuration");
48  }
49 
50  _isSet = true;
51 
52  // initialize sqlite
53  sqlite3_initialize();
54  }
55  }
56 
58  {
59  sqlite3_shutdown();
60  }
61  }
62 }