数据集从另一个数据集检索数据
我使用的应用程序从基于文件的数据存储切换到基于数据库的数据存储。它有大量专门针对基于文件的系统编写的代码。为了进行切换,我正在实现将像旧系统一样工作的功能,然后计划在新代码中更优化地使用数据库。
一个问题是基于文件的系统经常读取单个记录,并重复读取它们以获取报告。这导致对数据库进行大量查询,速度很慢。
我一直试图充实的想法是使用两个数据集。一个数据集用于检索整个表,另一个数据集用于针对第一个数据集进行查询,从而减少与数据库服务器的通信开销。
我尝试查看 TADODataSet
的 DataSource
属性,但数据集似乎仍然需要连接,并且它直接询问数据库是否Connection
已分配。
我更愿意在另一个数据集中获取结果,而不是导航第一个数据集的原因是,已经实现了大量用于模拟旧系统的逻辑。此逻辑基于仅包含使用旧接口查询的结果的数据集。
该功能只需支持读取数据,而不支持写回。
如何使用一个数据集为另一个数据集提供值以供选择?
我使用的是 Delphi 2007 和 MSSQL。
I work with an application that it switching from filebased datastorage to database based. It has a very large amount of code that is written specifically towards the filebased system. To make the switch I am implementing functionality that will work as the old system, the plan is then making more optimal use of the database in new code.
One problem is that the filebased system often was reading single records, and read them repeatedly for reports. This have become alot of queries to the database, which is slow.
The idea I have been trying to flesh out is using two datasets. One dataset to retrieve an entire table, and another dataset to query against the first, thereby decreasing communication overhead with the database server.
I've tried to look at the DataSource
property of TADODataSet
but the dataset still seems to require a connection, and it asks the database directly if Connection
is assigned.
The reason I would prefer to get the result in another dataset, rather than navigating the first one, is that there is already implemented a good amount of logic for emulating the old system. This logic is based on having a dataset containing only the results as queried with the old interface.
The functionality only have to support reading data, not writing it back.
How can I use one dataset to supply values for another dataset to select from?
I am using Delphi 2007 and MSSQL.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 ClientDataSet/DataSetProvider 对从现有 DataSet 中获取数据。您可以使用源数据集上的过滤器、ClientDataSet 上的过滤器和提供程序事件来将数据集仅修剪为感兴趣的记录。
我在几个迁移项目中成功地使用了这种技术,并缓解了类似的情况,即旧的 SQL Server 7 数据库被查询数千次以检索单个记录,从而带来了痛苦的性能成本。仅查询一次,然后将单个记录提取到客户端数据集,在当时不仅是一种优雅的解决方案,而且对特定应用程序的性能有很大的提升:最好的例子是将 8 小时的过程减少到 15 分钟。那时候可怜的用户爱我。
ClientDataSet 只是一个 TDataSet,您可以无缝集成到现有代码和 UI 中。
You can use a ClientDataSet/DataSetProvider pair to fetch data from an existing DataSet. You can use filters on the source dataset, filters on the ClientDataSet and provider events to trim the dataset only to the interesting records.
I've used this technique with success in a couple of migrating projects and to mitigate similar situation where a old SQL Server 7 database was queried thousands of times to retrieve individual records with painful performance costs. Querying it only one time and then fetching individual records to the client dataset was, at the time, not only an elegant solution but a great performance boost to that particular application: The most great example was an 8 hour process reduced to 15 minutes... poor users loved me that time.
A ClientDataSet is just a TDataSet you can seamlessly integrate into existing code and UI.