mysql_stmt_attr_set 函数设置获取行数和 mysql_stmt_store_result 的区别.
各位有知道的吗?给解释下......
3q
MySQL

解决方案 »

  1.   

    ......悲剧,看了下,不是我想要的答案.我的是mysql_stmt_attr_set 这个函数作用有通过打开光标,来设置每次从结果集获取的行数,
    我的疑惑是这个结果集是在服务器端生成还是在客户端生成,官网上说的是
    使用光标时,一次从服务器获取的行数。*arg的范围从1到unsigned long的最大值。默认值为1。
    如果为预处理语句打开了光标,没必要调用mysql_stmt_store_result(),这是因为,该函数会导致在客户端一侧对结果集进行缓冲处理。我的疑惑是:
    当fetch()行数结束时,再次从服务器获取下一个结果集的制定行数行数吗?mysql_stmt_store_result()是将整个结果加载到客户端,可能会出现能存溢出,这个内存溢出的上限,大概会是多少.(主要是这个很重要)mysql_use_result(),这个函数看来会比较耗费对表操作的时间,所以这个不考虑了.
      

  2.   

    MYSQL官方免费手册中有非常详细的说明, 可以对照的英语在线字典慢慢看。20.9.7.3. mysql_stmt_attr_set()
    my_bool mysql_stmt_attr_set(MYSQL_STMT *stmt, enum enum_stmt_attr_type option, const void *arg) Description Can be used to affect behavior for a prepared statement. This function may be called multiple times to set several options. The option argument is the option that you want to set. The arg argument is the value for the option. arg should point to a variable that is set to the desired attribute value. The variable type is as indicated in the following table. The following table shows the possible option values. Option Argument Type Function 
    STMT_ATTR_UPDATE_MAX_LENGTH my_bool * If set to 1, causes mysql_stmt_store_result() to update the metadata MYSQL_FIELD->max_length value. 
    STMT_ATTR_CURSOR_TYPE unsigned long * Type of cursor to open for statement when mysql_stmt_execute() is invoked. *arg can be CURSOR_TYPE_NO_CURSOR (the default) or CURSOR_TYPE_READ_ONLY. 
    STMT_ATTR_PREFETCH_ROWS unsigned long * Number of rows to fetch from server at a time when using a cursor. *arg can be in the range from 1 to the maximum value of unsigned long. The default is 1. If you use the STMT_ATTR_CURSOR_TYPE option with CURSOR_TYPE_READ_ONLY, a cursor is opened for the statement when you invoke mysql_stmt_execute(). If there is already an open cursor from a previous mysql_stmt_execute() call, it closes the cursor before opening a new one. mysql_stmt_reset() also closes any open cursor before preparing the statement for re-execution. mysql_stmt_free_result() closes any open cursor. If you open a cursor for a prepared statement, mysql_stmt_store_result() is unnecessary, because that function causes the result set to be buffered on the client side. Return Values Zero if successful. Nonzero if option is unknown. Errors None. Example The following example opens a cursor for a prepared statement and sets the number of rows to fetch at a time to 5: MYSQL_STMT *stmt;
    int rc;
    unsigned long type;
    unsigned long prefetch_rows = 5;stmt = mysql_stmt_init(mysql);
    type = (unsigned long) CURSOR_TYPE_READ_ONLY;
    rc = mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (void*) &type);
    /* ... check return value ... */
    rc = mysql_stmt_attr_set(stmt, STMT_ATTR_PREFETCH_ROWS,
                             (void*) &prefetch_rows);
    /* ... check return value ... */
      

  3.   

    20.9.7.27. mysql_stmt_store_result()
    int mysql_stmt_store_result(MYSQL_STMT *stmt) Description Result sets are produced by executing prepared statements for SQL statements such as SELECT, SHOW, DESCRIBE, and EXPLAIN. By default, result sets for successfully executed prepared statements are not buffered on the client and mysql_stmt_fetch() fetches them one at a time from the server. To cause the complete result set to be buffered on the client, call mysql_stmt_store_result() after binding data buffers with mysql_stmt_bind_result() and before calling mysql_stmt_fetch() to fetch rows. (For an example, see Section 20.9.7.11, “mysql_stmt_fetch()”.) mysql_stmt_store_result() is optional for result set processing, unless you will call mysql_stmt_data_seek(), mysql_stmt_row_seek(), or mysql_stmt_row_tell(). Those functions require a seekable result set. It is unnecessary to call mysql_stmt_store_result() after executing an SQL statement that does not produce a result set, but if you do, it does not harm or cause any notable performance problem. You can detect whether the statement produced a result set by checking if mysql_stmt_result_metadata() returns NULL. For more information, refer to Section 20.9.7.22, “mysql_stmt_result_metadata()”. Note
    MySQL doesn't by default calculate MYSQL_FIELD->max_length for all columns in mysql_stmt_store_result() because calculating this would slow down mysql_stmt_store_result() considerably and most applications don't need max_length. If you want max_length to be updated, you can call mysql_stmt_attr_set(MYSQL_STMT, STMT_ATTR_UPDATE_MAX_LENGTH, &flag) to enable this. See Section 20.9.7.3, “mysql_stmt_attr_set()”. Return Values Zero if the results are buffered successfully. Nonzero if an error occurred. Errors CR_COMMANDS_OUT_OF_SYNC Commands were executed in an improper order. CR_OUT_OF_MEMORY Out of memory. CR_SERVER_GONE_ERROR The MySQL server has gone away. CR_SERVER_LOST The connection to the server was lost during the query. CR_UNKNOWN_ERROR An unknown error occurred.