Use explicit types with get_row
Auto types aren't very neat as return values because they move the burden of knowledge to the reader. Using an explicit, and somewhat self-explanatory, type makes it easier to assess the code without knowing the implementation of the type.
This commit is contained in:
@ -525,9 +525,9 @@ int find_field(MYSQL* conn, const char* sql, const char* field_name, char* value
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> get_row(MYSQL* conn, std::string sql)
|
Row get_row(MYSQL* conn, std::string sql)
|
||||||
{
|
{
|
||||||
std::vector<std::string> rval;
|
Row rval;
|
||||||
MYSQL_RES* res;
|
MYSQL_RES* res;
|
||||||
|
|
||||||
if (mysql_query(conn, sql.c_str()) == 0 && (res = mysql_store_result(conn)))
|
if (mysql_query(conn, sql.c_str()) == 0 && (res = mysql_store_result(conn)))
|
||||||
|
@ -26,6 +26,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
typedef std::vector<std::string> Row;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens connection to DB: wropper over mysql_real_connect
|
* Opens connection to DB: wropper over mysql_real_connect
|
||||||
*
|
*
|
||||||
|
@ -21,20 +21,20 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
test.maxscales->connect();
|
test.maxscales->connect();
|
||||||
|
|
||||||
auto original_row = get_row(test.maxscales->conn_rwsplit[0], "SELECT @@server_id");
|
Row original_row = get_row(test.maxscales->conn_rwsplit[0], "SELECT @@server_id");
|
||||||
|
|
||||||
for (int i = 0; i < 10; i++)
|
for (int i = 0; i < 10; i++)
|
||||||
{
|
{
|
||||||
connections.emplace_back(query, test.maxscales->open_rwsplit_connection(), "SELECT SLEEP(10)");
|
connections.emplace_back(query, test.maxscales->open_rwsplit_connection(), "SELECT SLEEP(10)");
|
||||||
sleep(1);
|
sleep(1);
|
||||||
auto row = get_row(test.maxscales->conn_rwsplit[0], "SELECT @@server_id");
|
Row row = get_row(test.maxscales->conn_rwsplit[0], "SELECT @@server_id");
|
||||||
test.assert(row == original_row, "Value of @@server_id should not change: %s", row.at(0).c_str());
|
test.assert(row == original_row, "Value of @@server_id should not change: %s", row.at(0).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& a: connections)
|
for (auto& a: connections)
|
||||||
{
|
{
|
||||||
a.join();
|
a.join();
|
||||||
auto row = get_row(test.maxscales->conn_rwsplit[0], "SELECT @@server_id");
|
Row row = get_row(test.maxscales->conn_rwsplit[0], "SELECT @@server_id");
|
||||||
test.assert(row == original_row, "Value of @@server_id should not change: %s", row.at(0).c_str());
|
test.assert(row == original_row, "Value of @@server_id should not change: %s", row.at(0).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ bool query(TestConnections& test)
|
|||||||
test.maxscales->connect();
|
test.maxscales->connect();
|
||||||
execute_query_silent(test.maxscales->conn_rwsplit[0], "SET @a = 1") == 0;
|
execute_query_silent(test.maxscales->conn_rwsplit[0], "SET @a = 1") == 0;
|
||||||
sleep(5);
|
sleep(5);
|
||||||
auto row = get_row(test.maxscales->conn_rwsplit[0], "SELECT @a");
|
Row row = get_row(test.maxscales->conn_rwsplit[0], "SELECT @a");
|
||||||
test.maxscales->disconnect();
|
test.maxscales->disconnect();
|
||||||
return row[0] == "1";
|
return row[0] == "1";
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user