diff --git a/modules/database/query_result.cpp b/modules/database/query_result.cpp index 2519d32f7..1c41e581a 100644 --- a/modules/database/query_result.cpp +++ b/modules/database/query_result.cpp @@ -6,60 +6,39 @@ bool QueryResult::next_row() { return false; } -const char *QueryResult::get_cell(const int index) { +const char *QueryResult::get_cell_chr(const int index) { return ""; } -const String QueryResult::get_cell_str(const int index) { - return String(get_cell(index)); +String QueryResult::get_cell(const int index) { + return String(get_cell_chr(index)); } -const bool QueryResult::get_cell_bool(const int index) { +bool QueryResult::get_cell_bool(const int index) { return get_cell_int(index); } -const int QueryResult::get_cell_int(const int index) { +int QueryResult::get_cell_int(const int index) { if (is_cell_null(index)) { return 0; } - //todo better way - std::stringstream ss; - ss.str(get_cell(index)); - - int r; - ss >> r; - - return r; + return get_cell(index).to_int(); } -const float QueryResult::get_cell_float(const int index) { +float QueryResult::get_cell_float(const int index) { if (is_cell_null(index)) { return 0; } - //todo better way - std::stringstream ss; - ss.str(get_cell(index)); - - float r; - ss >> r; - - return r; + return get_cell(index).to_float(); } -const double QueryResult::get_cell_double(const int index) { +double QueryResult::get_cell_double(const int index) { if (is_cell_null(index)) { return 0; } - //todo better way - std::stringstream ss; - ss.str(get_cell(index)); - - double r; - ss >> r; - - return r; + return get_cell(index).to_double(); } bool QueryResult::is_cell_null(const int index) { @@ -75,3 +54,17 @@ QueryResult::QueryResult() { QueryResult::~QueryResult() { } + +void QueryResult::_bind_methods() { + ClassDB::bind_method(D_METHOD("next_row"), &QueryResult::next_row); + + ClassDB::bind_method(D_METHOD("get_cell", "index"), &QueryResult::get_cell); + ClassDB::bind_method(D_METHOD("get_cell_bool", "index"), &QueryResult::get_cell_bool); + ClassDB::bind_method(D_METHOD("get_cell_int", "index"), &QueryResult::get_cell_int); + ClassDB::bind_method(D_METHOD("get_cell_float", "index"), &QueryResult::get_cell_float); + 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_last_insert_rowid"), &QueryResult::get_last_insert_rowid); +} diff --git a/modules/database/query_result.h b/modules/database/query_result.h index a14424cfb..66de95726 100644 --- a/modules/database/query_result.h +++ b/modules/database/query_result.h @@ -1,28 +1,31 @@ #ifndef QUERY_RESULT_H #define QUERY_RESULT_H -#include "core/string.h" +#include "core/ustring.h" #include "core/reference.h" class QueryResult : public Reference { - RCPP_OBJECT(QueryResult, Reference); + GDCLASS(QueryResult, Reference); public: virtual bool next_row(); - virtual const char *get_cell(const int index); - virtual const String get_cell_str(const int index); - virtual const bool get_cell_bool(const int index); - virtual const int get_cell_int(const int index); - virtual const float get_cell_float(const int index); - virtual const double get_cell_double(const int index); - + virtual const char *get_cell_chr(const int index); + virtual String get_cell(const int index); + virtual bool get_cell_bool(const int index); + virtual int get_cell_int(const int index); + virtual float get_cell_float(const int index); + virtual double get_cell_double(const int index); + virtual bool is_cell_null(const int index); virtual int get_last_insert_rowid(); QueryResult(); virtual ~QueryResult(); + +protected: + static void _bind_methods(); }; -#endif \ No newline at end of file +#endif