Work on cleaning up QueryBuilder.

This commit is contained in:
Relintai 2022-07-05 20:34:12 +02:00
parent 5c1a702722
commit f9bbf772ca
2 changed files with 399 additions and 44 deletions

View File

@ -13,7 +13,6 @@ QueryBuilder *QueryBuilder::del() {
}
QueryBuilder *QueryBuilder::where() {
return this;
}
QueryBuilder *QueryBuilder::from() {
@ -73,9 +72,6 @@ QueryBuilder *QueryBuilder::from(const String &params) {
return nfrom(escape(params));
}
QueryBuilder *QueryBuilder::insert(const String &table_name) {
return this;
}
QueryBuilder *QueryBuilder::insert(const String &table_name, const String &columns) {
return this;
}
@ -87,18 +83,18 @@ QueryBuilder *QueryBuilder::val() {
return this;
}
QueryBuilder *QueryBuilder::val(const String &param) {
QueryBuilder *QueryBuilder::vals(const String &param) {
return nval(escape(param));
}
QueryBuilder *QueryBuilder::val(const char *param) {
QueryBuilder *QueryBuilder::vals(const char *param) {
return this;
}
QueryBuilder *QueryBuilder::val(const int param) {
QueryBuilder *QueryBuilder::vali(const int param) {
return this;
}
QueryBuilder *QueryBuilder::val(const bool param) {
QueryBuilder *QueryBuilder::valb(const bool param) {
return this;
}
@ -119,16 +115,16 @@ QueryBuilder *QueryBuilder::set() {
QueryBuilder *QueryBuilder::cset() {
return this;
}
QueryBuilder *QueryBuilder::setp(const String &col, const String &param) {
QueryBuilder *QueryBuilder::setps(const String &col, const String &param) {
return nsetp(col, escape(param));
}
QueryBuilder *QueryBuilder::setp(const String &col, const char *param) {
QueryBuilder *QueryBuilder::setps(const String &col, const char *param) {
return this;
}
QueryBuilder *QueryBuilder::setp(const String &col, const int param) {
QueryBuilder *QueryBuilder::setpi(const String &col, const int param) {
return this;
}
QueryBuilder *QueryBuilder::setp(const String &col, const bool param) {
QueryBuilder *QueryBuilder::setpb(const String &col, const bool param) {
return this;
}
QueryBuilder *QueryBuilder::setpf(const String &col, const float param) {
@ -138,16 +134,16 @@ QueryBuilder *QueryBuilder::setpd(const String &col, const double param) {
return this;
}
QueryBuilder *QueryBuilder::wp(const String &col, const String &param) {
QueryBuilder *QueryBuilder::wps(const String &col, const String &param) {
return nwp(col, escape(param));
}
QueryBuilder *QueryBuilder::wp(const String &col, const char *param) {
QueryBuilder *QueryBuilder::wps(const String &col, const char *param) {
return this;
}
QueryBuilder *QueryBuilder::wp(const String &col, const int param) {
QueryBuilder *QueryBuilder::wpi(const String &col, const int param) {
return this;
}
QueryBuilder *QueryBuilder::wp(const String &col, const bool param) {
QueryBuilder *QueryBuilder::wpb(const String &col, const bool param) {
return this;
}
@ -175,10 +171,10 @@ QueryBuilder *QueryBuilder::nvalues(const String &params_str) {
}
QueryBuilder *QueryBuilder::nval(const String &param) {
return val(escape(param));
return vals(escape(param));
}
QueryBuilder *QueryBuilder::nsetp(const String &col, const String &escape_param) {
return setp(col, escape(escape_param));
return setps(col, escape(escape_param));
}
QueryBuilder *QueryBuilder::nwp(const String &col, const String &escape_param) {
@ -276,13 +272,13 @@ String QueryBuilder::escape(const String &params) {
QueryBuilder *QueryBuilder::prepare() {
return this;
}
QueryBuilder *QueryBuilder::set_param(const int index, const String &value) {
QueryBuilder *QueryBuilder::set_params(const int index, const String &value) {
return this;
}
QueryBuilder *QueryBuilder::set_param(const int index, const int value) {
QueryBuilder *QueryBuilder::set_parami(const int index, const int value) {
return this;
}
QueryBuilder *QueryBuilder::set_param(const int index, const float value) {
QueryBuilder *QueryBuilder::set_paramf(const int index, const float value) {
return this;
}
@ -310,7 +306,8 @@ String QueryBuilder::get_result() {
}
void QueryBuilder::print() {
printf("%s\n", query_result.c_str());
//printf("%s\n", query_result.c_str());
ERR_PRINT(query_result);
}
QueryBuilder::QueryBuilder() {
@ -318,3 +315,257 @@ QueryBuilder::QueryBuilder() {
QueryBuilder::~QueryBuilder() {
}
void QueryBuilder::_bind_methods() {
ClassDB::bind_method(D_METHOD("next_row"), &QueryResult::next_row);
}
Ref<QueryBuilder> QueryBuilder::_select_bind() {
return Ref<QueryBuilder>(select());
}
Ref<QueryBuilder> QueryBuilder::_update_bind() {
return Ref<QueryBuilder>(update());
}
Ref<QueryBuilder> QueryBuilder::_del_bind() {
return Ref<QueryBuilder>(del());
}
Ref<QueryBuilder> QueryBuilder::_where_bind() {
return Ref<QueryBuilder>(where());
}
Ref<QueryBuilder> QueryBuilder::_from_bind() {
return Ref<QueryBuilder>(from());
}
Ref<QueryBuilder> QueryBuilder::_insert_bind() {
return Ref<QueryBuilder>(insert());
}
Ref<QueryBuilder> QueryBuilder::_values_bind() {
return Ref<QueryBuilder>(values());
}
Ref<QueryBuilder> QueryBuilder::_cvalues_bind() {
return Ref<QueryBuilder>(cvalues());
}
Ref<QueryBuilder> QueryBuilder::_next_value_bind() {
return Ref<QueryBuilder>(next_value());
}
Ref<QueryBuilder> QueryBuilder::_begin_transaction_bind() {
return Ref<QueryBuilder>(begin_transaction());
}
Ref<QueryBuilder> QueryBuilder::_commit_bind() {
return Ref<QueryBuilder>(commit());
}
Ref<QueryBuilder> QueryBuilder::_nl_bind() {
return Ref<QueryBuilder>(nl());
}
Ref<QueryBuilder> QueryBuilder::_str_bind() {
return Ref<QueryBuilder>(str());
}
Ref<QueryBuilder> QueryBuilder::_cstr_bind() {
return Ref<QueryBuilder>(cstr());
}
Ref<QueryBuilder> QueryBuilder::_like_bind() {
return Ref<QueryBuilder>(like());
}
Ref<QueryBuilder> QueryBuilder::_select_bind(const String &params) {
return Ref<QueryBuilder>(select());
}
Ref<QueryBuilder> QueryBuilder::_update_bind(const String &params) {
return Ref<QueryBuilder>(update());
}
Ref<QueryBuilder> QueryBuilder::_del_bind(const String &params) {
return Ref<QueryBuilder>(del());
}
Ref<QueryBuilder> QueryBuilder::_where_bind(const String &params) {
return Ref<QueryBuilder>(where());
}
Ref<QueryBuilder> QueryBuilder::_from_bind(const String &params) {
return Ref<QueryBuilder>(from());
}
Ref<QueryBuilder> QueryBuilder::_insert_bind(const String &table_name, const String &columns) {
return Ref<QueryBuilder>(insert());
}
Ref<QueryBuilder> QueryBuilder::_values_bind(const String &params_str) {
return Ref<QueryBuilder>(values());
}
Ref<QueryBuilder> QueryBuilder::_val_bind() {
return Ref<QueryBuilder>(val());
}
Ref<QueryBuilder> QueryBuilder::_vals_bind(const String &param) {
return Ref<QueryBuilder>(vals(param));
}
Ref<QueryBuilder> QueryBuilder::_vali_bind(const int param) {
return Ref<QueryBuilder>(vali(param));
}
Ref<QueryBuilder> QueryBuilder::_valb_bind(const bool param) {
return Ref<QueryBuilder>(valb(param));
}
Ref<QueryBuilder> QueryBuilder::_valf_bind(const float param) {
return Ref<QueryBuilder>(valf(param));
}
Ref<QueryBuilder> QueryBuilder::_vald_bind(const double param) {
return Ref<QueryBuilder>(vald(param));
}
Ref<QueryBuilder> QueryBuilder::_like_bind(const String &str) {
return Ref<QueryBuilder>(like());
}
Ref<QueryBuilder> QueryBuilder::_set_bind() {
return Ref<QueryBuilder>(set());
}
Ref<QueryBuilder> QueryBuilder::_cset_bind() {
return Ref<QueryBuilder>(cset());
}
Ref<QueryBuilder> QueryBuilder::_setps_bind(const String &col, const String &param) {
return Ref<QueryBuilder>(setps(col, param));
}
Ref<QueryBuilder> QueryBuilder::_setpi_bind(const String &col, const int param) {
return Ref<QueryBuilder>(setpi(col, param));
}
Ref<QueryBuilder> QueryBuilder::_setpb_bind(const String &col, const bool param) {
return Ref<QueryBuilder>(setpb(col, param));
}
Ref<QueryBuilder> QueryBuilder::_setpf_bind(const String &col, const float param) {
return Ref<QueryBuilder>(setpf(col, param));
}
Ref<QueryBuilder> QueryBuilder::_setpd_bind(const String &col, const double param) {
return Ref<QueryBuilder>(setpd(col, param));
}
Ref<QueryBuilder> QueryBuilder::_wps_bind(const String &col, const String &param) {
return Ref<QueryBuilder>(wps(col, param));
}
Ref<QueryBuilder> QueryBuilder::_wpi_bind(const String &col, const int param) {
return Ref<QueryBuilder>(wpi(col, param));
}
Ref<QueryBuilder> QueryBuilder::_wpb_bind(const String &col, const bool param) {
return Ref<QueryBuilder>(wpb(col, param));
}
Ref<QueryBuilder> QueryBuilder::_nselect_bind(const String &params) {
return Ref<QueryBuilder>(nselect(params));
}
Ref<QueryBuilder> QueryBuilder::_nupdate_bind(const String &params) {
return Ref<QueryBuilder>(nupdate(params));
}
Ref<QueryBuilder> QueryBuilder::_ndel_bind(const String &params) {
return Ref<QueryBuilder>(ndel(params));
}
Ref<QueryBuilder> QueryBuilder::_nwhere_bind(const String &params) {
return Ref<QueryBuilder>(nwhere(params));
}
Ref<QueryBuilder> QueryBuilder::_nfrom_bind(const String &params) {
return Ref<QueryBuilder>(nfrom(params));
}
Ref<QueryBuilder> QueryBuilder::_nlike_bind(const String &str) {
return Ref<QueryBuilder>(nlike(str));
}
Ref<QueryBuilder> QueryBuilder::_nvalues_bind(const String &params_str) {
return Ref<QueryBuilder>(nvalues(params_str));
}
Ref<QueryBuilder> QueryBuilder::_nval_bind(const String &param) {
return Ref<QueryBuilder>(nval(param));
}
//note col is NOT escaped
Ref<QueryBuilder> QueryBuilder::_nsetp_bind(const String &col, const String &escape_param) {
return Ref<QueryBuilder>(nsetp(col, escape_param));
}
//note col is NOT escaped
Ref<QueryBuilder> QueryBuilder::_nwp_bind(const String &col, const String &escape_param) {
return Ref<QueryBuilder>(nwp(col, escape_param));
}
Ref<QueryBuilder> QueryBuilder::_limit_bind(const int num) {
return Ref<QueryBuilder>(limit(num));
}
Ref<QueryBuilder> QueryBuilder::_offset_bind(const int num) {
return Ref<QueryBuilder>(offset(num));
}
Ref<QueryBuilder> QueryBuilder::_order_by_asc_bind(const String &col) {
return Ref<QueryBuilder>(order_by_asc(col));
}
Ref<QueryBuilder> QueryBuilder::_order_by_desc_bind(const String &col) {
return Ref<QueryBuilder>(order_by_desc(col));
}
Ref<QueryBuilder> QueryBuilder::_order_by_bind(const String &col) {
return Ref<QueryBuilder>(order_by(col));
}
Ref<QueryBuilder> QueryBuilder::_order_by_bind() {
return Ref<QueryBuilder>(order_by());
}
Ref<QueryBuilder> QueryBuilder::_corder_by_bind() {
return Ref<QueryBuilder>(corder_by());
}
Ref<QueryBuilder> QueryBuilder::_asc_bind() {
return Ref<QueryBuilder>(asc());
}
Ref<QueryBuilder> QueryBuilder::_desc_bind() {
return Ref<QueryBuilder>(desc());
}
Ref<QueryBuilder> QueryBuilder::_order_by_add_col_bind(const String &col) {
return Ref<QueryBuilder>(order_by_add_col(col));
}
Ref<QueryBuilder> QueryBuilder::_asc_bind(const String &col) {
return Ref<QueryBuilder>(asc(col));
}
Ref<QueryBuilder> QueryBuilder::_desc_bind(const String &col) {
return Ref<QueryBuilder>(desc(col));
}
//l=logical (and, or are operators)
Ref<QueryBuilder> QueryBuilder::_land_bind() {
return Ref<QueryBuilder>(land());
}
Ref<QueryBuilder> QueryBuilder::_lor_bind() {
return Ref<QueryBuilder>(lor());
}
Ref<QueryBuilder> QueryBuilder::_wildcard_bind() {
return Ref<QueryBuilder>(wildcard());
}
Ref<QueryBuilder> QueryBuilder::_w_bind(const String &str) {
return Ref<QueryBuilder>(w(str));
}
Ref<QueryBuilder> QueryBuilder::_ew_bind(const String &str) {
return Ref<QueryBuilder>(ew(str));
}
Ref<QueryBuilder> QueryBuilder::_select_last_insert_id_bind() {
return Ref<QueryBuilder>(select_last_insert_id());
}
Ref<String> QueryBuilder::_escape_bind(const String &params) {
return Ref<QueryBuilder>(escape(params));
}
Ref<QueryBuilder> QueryBuilder::_prepare_bind() {
return Ref<QueryBuilder>(prepare());
}
Ref<QueryBuilder> QueryBuilder::_set_params_bind(const int index, const String &value) {
return Ref<QueryBuilder>(set_params(index, value));
}
Ref<QueryBuilder> QueryBuilder::_set_parami_bind(const int index, const int value) {
return Ref<QueryBuilder>(set_parami(index, value));
}
Ref<QueryBuilder> QueryBuilder::_set_paramf_bind(const int index, const float value) {
return Ref<QueryBuilder>(set_paramf(index, value));
}
Ref<QueryBuilder> QueryBuilder::_end_command_bind() {
return Ref<QueryBuilder>(end_command());
}
Ref<QueryBuilder> QueryBuilder::_reset_bind() {
return Ref<QueryBuilder>(reset());
}

View File

@ -1,7 +1,7 @@
#ifndef QUERY_BUILDER_H
#define QUERY_BUILDER_H
#include "core/string.h"
#include "core/ustring.h"
#include "core/reference.h"
@ -10,7 +10,7 @@ class QueryResult;
//methods that start with an e escape their params.
class QueryBuilder : public Reference {
RCPP_OBJECT(QueryBuilder, Reference);
GDCLASS(QueryBuilder, Reference);
public:
virtual QueryBuilder *select();
@ -40,14 +40,13 @@ public:
virtual QueryBuilder *where(const String &params);
virtual QueryBuilder *from(const String &params);
virtual QueryBuilder *insert(const String &table_name);
virtual QueryBuilder *insert(const String &table_name, const String &columns);
virtual QueryBuilder *insert(const String &table_name, const String &columns = "");
virtual QueryBuilder *values(const String &params_str);
virtual QueryBuilder *val();
virtual QueryBuilder *val(const String &param);
virtual QueryBuilder *val(const char *param);
virtual QueryBuilder *val(const int param);
virtual QueryBuilder *val(const bool param);
virtual QueryBuilder *vals(const String &param);
virtual QueryBuilder *vals(const char *param);
virtual QueryBuilder *vali(const int param);
virtual QueryBuilder *valb(const bool param);
virtual QueryBuilder *valf(const float param);
virtual QueryBuilder *vald(const double param);
@ -56,17 +55,17 @@ public:
virtual QueryBuilder *set();
virtual QueryBuilder *cset();
virtual QueryBuilder *setp(const String &col, const String &param);
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);
virtual QueryBuilder *setps(const String &col, const String &param);
virtual QueryBuilder *setps(const String &col, const char *param);
virtual QueryBuilder *setpi(const String &col, const int param);
virtual QueryBuilder *setpb(const String &col, const bool param);
virtual QueryBuilder *setpf(const String &col, const float param);
virtual QueryBuilder *setpd(const String &col, const double param);
virtual QueryBuilder *wp(const String &col, const String &param);
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 *wps(const String &col, const String &param);
virtual QueryBuilder *wps(const String &col, const char *param);
virtual QueryBuilder *wpi(const String &col, const int param);
virtual QueryBuilder *wpb(const String &col, const bool param);
virtual QueryBuilder *nselect(const String &params);
virtual QueryBuilder *nupdate(const String &params);
@ -111,9 +110,9 @@ public:
virtual String escape(const String &params);
virtual QueryBuilder *prepare();
virtual QueryBuilder *set_param(const int index, const String &value);
virtual QueryBuilder *set_param(const int index, const int value);
virtual QueryBuilder *set_param(const int index, const float value);
virtual QueryBuilder *set_params(const int index, const String &value);
virtual QueryBuilder *set_parami(const int index, const int value);
virtual QueryBuilder *set_paramf(const int index, const float value);
virtual QueryBuilder *end_command();
@ -130,6 +129,111 @@ public:
virtual ~QueryBuilder();
String query_result;
protected:
static void _bind_methods();
Ref<QueryBuilder> _select_bind();
Ref<QueryBuilder> _update_bind();
Ref<QueryBuilder> _del_bind();
Ref<QueryBuilder> _where_bind();
Ref<QueryBuilder> _from_bind();
Ref<QueryBuilder> _insert_bind();
Ref<QueryBuilder> _values_bind();
Ref<QueryBuilder> _cvalues_bind();
Ref<QueryBuilder> _next_value_bind();
Ref<QueryBuilder> _begin_transaction_bind();
Ref<QueryBuilder> _commit_bind();
Ref<QueryBuilder> _nl_bind();
Ref<QueryBuilder> _str_bind();
Ref<QueryBuilder> _cstr_bind();
Ref<QueryBuilder> _like_bind();
Ref<QueryBuilder> _select_bind(const String &params);
Ref<QueryBuilder> _update_bind(const String &params);
Ref<QueryBuilder> _del_bind(const String &params);
Ref<QueryBuilder> _where_bind(const String &params);
Ref<QueryBuilder> _from_bind(const String &params);
Ref<QueryBuilder> _insert_bind(const String &table_name, const String &columns = "");
Ref<QueryBuilder> _values_bind(const String &params_str);
Ref<QueryBuilder> _val_bind();
Ref<QueryBuilder> _vals_bind(const String &param);
Ref<QueryBuilder> _vali_bind(const int param);
Ref<QueryBuilder> _valb_bind(const bool param);
Ref<QueryBuilder> _valf_bind(const float param);
Ref<QueryBuilder> _vald_bind(const double param);
Ref<QueryBuilder> _like_bind(const String &str);
Ref<QueryBuilder> _set_bind();
Ref<QueryBuilder> _cset_bind();
Ref<QueryBuilder> _setps_bind(const String &col, const String &param);
Ref<QueryBuilder> _setpi_bind(const String &col, const int param);
Ref<QueryBuilder> _setpb_bind(const String &col, const bool param);
Ref<QueryBuilder> _setpf_bind(const String &col, const float param);
Ref<QueryBuilder> _setpd_bind(const String &col, const double param);
Ref<QueryBuilder> _wps_bind(const String &col, const String &param);
Ref<QueryBuilder> _wpi_bind(const String &col, const int param);
Ref<QueryBuilder> _wpb_bind(const String &col, const bool param);
Ref<QueryBuilder> _nselect_bind(const String &params);
Ref<QueryBuilder> _nupdate_bind(const String &params);
Ref<QueryBuilder> _ndel_bind(const String &params);
Ref<QueryBuilder> _nwhere_bind(const String &params);
Ref<QueryBuilder> _nfrom_bind(const String &params);
Ref<QueryBuilder> _nlike_bind(const String &str);
Ref<QueryBuilder> _nvalues_bind(const String &params_str);
Ref<QueryBuilder> _nval_bind(const String &param);
//note col is NOT escaped
Ref<QueryBuilder> _nsetp_bind(const String &col, const String &escape_param);
//note col is NOT escaped
Ref<QueryBuilder> _nwp_bind(const String &col, const String &escape_param);
Ref<QueryBuilder> _limit_bind(const int num);
Ref<QueryBuilder> _offset_bind(const int num);
Ref<QueryBuilder> _order_by_asc_bind(const String &col);
Ref<QueryBuilder> _order_by_desc_bind(const String &col);
Ref<QueryBuilder> _order_by_bind(const String &col);
Ref<QueryBuilder> _order_by_bind();
Ref<QueryBuilder> _corder_by_bind();
Ref<QueryBuilder> _asc_bind();
Ref<QueryBuilder> _desc_bind();
Ref<QueryBuilder> _order_by_add_col_bind(const String &col);
Ref<QueryBuilder> _asc_bind(const String &col);
Ref<QueryBuilder> _desc_bind(const String &col);
//l=logical (and, or are operators)
Ref<QueryBuilder> _land_bind();
Ref<QueryBuilder> _lor_bind();
Ref<QueryBuilder> _wildcard_bind();
Ref<QueryBuilder> _w_bind(const String &str);
Ref<QueryBuilder> _ew_bind(const String &str);
Ref<QueryBuilder> _select_last_insert_id_bind();
Ref<String> _escape_bind(const String &params);
Ref<QueryBuilder> _prepare_bind();
Ref<QueryBuilder> _set_params_bind(const int index, const String &value);
Ref<QueryBuilder> _set_parami_bind(const int index, const int value);
Ref<QueryBuilder> _set_paramf_bind(const int index, const float value);
Ref<QueryBuilder> _end_command_bind();
Ref<QueryBuilder> _reset_bind();
};
#endif