For a "Select" sql, is it safe to reuse the connection for calling the my_xxxx_store() API (to cache all the result in client) multiple times, before we copy all rows by calling my_fetch_xxx() API, from the result sets that cached by calling my_xxxx_store() API?
For example, does this function correctly fetch data, without any issues, if its called from multiple threads, by passing different select statements. Like simultaneously calling
From thread-1: foo("select * from table1");
From thread-2: foo("select * from table2");
From thread-3: foo("select * from table3");
etc....
The function foo is something like.
/* Assume that "connection" is a valid properly initialiaed mysql connection handle global variabale*/
/* Assume that there is only one result set. (Means that we dont need to call mysql_next_result() ) */
foo( char *sqlStatement )
{
threadLock();
mysql_real_query( connection, sqlStatement, ... );
MYSQL_RES* result = mysql_store_result(connection);
threadUnLock();
/* The "connection" can be reused now, since all data is cached in client. */
while( more data rows )
{
MYSQL_ROW row = mysql_fetch_row(result);
/*
Copy data;
*/
}
mysql_free_result(result);
}
Also is it safe for prepared statements? Something like.
bar( char *sqlStatement, char *params[] )
{
threadLock();
MYSQL_STMT *stmt = mysql_stmt_init(connection);
mysql_stmt_prepare(stmt, sqlStatement, ...);
int paramCount= mysql_stmt_param_count(stmt);
MYSQL_RES *metaResult = mysql_stmt_result_metadata(stmt);
int columnCount= mysql_num_fields(metaResult)
mysql_stmt_execute(stmt);
mysql_stmt_bind_result(stmt, ....)
mysql_stmt_store_result(stmt);
threadUnLock();
/* The "connection" can be reused now, since all data is cached in client. */
while( more data rows )
{
MYSQL_ROW row = mysql_stmt_fetch(stmt);
/*
Copy data;
*/
}
mysql_free_result(metaResult);
mysql_stmt_free_result(stmt);
mysql_stmt_close(stmt);
}