mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2024-11-14 04:57:21 +01:00
Now the mysql query builder is usable.
This commit is contained in:
parent
8b4efc530d
commit
7a81053ebb
@ -5,10 +5,10 @@ void Database::connect(const std::string &connection_str) {
|
||||
|
||||
void Database::query(const std::string &query) {
|
||||
}
|
||||
/*
|
||||
std::shared_ptr<QueryBuilder> Database::get_builder() {
|
||||
return std::shared_ptr<QueryBuilder>();
|
||||
}*/
|
||||
|
||||
QueryBuilder *Database::get_builder() {
|
||||
return new QueryBuilder();
|
||||
}
|
||||
|
||||
Database::Database() {
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ public:
|
||||
virtual void connect(const std::string &connection_str);
|
||||
virtual void query(const std::string &query);
|
||||
|
||||
//virtual std::shared_ptr<QueryBuilder> get_builder();
|
||||
virtual QueryBuilder *get_builder();
|
||||
|
||||
Database();
|
||||
~Database();
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include "query_builder.h"
|
||||
|
||||
/*
|
||||
QueryBuilder *QueryBuilder::select(const std::string ¶ms) {
|
||||
return this;
|
||||
}
|
||||
@ -20,7 +19,10 @@ QueryBuilder *QueryBuilder::limit(const int min, const int max) {
|
||||
QueryBuilder *QueryBuilder::insert(const std::string &table_name, const std::string ¶ms_str) {
|
||||
return this;
|
||||
}
|
||||
*/
|
||||
|
||||
void QueryBuilder::finalize() {
|
||||
}
|
||||
|
||||
QueryBuilder::QueryBuilder() {
|
||||
}
|
||||
|
||||
|
@ -5,13 +5,13 @@
|
||||
|
||||
class QueryBuilder {
|
||||
public:
|
||||
/*
|
||||
virtual QueryBuilder *select(const std::string ¶ms);
|
||||
virtual QueryBuilder *where(const std::string ¶ms);
|
||||
virtual QueryBuilder *from(const std::string ¶ms);
|
||||
virtual QueryBuilder *limit(const int min, const int max);
|
||||
virtual QueryBuilder *insert(const std::string &table_name, const std::string ¶ms_str);
|
||||
*/
|
||||
virtual void finalize();
|
||||
|
||||
QueryBuilder();
|
||||
virtual ~QueryBuilder();
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include "core/database_manager.h"
|
||||
|
||||
#include "mysql_query_builder.h"
|
||||
|
||||
void MysqlDatabase::connect(const std::string &connection_str) {
|
||||
mysql = mysql_init(mysql);
|
||||
@ -52,16 +53,14 @@ void MysqlDatabase::query(const std::string &query) {
|
||||
mysql_free_result(result);
|
||||
}
|
||||
|
||||
/*
|
||||
std::shared_ptr<QueryBuilder> MysqlDatabase::get_builder() {
|
||||
//return std::make_shared<MysqlQueryBuilder>();
|
||||
return nullptr;
|
||||
|
||||
QueryBuilder *MysqlDatabase::get_builder() {
|
||||
return new MysqlQueryBuilder();
|
||||
}
|
||||
*/
|
||||
|
||||
MysqlDatabase::MysqlDatabase() :
|
||||
Database() {
|
||||
|
||||
//mysql = new MYSQL();
|
||||
mysql = nullptr;
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ public:
|
||||
void connect(const std::string &connection_str);
|
||||
void query(const std::string &query);
|
||||
|
||||
//virtual std::shared_ptr<QueryBuilder> get_builder();
|
||||
QueryBuilder *get_builder();
|
||||
|
||||
static Database *_creation_func();
|
||||
static void _register();
|
||||
|
@ -1,7 +1,7 @@
|
||||
//#include "mysql_query_builder.h"
|
||||
#include "mysql_query_builder.h"
|
||||
|
||||
/*
|
||||
QueryBuilder *QueryBuilder::select(const std::string ¶ms) {
|
||||
|
||||
QueryBuilder *MysqlQueryBuilder::select(const std::string ¶ms) {
|
||||
query_result += "SELECT " + params;
|
||||
|
||||
return this;
|
||||
@ -25,12 +25,15 @@ QueryBuilder *MysqlQueryBuilder::limit(const int min, const int max) {
|
||||
|
||||
QueryBuilder *MysqlQueryBuilder::insert(const std::string &table_name, const std::string ¶ms_str) {
|
||||
return this;
|
||||
}*/
|
||||
}
|
||||
|
||||
void MysqlQueryBuilder::finalize() {
|
||||
query_result += ";";
|
||||
}
|
||||
|
||||
/*
|
||||
MysqlQueryBuilder::MysqlQueryBuilder() {
|
||||
|
||||
}
|
||||
MysqlQueryBuilder::~MysqlQueryBuilder() {
|
||||
|
||||
}*/
|
||||
}
|
@ -1,20 +1,20 @@
|
||||
#ifndef MYSQL_QUERY_BUILDER_H
|
||||
#define MYSQL_QUERY_BUILDER_H
|
||||
|
||||
#include "core/query_builder.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "core/query_builder.h"
|
||||
|
||||
class MysqlQueryBuilder : public QueryBuilder {
|
||||
public:
|
||||
/*
|
||||
QueryBuilder *select(const std::string ¶ms);
|
||||
QueryBuilder *where(const std::string ¶ms);
|
||||
QueryBuilder *from(const std::string ¶ms);
|
||||
QueryBuilder *limit(const int min, const int max);
|
||||
QueryBuilder *insert(const std::string &table_name, const std::string ¶ms_str);
|
||||
*/
|
||||
void finalize();
|
||||
|
||||
MysqlQueryBuilder();
|
||||
~MysqlQueryBuilder();
|
||||
};
|
||||
|
6
main.cpp
6
main.cpp
@ -11,8 +11,6 @@
|
||||
|
||||
#include "database/db_init.h"
|
||||
|
||||
//#include "database/mysql/mysql_query_builder.h"
|
||||
|
||||
#define MAIN_CLASS RDNApplication
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
@ -29,10 +27,6 @@ int main(int argc, char **argv) {
|
||||
//db->_builder_creation_func = MysqlQueryBuilder::create;
|
||||
db->connect("");
|
||||
|
||||
//MysqlQueryBuilder * b = new MysqlQueryBuilder();
|
||||
|
||||
|
||||
|
||||
Application *app = new MAIN_CLASS();
|
||||
|
||||
app->setup_routes();
|
||||
|
@ -2,10 +2,20 @@
|
||||
|
||||
#include "core/database.h"
|
||||
|
||||
#include "core/query_builder.h"
|
||||
|
||||
void MessagePage::index(Request *request) {
|
||||
QueryBuilder *b = db->get_builder();
|
||||
|
||||
b->select("*")->from("tutorials_tbl")->finalize();
|
||||
|
||||
db->query(b->query_result);
|
||||
|
||||
/*
|
||||
db->query("show databases;");
|
||||
db->query("show tables;");
|
||||
db->query("SELECT * FROM tutorials_tbl;");
|
||||
*/
|
||||
|
||||
std::string r = "<html><body>";
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user