Add featch columns names

generic
mbandic 3 months ago
parent 6129774980
commit 0ae1c69782
  1. 5
      README.md
  2. 13
      lib/mysql.hpp
  3. 6
      test/test.cpp
  4. BIN
      test/test.o

@ -53,6 +53,11 @@ try { | | | |
cout << get<0>(row) << " " << get<1>(row) << endl;
}
// access columns name
for (auto column_name : response.columns_name) {
cout << column_name << endl;
}
} catch (const string err) {
cout << err << endl;
}

@ -5,7 +5,6 @@
#include <mutex>
#include <thread>
#include <future>
// #include <iostream>
#include <string>
#include <vector>
#include <tuple>
@ -36,7 +35,8 @@ class MySQL_Res : public vector<tuple<Types...>> {
bool have_result = false;
uint16_t affected = 0;
uint16_t rows = 0;
uint16_t columns = (int)tuple_size<tuple<Types...>>::value;
uint16_t columns = sizeof...(Types);
vector<string> columns_name;
};
/**
@ -156,8 +156,15 @@ class MySQL {
ResultSet* res = stmt->getResultSet();
result.rows = res->rowsCount();
ResultSetMetaData *metaData = res->getMetaData();
int columnCount = metaData->getColumnCount();
for (int i = 1; i <= columnCount; ++i) {
result.columns_name.push_back(metaData->getColumnName(i));
}
while (res->next()) {
result.push_back(MySQL::getRow<Types...>(res, std::make_index_sequence<sizeof...(Types)>{}));
result.push_back(MySQL::getRow<Types...>(res, make_index_sequence<sizeof...(Types)>{}));
}
res->close();

@ -11,7 +11,7 @@ using namespace marcelb;
int main() {
try {
// MySQL mydb("tcp://192.168.2.10:3306", "dinio", "H€r5elfInd1aH@nds", "dinio", 1);
MySQL mydb("tcp://192.168.2.10:3306", "dinio", "H€r5elfInd1aH@nds", "dinio", 5);
MySQL mydb("tcp://bitelex.ddns.net:3306", "dinio", "H€r5elfInd1aH@nds", "dinio", 5);
sleep(2);
@ -115,6 +115,10 @@ int main() {
cout << get<0>(row) << " " << get<1>(row) << endl;
}
for (auto column_name : response.columns_name) {
cout << column_name << endl;
}
} catch (const string err) {
cout << err << endl;
}

Binary file not shown.
Loading…
Cancel
Save