#ifndef QUERY_BUILDER_H #define QUERY_BUILDER_H /*************************************************************************/ /* query_builder.h */ /*************************************************************************/ /* This file is part of: */ /* PANDEMONIUM ENGINE */ /* https://github.com/Relintai/pandemonium_engine */ /*************************************************************************/ /* Copyright (c) 2022-present Péter Magyar. */ /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ /* "Software"), to deal in the Software without restriction, including */ /* without limitation the rights to use, copy, modify, merge, publish, */ /* distribute, sublicense, and/or sell copies of the Software, and to */ /* permit persons to whom the Software is furnished to do so, subject to */ /* the following conditions: */ /* */ /* The above copyright notice and this permission notice shall be */ /* included in all copies or substantial portions of the Software. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "core/string/string_builder.h" #include "core/string/ustring.h" #include "core/object/reference.h" class QueryResult; class PreparedStatement; //methods that start with an e escape their params. class QueryBuilder : public Reference { GDCLASS(QueryBuilder, Reference); public: String get_result(); void set_result(const String &val); virtual QueryBuilder *select(); virtual QueryBuilder *update(); virtual QueryBuilder *del(); virtual QueryBuilder *cvalues(); virtual QueryBuilder *next_value(); virtual QueryBuilder *begin_transaction(); virtual QueryBuilder *commit(); virtual QueryBuilder *nl(); virtual QueryBuilder *str(); virtual QueryBuilder *cstr(); virtual QueryBuilder *select(const String ¶ms); virtual QueryBuilder *update(const String ¶ms); virtual QueryBuilder *del(const String ¶ms); virtual QueryBuilder *where(const String ¶ms = ""); virtual QueryBuilder *from(const String ¶ms = ""); virtual QueryBuilder *insert(const String &table_name = "", const String &columns = ""); virtual QueryBuilder *values(const String ¶ms_str = ""); virtual QueryBuilder *val(); virtual QueryBuilder *vals(const String ¶m); 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); virtual QueryBuilder *valph(); virtual QueryBuilder *valphi(const String &p_id); virtual QueryBuilder *valphr(const String &p_raw_id); virtual QueryBuilder *like(const String &str = ""); //Object Already has set(), so think of it as set_sql virtual QueryBuilder *sets(); virtual QueryBuilder *cset(); virtual QueryBuilder *setps(const String &col, const String ¶m); 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 *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 ¶m); 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 *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 ¶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); //note col is NOT escaped virtual QueryBuilder *nsetp(const String &col, const String &escape_param); //note col is NOT escaped virtual QueryBuilder *nwp(const String &col, const String &escape_param); virtual QueryBuilder *limit(const int num); virtual QueryBuilder *offset(const int num); virtual QueryBuilder *order_by_asc(const String &col); virtual QueryBuilder *order_by_desc(const String &col); virtual QueryBuilder *order_by(const String &col = ""); virtual QueryBuilder *corder_by(); virtual QueryBuilder *order_by_add_col(const String &col); virtual QueryBuilder *asc(const String &col = ""); virtual QueryBuilder *desc(const String &col = ""); //l=logical (and, or are operators) virtual QueryBuilder *land(); virtual QueryBuilder *lor(); virtual QueryBuilder *wildcard(); // Prepared statement placeholders virtual QueryBuilder *psph(); virtual QueryBuilder *psphi(const String &p_id); virtual QueryBuilder *psphr(const String &p_raw_id); virtual QueryBuilder *w(const String &str); virtual QueryBuilder *ew(const String &str); virtual QueryBuilder *select_last_insert_id(); virtual String escape(const String ¶ms); virtual QueryBuilder *end_command(); virtual QueryBuilder *reset(); virtual Ref run(); virtual void run_query(); virtual Ref create_prepared_statement(); void print(); QueryBuilder(); virtual ~QueryBuilder(); protected: static void _bind_methods(); Ref _cvalues_bind(); Ref _next_value_bind(); Ref _begin_transaction_bind(); Ref _commit_bind(); Ref _nl_bind(); Ref _str_bind(); Ref _cstr_bind(); Ref _select_bind(const String ¶ms); Ref _update_bind(const String ¶ms); Ref _del_bind(const String ¶ms); Ref _where_bind(const String ¶ms = ""); Ref _from_bind(const String ¶ms = ""); Ref _insert_bind(const String &table_name = "", const String &columns = ""); Ref _values_bind(const String ¶ms_str = ""); Ref _val_bind(); Ref _vals_bind(const String ¶m); Ref _vali_bind(const int param); Ref _valb_bind(const bool param); Ref _valf_bind(const float param); Ref _vald_bind(const double param); Ref _valph_bind(); Ref _valphi_bind(const String &p_id); Ref _valphr_bind(const String &p_raw_id); Ref _like_bind(const String &str); Ref _sets_bind(); Ref _cset_bind(); Ref _setps_bind(const String &col, const String ¶m); Ref _setpi_bind(const String &col, const int param); Ref _setpb_bind(const String &col, const bool param); Ref _setpf_bind(const String &col, const float param); Ref _setpd_bind(const String &col, const double param); Ref _setph_bind(const String &col); Ref _setphi_bind(const String &col, const String &p_id); Ref _setphr_bind(const String &col, const String &p_raw_id); Ref _wps_bind(const String &col, const String ¶m); Ref _wpi_bind(const String &col, const int param); Ref _wpb_bind(const String &col, const bool param); Ref _wph_bind(const String &col); Ref _wphi_bind(const String &col, const String &p_id); Ref _wphr_bind(const String &col, const String &p_raw_id); Ref _nselect_bind(const String ¶ms); Ref _nupdate_bind(const String ¶ms); Ref _ndel_bind(const String ¶ms); Ref _nwhere_bind(const String ¶ms); Ref _nfrom_bind(const String ¶ms); Ref _nlike_bind(const String &str); Ref _nvalues_bind(const String ¶ms_str); Ref _nval_bind(const String ¶m); //note col is NOT escaped Ref _nsetp_bind(const String &col, const String &escape_param); //note col is NOT escaped Ref _nwp_bind(const String &col, const String &escape_param); Ref _limit_bind(const int num); Ref _offset_bind(const int num); Ref _order_by_asc_bind(const String &col); Ref _order_by_desc_bind(const String &col); Ref _order_by_bind(const String &col = ""); Ref _corder_by_bind(); Ref _order_by_add_col_bind(const String &col); Ref _asc_bind(const String &col = ""); Ref _desc_bind(const String &col = ""); //l=logical (and, or are operators) Ref _land_bind(); Ref _lor_bind(); Ref _wildcard_bind(); // Prepared statement placeholders Ref _psph_bind(); Ref _psphi_bind(const String &p_id); Ref _psphr_bind(const String &p_raw_id); Ref _w_bind(const String &str); Ref _ew_bind(const String &str); Ref _select_last_insert_id_bind(); Ref _end_command_bind(); Ref _reset_bind(); StringBuilder query_result; }; #endif