mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2025-05-06 17:51:36 +02:00
Added more getters to the query result.
This commit is contained in:
parent
af05bd037c
commit
1ae34a3500
@ -1,5 +1,7 @@
|
|||||||
#include "query_result.h"
|
#include "query_result.h"
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
bool QueryResult::next_row() {
|
bool QueryResult::next_row() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -8,6 +10,33 @@ const char *QueryResult::get_cell(const int index) {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::string QueryResult::get_cell_str(const int index) {
|
||||||
|
return std::string(get_cell(index));
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool QueryResult::get_cell_bool(const int index) {
|
||||||
|
return get_cell_int(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
const 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool QueryResult::is_cell_null(const int index) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
int QueryResult::get_last_insert_rowid() {
|
int QueryResult::get_last_insert_rowid() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,18 @@
|
|||||||
#ifndef QUERY_RESULT_H
|
#ifndef QUERY_RESULT_H
|
||||||
#define QUERY_RESULT_H
|
#define QUERY_RESULT_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
class QueryResult {
|
class QueryResult {
|
||||||
public:
|
public:
|
||||||
virtual bool next_row();
|
virtual bool next_row();
|
||||||
virtual const char *get_cell(const int index);
|
virtual const char *get_cell(const int index);
|
||||||
|
virtual const std::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 bool is_cell_null(const int index);
|
||||||
|
|
||||||
virtual int get_last_insert_rowid();
|
virtual int get_last_insert_rowid();
|
||||||
|
|
||||||
QueryResult();
|
QueryResult();
|
||||||
|
@ -7,7 +7,11 @@ bool Sqlite3QueryResult::next_row() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char *Sqlite3QueryResult::get_cell(const int index) {
|
const char *Sqlite3QueryResult::get_cell(const int index) {
|
||||||
return rows[current_row]->cells[index].c_str();
|
return rows[current_row]->cells[index].data.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Sqlite3QueryResult::is_cell_null(const int index) {
|
||||||
|
return rows[current_row]->cells[index].null;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Sqlite3QueryResult::get_last_insert_rowid() {
|
int Sqlite3QueryResult::get_last_insert_rowid() {
|
||||||
@ -31,12 +35,15 @@ int Sqlite3QueryResult::run_query_finished(void *data, int argc, char **argv, ch
|
|||||||
Sqlite3QueryResultRow *r = new Sqlite3QueryResultRow();
|
Sqlite3QueryResultRow *r = new Sqlite3QueryResultRow();
|
||||||
|
|
||||||
for (int i = 0; i < argc; ++i) {
|
for (int i = 0; i < argc; ++i) {
|
||||||
|
Cell c;
|
||||||
|
|
||||||
if (argv[i]) {
|
if (argv[i]) {
|
||||||
r->cells.push_back(argv[i]);
|
c.data = argv[i];
|
||||||
} else {
|
} else {
|
||||||
//todo mark nulls in cells
|
c.null = true;
|
||||||
r->cells.push_back("NULL");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
r->cells.push_back(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
res->rows.push_back(r);
|
res->rows.push_back(r);
|
||||||
|
@ -12,6 +12,9 @@ class Sqlite3QueryResult : public QueryResult {
|
|||||||
public:
|
public:
|
||||||
bool next_row();
|
bool next_row();
|
||||||
const char* get_cell(const int index);
|
const char* get_cell(const int index);
|
||||||
|
|
||||||
|
bool is_cell_null(const int index);
|
||||||
|
|
||||||
int get_last_insert_rowid();
|
int get_last_insert_rowid();
|
||||||
|
|
||||||
void query(const std::string &query, sqlite3 *conn);
|
void query(const std::string &query, sqlite3 *conn);
|
||||||
@ -24,8 +27,17 @@ public:
|
|||||||
char* err_msg;
|
char* err_msg;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
struct Cell {
|
||||||
|
bool null;
|
||||||
|
std::string data;
|
||||||
|
|
||||||
|
Cell() {
|
||||||
|
null = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
struct Sqlite3QueryResultRow {
|
struct Sqlite3QueryResultRow {
|
||||||
std::vector<std::string> cells;
|
std::vector<Cell> cells;
|
||||||
};
|
};
|
||||||
|
|
||||||
char **col_names;
|
char **col_names;
|
||||||
|
Loading…
Reference in New Issue
Block a user