#include "message_page.h" #include "core/database.h" #include "core/query_builder.h" #include "core/table_builder.h" #include "core/query_result.h" void MessagePage::index(Request *request) { QueryBuilder *b = db->get_query_builder(); b->select("text")->from("message_page")->finalize(); QueryResult *res = db->query(b->query_result); std::vector msgs; if (res) { while (res->next_row()) { msgs.push_back(res->get_cell(0)); } } delete res; delete b; std::string r = ""; for (uint32_t i = 0; i < messages.size(); ++i) { r += "

" + messages[i] + "


"; } for (uint32_t i = 0; i < msgs.size(); ++i) { r += "

" + msgs[i] + "


"; } r += ""; request->response->setBody(r); request->send(); } void MessagePage::migrate() { TableBuilder *t = db->get_table_builder(); t->create_table("message_page")->integer("id")->auto_increment()->primary_key()->next_row()->varchar("text", 30)->finalize(); printf("%s\n", t->result.c_str()); db->query(t->result); QueryBuilder *b = db->get_query_builder(); b->insert("message_page", "default, 'aaewdwd'"); printf("%s\n", b->query_result.c_str()); db->query_run(b->query_result); b->query_result.clear(); b->insert("message_page", "default, 'qqqqq'"); printf("%s\n", b->query_result.c_str()); db->query_run(b->query_result); delete t; } MessagePage::MessagePage() : Object() { messages.push_back("T message 1"); messages.push_back("T message 2"); } MessagePage::~MessagePage() { }