简体   繁体   English

使用C ++将多个记录添加到ADO记录集的最快方法

[英]Fastest way to add multiple records to ADO recordset using C++

We have a data model that supports single table databases hosted on multiple servers. 我们有一个数据模型,它支持在多个服务器上托管的单个表数据库。 However we occasionally need to compile data from multiple tables for display on classic ASP pages. 但是,有时我们需要从多个表中编译数据以在经典ASP页上显示。 This is done in a COM object in C++. 这是在C ++中的COM对象中完成的。 We gather the data from SQL Server using OleDb, with the OleDb logic writing the data straight into C++ structs. 我们使用OleDb从SQL Server收集数据,OleDb逻辑将数据直接写入C ++结构。 We then loop through the struct arrays adding the data to SafeArrays, then add these to the recordset. 然后,我们遍历结构数组,将数据添加到SafeArrays,然后将它们添加到记录集。 The logic to add the data to the recordset looks roughly like the following (initialisation and error handling logic omitted): 将数据添加到记录集的逻辑大致类似于以下内容(省略了初始化和错误处理逻辑):

SAFEARRAY* fields; // Initialised to integer array 0 -> max fields
SAFEARRAY* values;
VARIANT* arraydata;

... //  initialisation logic

SafeArrayAccessData(values, reinterpret_cast<void**>(&arrayData));

for(unsigned int i = 0; i < numDataValues1; ++i)
{
    // Add data
    arraydata[0].intVal = data[i].someValue;
    ... // etc.

    for(unsigned int j = 0; j < numDataValues2; ++j)
    {
        arraydata[21].intVal = data2[j].someValue;
        ... // etc.

        _recordset->raw_AddNew(fields, values);
        _recordset->Update();
    }
}

However it is relatively slow. 但是,它相对较慢。 It can take a second to add a 1000 rows of data, which is just too long in our environment. 添加1000行数据可能需要一秒钟,这在我们的环境中太长了。 If I comment out the calls to raw_AddNew and Update the logic flies. 如果我注释掉了对raw_AddNew的调用并更新了逻辑。 So the issue is with how I am adding the data to the recordset. 因此,问题在于我如何将数据添加到记录集。 Any suggestions or advice hugely appreciated. 任何建议或意见深表感谢。 Big thanks in advance. 预先非常感谢。

It has been a long time since I've coded ADO database connections, but if I remember right you need to change your locking to adLockBatchOptimistic and then do a batch update. 自从我编写ADO数据库连接以来已经有很长时间了,但是如果我没记错的话,您需要将锁定更改为adLockBatchOptimistic,然后进行批量更新。 It is much faster that way. 这样可以更快。

This might help you 这可能对您有帮助

If I remember right, it still was pretty slow. 如果我没记错的话,它仍然很慢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM