CDynamicAccessor + IRowsetFastLoad (more...)
- From: Chris Trueman <ctrueman@xxxxxxxxxxxxxxxx>
- Date: Tue, 11 Apr 2006 09:37:12 -0700
I am trying to use CDynamicAccess in conjunction with IRowsetFastLoad to
populate a SQL Server table that's created at runtime. I have code that
works if I know at compile time the structure of the table. But not
when the structure is determined at runtime.
What I see is rows being added to the table, but the contents of any
assigned field is blank.
Here's the code I'm using:
// This opens and prepares the IRowsetFastLoad.
HRESULT SqlServerBulkDataLoader::OpenDynamicRowsetFastLoad()
{
HRESULT hr;
// Enable fast load.
CComPtr<IDBProperties> properties;
CDBPropSet ps;
ps.SetGUID(DBPROPSET_SQLSERVERDATASOURCE);
ps.AddProperty(SSPROP_ENABLEFASTLOAD, true);
hr = m_DataSource.m_spInit->QueryInterface(IID_IDBProperties,
(LPVOID*) &properties);
if (FAILED(hr))
return (hr);
hr = properties->SetProperties(1, &ps);
if (FAILED(hr))
return (hr);
hr = m_Session.Open(m_DataSource);
if (FAILED(hr))
return (hr);
wchar_t tn[] = L"PerfDataLargeOleDb";
m_TableId.eKind = DBKIND_NAME;
m_TableId.uName.pwszName = new WCHAR[wcslen(tn) + sizeof
(wchar_t)];
wcscpy(m_TableId.uName.pwszName, tn);
hr = m_Session.m_spOpenRowset->OpenRowset(
NULL,
&m_TableId,
NULL,
IID_IRowsetFastLoad,
0,
NULL,
(LPUNKNOWN*) &m_RowsetFastLoad);
if (FAILED(hr))
return (hr);
hr = m_DynamicAccessor.BindColumns(m_RowsetFastLoad);
return (hr);
}
// This times and tests inserting rows using IRowsetFastLoad.
HRESULT SqlServerBulkDataLoader::DynamicRowsetFastLoadInsertData()
{
HRESULT hr;
PerfTimer t;
t.Start();
for (int iii = 0; iii < ROWS_TO_INSERT; ++iii)
{
// OK, I lied a little ... I do know that the table's first
// column is an int4.
m_DynamicAccessor.SetValue(1, iii);
hr = m_RowsetFastLoad->InsertRow(
m_DynamicAccessor.GetHAccessor(0),
m_DynamicAccessor.GetBuffer());
if (FAILED(hr))
return (hr);
}
hr = m_RowsetFastLoad->Commit(TRUE);
t.Stop();
printf("SqlServerBulkDataLoader/Dynamic\n");
printf("Rows: %d\n", ROWS_TO_INSERT);
printf("Total (s): %f\n", t.GetSeconds());
printf("Time per row (s): %f\n", t.GetSeconds() / ROWS_TO_INSERT);
if (FAILED(hr))
return (hr);
return (hr);
}
// And this closes the rowset/session.
HRESULT SqlServerBulkDataLoader::CloseDynamicRowsetFastLoad()
{
if (m_RowsetFastLoad)
{
m_DynamicAccessor.ReleaseAccessors(m_RowsetFastLoad);
m_DynamicAccessor.Close();
m_RowsetFastLoad = NULL;
}
m_Session.Close();
m_DataSource.Close();
if (NULL != m_TableId.uName.pwszName)
{
delete [] m_TableId.uName.pwszName;
m_TableId.uName.pwszName = NULL;
}
return (S_OK);
}
Any thoughts?
Chris.
.
- Follow-Ups:
- Re: CDynamicAccessor + IRowsetFastLoad (more...)
- From: Chris Trueman
- Re: CDynamicAccessor + IRowsetFastLoad (more...)
- Prev by Date: Re: Error with ole db for visual foxpro
- Next by Date: Re: CDynamicAccessor + IRowsetFastLoad (more...)
- Previous by thread: IRowsetFastLoad + Runtime Schema
- Next by thread: Re: CDynamicAccessor + IRowsetFastLoad (more...)
- Index(es):
Relevant Pages
|
|