diff options
Diffstat (limited to 'storage.cpp')
-rw-r--r-- | storage.cpp | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/storage.cpp b/storage.cpp index f7f15b1..f7b8b5d 100644 --- a/storage.cpp +++ b/storage.cpp @@ -27,7 +27,9 @@ Storage::Storage(const Config& config): m_stmt_setDocument_new(m_db, "INSERT INTO documents (id, value, rev, cursorpos, timestamp) values (?, ?, ?, ?, ?)"), m_stmt_setRevision(m_db, "UPDATE documents SET rev = ? WHERE id = ?"), m_stmt_setCursorPos(m_db, "UPDATE documents SET cursorpos = ? WHERE id = ?"), - m_stmt_setRow(m_db, "INSERT OR REPLACE INTO documents (id, value, rev, cursorpos, timestamp) values (?, ?, ?, ?, ?)") + m_stmt_setRow(m_db, "INSERT OR REPLACE INTO documents (id, value, rev, cursorpos, timestamp) values (?, ?, ?, ?, ?)"), + m_stmt_getDbSizeGross(m_db, "SELECT page_count * page_size as size FROM pragma_page_count(), pragma_page_size()"), + m_stmt_getDbSizeNet(m_db, "SELECT (page_count - freelist_count) * page_size as size FROM pragma_page_count(), pragma_freelist_count(), pragma_page_size()") { CompiledSQL::Guard g{m_stmt_create}; m_stmt_create.execute(); @@ -46,6 +48,24 @@ uint64_t Storage::getNumberOfDocuments() return m_stmt_getNumberOfDocuments.getColumn<int64_t>(0); } +uint64_t Storage::dbsize_gross() +{ + CompiledSQL::Guard g{m_stmt_getDbSizeGross}; + if (!m_stmt_getDbSizeGross.execute()) + throw std::runtime_error("DB size count (gross) not possible"); + + return m_stmt_getDbSizeGross.getColumn<int64_t>(0); +} + +uint64_t Storage::dbsize_net() +{ + CompiledSQL::Guard g{m_stmt_getDbSizeNet}; + if (!m_stmt_getDbSizeNet.execute()) + throw std::runtime_error("DB size count (net) not possible"); + + return m_stmt_getDbSizeNet.getColumn<int64_t>(0); +} + namespace { uint64_t unixepoch() { @@ -169,7 +189,7 @@ void Storage::setRow(const std::string& id, const std::string& document, int rev throw std::runtime_error("Unable to insert row with id "s + id); } -uint32_t Storage::checksum32(const std::string& s) +uint32_t checksum32(const std::string& s) { uint32_t result{0}; for (unsigned int i = 0; i < s.size(); i++) { |