From 862186ae7cbbd922057fa5f6b49509c36f9ade36 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Wed, 30 Oct 2024 14:07:01 +0100 Subject: generate dungeon kinda works --- frontend/DB.cpp | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'frontend/DB.cpp') 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(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 index) { return this->col(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) { } + -- cgit v1.2.3