@@ -88,6 +88,7 @@ namespace Plugin {
88
88
, _maxValue(maxValue)
89
89
, _limit(limit)
90
90
{
91
+ IntegrityCheck ();
91
92
Open ();
92
93
}
93
94
~Store2 () override
@@ -96,6 +97,28 @@ namespace Plugin {
96
97
}
97
98
98
99
private:
100
+ void IntegrityCheck ()
101
+ {
102
+ Core::File file (_path);
103
+ Core::Directory (file.PathName ().c_str ()).CreatePath ();
104
+ auto rc = sqlite3_open (_path.c_str (), &_data);
105
+ sqlite3_stmt* stmt;
106
+ sqlite3_prepare_v2 (_data, " pragma integrity_check;" ,
107
+ -1 , &stmt, nullptr );
108
+ while ((rc = sqlite3_step (stmt)) == SQLITE_ROW) {
109
+ TRACE (Trace::Information,
110
+ (_T (" %s %s" ), __FUNCTION__,
111
+ (const char *)sqlite3_column_text (stmt, 0 )));
112
+ }
113
+ sqlite3_finalize (stmt);
114
+ sqlite3_close_v2 (_data);
115
+ if (rc != SQLITE_DONE) {
116
+ OnError (__FUNCTION__, rc);
117
+ if ((rc == SQLITE_MISUSE) || (rc == SQLITE_CORRUPT)) {
118
+ ASSERT (file.Destroy ());
119
+ }
120
+ }
121
+ }
99
122
void Open ()
100
123
{
101
124
Core::File file (_path);
@@ -150,12 +173,13 @@ namespace Plugin {
150
173
+ std::to_string (_maxSize) + " then raise (fail, 'max size') end; end;" ,
151
174
" create temporary trigger if not exists item_limit_default insert on item"
152
175
" begin select case when"
153
- " (select length(new.key)+length(new.value)+sum(length(key)+length(value)) from item where ns = new.ns) > "
176
+ " (select sum(s) from (select sum(length(key)+length(value)) s from item where ns = new.ns"
177
+ " union all select length(new.key)+length(new.value) s)) > "
154
178
+ std::to_string (_limit) + " then raise (fail, 'limit') end; end;" ,
155
179
" create temporary trigger if not exists item_limit insert on item"
156
180
" begin select case when"
157
- " (select size-length(new.key)-length(new.value)-sum(length(key)+length(value)) from limits"
158
- " inner join item on limits.n = item.ns where n = new.ns) < 0"
181
+ " (select size-length(new.key)-length(new.value)-ifnull( sum(length(key)+length(value)), 0 ) from limits"
182
+ " left join item on limits.n = item.ns where n = new.ns) < 0"
159
183
" then raise (fail, 'limit') end; end;"
160
184
};
161
185
for (auto & sql : statements) {
@@ -172,6 +196,8 @@ namespace Plugin {
172
196
OnError (__FUNCTION__, rc);
173
197
}
174
198
}
199
+
200
+ private:
175
201
bool IsTimeSynced () const
176
202
{
177
203
#ifdef WITH_SYSMGR
0 commit comments