#include "query_builder.h" #include "query_result.h" String QueryBuilder::get_result() { return query_result; } void QueryBuilder::set_result(const String &val) { query_result = val; } QueryBuilder *QueryBuilder::select() { return this; } QueryBuilder *QueryBuilder::update() { return this; } QueryBuilder *QueryBuilder::del() { return this; } QueryBuilder *QueryBuilder::cvalues() { return this; } QueryBuilder *QueryBuilder::next_value() { return this; } QueryBuilder *QueryBuilder::begin_transaction() { return this; } QueryBuilder *QueryBuilder::commit() { return this; } QueryBuilder *QueryBuilder::nl() { query_result += "\n"; return this; } QueryBuilder *QueryBuilder::str() { return this; } QueryBuilder *QueryBuilder::cstr() { return this; } QueryBuilder *QueryBuilder::select(const String ¶ms) { return nselect(escape(params)); } QueryBuilder *QueryBuilder::update(const String ¶ms) { return nupdate(escape(params)); } QueryBuilder *QueryBuilder::del(const String ¶ms) { return ndel(escape(params)); } QueryBuilder *QueryBuilder::where(const String ¶ms) { return nwhere(escape(params)); } QueryBuilder *QueryBuilder::from(const String ¶ms) { return nfrom(escape(params)); } QueryBuilder *QueryBuilder::insert(const String &table_name, const String &columns) { return this; } QueryBuilder *QueryBuilder::values(const String ¶ms_str) { return nvalues(escape(params_str)); } QueryBuilder *QueryBuilder::val() { return this; } QueryBuilder *QueryBuilder::vals(const String ¶m) { return nval(escape(param)); } QueryBuilder *QueryBuilder::vals(const char *param) { return this; } QueryBuilder *QueryBuilder::vali(const int param) { return this; } QueryBuilder *QueryBuilder::valb(const bool param) { return this; } QueryBuilder *QueryBuilder::valf(const float param) { return this; } QueryBuilder *QueryBuilder::vald(const double param) { return this; } QueryBuilder *QueryBuilder::like(const String &str) { return nlike(escape(str)); } QueryBuilder *QueryBuilder::sets() { return this; } QueryBuilder *QueryBuilder::cset() { return this; } QueryBuilder *QueryBuilder::setps(const String &col, const String ¶m) { return nsetp(col, escape(param)); } QueryBuilder *QueryBuilder::setps(const String &col, const char *param) { return this; } QueryBuilder *QueryBuilder::setpi(const String &col, const int param) { return this; } QueryBuilder *QueryBuilder::setpb(const String &col, const bool param) { return this; } QueryBuilder *QueryBuilder::setpf(const String &col, const float param) { return this; } QueryBuilder *QueryBuilder::setpd(const String &col, const double param) { return this; } QueryBuilder *QueryBuilder::wps(const String &col, const String ¶m) { return nwp(col, escape(param)); } QueryBuilder *QueryBuilder::wps(const String &col, const char *param) { return this; } QueryBuilder *QueryBuilder::wpi(const String &col, const int param) { return this; } QueryBuilder *QueryBuilder::wpb(const String &col, const bool param) { return this; } QueryBuilder *QueryBuilder::nselect(const String ¶ms) { return this; } QueryBuilder *QueryBuilder::nupdate(const String ¶ms) { return this; } QueryBuilder *QueryBuilder::ndel(const String ¶ms) { return this; } QueryBuilder *QueryBuilder::nwhere(const String ¶ms) { return this; } QueryBuilder *QueryBuilder::nfrom(const String ¶ms) { return this; } QueryBuilder *QueryBuilder::nlike(const String &str) { return this; } QueryBuilder *QueryBuilder::nvalues(const String ¶ms_str) { return this; } QueryBuilder *QueryBuilder::nval(const String ¶m) { return vals(escape(param)); } QueryBuilder *QueryBuilder::nsetp(const String &col, const String &escape_param) { return setps(col, escape(escape_param)); } QueryBuilder *QueryBuilder::nwp(const String &col, const String &escape_param) { return this; } QueryBuilder *QueryBuilder::limit(const int num) { return this; } QueryBuilder *QueryBuilder::offset(const int num) { return this; } QueryBuilder *QueryBuilder::order_by_asc(const String &col) { query_result += "ORDER BY " + col + " ASC, "; return this; } QueryBuilder *QueryBuilder::order_by_desc(const String &col) { query_result += "ORDER BY " + col + " DESC, "; return this; } QueryBuilder *QueryBuilder::order_by(const String &col) { if (col == "") { query_result += "ORDER BY "; } else { query_result += "ORDER BY " + col + ", "; } return this; } QueryBuilder *QueryBuilder::corder_by() { query_result[query_result.size() - 2] = ' '; return this; } QueryBuilder *QueryBuilder::order_by_add_col(const String &col) { query_result += col + ", "; return this; } QueryBuilder *QueryBuilder::asc(const String &col) { if (col == "") { query_result += "ASC,"; } else { query_result += col + " ASC, "; } return this; } QueryBuilder *QueryBuilder::desc(const String &col) { if (col == "") { query_result += "DESC, "; } else { query_result += col + " DESC, "; } return this; } QueryBuilder *QueryBuilder::land() { return this; } QueryBuilder *QueryBuilder::lor() { return this; } QueryBuilder *QueryBuilder::wildcard() { return this; } QueryBuilder *QueryBuilder::w(const String &str) { query_result += str; return this; } QueryBuilder *QueryBuilder::ew(const String &str) { return w(escape(str)); } QueryBuilder *QueryBuilder::select_last_insert_id() { return this; } String QueryBuilder::escape(const String ¶ms) { return params; } QueryBuilder *QueryBuilder::prepare() { return this; } QueryBuilder *QueryBuilder::set_params(const int index, const String &value) { return this; } QueryBuilder *QueryBuilder::set_parami(const int index, const int value) { return this; } QueryBuilder *QueryBuilder::set_paramf(const int index, const float value) { return this; } QueryBuilder *QueryBuilder::end_command() { return this; } QueryBuilder *QueryBuilder::reset() { query_result = ""; return this; } Ref QueryBuilder::run() { return Ref(); } void QueryBuilder::run_query() { } void QueryBuilder::print() { //printf("%s\n", query_result.c_str()); ERR_PRINT(query_result); } QueryBuilder::QueryBuilder() { } QueryBuilder::~QueryBuilder() { } void QueryBuilder::_bind_methods() { ClassDB::bind_method(D_METHOD("get_result"), &QueryBuilder::get_result); ClassDB::bind_method(D_METHOD("set_result", "value"), &QueryBuilder::set_result); ADD_PROPERTY(PropertyInfo(Variant::STRING, "result"), "set_result", "get_result"); ClassDB::bind_method(D_METHOD("cvalues"), &QueryBuilder::_cvalues_bind); ClassDB::bind_method(D_METHOD("next_value"), &QueryBuilder::_next_value_bind); ClassDB::bind_method(D_METHOD("begin_transaction"), &QueryBuilder::_begin_transaction_bind); ClassDB::bind_method(D_METHOD("commit"), &QueryBuilder::_commit_bind); ClassDB::bind_method(D_METHOD("nl"), &QueryBuilder::_nl_bind); ClassDB::bind_method(D_METHOD("str"), &QueryBuilder::_str_bind); ClassDB::bind_method(D_METHOD("cstr"), &QueryBuilder::_cstr_bind); ClassDB::bind_method(D_METHOD("select", "params"), &QueryBuilder::_select_bind, ""); ClassDB::bind_method(D_METHOD("update", "params"), &QueryBuilder::_update_bind, ""); ClassDB::bind_method(D_METHOD("del", "params"), &QueryBuilder::_del_bind, ""); ClassDB::bind_method(D_METHOD("where", "params"), &QueryBuilder::_where_bind, ""); ClassDB::bind_method(D_METHOD("from", "params"), &QueryBuilder::_from_bind, ""); ClassDB::bind_method(D_METHOD("insert", "table_name", "colums"), &QueryBuilder::_insert_bind, "", ""); ClassDB::bind_method(D_METHOD("values", "params_str"), &QueryBuilder::_values_bind, ""); ClassDB::bind_method(D_METHOD("val"), &QueryBuilder::_val_bind); ClassDB::bind_method(D_METHOD("vals", "param"), &QueryBuilder::_vals_bind); ClassDB::bind_method(D_METHOD("vali", "param"), &QueryBuilder::_vali_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("vald", "param"), &QueryBuilder::_vald_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("cset"), &QueryBuilder::_cset_bind); ClassDB::bind_method(D_METHOD("setps", "col", "param"), &QueryBuilder::_setps_bind); ClassDB::bind_method(D_METHOD("setpi", "col", "param"), &QueryBuilder::_setpi_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("setpd", "col", "param"), &QueryBuilder::_setpd_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("wpb", "col", "param"), &QueryBuilder::_wpb_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("ndel", "params"), &QueryBuilder::_ndel_bind); ClassDB::bind_method(D_METHOD("nwhere", "params"), &QueryBuilder::_nwhere_bind); ClassDB::bind_method(D_METHOD("nfrom", "params"), &QueryBuilder::_nfrom_bind); ClassDB::bind_method(D_METHOD("nlike", "str"), &QueryBuilder::_nlike_bind); ClassDB::bind_method(D_METHOD("nvalues", "params_str"), &QueryBuilder::_nvalues_bind); ClassDB::bind_method(D_METHOD("nval", "param"), &QueryBuilder::_nval_bind); ClassDB::bind_method(D_METHOD("nsetp", "col", "escape_param"), &QueryBuilder::_nsetp_bind); ClassDB::bind_method(D_METHOD("nwp", "col", "escape_param"), &QueryBuilder::_nwp_bind); ClassDB::bind_method(D_METHOD("limit", "num"), &QueryBuilder::_limit_bind); ClassDB::bind_method(D_METHOD("offset", "num"), &QueryBuilder::_offset_bind); ClassDB::bind_method(D_METHOD("order_by_asc", "col"), &QueryBuilder::_order_by_asc_bind); ClassDB::bind_method(D_METHOD("order_by_desc", "col"), &QueryBuilder::_order_by_desc_bind); ClassDB::bind_method(D_METHOD("order_by", "col"), &QueryBuilder::_order_by_bind); ClassDB::bind_method(D_METHOD("corder_by"), &QueryBuilder::_corder_by_bind); ClassDB::bind_method(D_METHOD("order_by_add_col", "col"), &QueryBuilder::_order_by_add_col_bind); ClassDB::bind_method(D_METHOD("asc", "col"), &QueryBuilder::_asc_bind, ""); ClassDB::bind_method(D_METHOD("desc", "col"), &QueryBuilder::_desc_bind, ""); ClassDB::bind_method(D_METHOD("land"), &QueryBuilder::_land_bind); ClassDB::bind_method(D_METHOD("lor"), &QueryBuilder::_lor_bind); ClassDB::bind_method(D_METHOD("wildcard"), &QueryBuilder::_wildcard_bind); ClassDB::bind_method(D_METHOD("w", "str"), &QueryBuilder::_w_bind); ClassDB::bind_method(D_METHOD("ew", "str"), &QueryBuilder::_ew_bind); ClassDB::bind_method(D_METHOD("select_last_insert_id"), &QueryBuilder::_select_last_insert_id_bind); ClassDB::bind_method(D_METHOD("escape", "param"), &QueryBuilder::escape); ClassDB::bind_method(D_METHOD("prepare"), &QueryBuilder::_prepare_bind); ClassDB::bind_method(D_METHOD("set_params", "index", "value"), &QueryBuilder::_set_params_bind); ClassDB::bind_method(D_METHOD("set_parami", "index", "value"), &QueryBuilder::_set_parami_bind); ClassDB::bind_method(D_METHOD("set_paramf", "index", "value"), &QueryBuilder::_set_paramf_bind); ClassDB::bind_method(D_METHOD("end_command"), &QueryBuilder::_end_command_bind); ClassDB::bind_method(D_METHOD("reset"), &QueryBuilder::_reset_bind); ClassDB::bind_method(D_METHOD("run"), &QueryBuilder::run); ClassDB::bind_method(D_METHOD("run_query"), &QueryBuilder::run_query); } Ref QueryBuilder::_cvalues_bind() { return Ref(cvalues()); } Ref QueryBuilder::_next_value_bind() { return Ref(next_value()); } Ref QueryBuilder::_begin_transaction_bind() { return Ref(begin_transaction()); } Ref QueryBuilder::_commit_bind() { return Ref(commit()); } Ref QueryBuilder::_nl_bind() { return Ref(nl()); } Ref QueryBuilder::_str_bind() { return Ref(str()); } Ref QueryBuilder::_cstr_bind() { return Ref(cstr()); } Ref QueryBuilder::_select_bind(const String ¶ms) { return Ref(select(params)); } Ref QueryBuilder::_update_bind(const String ¶ms) { return Ref(update(params)); } Ref QueryBuilder::_del_bind(const String ¶ms) { return Ref(del(params)); } Ref QueryBuilder::_where_bind(const String ¶ms) { return Ref(where(params)); } Ref QueryBuilder::_from_bind(const String ¶ms) { return Ref(from(params)); } Ref QueryBuilder::_insert_bind(const String &table_name, const String &columns) { return Ref(insert(table_name, columns)); } Ref QueryBuilder::_values_bind(const String ¶ms_str) { return Ref(values(params_str)); } Ref QueryBuilder::_val_bind() { return Ref(val()); } Ref QueryBuilder::_vals_bind(const String ¶m) { return Ref(vals(param)); } Ref QueryBuilder::_vali_bind(const int param) { return Ref(vali(param)); } Ref QueryBuilder::_valb_bind(const bool param) { return Ref(valb(param)); } Ref QueryBuilder::_valf_bind(const float param) { return Ref(valf(param)); } Ref QueryBuilder::_vald_bind(const double param) { return Ref(vald(param)); } Ref QueryBuilder::_like_bind(const String &str) { return Ref(like(str)); } Ref QueryBuilder::_sets_bind() { return Ref(sets()); } Ref QueryBuilder::_cset_bind() { return Ref(cset()); } Ref QueryBuilder::_setps_bind(const String &col, const String ¶m) { return Ref(setps(col, param)); } Ref QueryBuilder::_setpi_bind(const String &col, const int param) { return Ref(setpi(col, param)); } Ref QueryBuilder::_setpb_bind(const String &col, const bool param) { return Ref(setpb(col, param)); } Ref QueryBuilder::_setpf_bind(const String &col, const float param) { return Ref(setpf(col, param)); } Ref QueryBuilder::_setpd_bind(const String &col, const double param) { return Ref(setpd(col, param)); } Ref QueryBuilder::_wps_bind(const String &col, const String ¶m) { return Ref(wps(col, param)); } Ref QueryBuilder::_wpi_bind(const String &col, const int param) { return Ref(wpi(col, param)); } Ref QueryBuilder::_wpb_bind(const String &col, const bool param) { return Ref(wpb(col, param)); } Ref QueryBuilder::_nselect_bind(const String ¶ms) { return Ref(nselect(params)); } Ref QueryBuilder::_nupdate_bind(const String ¶ms) { return Ref(nupdate(params)); } Ref QueryBuilder::_ndel_bind(const String ¶ms) { return Ref(ndel(params)); } Ref QueryBuilder::_nwhere_bind(const String ¶ms) { return Ref(nwhere(params)); } Ref QueryBuilder::_nfrom_bind(const String ¶ms) { return Ref(nfrom(params)); } Ref QueryBuilder::_nlike_bind(const String &str) { return Ref(nlike(str)); } Ref QueryBuilder::_nvalues_bind(const String ¶ms_str) { return Ref(nvalues(params_str)); } Ref QueryBuilder::_nval_bind(const String ¶m) { return Ref(nval(param)); } //note col is NOT escaped Ref QueryBuilder::_nsetp_bind(const String &col, const String &escape_param) { return Ref(nsetp(col, escape_param)); } //note col is NOT escaped Ref QueryBuilder::_nwp_bind(const String &col, const String &escape_param) { return Ref(nwp(col, escape_param)); } Ref QueryBuilder::_limit_bind(const int num) { return Ref(limit(num)); } Ref QueryBuilder::_offset_bind(const int num) { return Ref(offset(num)); } Ref QueryBuilder::_order_by_asc_bind(const String &col) { return Ref(order_by_asc(col)); } Ref QueryBuilder::_order_by_desc_bind(const String &col) { return Ref(order_by_desc(col)); } Ref QueryBuilder::_order_by_bind(const String &col) { return Ref(order_by(col)); } Ref QueryBuilder::_corder_by_bind() { return Ref(corder_by()); } Ref QueryBuilder::_order_by_add_col_bind(const String &col) { return Ref(order_by_add_col(col)); } Ref QueryBuilder::_asc_bind(const String &col) { return Ref(asc(col)); } Ref QueryBuilder::_desc_bind(const String &col) { return Ref(desc(col)); } //l=logical (and, or are operators) Ref QueryBuilder::_land_bind() { return Ref(land()); } Ref QueryBuilder::_lor_bind() { return Ref(lor()); } Ref QueryBuilder::_wildcard_bind() { return Ref(wildcard()); } Ref QueryBuilder::_w_bind(const String &str) { return Ref(w(str)); } Ref QueryBuilder::_ew_bind(const String &str) { return Ref(ew(str)); } Ref QueryBuilder::_select_last_insert_id_bind() { return Ref(select_last_insert_id()); } Ref QueryBuilder::_prepare_bind() { return Ref(prepare()); } Ref QueryBuilder::_set_params_bind(const int index, const String &value) { return Ref(set_params(index, value)); } Ref QueryBuilder::_set_parami_bind(const int index, const int value) { return Ref(set_parami(index, value)); } Ref QueryBuilder::_set_paramf_bind(const int index, const float value) { return Ref(set_paramf(index, value)); } Ref QueryBuilder::_end_command_bind() { return Ref(end_command()); } Ref QueryBuilder::_reset_bind() { return Ref(reset()); }