From c3576fe26de42ce22ad42aed034993cc344e7127 Mon Sep 17 00:00:00 2001 From: jie Date: Fri, 22 Nov 2024 17:14:20 +0800 Subject: [PATCH] fix get fields function --- include/sqlConnection.h | 24 +++++++++++++++++++----- src/main.cc | 17 ++++++++++------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/include/sqlConnection.h b/include/sqlConnection.h index f8ee946..64d69c0 100644 --- a/include/sqlConnection.h +++ b/include/sqlConnection.h @@ -1,3 +1,9 @@ +#define DEBUG + +#ifdef DEBUG +#include +#endif + #include #include #include @@ -10,13 +16,22 @@ #include "util.h" +template +void log(T msg){ +#ifdef DEBUG + std::cout< row; }; //Not Implemented; +[[maybe_unused]] class Result{ std::vector fields; std::map> datas; @@ -98,13 +113,12 @@ public: std::vector get_fields(std::string_view table_name){ std::vector really_result; std::string command; - std::format_to(std::back_inserter(command), "SHOW COLUMNS FROM %s;", table_name); + std::format_to(std::back_inserter(command), "SHOW COLUMNS FROM {};", table_name); auto _ = mysql_query(&mysql_client, command.c_str()); if(auto mysql_result = mysql_store_result(&mysql_client); mysql_result != nullptr){ auto field_length = mysql_num_fields(mysql_result); - auto row = mysql_fetch_row(mysql_result); - for(int i=0; i GetTables(){ + std::vector get_tables(){ std::vector really_result; mysql_query(&mysql_client, "SHOW TABLES;"); if(auto mysql_result = mysql_store_result(&mysql_client); mysql_result != nullptr){ diff --git a/src/main.cc b/src/main.cc index 15c59a4..1a13a2c 100644 --- a/src/main.cc +++ b/src/main.cc @@ -8,14 +8,17 @@ using namespace std; int main(int argc, char** const argv){ SqlConnection conn{}; auto resp = conn.Connect("192.168.1.17", "3306", "root", "", "mobiletek_mmi"); + auto table_result = conn.get_tables(); + auto fields = conn.get_fields("r303"); + ranges::for_each(fields, [](auto item){cout<