Added get_stored_row_count() and get_cell_count() helper methods to QueryResult.

This commit is contained in:
Relintai 2024-12-11 16:34:00 +01:00
parent 9e93b4426a
commit e210e8dc0a
4 changed files with 27 additions and 0 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);
}

View File

@ -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();