query down

This commit is contained in:
jie
2024-10-24 14:14:12 +08:00
parent 4fe6f23da9
commit 100e689d1b
4 changed files with 20 additions and 6 deletions

View File

@@ -111,23 +111,31 @@ public:
return really_result;
}
std::expected<std::map<std::string_view, std::vector<std::string_view>>, std::string_view> Query(std::string_view command){
std::expected<std::vector<std::vector<std::string_view>>, std::string_view> Query(std::string_view command){
//Not Implemented;
std::map<std::string_view, std::vector<std::string_view>> really_result;
std::vector<std::vector<std::string_view>> really_result;
mysql_query(&mysql_client, command.data());
if(auto mysql_result = mysql_store_result(&mysql_client); mysql_result != nullptr){
auto row_length = mysql_fetch_lengths(mysql_result);
auto field_length = mysql_num_fields(mysql_result);
std::vector<std::string_view> temp;
while(auto row = mysql_fetch_row(mysql_result)){
temp.clear();
for(int i=0; i<field_length; i++){
if(row[i] != nullptr){
temp.emplace_back(row[i]);
}else{
temp.emplace_back("");
}
}
really_result.emplace_back(temp);
}
mysql_free_result(mysql_result);
}
return std::unexpected(get_error_msg());
return really_result;
}
bool Execute(std::string_view command){