"Michael Cheng [MSFT]" <v-mingqc@online.microsoft.com> wrote in
message news:zSuLO8K$FHA.3764@TK2MSFTNGXA02.phx.gbl...
[quoted text, click to view] > Hi Arnie,
>
> Thanks for your patience.
You're welcome. I appreciate your help.
[quoted text, click to view] > Sincerely yours,
>
> Michael Cheng
> Microsoft Online Partner Support
I'm supplying sample code below though it doesn't use Northwind.
I have a table (aem_blob) with an integer column and an image
column. It has two rows. The first has (100, 1KB BLOB). The
second row has (200, big_blob). I change the size of the
big_blob based on where I'm testing: From home over the VPN it's
5MB, from work over the LAN it's 50MB. This lets me 'feel'
what's happening as I step over the fetches in the debugger. An
SQLFetch() on the second row takes quite a while.
Please let me know if you need any more info.
// ODBCBLOB.cpp : Defines the entry point for the console
application.
//
#include "stdafx.h"
#include <string>
using namespace std;
int main(int argc, char * argv[])
{
SQLHENV hEnv;
SQLHDBC hDbc;
SQLHSTMT hStmt;
// Allocate an environment handle
SQLAllocHandle( SQL_HANDLE_ENV, SQL_NULL_HANDLE, & hEnv );
// We want version >= 3.0
SQLSetEnvAttr( hEnv, SQL_ATTR_ODBC_VERSION, (void*) SQL_OV_ODBC3,
0 );
// Allocate a ODBC connection handle
SQLAllocConnect( hEnv, & hDbc );
SQLRETURN rc;
// Connect to the DB
// The default catalog is what we're looking for
rc = SQLConnect( hDbc, (SQLCHAR *) "DVSQLSCB", SQL_NTS,
(SQLCHAR *) "mx", SQL_NTS, (SQLCHAR *) "expert", SQL_NTS );
// Create the statement handle
rc = SQLAllocHandle(SQL_HANDLE_STMT, hDbc, & hStmt );
// Force a server cursor
SQLSetStmtAttr( hStmt, SQL_ATTR_CURSOR_SCROLLABLE,
(SQLPOINTER) SQL_SCROLLABLE, 0 );
// Prepare the statement and build the Fields collection
rc = SQLPrepare( hStmt, (SQLCHAR *) "SELECT aBlob FROM aem_blob",
SQL_NTS );
// Open the query and position to the first row of the result set
rc = SQLExecute( hStmt );
// NOTE: *** The BLOB column is not bound ***
// Read the first row with the small BLOB - instant
// SQLFetchScroll() works properly
rc = SQLFetch( hStmt );
// rc = SQLFetchScroll( hStmt, SQL_FETCH_NEXT, 0 );
// Read the row with the big BLOB - long delay
rc = SQLFetch( hStmt );
// rc = SQLFetchScroll( hStmt, SQL_FETCH_NEXT, 0 );
long valLen = 0;
unsigned char * blob = new unsigned char[5000000];
// Read the data with SQLFetchScroll, read the data AGAIN
// when using SQLFetch().
rc = SQLGetData( hStmt, 1, SQL_C_BINARY,
(SQLPOINTER) ((char *) (blob)),(SQLINTEGER) 5000000,
(SQLLEN *) &valLen );
rc = SQLFreeStmt( hStmt, SQL_CLOSE );
rc = SQLFreeHandle( SQL_HANDLE_DBC, hDbc );
rc = SQLFreeHandle( SQL_HANDLE_ENV, hEnv );
return 0;
}