2020-12-01 21:48:13 +01:00
|
|
|
#ifndef QUERY_BUILDER_H
|
|
|
|
#define QUERY_BUILDER_H
|
|
|
|
|
2021-11-01 17:31:04 +01:00
|
|
|
#include "core/string.h"
|
2020-12-01 21:48:13 +01:00
|
|
|
|
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-11-01 17:00:55 +01:00
|
|
|
virtual QueryBuilder *update();
|
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();
|
2021-11-14 19:22:49 +01:00
|
|
|
virtual QueryBuilder *next_value();
|
|
|
|
|
|
|
|
virtual QueryBuilder *begin_transaction();
|
|
|
|
virtual QueryBuilder *commit();
|
|
|
|
|
|
|
|
virtual QueryBuilder *nl();
|
2021-08-19 14:12:02 +02:00
|
|
|
|
2021-08-22 21:44:20 +02:00
|
|
|
virtual QueryBuilder *str();
|
|
|
|
virtual QueryBuilder *cstr();
|
|
|
|
|
|
|
|
virtual QueryBuilder *like();
|
|
|
|
|
2021-11-01 17:31:04 +01:00
|
|
|
virtual QueryBuilder *select(const String ¶ms);
|
|
|
|
virtual QueryBuilder *update(const String ¶ms);
|
|
|
|
virtual QueryBuilder *del(const String ¶ms);
|
2021-08-20 12:49:57 +02:00
|
|
|
|
2021-11-01 17:31:04 +01:00
|
|
|
virtual QueryBuilder *where(const String ¶ms);
|
|
|
|
virtual QueryBuilder *from(const String ¶ms);
|
|
|
|
virtual QueryBuilder *insert(const String &table_name);
|
|
|
|
virtual QueryBuilder *insert(const String &table_name, const String &columns);
|
|
|
|
virtual QueryBuilder *values(const String ¶ms_str);
|
2021-08-20 01:32:43 +02:00
|
|
|
virtual QueryBuilder *val();
|
2021-11-01 17:31:04 +01:00
|
|
|
virtual QueryBuilder *val(const String ¶m);
|
2021-08-20 01:32:43 +02:00
|
|
|
virtual QueryBuilder *val(const char *param);
|
|
|
|
virtual QueryBuilder *val(const int param);
|
|
|
|
virtual QueryBuilder *val(const bool param);
|
2021-11-14 21:05:08 +01:00
|
|
|
virtual QueryBuilder *valf(const float param);
|
|
|
|
virtual QueryBuilder *vald(const double param);
|
2021-08-19 14:12:02 +02:00
|
|
|
|
2021-11-01 17:31:04 +01:00
|
|
|
virtual QueryBuilder *like(const String &str);
|
2021-08-22 21:44:20 +02:00
|
|
|
|
2021-08-20 12:11:27 +02:00
|
|
|
virtual QueryBuilder *set();
|
|
|
|
virtual QueryBuilder *cset();
|
|
|
|
|
2021-11-01 17:31:04 +01:00
|
|
|
virtual QueryBuilder *setp(const String &col, const String ¶m);
|
|
|
|
virtual QueryBuilder *setp(const String &col, const char *param);
|
|
|
|
virtual QueryBuilder *setp(const String &col, const int param);
|
|
|
|
virtual QueryBuilder *setp(const String &col, const bool param);
|
2021-11-14 21:05:08 +01:00
|
|
|
virtual QueryBuilder *setpf(const String &col, const float param);
|
|
|
|
virtual QueryBuilder *setpd(const String &col, const double param);
|
2021-11-01 17:31:04 +01:00
|
|
|
|
|
|
|
virtual QueryBuilder *wp(const String &col, const String ¶m);
|
|
|
|
virtual QueryBuilder *wp(const String &col, const char *param);
|
|
|
|
virtual QueryBuilder *wp(const String &col, const int param);
|
|
|
|
virtual QueryBuilder *wp(const String &col, const bool param);
|
|
|
|
|
|
|
|
virtual QueryBuilder *nselect(const String ¶ms);
|
|
|
|
virtual QueryBuilder *nupdate(const String ¶ms);
|
|
|
|
virtual QueryBuilder *ndel(const String ¶ms);
|
|
|
|
|
|
|
|
virtual QueryBuilder *nwhere(const String ¶ms);
|
|
|
|
virtual QueryBuilder *nfrom(const String ¶ms);
|
|
|
|
virtual QueryBuilder *nlike(const String &str);
|
|
|
|
virtual QueryBuilder *nvalues(const String ¶ms_str);
|
|
|
|
virtual QueryBuilder *nval(const String ¶m);
|
2021-08-20 12:11:27 +02:00
|
|
|
//note col is NOT escaped
|
2021-11-01 17:31:04 +01:00
|
|
|
virtual QueryBuilder *nsetp(const String &col, const String &escape_param);
|
2021-08-20 12:49:57 +02:00
|
|
|
//note col is NOT escaped
|
2021-11-01 17:31:04 +01:00
|
|
|
virtual QueryBuilder *nwp(const String &col, const 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-22 21:44:20 +02:00
|
|
|
virtual QueryBuilder *wildcard();
|
|
|
|
|
2021-11-01 17:31:04 +01:00
|
|
|
virtual QueryBuilder *w(const String &str);
|
|
|
|
virtual QueryBuilder *ew(const String &str);
|
2021-08-20 12:11:27 +02:00
|
|
|
|
2021-08-20 01:32:43 +02:00
|
|
|
virtual QueryBuilder *select_last_insert_id();
|
|
|
|
|
2021-11-01 17:31:04 +01:00
|
|
|
virtual String escape(const String ¶ms);
|
2021-08-19 14:12:02 +02:00
|
|
|
|
|
|
|
virtual QueryBuilder *prepare();
|
2021-11-01 17:31:04 +01:00
|
|
|
virtual QueryBuilder *set_param(const int index, const String &value);
|
2021-08-19 14:12:02 +02:00
|
|
|
virtual QueryBuilder *set_param(const int index, const int value);
|
|
|
|
virtual QueryBuilder *set_param(const int index, const float value);
|
|
|
|
|
2021-11-14 19:22:49 +01:00
|
|
|
virtual QueryBuilder *end_command();
|
2021-08-19 14:12:02 +02:00
|
|
|
|
2021-08-20 12:49:57 +02:00
|
|
|
virtual QueryBuilder *reset();
|
|
|
|
|
2021-11-01 16:57:22 +01:00
|
|
|
virtual Ref<QueryResult> run();
|
2021-08-19 22:03:22 +02:00
|
|
|
virtual void run_query();
|
2021-08-19 14:12:02 +02:00
|
|
|
|
2021-11-01 17:31:04 +01:00
|
|
|
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();
|
|
|
|
|
2021-11-01 17:31:04 +01:00
|
|
|
String query_result;
|
2020-12-01 21:48:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|