对于“选择” sql,在我们通过调用 my_fetch_xxx() API 从结果集中复制所有行之前,多次重复调用 my_xxxx_store() API(以缓存客户端中的所有结果)的连接是否安全通过调用 my_xxxx_store() API 缓存?
例如,如果从多个线程调用此函数,是否通过传递不同的 select 语句正确地获取数据,没有任何问题。就像同时调用
From thread-1: foo("select * from table1");
From thread-2: foo("select * from table2");
From thread-3: foo("select * from table3");
etc....
函数 foo 类似于。
/* 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);
}
准备好的陈述也安全吗?就像是。
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);
}