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:
parent
b6e421e13b
commit
e3b11d866f
@ -525,9 +525,9 @@ int find_field(MYSQL* conn, const char* sql, const char* field_name, char* value
|
||||
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;
|
||||
|
||||
if (mysql_query(conn, sql.c_str()) == 0 && (res = mysql_store_result(conn)))
|
||||
|
@ -26,6 +26,8 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
typedef std::vector<std::string> Row;
|
||||
|
||||
/**
|
||||
* Opens connection to DB: wropper over mysql_real_connect
|
||||
*
|
||||
|
@ -21,20 +21,20 @@ int main(int argc, char** argv)
|
||||
|
||||
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++)
|
||||
{
|
||||
connections.emplace_back(query, test.maxscales->open_rwsplit_connection(), "SELECT SLEEP(10)");
|
||||
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());
|
||||
}
|
||||
|
||||
for (auto& a: connections)
|
||||
{
|
||||
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());
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ bool query(TestConnections& test)
|
||||
test.maxscales->connect();
|
||||
execute_query_silent(test.maxscales->conn_rwsplit[0], "SET @a = 1") == 0;
|
||||
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();
|
||||
return row[0] == "1";
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user