Added get_cell_float and get_cell_double helpers to QueryResult.

This commit is contained in:
Relintai 2021-11-14 21:04:48 +01:00
parent 1bd90ceb4a
commit 4393c60e5f
4 changed files with 72 additions and 0 deletions

View File

@ -33,6 +33,35 @@ const int QueryResult::get_cell_int(const int index) {
return r;
}
const 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;
}
const 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;
}
bool QueryResult::is_cell_null(const int index) {
return true;
}

View File

@ -12,6 +12,8 @@ public:
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 bool is_cell_null(const int index);

View File

@ -162,6 +162,25 @@ QueryBuilder *SQLite3QueryBuilder::val(const bool param) {
return this;
}
QueryBuilder *SQLite3QueryBuilder::valf(const float param) {
//todo add a better way
std::stringstream ss;
ss << param;
query_result += ss.str() + ", ";
return this;
}
QueryBuilder *SQLite3QueryBuilder::vald(const double param) {
//todo add a better way
std::stringstream ss;
ss << param;
query_result += ss.str() + ", ";
return this;
}
QueryBuilder *SQLite3QueryBuilder::nlike(const String &str) {
query_result += "LIKE '" + str + "' ";
@ -205,6 +224,24 @@ QueryBuilder *SQLite3QueryBuilder::setp(const String &col, const bool param) {
return this;
}
QueryBuilder *SQLite3QueryBuilder::setpf(const String &col, const float param) {
//todo add a better way
std::stringstream ss;
ss << param;
query_result += col + "=" + ss.str() + ", ";
return this;
}
QueryBuilder *SQLite3QueryBuilder::setpd(const String &col, const double param) {
//todo add a better way
std::stringstream ss;
ss << param;
query_result += col + "=" + ss.str() + ", ";
return this;
}
QueryBuilder *SQLite3QueryBuilder::nwp(const String &col, const String &param) {
query_result += col + "='" + param + "' ";

View File

@ -43,6 +43,8 @@ public:
QueryBuilder *val(const char *param);
QueryBuilder *val(const int param);
QueryBuilder *val(const bool param);
QueryBuilder *valf(const float param);
QueryBuilder *vald(const double param);
QueryBuilder *nlike(const String &str);
@ -52,6 +54,8 @@ public:
QueryBuilder *setp(const String &col, const char *param);
QueryBuilder *setp(const String &col, const int param);
QueryBuilder *setp(const String &col, const bool param);
QueryBuilder *setpf(const String &col, const float param);
QueryBuilder *setpd(const String &col, const double param);
QueryBuilder *nwp(const String &col, const String &param);
QueryBuilder *wp(const String &col, const char *param);