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

12
main.cc
View File

@ -7,9 +7,15 @@ using namespace std;
int main(int argc, char** const argv){
SqlConnection conn{};
auto resp = conn.Connect("192.168.1.17", "3306", "root", "", "mysql");
auto resp = conn.Connect("192.168.1.17", "3306", "root", "", "mobiletek_mmi");
// resp.or_else([](auto err_msg){cout<<err_msg<<"\n";});
auto table_result = conn.GetTables();
ranges::for_each(table_result, [](auto item){cout<<item<<endl;});
// auto table_result = conn.GetTables();
auto result = conn.Query("SELECT IMEI_1 FROM R303 WHERE Powertest=1;");
ranges::for_each(result.value(), [](auto row){
ranges::for_each(row, [](auto item){
cout<<item<<", ";
});
cout<<endl;
});
return 0;
}

0
result Normal file
View File

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){

BIN
sqlconn

Binary file not shown.