Added more helper methods to deal with prepared statements to QueryBuilder.

This commit is contained in:
Relintai 2024-04-27 20:37:23 +02:00
parent ef3aa03887
commit 2cb6e3d97f
4 changed files with 158 additions and 5 deletions

View File

@ -106,28 +106,33 @@ QueryBuilder *QueryBuilder::values(const String &params_str) {
QueryBuilder *QueryBuilder::val() { QueryBuilder *QueryBuilder::val() {
return this; return this;
} }
QueryBuilder *QueryBuilder::vals(const String &param) { QueryBuilder *QueryBuilder::vals(const String &param) {
return nval(escape(param)); return nval(escape(param));
} }
QueryBuilder *QueryBuilder::vals(const char *param) { QueryBuilder *QueryBuilder::vals(const char *param) {
return this; return this;
} }
QueryBuilder *QueryBuilder::vali(const int param) { QueryBuilder *QueryBuilder::vali(const int param) {
return this; return this;
} }
QueryBuilder *QueryBuilder::valb(const bool param) { QueryBuilder *QueryBuilder::valb(const bool param) {
return this; return this;
} }
QueryBuilder *QueryBuilder::valf(const float param) { QueryBuilder *QueryBuilder::valf(const float param) {
return this; return this;
} }
QueryBuilder *QueryBuilder::vald(const double param) { QueryBuilder *QueryBuilder::vald(const double param) {
return this; return this;
} }
QueryBuilder *QueryBuilder::valph() {
return this;
}
QueryBuilder *QueryBuilder::valphi(const String &p_id) {
return this;
}
QueryBuilder *QueryBuilder::valphr(const String &p_raw_id) {
return this;
}
QueryBuilder *QueryBuilder::like(const String &str) { QueryBuilder *QueryBuilder::like(const String &str) {
return nlike(escape(str)); return nlike(escape(str));
@ -157,6 +162,15 @@ QueryBuilder *QueryBuilder::setpf(const String &col, const float param) {
QueryBuilder *QueryBuilder::setpd(const String &col, const double param) { QueryBuilder *QueryBuilder::setpd(const String &col, const double param) {
return this; return this;
} }
QueryBuilder *QueryBuilder::setph(const String &col) {
return this;
}
QueryBuilder *QueryBuilder::setphi(const String &col, const String &p_id) {
return this;
}
QueryBuilder *QueryBuilder::setphr(const String &col, const String &p_raw_id) {
return this;
}
QueryBuilder *QueryBuilder::wps(const String &col, const String &param) { QueryBuilder *QueryBuilder::wps(const String &col, const String &param) {
return nwp(col, escape(param)); return nwp(col, escape(param));
@ -170,6 +184,15 @@ QueryBuilder *QueryBuilder::wpi(const String &col, const int param) {
QueryBuilder *QueryBuilder::wpb(const String &col, const bool param) { QueryBuilder *QueryBuilder::wpb(const String &col, const bool param) {
return this; return this;
} }
QueryBuilder *QueryBuilder::wph(const String &col) {
return this;
}
QueryBuilder *QueryBuilder::wphi(const String &col, const String &p_id) {
return this;
}
QueryBuilder *QueryBuilder::wphr(const String &col, const String &p_raw_id) {
return this;
}
QueryBuilder *QueryBuilder::nselect(const String &params) { QueryBuilder *QueryBuilder::nselect(const String &params) {
return this; return this;
@ -370,6 +393,9 @@ void QueryBuilder::_bind_methods() {
ClassDB::bind_method(D_METHOD("valb", "param"), &QueryBuilder::_valb_bind); ClassDB::bind_method(D_METHOD("valb", "param"), &QueryBuilder::_valb_bind);
ClassDB::bind_method(D_METHOD("valf", "param"), &QueryBuilder::_valf_bind); ClassDB::bind_method(D_METHOD("valf", "param"), &QueryBuilder::_valf_bind);
ClassDB::bind_method(D_METHOD("vald", "param"), &QueryBuilder::_vald_bind); ClassDB::bind_method(D_METHOD("vald", "param"), &QueryBuilder::_vald_bind);
ClassDB::bind_method(D_METHOD("valph"), &QueryBuilder::_valph_bind);
ClassDB::bind_method(D_METHOD("valphi", "id"), &QueryBuilder::_valphi_bind);
ClassDB::bind_method(D_METHOD("valphr", "raw_id"), &QueryBuilder::_valphr_bind);
ClassDB::bind_method(D_METHOD("like", "str"), &QueryBuilder::_like_bind, ""); ClassDB::bind_method(D_METHOD("like", "str"), &QueryBuilder::_like_bind, "");
ClassDB::bind_method(D_METHOD("sets"), &QueryBuilder::_sets_bind); ClassDB::bind_method(D_METHOD("sets"), &QueryBuilder::_sets_bind);
@ -380,10 +406,16 @@ void QueryBuilder::_bind_methods() {
ClassDB::bind_method(D_METHOD("setpb", "col", "param"), &QueryBuilder::_setpb_bind); ClassDB::bind_method(D_METHOD("setpb", "col", "param"), &QueryBuilder::_setpb_bind);
ClassDB::bind_method(D_METHOD("setpf", "col", "param"), &QueryBuilder::_setpf_bind); ClassDB::bind_method(D_METHOD("setpf", "col", "param"), &QueryBuilder::_setpf_bind);
ClassDB::bind_method(D_METHOD("setpd", "col", "param"), &QueryBuilder::_setpd_bind); ClassDB::bind_method(D_METHOD("setpd", "col", "param"), &QueryBuilder::_setpd_bind);
ClassDB::bind_method(D_METHOD("setph", "col"), &QueryBuilder::_setph_bind);
ClassDB::bind_method(D_METHOD("setphi", "col", "id"), &QueryBuilder::_setphi_bind);
ClassDB::bind_method(D_METHOD("setphr", "col", "raw_id"), &QueryBuilder::_setphr_bind);
ClassDB::bind_method(D_METHOD("wps", "col", "param"), &QueryBuilder::_wps_bind); ClassDB::bind_method(D_METHOD("wps", "col", "param"), &QueryBuilder::_wps_bind);
ClassDB::bind_method(D_METHOD("wpi", "col", "param"), &QueryBuilder::_wpi_bind); ClassDB::bind_method(D_METHOD("wpi", "col", "param"), &QueryBuilder::_wpi_bind);
ClassDB::bind_method(D_METHOD("wpb", "col", "param"), &QueryBuilder::_wpb_bind); ClassDB::bind_method(D_METHOD("wpb", "col", "param"), &QueryBuilder::_wpb_bind);
ClassDB::bind_method(D_METHOD("wph", "col"), &QueryBuilder::_wph_bind);
ClassDB::bind_method(D_METHOD("wphi", "col", "id"), &QueryBuilder::_wphi_bind);
ClassDB::bind_method(D_METHOD("wphr", "col", "raw_id"), &QueryBuilder::_wphr_bind);
ClassDB::bind_method(D_METHOD("nselect", "params"), &QueryBuilder::_nselect_bind); ClassDB::bind_method(D_METHOD("nselect", "params"), &QueryBuilder::_nselect_bind);
ClassDB::bind_method(D_METHOD("nupdate", "params"), &QueryBuilder::_nupdate_bind); ClassDB::bind_method(D_METHOD("nupdate", "params"), &QueryBuilder::_nupdate_bind);
@ -500,6 +532,15 @@ Ref<QueryBuilder> QueryBuilder::_valf_bind(const float param) {
Ref<QueryBuilder> QueryBuilder::_vald_bind(const double param) { Ref<QueryBuilder> QueryBuilder::_vald_bind(const double param) {
return Ref<QueryBuilder>(vald(param)); return Ref<QueryBuilder>(vald(param));
} }
Ref<QueryBuilder> QueryBuilder::_valph_bind() {
return Ref<QueryBuilder>(valph());
}
Ref<QueryBuilder> QueryBuilder::_valphi_bind(const String &p_id) {
return Ref<QueryBuilder>(valphi(p_id));
}
Ref<QueryBuilder> QueryBuilder::_valphr_bind(const String &p_raw_id) {
return Ref<QueryBuilder>(valphr(p_raw_id));
}
Ref<QueryBuilder> QueryBuilder::_like_bind(const String &str) { Ref<QueryBuilder> QueryBuilder::_like_bind(const String &str) {
return Ref<QueryBuilder>(like(str)); return Ref<QueryBuilder>(like(str));
@ -527,6 +568,15 @@ Ref<QueryBuilder> QueryBuilder::_setpf_bind(const String &col, const float param
Ref<QueryBuilder> QueryBuilder::_setpd_bind(const String &col, const double param) { Ref<QueryBuilder> QueryBuilder::_setpd_bind(const String &col, const double param) {
return Ref<QueryBuilder>(setpd(col, param)); return Ref<QueryBuilder>(setpd(col, param));
} }
Ref<QueryBuilder> QueryBuilder::_setph_bind(const String &col) {
return Ref<QueryBuilder>(setph(col));
}
Ref<QueryBuilder> QueryBuilder::_setphi_bind(const String &col, const String &p_id) {
return Ref<QueryBuilder>(setphi(col, p_id));
}
Ref<QueryBuilder> QueryBuilder::_setphr_bind(const String &col, const String &p_raw_id) {
return Ref<QueryBuilder>(setphr(col, p_raw_id));
}
Ref<QueryBuilder> QueryBuilder::_wps_bind(const String &col, const String &param) { Ref<QueryBuilder> QueryBuilder::_wps_bind(const String &col, const String &param) {
return Ref<QueryBuilder>(wps(col, param)); return Ref<QueryBuilder>(wps(col, param));
@ -537,6 +587,15 @@ Ref<QueryBuilder> QueryBuilder::_wpi_bind(const String &col, const int param) {
Ref<QueryBuilder> QueryBuilder::_wpb_bind(const String &col, const bool param) { Ref<QueryBuilder> QueryBuilder::_wpb_bind(const String &col, const bool param) {
return Ref<QueryBuilder>(wpb(col, param)); return Ref<QueryBuilder>(wpb(col, param));
} }
Ref<QueryBuilder> QueryBuilder::_wph_bind(const String &col) {
return Ref<QueryBuilder>(wph(col));
}
Ref<QueryBuilder> QueryBuilder::_wphi_bind(const String &col, const String &p_id) {
return Ref<QueryBuilder>(wphi(col, p_id));
}
Ref<QueryBuilder> QueryBuilder::_wphr_bind(const String &col, const String &p_raw_id) {
return Ref<QueryBuilder>(wphr(col, p_raw_id));
}
Ref<QueryBuilder> QueryBuilder::_nselect_bind(const String &params) { Ref<QueryBuilder> QueryBuilder::_nselect_bind(const String &params) {
return Ref<QueryBuilder>(nselect(params)); return Ref<QueryBuilder>(nselect(params));

View File

@ -32,8 +32,8 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#include "core/string/ustring.h"
#include "core/string/string_builder.h" #include "core/string/string_builder.h"
#include "core/string/ustring.h"
#include "core/object/reference.h" #include "core/object/reference.h"
@ -79,6 +79,9 @@ public:
virtual QueryBuilder *valb(const bool param); virtual QueryBuilder *valb(const bool param);
virtual QueryBuilder *valf(const float param); virtual QueryBuilder *valf(const float param);
virtual QueryBuilder *vald(const double param); virtual QueryBuilder *vald(const double param);
virtual QueryBuilder *valph();
virtual QueryBuilder *valphi(const String &p_id);
virtual QueryBuilder *valphr(const String &p_raw_id);
virtual QueryBuilder *like(const String &str = ""); virtual QueryBuilder *like(const String &str = "");
@ -92,11 +95,18 @@ public:
virtual QueryBuilder *setpb(const String &col, const bool param); virtual QueryBuilder *setpb(const String &col, const bool param);
virtual QueryBuilder *setpf(const String &col, const float param); virtual QueryBuilder *setpf(const String &col, const float param);
virtual QueryBuilder *setpd(const String &col, const double param); virtual QueryBuilder *setpd(const String &col, const double param);
virtual QueryBuilder *setph(const String &col);
virtual QueryBuilder *setphi(const String &col, const String &p_id);
virtual QueryBuilder *setphr(const String &col, const String &p_raw_id);
// Where param helpers
virtual QueryBuilder *wps(const String &col, const String &param); virtual QueryBuilder *wps(const String &col, const String &param);
virtual QueryBuilder *wps(const String &col, const char *param); virtual QueryBuilder *wps(const String &col, const char *param);
virtual QueryBuilder *wpi(const String &col, const int param); virtual QueryBuilder *wpi(const String &col, const int param);
virtual QueryBuilder *wpb(const String &col, const bool param); virtual QueryBuilder *wpb(const String &col, const bool param);
virtual QueryBuilder *wph(const String &col);
virtual QueryBuilder *wphi(const String &col, const String &p_id);
virtual QueryBuilder *wphr(const String &col, const String &p_raw_id);
virtual QueryBuilder *nselect(const String &params); virtual QueryBuilder *nselect(const String &params);
virtual QueryBuilder *nupdate(const String &params); virtual QueryBuilder *nupdate(const String &params);
@ -184,6 +194,9 @@ protected:
Ref<QueryBuilder> _valb_bind(const bool param); Ref<QueryBuilder> _valb_bind(const bool param);
Ref<QueryBuilder> _valf_bind(const float param); Ref<QueryBuilder> _valf_bind(const float param);
Ref<QueryBuilder> _vald_bind(const double param); Ref<QueryBuilder> _vald_bind(const double param);
Ref<QueryBuilder> _valph_bind();
Ref<QueryBuilder> _valphi_bind(const String &p_id);
Ref<QueryBuilder> _valphr_bind(const String &p_raw_id);
Ref<QueryBuilder> _like_bind(const String &str); Ref<QueryBuilder> _like_bind(const String &str);
@ -195,10 +208,16 @@ protected:
Ref<QueryBuilder> _setpb_bind(const String &col, const bool param); Ref<QueryBuilder> _setpb_bind(const String &col, const bool param);
Ref<QueryBuilder> _setpf_bind(const String &col, const float param); Ref<QueryBuilder> _setpf_bind(const String &col, const float param);
Ref<QueryBuilder> _setpd_bind(const String &col, const double param); Ref<QueryBuilder> _setpd_bind(const String &col, const double param);
Ref<QueryBuilder> _setph_bind(const String &col);
Ref<QueryBuilder> _setphi_bind(const String &col, const String &p_id);
Ref<QueryBuilder> _setphr_bind(const String &col, const String &p_raw_id);
Ref<QueryBuilder> _wps_bind(const String &col, const String &param); Ref<QueryBuilder> _wps_bind(const String &col, const String &param);
Ref<QueryBuilder> _wpi_bind(const String &col, const int param); Ref<QueryBuilder> _wpi_bind(const String &col, const int param);
Ref<QueryBuilder> _wpb_bind(const String &col, const bool param); Ref<QueryBuilder> _wpb_bind(const String &col, const bool param);
Ref<QueryBuilder> _wph_bind(const String &col);
Ref<QueryBuilder> _wphi_bind(const String &col, const String &p_id);
Ref<QueryBuilder> _wphr_bind(const String &col, const String &p_raw_id);
Ref<QueryBuilder> _nselect_bind(const String &params); Ref<QueryBuilder> _nselect_bind(const String &params);
Ref<QueryBuilder> _nupdate_bind(const String &params); Ref<QueryBuilder> _nupdate_bind(const String &params);

View File

@ -208,6 +208,24 @@ QueryBuilder *SQLite3QueryBuilder::vald(const double param) {
return this; return this;
} }
QueryBuilder *SQLite3QueryBuilder::valph() {
psph();
query_result += ", ";
return this;
}
QueryBuilder *SQLite3QueryBuilder::valphi(const String &p_id) {
psphi(p_id);
query_result += ", ";
return this;
}
QueryBuilder *SQLite3QueryBuilder::valphr(const String &p_raw_id) {
psphi(p_raw_id);
query_result += ", ";
return this;
}
QueryBuilder *SQLite3QueryBuilder::nlike(const String &str) { QueryBuilder *SQLite3QueryBuilder::nlike(const String &str) {
query_result += "LIKE '"; query_result += "LIKE '";
@ -285,6 +303,30 @@ QueryBuilder *SQLite3QueryBuilder::setpd(const String &col, const double param)
return this; return this;
} }
QueryBuilder *SQLite3QueryBuilder::setph(const String &col) {
query_result += col;
query_result += "=";
psph();
query_result += ", ";
return this;
}
QueryBuilder *SQLite3QueryBuilder::setphi(const String &col, const String &p_id) {
query_result += col;
query_result += "=";
psphi(p_id);
query_result += ", ";
return this;
}
QueryBuilder *SQLite3QueryBuilder::setphr(const String &col, const String &p_raw_id) {
query_result += col;
query_result += "=";
psphr(p_raw_id);
query_result += ", ";
return this;
}
QueryBuilder *SQLite3QueryBuilder::nwp(const String &col, const String &param) { QueryBuilder *SQLite3QueryBuilder::nwp(const String &col, const String &param) {
query_result += col; query_result += col;
@ -321,6 +363,30 @@ QueryBuilder *SQLite3QueryBuilder::wpb(const String &col, const bool param) {
return this; return this;
} }
QueryBuilder *SQLite3QueryBuilder::wph(const String &col) {
query_result += col;
query_result += "='";
psph();
query_result += "' ";
return this;
}
QueryBuilder *SQLite3QueryBuilder::wphi(const String &col, const String &p_id) {
query_result += col;
query_result += "='";
psphi(p_id);
query_result += "' ";
return this;
}
QueryBuilder *SQLite3QueryBuilder::wphr(const String &col, const String &p_raw_id) {
query_result += col;
query_result += "='";
psphr(p_raw_id);
query_result += "' ";
return this;
}
QueryBuilder *SQLite3QueryBuilder::limit(const int num) { QueryBuilder *SQLite3QueryBuilder::limit(const int num) {
query_result += "LIMIT "; query_result += "LIMIT ";

View File

@ -44,6 +44,9 @@ public:
QueryBuilder *valb(const bool param); QueryBuilder *valb(const bool param);
QueryBuilder *valf(const float param); QueryBuilder *valf(const float param);
QueryBuilder *vald(const double param); QueryBuilder *vald(const double param);
virtual QueryBuilder *valph();
virtual QueryBuilder *valphi(const String &p_id);
virtual QueryBuilder *valphr(const String &p_raw_id);
QueryBuilder *nlike(const String &str); QueryBuilder *nlike(const String &str);
@ -57,12 +60,18 @@ public:
QueryBuilder *setpb(const String &col, const bool param); QueryBuilder *setpb(const String &col, const bool param);
QueryBuilder *setpf(const String &col, const float param); QueryBuilder *setpf(const String &col, const float param);
QueryBuilder *setpd(const String &col, const double param); QueryBuilder *setpd(const String &col, const double param);
virtual QueryBuilder *setph(const String &col);
virtual QueryBuilder *setphi(const String &col, const String &p_id);
virtual QueryBuilder *setphr(const String &col, const String &p_raw_id);
QueryBuilder *nwp(const String &col, const String &param); QueryBuilder *nwp(const String &col, const String &param);
QueryBuilder *wps(const String &col, const char *param); QueryBuilder *wps(const String &col, const char *param);
QueryBuilder *wpi(const String &col, const int param); QueryBuilder *wpi(const String &col, const int param);
QueryBuilder *wpb(const String &col, const bool param); QueryBuilder *wpb(const String &col, const bool param);
virtual QueryBuilder *wph(const String &col);
virtual QueryBuilder *wphi(const String &col, const String &p_id);
virtual QueryBuilder *wphr(const String &col, const String &p_raw_id);
QueryBuilder *limit(const int num); QueryBuilder *limit(const int num);
QueryBuilder *offset(const int num); QueryBuilder *offset(const int num);