Tags: bulk, datatype, fields, insert, irowsetfastloadinsertrow, programming, real, record, sql, sqloledb, working

SQLOLEDB: Problem with IRowsetFastLoad::InsertRow

On Programmer » SQL

4,476 words with 0 Comments; publish: Thu, 29 May 2008 04:37:00 GMT; (20031.25, « »)

Hi,

I'm looking to a bulk insert with 512 fields in each record, all of datatype

real, but its not working. I've now tried using a smaller example with just

a few columns, but still with no success. Here's what i've done:

I've modified the bulk copy sample code in Sql Books online to use more

than one column, but its not working. The call to IRowsetFastLoad::InsertRow

is failing with 0x80004005 E_FAIL and the IErrorInfo interface isnt

returning any meaningful data.

My sample code attempts to insert a row of 3 integer values into a table of

3 columns.

Can anyone spot where I might be going wrong?

Sample code is as follows:

Create table TB_TestBlock (field1 int not null primary key, field2 int,

field3 int)

struct SmallTestBlock

{

unsigned long value1;

DWORD valueStatus1;

unsigned long value2;

DWORD valueStatus2;

unsigned long value3;

DWORD valueStatus3;

};

int MySqlServerClass::ProcessDataTestBlock()

{

SmallTestBlock stb;

stb.value1 = 2;

stb.valueStatus1 = 0;

stb.value2 = 4;

stb.valueStatus2 = 0;

stb.value3 = 8;

stb.valueStatus3 = 0;

ret = SetFastLoadProperty(true);

// Use IRowsetFastLoad

IRowsetFastLoad *pIRowsetFastLoad;

DBID TableID;

TableID.eKind = DBKIND_NAME;

_bstr_t bs2 = "TB_TestBlock";

TableID.uName.pwszName = SysAllocStringLen(bs2, wcslen(bs2));

IOpenRowset *pIOpenRowsetFL;

HRESULT hr = pIDBCreateSession->CreateSession(NULL, IID_IOpenRowset,

(IUnknown **)&pIOpenRowsetFL);

if (FAILED(hr))

{

PrintMinorErrorInfo(IID_IDBInitialize, pIDBInitialize);

}

hr = pIOpenRowsetFL->OpenRowset(NULL, &TableID, NULL, IID_IRowsetFastLoad,

0, NULL, (IUnknown **)&pIRowsetFastLoad);

if (FAILED(hr))

{

PrintMinorErrorInfo(IID_IDBInitialize, pIDBInitialize);

}

// Set up an accesssor for the data

DBBINDING columnBindings[3];

ULONG ulOffset = 0;

for (i=0;i<3;i++)

{

columnBindings[i].dwPart = DBPART_VALUE | DBPART_STATUS;

columnBindings[i].iOrdinal = i+1;

columnBindings[i].pTypeInfo = NULL;

columnBindings[i].obLength = 0; // ignored for fixed size fields

columnBindings[i].cbMaxLen = sizeof(unsigned long);

columnBindings[i].pTypeInfo = NULL;

columnBindings[i].pObject = NULL;

columnBindings[i].pBindExt = NULL;

columnBindings[i].dwFlags = 0;

columnBindings[i].eParamIO = DBPARAMIO_NOTPARAM;

columnBindings[i].dwMemOwner = DBMEMOWNER_CLIENTOWNED;

columnBindings[i].bPrecision= 0;

columnBindings[i].bScale = 0;

columnBindings[i].wType = DBTYPE_I4; // unsigned long

}

columnBindings[0].obValue = ulOffset + offsetof(SmallTestBlock,value1);

columnBindings[0].obStatus = ulOffset +

offsetof(SmallTestBlock,valueStatus1);

columnBindings[1].obValue = ulOffset + offsetof(SmallTestBlock,value2);

columnBindings[1].obStatus = ulOffset +

offsetof(SmallTestBlock,valueStatus2);

columnBindings[2].obValue = ulOffset + offsetof(SmallTestBlock,value3);

columnBindings[2].obStatus = ulOffset +

offsetof(SmallTestBlock,valueStatus3);

ulOffset = columnBindings[2].cbMaxLen + columnBindings[2].obValue;

ulOffset = ROUND_UP( ulOffset, COLUMN_ALIGNVAL );

IAccessor *pIAccessor;

HACCESSOR hAccessor = 0;

DBBINDSTATUS columnStatus[3];

for (i=0;i<3;i++)

{

columnStatus[i]=0;

}

if( FAILED( hr = pIRowsetFastLoad->QueryInterface(IID_IAccessor, (void

**) &pIAccessor)))

{

char errorMsg[200];

GetErrorString(hr, (char *)&errorMsg, 200);

PrintMinorErrorInfo(IID_IDBInitialize, pIDBInitialize);

return hr;

}

if(FAILED(hr = pIAccessor->CreateAccessor(DBACCESSOR_ROWDATA, 3,

&columnBindings[0], ulOffset, &hAccessor, &columnStatus[0])))

{

char errorMsg[200];

GetErrorString(hr, (char *)&errorMsg, 200);

PrintMinorErrorInfo(IID_IDBInitialize, pIDBInitialize);

return hr;

}

do

{

hr = pIRowsetFastLoad->InsertRow(hAccessor, (void *)&stb); // this

fails

if (FAILED(hr))

{

PrintMinorErrorInfo(IID_IDBInitialize, pIDBInitialize);

goto cleanup;

}

i++;

} while (i<10);

hr = pIRowsetFastLoad->Commit(TRUE);

if (FAILED(hr))

{

PrintMinorErrorInfo(IID_IDBInitialize, pIDBInitialize);

goto cleanup;

}

thanks,

Mark

All Comments

Leave a comment...

  • 0 Comments