2020-12-01 21:48:13 +01:00
|
|
|
#ifndef QUERY_BUILDER_H
|
|
|
|
#define QUERY_BUILDER_H
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2021-08-22 20:41:59 +02:00
|
|
|
#include "core/reference.h"
|
|
|
|
|
2021-08-19 14:12:02 +02:00
|
|
|
class QueryResult;
|
|
|
|
|
|
|
|
//methods that start with an e escape their params.
|
|
|
|
|
2021-08-22 20:41:59 +02:00
|
|
|
class QueryBuilder : public Reference {
|
2020-12-01 21:48:13 +01:00
|
|
|
public:
|
2021-08-19 14:12:02 +02:00
|
|
|
virtual QueryBuilder *select();
|
2021-08-20 12:11:27 +02:00
|
|
|
virtual QueryBuilder *udpate();
|
2021-08-20 12:49:57 +02:00
|
|
|
virtual QueryBuilder *del();
|
2021-08-20 12:11:27 +02:00
|
|
|
|
2021-08-20 12:49:57 +02:00
|
|
|
virtual QueryBuilder *where();
|
2021-08-19 14:12:02 +02:00
|
|
|
virtual QueryBuilder *from();
|
|
|
|
virtual QueryBuilder *insert();
|
|
|
|
virtual QueryBuilder *values();
|
|
|
|
virtual QueryBuilder *cvalues();
|
|
|
|
|
2020-12-01 21:48:13 +01:00
|
|
|
virtual QueryBuilder *select(const std::string ¶ms);
|
2021-08-20 12:11:27 +02:00
|
|
|
virtual QueryBuilder *udpate(const std::string ¶ms);
|
2021-08-20 12:49:57 +02:00
|
|
|
virtual QueryBuilder *del(const std::string ¶ms);
|
|
|
|
|
2020-12-01 21:48:13 +01:00
|
|
|
virtual QueryBuilder *where(const std::string ¶ms);
|
|
|
|
virtual QueryBuilder *from(const std::string ¶ms);
|
2021-08-19 14:12:02 +02:00
|
|
|
virtual QueryBuilder *insert(const std::string &table_name);
|
2021-08-20 01:32:43 +02:00
|
|
|
virtual QueryBuilder *insert(const std::string &table_name, const std::string &columns);
|
2021-08-19 14:12:02 +02:00
|
|
|
virtual QueryBuilder *values(const std::string ¶ms_str);
|
2021-08-20 01:32:43 +02:00
|
|
|
virtual QueryBuilder *val();
|
|
|
|
virtual QueryBuilder *val(const std::string ¶m);
|
|
|
|
virtual QueryBuilder *val(const char *param);
|
|
|
|
virtual QueryBuilder *val(const int param);
|
|
|
|
virtual QueryBuilder *val(const bool param);
|
2021-08-19 14:12:02 +02:00
|
|
|
|
2021-08-20 12:11:27 +02:00
|
|
|
virtual QueryBuilder *set();
|
|
|
|
virtual QueryBuilder *cset();
|
|
|
|
|
|
|
|
virtual QueryBuilder *setp(const std::string &col, const std::string ¶m);
|
|
|
|
virtual QueryBuilder *setp(const std::string &col, const char *param);
|
|
|
|
virtual QueryBuilder *setp(const std::string &col, const int param);
|
|
|
|
virtual QueryBuilder *setp(const std::string &col, const bool param);
|
|
|
|
|
2021-08-20 12:49:57 +02:00
|
|
|
virtual QueryBuilder *wp(const std::string &col, const std::string ¶m);
|
|
|
|
virtual QueryBuilder *wp(const std::string &col, const char *param);
|
|
|
|
virtual QueryBuilder *wp(const std::string &col, const int param);
|
|
|
|
virtual QueryBuilder *wp(const std::string &col, const bool param);
|
|
|
|
|
2021-08-19 14:12:02 +02:00
|
|
|
virtual QueryBuilder *eselect(const std::string ¶ms);
|
2021-08-20 12:11:27 +02:00
|
|
|
virtual QueryBuilder *eudpate(const std::string ¶ms);
|
2021-08-20 12:49:57 +02:00
|
|
|
virtual QueryBuilder *edel(const std::string ¶ms);
|
|
|
|
|
2021-08-19 14:12:02 +02:00
|
|
|
virtual QueryBuilder *ewhere(const std::string ¶ms);
|
|
|
|
virtual QueryBuilder *efrom(const std::string ¶ms);
|
|
|
|
virtual QueryBuilder *einsert(const std::string &table_name);
|
|
|
|
virtual QueryBuilder *evalues(const std::string ¶ms_str);
|
2021-08-20 01:32:43 +02:00
|
|
|
virtual QueryBuilder *eval(const std::string ¶m);
|
2021-08-20 12:11:27 +02:00
|
|
|
//note col is NOT escaped
|
2021-08-20 12:49:57 +02:00
|
|
|
virtual QueryBuilder *esetp(const std::string &col, const std::string &escape_param);
|
|
|
|
//note col is NOT escaped
|
|
|
|
virtual QueryBuilder *ewp(const std::string &col, const std::string &escape_param);
|
2021-08-19 14:12:02 +02:00
|
|
|
|
2021-08-19 22:03:22 +02:00
|
|
|
virtual QueryBuilder *limit(const int num);
|
|
|
|
virtual QueryBuilder *offset(const int num);
|
2021-07-08 18:52:59 +02:00
|
|
|
|
2021-08-20 13:14:06 +02:00
|
|
|
//l=logical (and, or are operators)
|
|
|
|
virtual QueryBuilder *land();
|
|
|
|
virtual QueryBuilder *lor();
|
|
|
|
|
2021-08-20 12:11:27 +02:00
|
|
|
virtual QueryBuilder *w(const std::string &str);
|
|
|
|
virtual QueryBuilder *ew(const std::string &str);
|
|
|
|
|
2021-08-20 01:32:43 +02:00
|
|
|
virtual QueryBuilder *select_last_insert_id();
|
|
|
|
|
2021-08-19 14:12:02 +02:00
|
|
|
virtual std::string escape(const std::string ¶ms);
|
|
|
|
|
|
|
|
virtual QueryBuilder *prepare();
|
|
|
|
virtual QueryBuilder *set_param(const int index, const std::string &value);
|
|
|
|
virtual QueryBuilder *set_param(const int index, const int value);
|
|
|
|
virtual QueryBuilder *set_param(const int index, const float value);
|
|
|
|
|
|
|
|
virtual void end_command();
|
|
|
|
|
2021-08-20 12:49:57 +02:00
|
|
|
virtual QueryBuilder *reset();
|
|
|
|
|
2021-08-19 14:12:02 +02:00
|
|
|
virtual QueryResult *run();
|
2021-08-19 22:03:22 +02:00
|
|
|
virtual void run_query();
|
2021-08-19 14:12:02 +02:00
|
|
|
|
|
|
|
std::string get_result();
|
2020-12-01 22:23:28 +01:00
|
|
|
|
2021-08-20 01:32:43 +02:00
|
|
|
void print();
|
|
|
|
|
2020-12-01 21:48:13 +01:00
|
|
|
QueryBuilder();
|
|
|
|
virtual ~QueryBuilder();
|
|
|
|
|
|
|
|
std::string query_result;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|