summary refs log tree commit diff stats
path: root/lib/database.h
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2017-11-08 14:53:26 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2017-11-08 14:53:26 -0500
commit350bfdb5ea9b4f7e50746c50a46d8032cbc5a104 (patch)
treee339d118669f85de1afb858828a7affd0b47c745 /lib/database.h
parentb92db337bf7cbe2ea0564be6c63c336d2bcd4567 (diff)
downloadverbly-d1.0.tar.gz
verbly-d1.0.tar.bz2
verbly-d1.0.zip
Created database versioning system d1.0
Also added an ANALYZE statement to the end of the datafile generation
process. This generates information that allows sqlite to sometimes come
up with a better query plan, and in many cases can significant speed up
queries. This constitutes a minor database update, but because this is
the first version that uses the database versioning system, older
versions are essentially incompatible.

refs #2
Diffstat (limited to 'lib/database.h')
-rw-r--r--lib/database.h44
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/database.h b/lib/database.h index ef5ff87..efb54e1 100644 --- a/lib/database.h +++ b/lib/database.h
@@ -3,6 +3,7 @@
3 3
4#include <string> 4#include <string>
5#include <exception> 5#include <exception>
6#include <stdexcept>
6#include <list> 7#include <list>
7#include <set> 8#include <set>
8#include "notion.h" 9#include "notion.h"
@@ -45,6 +46,18 @@ namespace verbly {
45 46
46 ~database(); 47 ~database();
47 48
49 // Information
50
51 int getMajorVersion() const
52 {
53 return major_;
54 }
55
56 int getMinorVersion() const
57 {
58 return minor_;
59 }
60
48 // Queries 61 // Queries
49 62
50 query<notion> notions(filter where, order sortOrder = {}, int limit = 1) const; 63 query<notion> notions(filter where, order sortOrder = {}, int limit = 1) const;
@@ -69,6 +82,37 @@ namespace verbly {
69 82
70 sqlite3* ppdb_ = nullptr; 83 sqlite3* ppdb_ = nullptr;
71 84
85 int major_;
86 int minor_;
87
88 };
89
90 class database_version_mismatch : public std::logic_error {
91 public:
92
93 database_version_mismatch(int right, int wrong) :
94 std::logic_error(generateMessage(right, wrong)),
95 right_(right),
96 wrong_(wrong)
97 {
98 }
99
100 int getRightVersion() const noexcept
101 {
102 return right_;
103 }
104
105 int getWrongVersion() const noexcept
106 {
107 return wrong_;
108 }
109
110 private:
111
112 static std::string generateMessage(int right, int wrong);
113
114 int right_;
115 int wrong_;
72 }; 116 };
73 117
74}; 118};