我正在同一应用程序中使用多个数据库。我正在使用来自两家不同公司的驱动程序。两家公司都有运行良好的 tTable 和 tQuery 后代。
我需要一种对数据进行通用访问的方法,无论我使用哪个驱动程序/tQuery 组件来返回一组数据。这些数据不会与组件相关,而只会与我的逻辑相关。
例如...(伪代码)让我们创建一个可以针对任一 tQuery 组件运行的函数
function ListAllTables(NameOfDatabase : String) :ReturnSet??
begin
If NameOfDataBase = 'X' then use tQuery(Vendor 1)
else use tQuery(Vendor 2)
RunQuery;
Return Answer...
end;
当正常运行查询时,我会执行
Query.Open;
While not Query.EOF do
begin
Read my rows..
next;
end;
如果我调用 ListAllTables,我的返回类型是什么,以便我可以迭代行?每个 tQuery 供应商都是不同的,所以我不能使用它(我可以吗?如果是的话,我会想要吗?)我可以构建一个内存表,并将其传回,但这似乎是 ListAllRows 构建一个内存表的额外工作内存表,然后将其传递回调用例程,以便它可以“取消构建”,即迭代行......
您的想法和建议是什么?
谢谢
GS
I am working with multiple databases within the same application. I am using drivers from two different companies. Both companies have tTable and tQuery Descendants that work well.
I need a way to have generic access to the data, regardless of which driver/tQuery component I am using to return a set of data. This data would NOT tie to components, just to my logic.
For example...(pseudocode) Let's create a function which can run against either tQuery component
function ListAllTables(NameOfDatabase : String) :ReturnSet??
begin
If NameOfDataBase = 'X' then use tQuery(Vendor 1)
else use tQuery(Vendor 2)
RunQuery;
Return Answer...
end;
When NORMALLY running a query, I do
Query.Open;
While not Query.EOF do
begin
Read my rows..
next;
end;
If I am CALLING ListAllTables, what is my return type so that I can iterate through the rows? Each tQuery Vendor is different, so I can't use that (can I, and if so, would I want to?) I could build a Memory Table, and pass that back, but that seems like extra work for ListAllRows to build a memory table, and then to pass it back to the calling routine so that it can "un-build", i.e. iterate through the rows...
What are your ideas and suggestions?
Thanks
GS
发布评论
评论(4)
几乎所有 Delphi 数据集都源自 TDataset,并且最有用的行为是在 TDataset 上定义的。
因此,如果将每个表或查询分配给 TDataset 类型的变量,则应该能够以供应商中立的方式对该数据集执行逻辑。
我还将数据集的生成隔离到一组工厂函数中,这些函数仅创建特定于供应商的数据集并将其作为 TDataset 返回。每个工厂功能都有自己的单元。然后,只有那些小单元需要了解供应商特定组件。
Almost all Delphi datasets descend from TDataset, and most useful behavior is defined on TDataset.
Therefore, if you assign each table or query to a variable of type TDataset, you should be able to perform your logic on that dataset in a vendor neutral fashion.
I would also isolate the production of the datasets into a set of factory functions that only create the vendor-specific dataset and return it as a TDataset. Each factory function goes in it's own unit. Then, only those small units need have any knowledge of the vendor specific components.
例如:
For example:
也许您可以考虑使用通用数据访问组件,例如 UniDAC 或 AnyDAC。这允许您仅使用一个组件集以一致的方式访问不同的数据库。
您可能还对 RemObjects 的 DataAbstract 感兴趣。一个强大的数据抽象、多层、远程处理解决方案,具有许多功能。不便宜,但物超所值。
相关链接:
Perhaps you could consider a universal data access component such as UniDAC or AnyDAC. This allows you to use only one component set to access different databases in a consistent way.
You might also be interested in DataAbstract from RemObjects. A powerful data abstraction, multi-tier, remoting solution with a lot of features. Not inexpensive, but excellent value for the money.
Relevant links:
一个简单的方法是让 ListAllTables 返回(或填充)一个字符串列表。
A simple approach would be to have ListAllTables return (or populate) a stringlist.