From e210e8dc0a11350413db2749e6b79fa27187e540 Mon Sep 17 00:00:00 2001 From: Relintai Date: Wed, 11 Dec 2024 16:34:00 +0100 Subject: [PATCH] Added get_stored_row_count() and get_cell_count() helper methods to QueryResult. --- modules/database/query_result.cpp | 10 ++++++++++ modules/database/query_result.h | 2 ++ modules/database_sqlite/sqlite3_query_result.cpp | 12 ++++++++++++ modules/database_sqlite/sqlite3_query_result.h | 3 +++ 4 files changed, 27 insertions(+) diff --git a/modules/database/query_result.cpp b/modules/database/query_result.cpp index f47a4670d..696e4df8e 100644 --- a/modules/database/query_result.cpp +++ b/modules/database/query_result.cpp @@ -37,6 +37,10 @@ bool QueryResult::next_row() { return false; } +int QueryResult::get_stored_row_count() { + return 0; +} + String QueryResult::get_cell(const int index) { return String(); } @@ -72,6 +76,10 @@ bool QueryResult::is_cell_null(const int index) { return true; } +int QueryResult::get_cell_count() { + return 0; +} + int QueryResult::get_current_cell_index() const { return _current_cell_index; } @@ -115,6 +123,7 @@ QueryResult::~QueryResult() { void QueryResult::_bind_methods() { ClassDB::bind_method(D_METHOD("next_row"), &QueryResult::next_row); + ClassDB::bind_method(D_METHOD("get_stored_row_count"), &QueryResult::get_stored_row_count); ClassDB::bind_method(D_METHOD("get_cell", "index"), &QueryResult::get_cell); ClassDB::bind_method(D_METHOD("get_cell_bool", "index"), &QueryResult::get_cell_bool); @@ -123,6 +132,7 @@ void QueryResult::_bind_methods() { ClassDB::bind_method(D_METHOD("get_cell_double", "index"), &QueryResult::get_cell_double); ClassDB::bind_method(D_METHOD("is_cell_null", "index"), &QueryResult::is_cell_null); + ClassDB::bind_method(D_METHOD("get_cell_count"), &QueryResult::get_cell_count); ClassDB::bind_method(D_METHOD("get_current_cell_index"), &QueryResult::get_current_cell_index); ClassDB::bind_method(D_METHOD("set_current_cell_index", "index"), &QueryResult::set_current_cell_index); diff --git a/modules/database/query_result.h b/modules/database/query_result.h index bf1df3795..4dbdd338c 100644 --- a/modules/database/query_result.h +++ b/modules/database/query_result.h @@ -41,6 +41,7 @@ class QueryResult : public Reference { public: virtual bool next_row(); + virtual int get_stored_row_count(); virtual String get_cell(const int index); virtual bool get_cell_bool(const int index); @@ -49,6 +50,7 @@ public: virtual double get_cell_double(const int index); virtual bool is_cell_null(const int index); + virtual int get_cell_count(); int get_current_cell_index() const; void set_current_cell_index(const int p_index); diff --git a/modules/database_sqlite/sqlite3_query_result.cpp b/modules/database_sqlite/sqlite3_query_result.cpp index 625c4cfaf..7b5aae6d9 100644 --- a/modules/database_sqlite/sqlite3_query_result.cpp +++ b/modules/database_sqlite/sqlite3_query_result.cpp @@ -11,6 +11,10 @@ bool Sqlite3QueryResult::next_row() { return ++current_row < rows.size(); } +int Sqlite3QueryResult::get_stored_row_count() { + return rows.size(); +} + String Sqlite3QueryResult::get_cell(const int index) { return rows[current_row]->cells[index].data; } @@ -19,6 +23,14 @@ bool Sqlite3QueryResult::is_cell_null(const int index) { return rows[current_row]->cells[index].null; } +int Sqlite3QueryResult::get_cell_count() { + if (current_row < 0 || rows.size() >= current_row) { + return 0; + } + + return rows[current_row]->cells.size(); +} + int Sqlite3QueryResult::get_last_insert_rowid() { return sqlite3_last_insert_rowid(_connection); } diff --git a/modules/database_sqlite/sqlite3_query_result.h b/modules/database_sqlite/sqlite3_query_result.h index b31786f37..a08d9e0e6 100644 --- a/modules/database_sqlite/sqlite3_query_result.h +++ b/modules/database_sqlite/sqlite3_query_result.h @@ -13,8 +13,11 @@ class Sqlite3QueryResult : public QueryResult { public: bool next_row(); + int get_stored_row_count(); + String get_cell(const int index); bool is_cell_null(const int index); + int get_cell_count(); int get_last_insert_rowid(); String get_error_message();