diff --git a/core/database/query_builder.cpp b/core/database/query_builder.cpp index 0434d50..5d51b5d 100644 --- a/core/database/query_builder.cpp +++ b/core/database/query_builder.cpp @@ -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 ¶ms) { 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 ¶ms_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 + " "; diff --git a/core/database/query_builder.h b/core/database/query_builder.h index eff00b8..f6ac0e1 100644 --- a/core/database/query_builder.h +++ b/core/database/query_builder.h @@ -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 ¶ms); virtual QueryBuilder *udpate(const std::string ¶ms); virtual QueryBuilder *del(const std::string ¶ms); @@ -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 ¶ms); virtual QueryBuilder *efrom(const std::string ¶ms); virtual QueryBuilder *einsert(const std::string &table_name); + virtual QueryBuilder *elike(const std::string &str); virtual QueryBuilder *evalues(const std::string ¶ms_str); virtual QueryBuilder *eval(const std::string ¶m); //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); diff --git a/database/sqlite/sqlite3_query_builder.cpp b/database/sqlite/sqlite3_query_builder.cpp index 8786989..cacd9a1 100644 --- a/database/sqlite/sqlite3_query_builder.cpp +++ b/database/sqlite/sqlite3_query_builder.cpp @@ -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 ¶ms) { 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 ¶ms) { if (!_db) { printf("SQLite3QueryBuilder::escape !db!\n"); diff --git a/database/sqlite/sqlite3_query_builder.h b/database/sqlite/sqlite3_query_builder.h index 4c827e4..2739d62 100644 --- a/database/sqlite/sqlite3_query_builder.h +++ b/database/sqlite/sqlite3_query_builder.h @@ -20,6 +20,11 @@ public: QueryBuilder *values(); QueryBuilder *cvalues(); + QueryBuilder *str(); + QueryBuilder *cstr(); + + QueryBuilder *like(); + QueryBuilder *select(const std::string ¶ms); QueryBuilder *udpate(const std::string ¶ms); QueryBuilder *del(const std::string ¶ms); @@ -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 ¶m); @@ -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();