| Bug #3487 | use mysql_use_result() functoin also for mysql_stmt based handling | ||
|---|---|---|---|
| Submitted: | 16 Apr 2004 17:05 | Modified: | 30 Nov 2009 14:20 |
| Reporter: | wim delvaux | Email Updates: | |
| Status: | Closed | Impact on me: | |
| Category: | MySQL Server: C API (client library) | Severity: | S4 (Feature request) |
| Version: | 4.1.2 | OS: | Linux (Linux) |
| Assigned to: | CPU Architecture: | Any | |
[16 Apr 2004 17:05]
wim delvaux
[12 May 2004 21:48]
Konstantin Osipov
Yes, now there is no way to find out length of long column before actual fetch.
If you use mysql_stmt_store_result function and buffer entire result set in the statement,
you can use field->max_length for this column from statement result metadata (which can be
obtained by mysql_stmt_result_metadata).
But this works only if you set STMT_ATTR_UPDATE_MAX_LENGTH attribute of the statement with
recently implemented mysql_stmt_attr_set.
Alternatively you can use mysql_stmt_fetch with buffer for this column of zero length and
pointer to write real lenght to, followed by mysql_stmt_fetch_column.
Example:
real_length= 0;
bind[0].buffer= 0;
bind[0].buffer_length= 0;
bind[0].length= &real_length
mysql_stmt_bind_result(stmt, bind);
mysql_stmt_fetch(stmt);
if (real_length > 0)
{
data= malloc(real_length);
bind[0].buffer= data;
bind[0].buffer_length= real_length;
mysql_stmt_fetch_column(stmt, 0, bind, 0);
}
[13 May 2004 1:39]
wim delvaux
OK thanx for the reply. Perhaps the documentation should be a be more clear on that W
[30 Nov 2009 14:20]
Valeriy Kravchuk
I think this is properly documented already. See http://dev.mysql.com/doc/refman/5.1/en/mysql-stmt-attr-set.html http://dev.mysql.com/doc/refman/5.1/en/mysql-stmt-fetch.html
