RE: Determine actual size of binary column in result set
- From: Pak-Ming Cheung [MSFT] <PakMingCheungMSFT@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 13 Feb 2008 02:16:00 -0800
So, you mean that you want to find out the amount of data inside a column.
However, it seems that there is no good method with SQLBindCol.
For SQL-Server specific application, you may use: "select max(datalength(b))
from test".
For generic application, you may use SQLFetch + SQLGetData to obtain the
maximum length and data. Actually, for a very long column (image datatype),
it is recommended to use SQLGetData since you can get the data in chunk,
instead of pre-allocating a large buffer. However, if the amount of data is
not so large, you may use the datatype "varbinary(2048)".
Ming.
MDAC Team, Microsoft.
====================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
"Howard Rodstein" wrote:
I'm writing a generic application that is supposed to be able to work with.
any ODBC-compatible database.
I have created a test database with a binary column. With MySQL I am using
datatype BLOB and in MS SQL Server I am using datatype IMAGE. In my test case
I know that the binary data is 2048 bytes but in general, I will not know the
size of the binary column.
When I fetch data, I first use SQLBindCol to bind each column in the result
set to memory I have allocated for that column. Before I bind to the binary
column, I need to determine how big it is so I can allocate memory. This is
where I am running into a problem.
According to Microsoft's ODBC documentation, I should be able to use the
SQLColAttribute function with a field type of SQL_DESC_LENGTH to find the
ACTUAL data length. From the SQLColAttribute documentation for
SQL_DESC_LENGTH:
A numeric value that is either the maximum or actual character length of a
character string or binary data type. It is the maximum character length for
a fixed-length data type, or the actual character length for a variable-length
data type.
The IMAGE data type is variable-length and therefore
SQLColAttribute(SQL_DESC_LENGTH) should return the actual data length.
However, when running with MS SQL Server 2005 Express Edition with the SQL
Native Client driver, the returned value is 2^31-1 - that is, it is returning
the MAXIMUM length, not the ACTUAL length.
How can I determine the ACTUAL length?
Thanks.
- Prev by Date: RE: SSMA problem
- Next by Date: RE: Is this correct syntax for OLE DB for ODBC parameter query?
- Previous by thread: RE: SSMA problem
- Next by thread: RE: Is this correct syntax for OLE DB for ODBC parameter query?
- Index(es):
Relevant Pages
|
|