aboutsummaryrefslogtreecommitdiff
path: root/frontend/DB.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/DB.cpp')
-rw-r--r--frontend/DB.cpp37
1 files changed, 36 insertions, 1 deletions
diff --git a/frontend/DB.cpp b/frontend/DB.cpp
index d4527b8..d51315b 100644
--- a/frontend/DB.cpp
+++ b/frontend/DB.cpp
@@ -75,7 +75,6 @@ DBQueryRow DBStatement::row() {
DBQueryRow::DBQueryRow(DBStatement & parent) : parent(parent) { }
-
template <>
const char * DBQueryRow::col<const char*>(int index, const char * const & default_value) {
int type = sqlite3_column_type(this->parent.stmt.get(), index);
@@ -98,3 +97,39 @@ int DBQueryRow::col<int>(int index) {
return this->col<int>(index, 0);
}
+DBQueryRowRange DBStatement::rows() {
+ return { *this };
+}
+
+DBQueryRowRange::DBQueryRowIterator & DBQueryRowRange::DBQueryRowIterator::operator ++ () {
+ int ret = sqlite3_step(this->parent.parent.stmt.get());
+ if (ret == SQLITE_DONE) {
+ this->end = true;
+ return *this;
+ }
+ if (ret != SQLITE_ROW)
+ throw Exception("sqlite3_step: %d", ret);
+ return *this;
+}
+
+bool DBQueryRowRange::DBQueryRowIterator::operator != (const DBQueryRowIterator &) const {
+ return !this->end;
+}
+
+DBQueryRow & DBQueryRowRange::DBQueryRowIterator::operator * () const {
+ return this->parent.row;
+}
+
+DBQueryRowRange::DBQueryRowIterator DBQueryRowRange::begin() {
+ DBQueryRowRange::DBQueryRowIterator it = { *this };
+ return ++it;
+}
+
+DBQueryRowRange::DBQueryRowIterator DBQueryRowRange::end() {
+ return { *this };
+}
+
+DBQueryRowRange::DBQueryRowRange(DBStatement & parent) : parent(parent), row(parent) { }
+
+DBQueryRowRange::DBQueryRowIterator::DBQueryRowIterator(DBQueryRowRange & parent) : parent(parent) { }
+