mysql_t MysqlSelect(char *base, char *sql)
{
if(base != NULL && sql != NULL)
{
if(mysql.array != NULL)
{
for(int step = 0; step <= mysql.array_len; step++)
if(mysql.array[step] != NULL)
free(mysql.array[step]);
free(mysql.array);
mysql.array_len = 0;
}
for(int step = 0; step < strlen(sql); step++)
if(sql[step] == ',')
mysql.array_len++;
mysql.connect = mysql_connection_setup(base);
mysql.result = mysql_perform_query(mysql.connect, sql);
if((mysql.row = mysql_fetch_row(mysql.result)) != NULL)
{
long int size_str = 0;
if(mysql.array_len == 0)
size_str = strlen(mysql.row[0]) + 1;
else
{
for(int step = 0; step <= mysql.array_len; step++)
size_str = size_str + strlen(mysql.row[step]);
}
mysql.array = (char**)calloc(size_str, sizeof(char*));
for(int step = 0; step <= mysql.array_len; step++)
{
mysql.array[step] = (char*)calloc(size_str, sizeof(char));
strncpy(mysql.array[step], mysql.row[step], size_str);
}
}
else
mysql.array = NULL;
mysql_free_result(mysql.result);
mysql_close(mysql.connect);
}
else
printf("--> Log: input variables are nulled\n");
return mysql;
}