Cleaned up QueryResult.

This commit is contained in:
Relintai 2022-07-05 20:01:15 +02:00
parent 614129ce2f
commit 5c1a702722
2 changed files with 37 additions and 41 deletions

View File

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

View File

@ -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
#endif