Skip to content

Commit

Permalink
Boss/Mod/OnchainFeeMonitor.cpp: Avoid DELETE...ORDER BY, which might …
Browse files Browse the repository at this point in the history
…not be enabled on some SQLITE3 installs.
  • Loading branch information
ZmnSCPxj committed Nov 28, 2020
1 parent c4e7378 commit 91f8f0b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
30 changes: 28 additions & 2 deletions Boss/Mod/OnchainFeeMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include"Sqlite3.hpp"
#include"Stats/RunningMean.hpp"
#include"Util/make_unique.hpp"
#include<vector>

namespace {

Expand Down Expand Up @@ -493,15 +494,40 @@ class OnchainFeeMonitor::Impl {

if (num > num_samples) {
/* We did! Delete old ones. */
tx.query(R"QRY(
DELETE FROM "OnchainFeeMonitor_samples"

/** FIXME: This could have been done with
* `DELETE ... ORDER BY id LIMIT :limit`,
* but not all OSs (presumably FreeBSD or
* MacOS) have a default SQLITE3 with
* `SQLITE_ENABLE_UPDATE_DELETE_LIMIT`
* enabled.
* The real fix is to put SQLITE3 into our
* `external/` dir where we can strictly
* control the flags it gets compiled
* with.
*/
auto ids = std::vector<std::uint64_t>();
auto fetch = tx.query(R"QRY(
SELECT id FROM "OnchainFeeMonitor_samples"
ORDER BY id
LIMIT :limit
;
)QRY")
.bind(":limit", num - num_samples)
.execute()
;
for (auto& r : fetch)
ids.push_back(r.get<std::uint64_t>(0));
for (auto id : ids) {
tx.query(R"QRY(
DELETE FROM "OnchainFeeMonitor_samples"
WHERE id = :id
;
)QRY")
.bind(":id", id)
.execute()
;
}
}
}

Expand Down
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- Avoid `DELETE ... ORDER BY`, which might not be enabled on the SQLITE3 available on some systems.
- Fix a roundoff error with command `id`s.

0.8
Expand Down

0 comments on commit 91f8f0b

Please sign in to comment.