2022-06-30 13:23:48 +02:00
|
|
|
#ifndef QUERY_BUILDER_H
|
|
|
|
#define QUERY_BUILDER_H
|
|
|
|
|
2023-12-17 23:07:28 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* 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. */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2024-04-27 18:54:12 +02:00
|
|
|
#include "core/string/string_builder.h"
|
2024-04-27 20:37:23 +02:00
|
|
|
#include "core/string/ustring.h"
|
2022-06-30 13:23:48 +02:00
|
|
|
|
2022-08-17 13:45:14 +02:00
|
|
|
#include "core/object/reference.h"
|
2022-06-30 13:23:48 +02:00
|
|
|
|
|
|
|
class QueryResult;
|
2024-04-27 16:26:58 +02:00
|
|
|
class PreparedStatement;
|
2022-06-30 13:23:48 +02:00
|
|
|
|
|
|
|
//methods that start with an e escape their params.
|
|
|
|
|
|
|
|
class QueryBuilder : public Reference {
|
2022-07-05 20:34:12 +02:00
|
|
|
GDCLASS(QueryBuilder, Reference);
|
2022-06-30 13:23:48 +02:00
|
|
|
|
|
|
|
public:
|
2022-07-06 22:14:37 +02:00
|
|
|
String get_result();
|
|
|
|
void set_result(const String &val);
|
|
|
|
|
2022-06-30 13:23:48 +02:00
|
|
|
virtual QueryBuilder *select();
|
|
|
|
virtual QueryBuilder *update();
|
|
|
|
virtual QueryBuilder *del();
|
|
|
|
|
|
|
|
virtual QueryBuilder *cvalues();
|
|
|
|
virtual QueryBuilder *next_value();
|
2022-07-05 20:34:12 +02:00
|
|
|
|
2022-06-30 13:23:48 +02:00
|
|
|
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);
|
|
|
|
|
2022-07-05 23:05:07 +02:00
|
|
|
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 = "");
|
2022-06-30 13:23:48 +02:00
|
|
|
virtual QueryBuilder *val();
|
2022-07-05 20:34:12 +02:00
|
|
|
virtual QueryBuilder *vals(const String ¶m);
|
|
|
|
virtual QueryBuilder *vals(const char *param);
|
|
|
|
virtual QueryBuilder *vali(const int param);
|
|
|
|
virtual QueryBuilder *valb(const bool param);
|
2022-06-30 13:23:48 +02:00
|
|
|
virtual QueryBuilder *valf(const float param);
|
|
|
|
virtual QueryBuilder *vald(const double param);
|
2024-04-27 20:37:23 +02:00
|
|
|
virtual QueryBuilder *valph();
|
|
|
|
virtual QueryBuilder *valphi(const String &p_id);
|
|
|
|
virtual QueryBuilder *valphr(const String &p_raw_id);
|
2022-06-30 13:23:48 +02:00
|
|
|
|
2022-07-05 23:05:07 +02:00
|
|
|
virtual QueryBuilder *like(const String &str = "");
|
2022-06-30 13:23:48 +02:00
|
|
|
|
2022-07-05 23:05:07 +02:00
|
|
|
//Object Already has set(), so think of it as set_sql
|
|
|
|
virtual QueryBuilder *sets();
|
2022-06-30 13:23:48 +02:00
|
|
|
virtual QueryBuilder *cset();
|
|
|
|
|
2022-07-05 20:34:12 +02:00
|
|
|
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);
|
2022-06-30 13:23:48 +02:00
|
|
|
virtual QueryBuilder *setpf(const String &col, const float param);
|
|
|
|
virtual QueryBuilder *setpd(const String &col, const double param);
|
2024-04-27 20:37:23 +02:00
|
|
|
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);
|
2022-06-30 13:23:48 +02:00
|
|
|
|
2024-04-27 20:37:23 +02:00
|
|
|
// Where param helpers
|
2022-07-05 20:34:12 +02:00
|
|
|
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);
|
2024-04-27 20:37:23 +02:00
|
|
|
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);
|
2022-06-30 13:23:48 +02:00
|
|
|
|
|
|
|
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);
|
2022-07-05 23:05:07 +02:00
|
|
|
virtual QueryBuilder *order_by(const String &col = "");
|
2022-06-30 13:23:48 +02:00
|
|
|
|
|
|
|
virtual QueryBuilder *corder_by();
|
|
|
|
virtual QueryBuilder *order_by_add_col(const String &col);
|
2022-07-05 23:05:07 +02:00
|
|
|
virtual QueryBuilder *asc(const String &col = "");
|
|
|
|
virtual QueryBuilder *desc(const String &col = "");
|
2022-06-30 13:23:48 +02:00
|
|
|
|
|
|
|
//l=logical (and, or are operators)
|
|
|
|
virtual QueryBuilder *land();
|
|
|
|
virtual QueryBuilder *lor();
|
|
|
|
|
|
|
|
virtual QueryBuilder *wildcard();
|
|
|
|
|
2024-04-27 18:37:56 +02:00
|
|
|
// Prepared statement placeholders
|
|
|
|
virtual QueryBuilder *psph();
|
|
|
|
virtual QueryBuilder *psphi(const String &p_id);
|
|
|
|
virtual QueryBuilder *psphr(const String &p_raw_id);
|
|
|
|
|
2022-06-30 13:23:48 +02:00
|
|
|
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<QueryResult> run();
|
|
|
|
virtual void run_query();
|
|
|
|
|
2024-04-27 16:26:58 +02:00
|
|
|
virtual Ref<PreparedStatement> create_prepared_statement();
|
|
|
|
|
2022-06-30 13:23:48 +02:00
|
|
|
void print();
|
|
|
|
|
|
|
|
QueryBuilder();
|
|
|
|
virtual ~QueryBuilder();
|
|
|
|
|
2022-07-05 20:34:12 +02:00
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
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> _select_bind(const String ¶ms);
|
|
|
|
Ref<QueryBuilder> _update_bind(const String ¶ms);
|
|
|
|
Ref<QueryBuilder> _del_bind(const String ¶ms);
|
|
|
|
|
2022-07-05 23:05:07 +02:00
|
|
|
Ref<QueryBuilder> _where_bind(const String ¶ms = "");
|
|
|
|
Ref<QueryBuilder> _from_bind(const String ¶ms = "");
|
|
|
|
Ref<QueryBuilder> _insert_bind(const String &table_name = "", const String &columns = "");
|
|
|
|
Ref<QueryBuilder> _values_bind(const String ¶ms_str = "");
|
2022-07-05 20:34:12 +02:00
|
|
|
Ref<QueryBuilder> _val_bind();
|
|
|
|
Ref<QueryBuilder> _vals_bind(const String ¶m);
|
|
|
|
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);
|
2024-04-27 20:37:23 +02:00
|
|
|
Ref<QueryBuilder> _valph_bind();
|
|
|
|
Ref<QueryBuilder> _valphi_bind(const String &p_id);
|
|
|
|
Ref<QueryBuilder> _valphr_bind(const String &p_raw_id);
|
2022-07-05 20:34:12 +02:00
|
|
|
|
|
|
|
Ref<QueryBuilder> _like_bind(const String &str);
|
|
|
|
|
2022-07-05 23:05:07 +02:00
|
|
|
Ref<QueryBuilder> _sets_bind();
|
2022-07-05 20:34:12 +02:00
|
|
|
Ref<QueryBuilder> _cset_bind();
|
|
|
|
|
|
|
|
Ref<QueryBuilder> _setps_bind(const String &col, const String ¶m);
|
|
|
|
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);
|
2024-04-27 20:37:23 +02:00
|
|
|
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);
|
2022-07-05 20:34:12 +02:00
|
|
|
|
|
|
|
Ref<QueryBuilder> _wps_bind(const String &col, const String ¶m);
|
|
|
|
Ref<QueryBuilder> _wpi_bind(const String &col, const int param);
|
|
|
|
Ref<QueryBuilder> _wpb_bind(const String &col, const bool param);
|
2024-04-27 20:37:23 +02:00
|
|
|
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);
|
2022-07-05 20:34:12 +02:00
|
|
|
|
|
|
|
Ref<QueryBuilder> _nselect_bind(const String ¶ms);
|
|
|
|
Ref<QueryBuilder> _nupdate_bind(const String ¶ms);
|
|
|
|
Ref<QueryBuilder> _ndel_bind(const String ¶ms);
|
|
|
|
|
|
|
|
Ref<QueryBuilder> _nwhere_bind(const String ¶ms);
|
|
|
|
Ref<QueryBuilder> _nfrom_bind(const String ¶ms);
|
|
|
|
Ref<QueryBuilder> _nlike_bind(const String &str);
|
|
|
|
Ref<QueryBuilder> _nvalues_bind(const String ¶ms_str);
|
|
|
|
Ref<QueryBuilder> _nval_bind(const String ¶m);
|
|
|
|
//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);
|
2022-07-05 23:05:07 +02:00
|
|
|
Ref<QueryBuilder> _order_by_bind(const String &col = "");
|
2022-07-05 20:34:12 +02:00
|
|
|
|
|
|
|
Ref<QueryBuilder> _corder_by_bind();
|
|
|
|
Ref<QueryBuilder> _order_by_add_col_bind(const String &col);
|
2022-07-05 23:05:07 +02:00
|
|
|
Ref<QueryBuilder> _asc_bind(const String &col = "");
|
|
|
|
Ref<QueryBuilder> _desc_bind(const String &col = "");
|
2022-07-05 20:34:12 +02:00
|
|
|
|
|
|
|
//l=logical (and, or are operators)
|
|
|
|
Ref<QueryBuilder> _land_bind();
|
|
|
|
Ref<QueryBuilder> _lor_bind();
|
|
|
|
|
|
|
|
Ref<QueryBuilder> _wildcard_bind();
|
|
|
|
|
2024-04-27 18:37:56 +02:00
|
|
|
// Prepared statement placeholders
|
|
|
|
Ref<QueryBuilder> _psph_bind();
|
|
|
|
Ref<QueryBuilder> _psphi_bind(const String &p_id);
|
|
|
|
Ref<QueryBuilder> _psphr_bind(const String &p_raw_id);
|
2024-04-27 18:39:31 +02:00
|
|
|
|
2022-07-05 20:34:12 +02:00
|
|
|
Ref<QueryBuilder> _w_bind(const String &str);
|
|
|
|
Ref<QueryBuilder> _ew_bind(const String &str);
|
|
|
|
|
|
|
|
Ref<QueryBuilder> _select_last_insert_id_bind();
|
|
|
|
|
|
|
|
Ref<QueryBuilder> _end_command_bind();
|
|
|
|
|
|
|
|
Ref<QueryBuilder> _reset_bind();
|
2024-04-27 18:39:31 +02:00
|
|
|
|
2024-04-27 18:54:12 +02:00
|
|
|
StringBuilder query_result;
|
2022-06-30 13:23:48 +02:00
|
|
|
};
|
|
|
|
|
2022-07-05 20:34:12 +02:00
|
|
|
#endif
|