rcpp_framework/database/mysql/mysql_query_builder.cpp

134 lines
2.5 KiB
C++
Raw Normal View History

2020-12-01 22:23:28 +01:00
#include "mysql_query_builder.h"
#include "mysql_database.h"
#include "mysql_query_result.h"
QueryBuilder *MysqlQueryBuilder::select() {
query_result += "SELECT ";
return this;
}
QueryBuilder *MysqlQueryBuilder::where() {
query_result += "WHERE ";
return this;
}
QueryBuilder *MysqlQueryBuilder::from() {
query_result += "FROM ";
return this;
}
QueryBuilder *MysqlQueryBuilder::insert() {
query_result += "INSERT INTO ";
return this;
}
QueryBuilder *MysqlQueryBuilder::values() {
query_result += "VALUES(";
return this;
}
QueryBuilder *MysqlQueryBuilder::cvalues() {
query_result += ") ";
return this;
}
2020-12-01 22:23:28 +01:00
2021-11-01 17:31:04 +01:00
QueryBuilder *MysqlQueryBuilder::nselect(const String &params) {
query_result += "SELECT " + params + " ";
return this;
}
2021-11-01 17:31:04 +01:00
QueryBuilder *MysqlQueryBuilder::nwhere(const String &params) {
query_result += "WHERE " + params + " ";
return this;
}
2021-11-01 17:31:04 +01:00
QueryBuilder *MysqlQueryBuilder::nfrom(const String &params) {
query_result += "FROM " + params + " ";
return this;
}
2021-11-01 17:31:04 +01:00
QueryBuilder *MysqlQueryBuilder::ninsert(const String &table_name) {
query_result += "INSERT INTO " + table_name + " ";
return this;
}
2021-11-01 17:31:04 +01:00
QueryBuilder *MysqlQueryBuilder::nvalues(const String &params_str) {
query_result += "VALUES(" + params_str + ") ";
return this;
}
2021-11-01 17:31:04 +01:00
String MysqlQueryBuilder::escape(const String &params) {
if (!_db) {
printf("MysqlQueryBuilder::escape !db!\n");
return "";
}
return _db->escape(params);
}
QueryBuilder *MysqlQueryBuilder::prepare() {
return this;
}
2021-11-01 17:31:04 +01:00
QueryBuilder *MysqlQueryBuilder::set_param(const int index, const String &value) {
return this;
}
QueryBuilder *MysqlQueryBuilder::set_param(const int index, const int value) {
return this;
}
QueryBuilder *MysqlQueryBuilder::set_param(const int index, const float value) {
return this;
2020-12-01 22:23:28 +01:00
}
void MysqlQueryBuilder::end_command() {
2020-12-01 22:23:28 +01:00
query_result += ";";
}
Ref<QueryResult> MysqlQueryBuilder::run() {
2021-08-19 22:03:22 +02:00
end_command();
if (!_db) {
printf("MysqlQueryBuilder::run !db!\n");
return nullptr;
}
return _db->query(query_result);
}
2021-08-19 22:03:22 +02:00
void MysqlQueryBuilder::run_query() {
end_command();
if (!_db) {
printf("MysqlQueryBuilder::run_query !db!\n");
return;
}
_db->query_run(query_result);
2021-08-19 22:03:22 +02:00
}
QueryBuilder *MysqlQueryBuilder::limit(const int num) {
//query_result += "LIMIT " + num + " ";
2021-08-19 22:03:22 +02:00
return this;
}
QueryBuilder *MysqlQueryBuilder::offset(const int num) {
//query_result += "OFFSET " + num + " ";
2021-08-19 22:03:22 +02:00
return this;
}
MysqlQueryBuilder::MysqlQueryBuilder() {
}
MysqlQueryBuilder::~MysqlQueryBuilder() {
2020-12-01 22:23:28 +01:00
}