Added more things to QueryBuilder.

This commit is contained in:
Relintai 2021-08-22 21:44:20 +02:00
parent d2cff831bd
commit 928475d733
4 changed files with 72 additions and 2 deletions

View File

@ -29,6 +29,17 @@ QueryBuilder *QueryBuilder::cvalues() {
return this;
}
QueryBuilder *QueryBuilder::str() {
return this;
}
QueryBuilder *QueryBuilder::cstr() {
return this;
}
QueryBuilder *QueryBuilder::like() {
return this;
}
QueryBuilder *QueryBuilder::select(const std::string &params) {
return this;
}
@ -75,6 +86,10 @@ QueryBuilder *QueryBuilder::val(const bool param) {
return this;
}
QueryBuilder *QueryBuilder::like(const std::string &str) {
return this;
}
QueryBuilder *QueryBuilder::set() {
return this;
}
@ -128,6 +143,9 @@ QueryBuilder *QueryBuilder::einsert(const std::string &table_name) {
return this;
}
QueryBuilder *QueryBuilder::elike(const std::string &str) {
return like(escape(str));
}
QueryBuilder *QueryBuilder::evalues(const std::string &params_str) {
return values(escape(params_str));
}
@ -158,6 +176,10 @@ QueryBuilder *QueryBuilder::lor() {
return this;
}
QueryBuilder *QueryBuilder::wildcard() {
return this;
}
QueryBuilder *QueryBuilder::w(const std::string &str) {
query_result += str + " ";

View File

@ -21,6 +21,11 @@ public:
virtual QueryBuilder *values();
virtual QueryBuilder *cvalues();
virtual QueryBuilder *str();
virtual QueryBuilder *cstr();
virtual QueryBuilder *like();
virtual QueryBuilder *select(const std::string &params);
virtual QueryBuilder *udpate(const std::string &params);
virtual QueryBuilder *del(const std::string &params);
@ -36,6 +41,8 @@ public:
virtual QueryBuilder *val(const int param);
virtual QueryBuilder *val(const bool param);
virtual QueryBuilder *like(const std::string &str);
virtual QueryBuilder *set();
virtual QueryBuilder *cset();
@ -56,6 +63,7 @@ public:
virtual QueryBuilder *ewhere(const std::string &params);
virtual QueryBuilder *efrom(const std::string &params);
virtual QueryBuilder *einsert(const std::string &table_name);
virtual QueryBuilder *elike(const std::string &str);
virtual QueryBuilder *evalues(const std::string &params_str);
virtual QueryBuilder *eval(const std::string &param);
//note col is NOT escaped
@ -70,6 +78,8 @@ public:
virtual QueryBuilder *land();
virtual QueryBuilder *lor();
virtual QueryBuilder *wildcard();
virtual QueryBuilder *w(const std::string &str);
virtual QueryBuilder *ew(const std::string &str);

View File

@ -48,6 +48,23 @@ QueryBuilder *SQLite3QueryBuilder::cvalues() {
return this;
}
QueryBuilder *SQLite3QueryBuilder::str() {
query_result += "'";
return this;
}
QueryBuilder *SQLite3QueryBuilder::cstr() {
query_result += "'";
return this;
}
QueryBuilder *SQLite3QueryBuilder::like() {
query_result += "LIKE ";
return this;
}
QueryBuilder *SQLite3QueryBuilder::select(const std::string &params) {
query_result += "SELECT " + params + " ";
@ -128,6 +145,12 @@ QueryBuilder *SQLite3QueryBuilder::val(const bool param) {
return this;
}
QueryBuilder *SQLite3QueryBuilder::like(const std::string &str) {
query_result += "LIKE '" + str + "' ";
return this;
}
QueryBuilder *SQLite3QueryBuilder::set() {
query_result += "SET ";
@ -225,6 +248,12 @@ QueryBuilder *SQLite3QueryBuilder::lor() {
return this;
}
QueryBuilder *SQLite3QueryBuilder::wildcard() {
query_result += "%";
return this;
}
std::string SQLite3QueryBuilder::escape(const std::string &params) {
if (!_db) {
printf("SQLite3QueryBuilder::escape !db!\n");

View File

@ -20,6 +20,11 @@ public:
QueryBuilder *values();
QueryBuilder *cvalues();
QueryBuilder *str();
QueryBuilder *cstr();
QueryBuilder *like();
QueryBuilder *select(const std::string &params);
QueryBuilder *udpate(const std::string &params);
QueryBuilder *del(const std::string &params);
@ -35,6 +40,8 @@ public:
QueryBuilder *val(const int param);
QueryBuilder *val(const bool param);
QueryBuilder *like(const std::string &str);
QueryBuilder *set();
QueryBuilder *cset();
QueryBuilder *setp(const std::string &col, const std::string &param);
@ -51,8 +58,10 @@ public:
QueryBuilder *offset(const int num);
//l=logical (and, or are operators)
virtual QueryBuilder *land();
virtual QueryBuilder *lor();
QueryBuilder *land();
QueryBuilder *lor();
QueryBuilder *wildcard();
QueryBuilder *select_last_insert_id();