c mysql读取text_MySQL C API处理TEXT字段

当使用MySQL C API中的Prepared Statements来处理TEXT字段结果时,必须指定out绑定的字符串长度:

MYSQL_BIND out_bind;

char str_data[STRING_SIZE];

my_bool is_null;

my_bool error;

....

/* STRING COLUMN */

out_bind.buffer_type = MYSQL_TYPE_STRING;

out_bind.buffer = str_data;

out_bind.buffer_length = STRING_SIZE;

out_bind.is_null= &is_null;

out_bind.length= &length;

out_bind.error= &error;

mysql_stmt_bind_result(statement, out_bind)

在给定的示例中,STRING_SIZE是已知常量,但如何使用TEXT字段,其中数据长度可以从小尺寸变为兆字节?

这有标准的方法吗?

解决方法:

In some cases you might want to determine the length of a column value before fetching it with mysql_stmt_fetch(). … To accomplish this, you can use these strategies:

Before invoking mysql_stmt_fetch() to retrieve individual rows, pass STMT_ATTR_UPDATE_MAX_LENGTH to mysql_stmt_attr_set(), then invoke mysql_stmt_store_result() to buffer the entire result on the client side. Setting the STMT_ATTR_UPDATE_MAX_LENGTH attribute causes the maximal length of column values to be indicated by the max_length member of the result set metadata returned by mysql_stmt_result_metadata().

Invoke mysql_stmt_fetch() with a zero-length buffer for the column in question and a pointer in which the real length can be stored. Then use the real length with mysql_stmt_fetch_column().

标签:mysql,c-3,mysql-connector

来源: https://codeday.me/bug/20190626/1295215.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值