diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-30 14:07:01 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-30 14:07:01 +0100 |
commit | 862186ae7cbbd922057fa5f6b49509c36f9ade36 (patch) | |
tree | 10193494e1c4bdff793a2daafc2b3359e8794303 /frontend/DB.cpp | |
parent | b1d5d7936bed17a684daff15b0294ef70754e8b9 (diff) |
generate dungeon kinda works
Diffstat (limited to 'frontend/DB.cpp')
-rw-r--r-- | frontend/DB.cpp | 37 |
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) { } + |