summaryrefslogtreecommitdiffhomepage
path: root/storage.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'storage.cpp')
-rw-r--r--storage.cpp19
1 files changed, 15 insertions, 4 deletions
diff --git a/storage.cpp b/storage.cpp
index c5caa79..6060caf 100644
--- a/storage.cpp
+++ b/storage.cpp
@@ -30,7 +30,8 @@ Storage::Storage(const Config& config):
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_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()")
+ m_stmt_getDbSizeNet(m_db, "SELECT (page_count - freelist_count) * page_size as size FROM pragma_page_count(), pragma_freelist_count(), pragma_page_size()"),
+ m_stmt_touchDocument(m_db, "UPDATE documents SET timestamp = ? WHERE id = ?")
{
CompiledSQL::Guard g{m_stmt_create};
m_stmt_create.execute();
@@ -154,7 +155,8 @@ void Storage::setDocument(const std::string& id, const std::string& document)
m_stmt_setDocument_new.bind(3, 0);
m_stmt_setDocument_new.bind(4, 0);
m_stmt_setDocument_new.bind(5, static_cast<int64_t>(unixepoch()));
- m_stmt_setDocument_new.execute();
+ if (!m_stmt_setDocument_new.execute())
+ throw std::runtime_error("Unable to create document with id "s + id);
}
}
@@ -165,7 +167,7 @@ void Storage::setRevision(const std::string& id, int rev)
m_stmt_setRevision.bind(2, id);
if (!m_stmt_setRevision.execute())
- throw std::runtime_error("Unable to insert row with id "s + id);
+ throw std::runtime_error("Unable to set revision for id "s + id);
}
void Storage::setCursorPos(const std::string& id, int cursorPos)
@@ -175,7 +177,7 @@ void Storage::setCursorPos(const std::string& id, int cursorPos)
m_stmt_setCursorPos.bind(2, id);
if (!m_stmt_setCursorPos.execute())
- throw std::runtime_error("Unable to insert row with id "s + id);
+ throw std::runtime_error("Unable to set cursor position for id "s + id);
}
void Storage::setRow(const std::string& id, const std::string& document, int rev, int cursorPos)
@@ -222,3 +224,12 @@ std::string Storage::generate_id()
return "endofcodes";
}
+void Storage::touchDocument(const std::string& id)
+{
+ CompiledSQL::Guard g{m_stmt_touchDocument};
+ m_stmt_touchDocument.bind(1, static_cast<int64_t>(unixepoch()));
+ m_stmt_touchDocument.bind(2, id);
+ if (!m_stmt_touchDocument.execute())
+ throw std::runtime_error("Unable to touch document with id "s + id);
+}
+