fix get fields function
This commit is contained in:
@@ -1,3 +1,9 @@
|
||||
#define DEBUG
|
||||
|
||||
#ifdef DEBUG
|
||||
#include <iostream>
|
||||
#endif
|
||||
|
||||
#include <optional>
|
||||
#include <ranges>
|
||||
#include <algorithm>
|
||||
@@ -10,13 +16,22 @@
|
||||
|
||||
#include "util.h"
|
||||
|
||||
template<typename T>
|
||||
void log(T msg){
|
||||
#ifdef DEBUG
|
||||
std::cout<<msg<<std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
using util::_support_string;
|
||||
|
||||
[[maybe_unused]]
|
||||
struct RowItem{
|
||||
std::vector<std::string_view> row;
|
||||
};
|
||||
|
||||
//Not Implemented;
|
||||
[[maybe_unused]]
|
||||
class Result{
|
||||
std::vector<std::string_view> fields;
|
||||
std::map<std::string_view, std::vector<std::string_view>> datas;
|
||||
@@ -98,13 +113,12 @@ public:
|
||||
std::vector<std::string_view> get_fields(std::string_view table_name){
|
||||
std::vector<std::string_view> 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<field_length; i++){
|
||||
really_result.emplace_back(row[i]);
|
||||
while(auto row = mysql_fetch_row(mysql_result)){
|
||||
really_result.emplace_back(row[0]);
|
||||
}
|
||||
mysql_free_result(mysql_result);
|
||||
}
|
||||
@@ -143,7 +157,7 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::string_view> GetTables(){
|
||||
std::vector<std::string_view> get_tables(){
|
||||
std::vector<std::string_view> really_result;
|
||||
mysql_query(&mysql_client, "SHOW TABLES;");
|
||||
if(auto mysql_result = mysql_store_result(&mysql_client); mysql_result != nullptr){
|
||||
|
||||
Reference in New Issue
Block a user