468,544 Members | 1,767 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,544 developers. It's quick & easy.

C API question: using mysql_bind_result to fetch string data of variable length (text, blob)

Hi,
In the C API, is there any way to execute a query, store all the
results, and somehow find the maximum realized width for each of the
fields before fetching each row?

Otherwise there is no way to efficiently retrieve string data. The
best you can do is either allocate a static buffer of 64K (max size
for a blob) or some smaller buffer that may not actually be able to
contain all the data.

In fact, all the mysql documentation examples, both on in the manual
and in the test/client_test.c file that comes with the source
distribution, seem to choose the latter approach, arbitrarily fixing
the max size of their strings to, say, 255 bytes, binding using that
as the buffer_length, and then fetch()ing. In my application I need to
ensure that I get all the data, so this is unacceptable.

I have tried using mysql_get_metadata() after
mysql_stmt_store_result(), but even then the max_length value for the
fields in question is always set to 0, not the maximum size of the
field for the returned results.

What I would love to do is somehow get the field width right before
fetching each row so that I can allocate the right-sized buffer for
it. Or, less ideally, tell mysql to allocate memory for me.

Does anyone know of a way to do this?

I am using MySQL version 4.1.1-alpha-standard on RedHat Linux 9,
installed from the RPMs (server, client, devel) on the mysql.com
website.

Thanks very much,
AJ
Jul 19 '05 #1
0 1836

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by Good Man | last post: by
4 posts views Thread by annoyingmouse2002 | last post: by
1 post views Thread by Randy Howard | last post: by
1 post views Thread by UniDue | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.