Add helper function for reading values by field name

The helper function provides map-like access to row values. This is used
to retrieve the values for all MariaDB 10.0+ versions as there are
differences in the returned results between 10.1 and 10.2.
This commit is contained in:
Markus Mäkelä
2017-10-27 12:33:56 +03:00
parent 2d1e5f46fa
commit 0bc439641a
3 changed files with 36 additions and 8 deletions

View File

@ -23,6 +23,7 @@
#include <maxscale/mysql_utils.h>
#include <string.h>
#include <strings.h>
#include <stdbool.h>
#include <errmsg.h>
@ -210,6 +211,22 @@ int mxs_mysql_query(MYSQL* conn, const char* query)
return rc;
}
const char* mxs_mysql_get_value(MYSQL_RES* result, MYSQL_ROW row, const char* key)
{
MYSQL_FIELD* f = mysql_fetch_fields(result);
int nfields = mysql_num_fields(result);
for (int i = 0; i < nfields; i++)
{
if (strcasecmp(f[i].name, key) == 0)
{
return row[i];
}
}
return NULL;
}
bool mxs_mysql_trim_quotes(char *s)
{
bool dequoted = true;