views:

436

answers:

1

How do I get the size of data in a BLOB field in the Result Set? (Using C++ and MySQL Connector C++)

In order to read the data from the result set, I have allocate memory for it first. In order to allocate memory, I need to know the size of the blob data in the result set.

Searching the web and StackOverflow, I have found two methods: OCTECT and BLOB stream.

One method to find the BLOB size is to use OCTECT() function, which requires a new query and produces a new result set. I would rather not use this method.

Another method is to use the blob stream and seek to the end, and get the file position. However, I don't know if the stream can be rewound to the beginning in order to read the data. This method requires an additional read of the entire stream.

The ResultSet and ResultSetMetaData interfaces of MySQL Connector C++ 1.0.5 do not provide a method for obtaining the size of the data in a field (column).

Is there a process for obtaining the size of the data in a BLOB field given only the result set and a field name?

I am using MySQL Connector C++ 1.0.5, C++, Visual Studio 2008, Windows Vista / XP and "Server version: 5.1.41-community MySQL Community Server (GPL)".

A: 

You could do a select like:

select LENGTH(content),content where id=123;

where content is the BLOB field.

Regards. see: LENGTH(str)

elou
What is the field name, in the result set, for the LENGTH() field?
Thomas Matthews
It should be possible to access the result with the index (here 1).In java I will call 'rs.setInt(1)'.
elou
The field name for the length() is as written: `length(content)`. To get a sensible name you have to do `length(content) as contentLength` or similar.
Core Xii