开发者

MySQL, C++: Need Blob size to read blob data

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)".


You could do a select like:

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

where content is the BLOB field.

Regards. see: LENGTH(str)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜