mysql stmt attr set_MySQL 5.1 英文手册 :: 21.9.7.3 mysql_stmt_attr_set()

21.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 ... */

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值