about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2023-02-16 22:35:14 -0500
committerStar Rauchenberger <fefferburbia@gmail.com>2023-02-16 22:35:14 -0500
commitade8cc43b138fb776c16fe2b4de18c92e148c9c7 (patch)
tree6a495360d0ea7572214b186c83a5df4e3d8ada55
parentfdddefbbbb8f3c0bd223280c74fa7e05bfdc3521 (diff)
downloadhkutil-ade8cc43b138fb776c16fe2b4de18c92e148c9c7.tar.gz
hkutil-ade8cc43b138fb776c16fe2b4de18c92e148c9c7.tar.bz2
hkutil-ade8cc43b138fb776c16fe2b4de18c92e148c9c7.zip
Added query timeout
-rw-r--r--hkutil/database.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/hkutil/database.h b/hkutil/database.h index f4e7a9a..7425756 100644 --- a/hkutil/database.h +++ b/hkutil/database.h
@@ -194,6 +194,11 @@ namespace hatkirby {
194 std::string queryString, 194 std::string queryString,
195 std::list<binding> bindings = {}) 195 std::list<binding> bindings = {})
196 { 196 {
197 if (timeout_ > 0)
198 {
199 deadline_ = static_cast<long long>(std::time(nullptr)) + timeout_;
200 }
201
197 sqlite3_stmt* tempStmt; 202 sqlite3_stmt* tempStmt;
198 203
199 int ret = sqlite3_prepare_v2( 204 int ret = sqlite3_prepare_v2(
@@ -310,6 +315,22 @@ namespace hatkirby {
310 return result; 315 return result;
311 } 316 }
312 317
318 void setTimeout(int seconds)
319 {
320 timeout_ = seconds;
321 if (timeout_ > 0)
322 {
323 sqlite3_progress_handler(ppdb_.get(), 1000, [](void* db){
324 if (static_cast<long long>(std::time(nullptr)) > static_cast<database*>(db)->deadline_) {
325 return 1;
326 }
327 return 0;
328 }, this);
329 } else {
330 sqlite3_progress_handler(ppdb_.get(), 0, nullptr, nullptr);
331 }
332 }
333
313 private: 334 private:
314 335
315 class sqlite3_deleter { 336 class sqlite3_deleter {
@@ -392,6 +413,8 @@ namespace hatkirby {
392 } 413 }
393 414
394 ppdb_type ppdb_; 415 ppdb_type ppdb_;
416 long long timeout_ = -1;
417 long long deadline_ = 0;
395 418
396 }; 419 };
397 420