我必须像这样运行一个组查询:
GROUP ON System.ItemName OVER ( SELECT TOP 20 System.ItemName FROM SystemIndex )
但是当我使用C ++ ADO Recordset运行它时,我在Open时得到一个异常(当我搜索SELECT TOP 20 System.ItemName FROM SystemIndex
查询时,它会很好地进行调查)。
所以...如何进行这样的群组搜索?
ADO代码:
_ConnectionPtr connection = NULL;
hr = connection.CreateInstance(__uuidof(Connection));
_RecordsetPtr recordset = NULL;
hr = recordset.CreateInstance(__uuidof(Recordset));
hr = recordset->Open("GROUP ON System.Kind AGGREGATE COUNT() as 'Total' OVER ( SELECT TOP 20 System.ItemName, System.ItemUrl FROM SystemIndex )",
connection.GetInterfacePtr(), adOpenForwardOnly, adLockReadOnly, adCmdText);
经过很长一段时间的努力,我决定直接进入OLE DB,但似乎难以检索搜索数据
OLE DB代码:
CDataSource cDataSource; hr = cDataSource.OpenFromInitializationString(connectionstring);
if (SUCCEEDED(hr))
{
CSession cSession;
if (SUCCEEDED(hr))
{
CCommand<CDynamicAccessor, CRowset> cCommand;
hr = cCommand.Open(cSession, L"GROUP ON System.ItemName OVER ( SELECT TOP 20 System.ItemName, System.Itemurl FROM SystemIndex )");
if (SUCCEEDED(hr))
{
for (hr = cCommand.MoveFirst(); S_OK == hr; hr = cCommand.MoveNext())
{
DBORDINAL columns= cCommand.GetColumnCount();
for (DBORDINAL i = 1; i <= columns; i++)
{
PCWSTR pszName = cCommand.GetColumnName(i);
//HOW TO GET DATA TO A sdt::string ?
}
}
cCommand.Close();
}
}
}