Now QueryBuilder is using my string.

This commit is contained in:
Relintai 2021-11-01 17:31:04 +01:00
parent cfb5f877c8
commit faac12d3b1
8 changed files with 136 additions and 127 deletions

View File

@ -40,30 +40,30 @@ QueryBuilder *QueryBuilder::like() {
return this;
}
QueryBuilder *QueryBuilder::select(const std::string &params) {
QueryBuilder *QueryBuilder::select(const String &params) {
return nselect(escape(params));
}
QueryBuilder *QueryBuilder::update(const std::string &params) {
QueryBuilder *QueryBuilder::update(const String &params) {
return nupdate(escape(params));
}
QueryBuilder *QueryBuilder::del(const std::string &params) {
QueryBuilder *QueryBuilder::del(const String &params) {
return ndel(escape(params));
}
QueryBuilder *QueryBuilder::where(const std::string &params) {
QueryBuilder *QueryBuilder::where(const String &params) {
return nwhere(escape(params));
}
QueryBuilder *QueryBuilder::from(const std::string &params) {
QueryBuilder *QueryBuilder::from(const String &params) {
return nfrom(escape(params));
}
QueryBuilder *QueryBuilder::insert(const std::string &table_name) {
QueryBuilder *QueryBuilder::insert(const String &table_name) {
return this;
}
QueryBuilder *QueryBuilder::insert(const std::string &table_name, const std::string &columns) {
QueryBuilder *QueryBuilder::insert(const String &table_name, const String &columns) {
return this;
}
QueryBuilder *QueryBuilder::values(const std::string &params_str) {
QueryBuilder *QueryBuilder::values(const String &params_str) {
return nvalues(escape(params_str));
}
@ -71,7 +71,7 @@ QueryBuilder *QueryBuilder::val() {
return this;
}
QueryBuilder *QueryBuilder::val(const std::string &param) {
QueryBuilder *QueryBuilder::val(const String &param) {
return nval(escape(param));
}
@ -86,7 +86,7 @@ QueryBuilder *QueryBuilder::val(const bool param) {
return this;
}
QueryBuilder *QueryBuilder::like(const std::string &str) {
QueryBuilder *QueryBuilder::like(const String &str) {
return nlike(escape(str));
}
@ -96,63 +96,63 @@ QueryBuilder *QueryBuilder::set() {
QueryBuilder *QueryBuilder::cset() {
return this;
}
QueryBuilder *QueryBuilder::setp(const std::string &col, const std::string &param) {
QueryBuilder *QueryBuilder::setp(const String &col, const String &param) {
return nsetp(col, escape(param));
}
QueryBuilder *QueryBuilder::setp(const std::string &col, const char *param) {
QueryBuilder *QueryBuilder::setp(const String &col, const char *param) {
return this;
}
QueryBuilder *QueryBuilder::setp(const std::string &col, const int param) {
QueryBuilder *QueryBuilder::setp(const String &col, const int param) {
return this;
}
QueryBuilder *QueryBuilder::setp(const std::string &col, const bool param) {
QueryBuilder *QueryBuilder::setp(const String &col, const bool param) {
return this;
}
QueryBuilder *QueryBuilder::wp(const std::string &col, const std::string &param) {
QueryBuilder *QueryBuilder::wp(const String &col, const String &param) {
return nwp(col, escape(param));
}
QueryBuilder *QueryBuilder::wp(const std::string &col, const char *param) {
QueryBuilder *QueryBuilder::wp(const String &col, const char *param) {
return this;
}
QueryBuilder *QueryBuilder::wp(const std::string &col, const int param) {
QueryBuilder *QueryBuilder::wp(const String &col, const int param) {
return this;
}
QueryBuilder *QueryBuilder::wp(const std::string &col, const bool param) {
QueryBuilder *QueryBuilder::wp(const String &col, const bool param) {
return this;
}
QueryBuilder *QueryBuilder::nselect(const std::string &params) {
QueryBuilder *QueryBuilder::nselect(const String &params) {
return this;
}
QueryBuilder *QueryBuilder::nupdate(const std::string &params) {
QueryBuilder *QueryBuilder::nupdate(const String &params) {
return this;
}
QueryBuilder *QueryBuilder::ndel(const std::string &params) {
QueryBuilder *QueryBuilder::ndel(const String &params) {
return this;
}
QueryBuilder *QueryBuilder::nwhere(const std::string &params) {
QueryBuilder *QueryBuilder::nwhere(const String &params) {
return this;
}
QueryBuilder *QueryBuilder::nfrom(const std::string &params) {
QueryBuilder *QueryBuilder::nfrom(const String &params) {
return this;
}
QueryBuilder *QueryBuilder::nlike(const std::string &str) {
QueryBuilder *QueryBuilder::nlike(const String &str) {
return this;
}
QueryBuilder *QueryBuilder::nvalues(const std::string &params_str) {
QueryBuilder *QueryBuilder::nvalues(const String &params_str) {
return this;
}
QueryBuilder *QueryBuilder::nval(const std::string &param) {
QueryBuilder *QueryBuilder::nval(const String &param) {
return val(escape(param));
}
QueryBuilder *QueryBuilder::nsetp(const std::string &col, const std::string &escape_param) {
QueryBuilder *QueryBuilder::nsetp(const String &col, const String &escape_param) {
return setp(col, escape(escape_param));
}
QueryBuilder *QueryBuilder::nwp(const std::string &col, const std::string &escape_param) {
QueryBuilder *QueryBuilder::nwp(const String &col, const String &escape_param) {
return this;
}
@ -175,12 +175,12 @@ QueryBuilder *QueryBuilder::wildcard() {
return this;
}
QueryBuilder *QueryBuilder::w(const std::string &str) {
QueryBuilder *QueryBuilder::w(const String &str) {
query_result += str + " ";
return this;
}
QueryBuilder *QueryBuilder::ew(const std::string &str) {
QueryBuilder *QueryBuilder::ew(const String &str) {
return w(escape(str));
}
@ -188,14 +188,14 @@ QueryBuilder *QueryBuilder::select_last_insert_id() {
return this;
}
std::string QueryBuilder::escape(const std::string &params) {
String QueryBuilder::escape(const String &params) {
return params;
}
QueryBuilder *QueryBuilder::prepare() {
return this;
}
QueryBuilder *QueryBuilder::set_param(const int index, const std::string &value) {
QueryBuilder *QueryBuilder::set_param(const int index, const String &value) {
return this;
}
QueryBuilder *QueryBuilder::set_param(const int index, const int value) {
@ -221,7 +221,7 @@ Ref<QueryResult> QueryBuilder::run() {
void QueryBuilder::run_query() {
}
std::string QueryBuilder::get_result() {
String QueryBuilder::get_result() {
end_command();
return query_result;

View File

@ -1,7 +1,7 @@
#ifndef QUERY_BUILDER_H
#define QUERY_BUILDER_H
#include <string>
#include "core/string.h"
#include "core/reference.h"
@ -26,49 +26,49 @@ public:
virtual QueryBuilder *like();
virtual QueryBuilder *select(const std::string &params);
virtual QueryBuilder *update(const std::string &params);
virtual QueryBuilder *del(const std::string &params);
virtual QueryBuilder *select(const String &params);
virtual QueryBuilder *update(const String &params);
virtual QueryBuilder *del(const String &params);
virtual QueryBuilder *where(const std::string &params);
virtual QueryBuilder *from(const std::string &params);
virtual QueryBuilder *insert(const std::string &table_name);
virtual QueryBuilder *insert(const std::string &table_name, const std::string &columns);
virtual QueryBuilder *values(const std::string &params_str);
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 *values(const String &params_str);
virtual QueryBuilder *val();
virtual QueryBuilder *val(const std::string &param);
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 *like(const std::string &str);
virtual QueryBuilder *like(const String &str);
virtual QueryBuilder *set();
virtual QueryBuilder *cset();
virtual QueryBuilder *setp(const std::string &col, const std::string &param);
virtual QueryBuilder *setp(const std::string &col, const char *param);
virtual QueryBuilder *setp(const std::string &col, const int param);
virtual QueryBuilder *setp(const std::string &col, const bool param);
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 *wp(const std::string &col, const std::string &param);
virtual QueryBuilder *wp(const std::string &col, const char *param);
virtual QueryBuilder *wp(const std::string &col, const int param);
virtual QueryBuilder *wp(const std::string &col, const bool 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 *nselect(const std::string &params);
virtual QueryBuilder *nupdate(const std::string &params);
virtual QueryBuilder *ndel(const std::string &params);
virtual QueryBuilder *nselect(const String &params);
virtual QueryBuilder *nupdate(const String &params);
virtual QueryBuilder *ndel(const String &params);
virtual QueryBuilder *nwhere(const std::string &params);
virtual QueryBuilder *nfrom(const std::string &params);
virtual QueryBuilder *nlike(const std::string &str);
virtual QueryBuilder *nvalues(const std::string &params_str);
virtual QueryBuilder *nval(const std::string &param);
virtual QueryBuilder *nwhere(const String &params);
virtual QueryBuilder *nfrom(const String &params);
virtual QueryBuilder *nlike(const String &str);
virtual QueryBuilder *nvalues(const String &params_str);
virtual QueryBuilder *nval(const String &param);
//note col is NOT escaped
virtual QueryBuilder *nsetp(const std::string &col, const std::string &escape_param);
virtual QueryBuilder *nsetp(const String &col, const String &escape_param);
//note col is NOT escaped
virtual QueryBuilder *nwp(const std::string &col, const std::string &escape_param);
virtual QueryBuilder *nwp(const String &col, const String &escape_param);
virtual QueryBuilder *limit(const int num);
virtual QueryBuilder *offset(const int num);
@ -79,15 +79,15 @@ public:
virtual QueryBuilder *wildcard();
virtual QueryBuilder *w(const std::string &str);
virtual QueryBuilder *ew(const std::string &str);
virtual QueryBuilder *w(const String &str);
virtual QueryBuilder *ew(const String &str);
virtual QueryBuilder *select_last_insert_id();
virtual std::string escape(const std::string &params);
virtual String escape(const String &params);
virtual QueryBuilder *prepare();
virtual QueryBuilder *set_param(const int index, const std::string &value);
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);
@ -98,14 +98,14 @@ public:
virtual Ref<QueryResult> run();
virtual void run_query();
std::string get_result();
String get_result();
void print();
QueryBuilder();
virtual ~QueryBuilder();
std::string query_result;
String query_result;
};
#endif

View File

@ -461,7 +461,7 @@ const char String::operator[](const int index) const {
return _data[index];
}
char String::operator[](const int index) {
char &String::operator[](const int index) {
return _data[index];
}
@ -624,6 +624,14 @@ String& String::operator=(const std::string &other) {
return *this;
}
String& String::operator=(const char* other) {
clear();
append_str(other);
return *this;
}
String::String() {
_data = nullptr;
_actual_size = 0;

View File

@ -68,7 +68,7 @@ public:
const char *data() const;
const char operator[](const int index) const;
char operator[](const int index);
char &operator[](const int index);
String &operator+=(const String &b);
String &operator+=(const char chr);
@ -100,6 +100,7 @@ public:
String& operator=(const String &other);
String& operator=(const std::string &other);
String& operator=(const char* other);
String();
String(const String &other);

View File

@ -34,37 +34,37 @@ QueryBuilder *MysqlQueryBuilder::cvalues() {
return this;
}
QueryBuilder *MysqlQueryBuilder::nselect(const std::string &params) {
QueryBuilder *MysqlQueryBuilder::nselect(const String &params) {
query_result += "SELECT " + params + " ";
return this;
}
QueryBuilder *MysqlQueryBuilder::nwhere(const std::string &params) {
QueryBuilder *MysqlQueryBuilder::nwhere(const String &params) {
query_result += "WHERE " + params + " ";
return this;
}
QueryBuilder *MysqlQueryBuilder::nfrom(const std::string &params) {
QueryBuilder *MysqlQueryBuilder::nfrom(const String &params) {
query_result += "FROM " + params + " ";
return this;
}
QueryBuilder *MysqlQueryBuilder::ninsert(const std::string &table_name) {
QueryBuilder *MysqlQueryBuilder::ninsert(const String &table_name) {
query_result += "INSERT INTO " + table_name + " ";
return this;
}
QueryBuilder *MysqlQueryBuilder::nvalues(const std::string &params_str) {
QueryBuilder *MysqlQueryBuilder::nvalues(const String &params_str) {
query_result += "VALUES(" + params_str + ") ";
return this;
}
std::string MysqlQueryBuilder::escape(const std::string &params) {
String MysqlQueryBuilder::escape(const String &params) {
if (!_db) {
printf("MysqlQueryBuilder::escape !db!\n");
@ -78,7 +78,7 @@ QueryBuilder *MysqlQueryBuilder::prepare() {
return this;
}
QueryBuilder *MysqlQueryBuilder::set_param(const int index, const std::string &value) {
QueryBuilder *MysqlQueryBuilder::set_param(const int index, const String &value) {
return this;
}
QueryBuilder *MysqlQueryBuilder::set_param(const int index, const int value) {

View File

@ -18,19 +18,19 @@ public:
QueryBuilder *values();
QueryBuilder *cvalues();
QueryBuilder *nselect(const std::string &params);
QueryBuilder *nwhere(const std::string &params);
QueryBuilder *nfrom(const std::string &params);
QueryBuilder *ninsert(const std::string &table_name);
QueryBuilder *nvalues(const std::string &params_str);
QueryBuilder *nselect(const String &params);
QueryBuilder *nwhere(const String &params);
QueryBuilder *nfrom(const String &params);
QueryBuilder *ninsert(const String &table_name);
QueryBuilder *nvalues(const String &params_str);
QueryBuilder *limit(const int num);
QueryBuilder *offset(const int num);
std::string escape(const std::string &params);
String escape(const String &params);
QueryBuilder *prepare();
QueryBuilder *set_param(const int index, const std::string &value);
QueryBuilder *set_param(const int index, const String &value);
QueryBuilder *set_param(const int index, const int value);
QueryBuilder *set_param(const int index, const float value);

View File

@ -65,45 +65,45 @@ QueryBuilder *SQLite3QueryBuilder::like() {
return this;
}
QueryBuilder *SQLite3QueryBuilder::nselect(const std::string &params) {
QueryBuilder *SQLite3QueryBuilder::nselect(const String &params) {
query_result += "SELECT " + params + " ";
return this;
}
QueryBuilder *SQLite3QueryBuilder::nupdate(const std::string &params) {
QueryBuilder *SQLite3QueryBuilder::nupdate(const String &params) {
query_result += "UPDATE " + params + " ";
return this;
}
QueryBuilder *SQLite3QueryBuilder::ndel(const std::string &params) {
QueryBuilder *SQLite3QueryBuilder::ndel(const String &params) {
query_result += "DELETE FROM " + params + " ";
return this;
}
QueryBuilder *SQLite3QueryBuilder::nwhere(const std::string &params) {
QueryBuilder *SQLite3QueryBuilder::nwhere(const String &params) {
query_result += "WHERE " + params + " ";
return this;
}
QueryBuilder *SQLite3QueryBuilder::nfrom(const std::string &params) {
QueryBuilder *SQLite3QueryBuilder::nfrom(const String &params) {
query_result += "FROM " + params + " ";
return this;
}
QueryBuilder *SQLite3QueryBuilder::insert(const std::string &table_name) {
QueryBuilder *SQLite3QueryBuilder::insert(const String &table_name) {
query_result += "INSERT INTO " + table_name + " ";
return this;
}
QueryBuilder *SQLite3QueryBuilder::insert(const std::string &table_name, const std::string &columns) {
QueryBuilder *SQLite3QueryBuilder::insert(const String &table_name, const String &columns) {
query_result += "INSERT INTO " + table_name + "(" + columns + ") ";
return this;
}
QueryBuilder *SQLite3QueryBuilder::nvalues(const std::string &params_str) {
QueryBuilder *SQLite3QueryBuilder::nvalues(const String &params_str) {
query_result += "VALUES(" + params_str + ") ";
return this;
@ -115,14 +115,14 @@ QueryBuilder *SQLite3QueryBuilder::val() {
return this;
}
QueryBuilder *SQLite3QueryBuilder::nval(const std::string &param) {
QueryBuilder *SQLite3QueryBuilder::nval(const String &param) {
query_result += "'" + param + "', ";
return this;
}
QueryBuilder *SQLite3QueryBuilder::val(const char *param) {
query_result += "'" + std::string(param) + "', ";
query_result += "'" + String(param) + "', ";
return this;
}
@ -145,7 +145,7 @@ QueryBuilder *SQLite3QueryBuilder::val(const bool param) {
return this;
}
QueryBuilder *SQLite3QueryBuilder::nlike(const std::string &str) {
QueryBuilder *SQLite3QueryBuilder::nlike(const String &str) {
query_result += "LIKE '" + str + "' ";
return this;
@ -161,17 +161,17 @@ QueryBuilder *SQLite3QueryBuilder::cset() {
return this;
}
QueryBuilder *SQLite3QueryBuilder::nsetp(const std::string &col, const std::string &param) {
QueryBuilder *SQLite3QueryBuilder::nsetp(const String &col, const String &param) {
query_result += col + "='" + param + "', ";
return this;
}
QueryBuilder *SQLite3QueryBuilder::setp(const std::string &col, const char *param) {
query_result += col + "='" + std::string(param) + "', ";
QueryBuilder *SQLite3QueryBuilder::setp(const String &col, const char *param) {
query_result += col + "='" + String(param) + "', ";
return this;
}
QueryBuilder *SQLite3QueryBuilder::setp(const std::string &col, const int param) {
QueryBuilder *SQLite3QueryBuilder::setp(const String &col, const int param) {
//todo add a better way
std::stringstream ss;
ss << param;
@ -180,7 +180,7 @@ QueryBuilder *SQLite3QueryBuilder::setp(const std::string &col, const int param)
return this;
}
QueryBuilder *SQLite3QueryBuilder::setp(const std::string &col, const bool param) {
QueryBuilder *SQLite3QueryBuilder::setp(const String &col, const bool param) {
if (param)
query_result += col + "=1, ";
else
@ -189,17 +189,17 @@ QueryBuilder *SQLite3QueryBuilder::setp(const std::string &col, const bool param
return this;
}
QueryBuilder *SQLite3QueryBuilder::nwp(const std::string &col, const std::string &param) {
QueryBuilder *SQLite3QueryBuilder::nwp(const String &col, const String &param) {
query_result += col + "='" + param + "' ";
return this;
}
QueryBuilder *SQLite3QueryBuilder::wp(const std::string &col, const char *param) {
query_result += col + "='" + std::string(param) + "' ";
QueryBuilder *SQLite3QueryBuilder::wp(const String &col, const char *param) {
query_result += col + "='" + String(param) + "' ";
return this;
}
QueryBuilder *SQLite3QueryBuilder::wp(const std::string &col, const int param) {
QueryBuilder *SQLite3QueryBuilder::wp(const String &col, const int param) {
//todo add a better way
std::stringstream ss;
ss << param;
@ -208,7 +208,7 @@ QueryBuilder *SQLite3QueryBuilder::wp(const std::string &col, const int param) {
return this;
}
QueryBuilder *SQLite3QueryBuilder::wp(const std::string &col, const bool param) {
QueryBuilder *SQLite3QueryBuilder::wp(const String &col, const bool param) {
if (param)
query_result += col + "=1 ";
else
@ -254,7 +254,7 @@ QueryBuilder *SQLite3QueryBuilder::wildcard() {
return this;
}
std::string SQLite3QueryBuilder::escape(const std::string &params) {
String SQLite3QueryBuilder::escape(const String &params) {
if (!_db) {
printf("SQLite3QueryBuilder::escape !db!\n");
@ -268,7 +268,7 @@ QueryBuilder *SQLite3QueryBuilder::prepare() {
return this;
}
QueryBuilder *SQLite3QueryBuilder::set_param(const int index, const std::string &value) {
QueryBuilder *SQLite3QueryBuilder::set_param(const int index, const String &value) {
return this;
}
QueryBuilder *SQLite3QueryBuilder::set_param(const int index, const int value) {

View File

@ -25,34 +25,34 @@ public:
QueryBuilder *like();
QueryBuilder *nselect(const std::string &params);
QueryBuilder *nupdate(const std::string &params);
QueryBuilder *ndel(const std::string &params);
QueryBuilder *nselect(const String &params);
QueryBuilder *nupdate(const String &params);
QueryBuilder *ndel(const String &params);
QueryBuilder *nwhere(const std::string &params);
QueryBuilder *nfrom(const std::string &params);
QueryBuilder *insert(const std::string &table_name);
QueryBuilder *insert(const std::string &table_name, const std::string &columns);
QueryBuilder *nvalues(const std::string &params_str);
QueryBuilder *nwhere(const String &params);
QueryBuilder *nfrom(const String &params);
QueryBuilder *insert(const String &table_name);
QueryBuilder *insert(const String &table_name, const String &columns);
QueryBuilder *nvalues(const String &params_str);
QueryBuilder *val();
QueryBuilder *nval(const std::string &param);
QueryBuilder *nval(const String &param);
QueryBuilder *val(const char *param);
QueryBuilder *val(const int param);
QueryBuilder *val(const bool param);
QueryBuilder *nlike(const std::string &str);
QueryBuilder *nlike(const String &str);
QueryBuilder *set();
QueryBuilder *cset();
QueryBuilder *nsetp(const std::string &col, const std::string &param);
QueryBuilder *setp(const std::string &col, const char *param);
QueryBuilder *setp(const std::string &col, const int param);
QueryBuilder *setp(const std::string &col, const bool param);
QueryBuilder *nsetp(const String &col, const String &param);
QueryBuilder *setp(const String &col, const char *param);
QueryBuilder *setp(const String &col, const int param);
QueryBuilder *setp(const String &col, const bool param);
QueryBuilder *nwp(const std::string &col, const std::string &param);
QueryBuilder *wp(const std::string &col, const char *param);
QueryBuilder *wp(const std::string &col, const int param);
QueryBuilder *wp(const std::string &col, const bool param);
QueryBuilder *nwp(const String &col, const String &param);
QueryBuilder *wp(const String &col, const char *param);
QueryBuilder *wp(const String &col, const int param);
QueryBuilder *wp(const String &col, const bool param);
QueryBuilder *limit(const int num);
QueryBuilder *offset(const int num);
@ -65,10 +65,10 @@ public:
QueryBuilder *select_last_insert_id();
std::string escape(const std::string &params);
String escape(const String &params);
QueryBuilder *prepare();
QueryBuilder *set_param(const int index, const std::string &value);
QueryBuilder *set_param(const int index, const String &value);
QueryBuilder *set_param(const int index, const int value);
QueryBuilder *set_param(const int index, const float value);