使用 BDE 和 Delphi 访问 dBase 文件的好方法是什么?

发布于 2024-09-09 11:12:49 字数 624 浏览 2 评论 0原文

首先,我必须声明,当谈到 Delphi 时,我是一个完全的新手,尽管大约 14 年前我在学校做过一些 Turbo Pascal 编程...

我有一个商业 Delphi 程序,它使用 dBase 数据库和 BDE访问它们。我基本上需要将另一个用 C# 编写的应用程序连接到该数据库,以便能够执行 SQL 操作,例如选择、插入、更新和删除。

不幸的是,对 dBase 使用 OLEDB 会导致索引损坏,似乎只有本机 BDE 应用程序才能安全地访问数据。

总体思路是创建一个简单的 Delphi 控制台应用程序,它可以从标准输入 (Read/ReadLn) 读取 SQL 语句,并将 CSV 数据输出到标准输出 (WriteLn)。

我该怎么做呢?

我已经成功地获得了简单的 TTable 访问,使用以下代码:

tbl := TTable.Create(nil);

tbl.DatabaseName := 'Exceline';
tbl.TableName := 'KUNDE.DBF';
tbl.Active := True;

WriteLn(tbl.RecordCount);

tbl.Active := False;

有没有一种方法可以通过执行直接 SQL 语句来实现相同的目的?

First of all, I must state that I'm a complete newb when it comes to Delphi, although I did some Turbo Pascal programming in school, some fourteen years ago...

I have a commercial Delphi program which uses dBase database and BDE for accessing them. I basically need to interface another application written in C# to this database, to be able to do SQL operations such as select, insert, update and delete.

Unfortunately using OLEDB against dBase results in broken indexes, only native BDE apps seem to be able to safely access the data.

The general idea was to create a simple Delphi console application which could read SQL statements from standard input (Read/ReadLn) and output CSV data to standard output (WriteLn).

How would I go about doing this?

I have successfully gotten simple TTable-access to work, with the following code:

tbl := TTable.Create(nil);

tbl.DatabaseName := 'Exceline';
tbl.TableName := 'KUNDE.DBF';
tbl.Active := True;

WriteLn(tbl.RecordCount);

tbl.Active := False;

Is there a way I could achieve the same but by executing direct SQL statements instead?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

待"谢繁草 2024-09-16 11:12:49

您可以使用 TQuery 组件执行相同的操作:

qry := TQuery.Create(nil);

qry.DatabaseName := 'Exceline';
qry.SQL.Add('SELECT COUNT(*) AS CNT FROM KUNDE');
qry.Active := True;

WriteLn(qry.FieldByName('CNT').AsString);

qry.Active := False;

You can do the same using TQuery component:

qry := TQuery.Create(nil);

qry.DatabaseName := 'Exceline';
qry.SQL.Add('SELECT COUNT(*) AS CNT FROM KUNDE');
qry.Active := True;

WriteLn(qry.FieldByName('CNT').AsString);

qry.Active := False;
药祭#氼 2024-09-16 11:12:49

正如 Serg 已经写的:您可以使用 tquery 对象在 dbase 表上执行 sql 查询。但要注意:您建议这样做的方式 - 通过 stdin 将 sql 查询传递给程序并让它在 stdout 上返回结果 - 在 Windows 上非常慢。

此外,如果查询结果很大,您还必须向程序添加额外的命令以批量返回数据。
在 Delphi 中编写 COM 服务器并使用 C# 可能更容易,并且会给您带来更好的性能。

最后一点:BDE 多年来一直没有得到 Borland/Codegear/Embarcadero 的支持。它仍然有效,但保持这种状态变得越来越困难,尤其是对于比 XP 更新的 Windows 版本。一种替代方案可能是 tdbf(请参阅 sourceforge),但我对此没有足够的经验,无法为您提供明智的意见。

As Serg already wrote: You can use a tquery object to execute sql queries on dbase tables. But beware: The way you propose to do that - passing a sql query to a program via stdin and having it return the results on stdout - is very slow on Windows.

Also, you will have to add additional commands to your program for returning the data in batches if the result of a query is huge.
It's probably easier and will give you much better performance to write a COM server in Delphi an use that from C#.

And one last point: The BDE has not been supported by Borland/Codegear/Embarcadero for several years. It still works but it gets harder and harder to keep it that way, especially with newer Windows versions than XP. One alternative might be tdbf (see sourceforge), but I have not enough experience with that to give you an informed opinion on it.

笑梦风尘 2024-09-16 11:12:49

由于 BDE 自 10 年前被弃用以来一直没有得到维护:

您是否考虑过 Advantage 数据库服务器?它是一个可以访问 dBase、Clipper 和其他 xBase 的服务器,

它工作得非常好,而且有是一个可用的.NET 数据提供程序

这将使您的解决方案路径变得不那么复杂。

——杰罗恩

Since the BDE has not been maintained since it was deprecated 10 years ago:

Did you consider Advantage Database Server? It is a server that can access dBase, Clipper and other xBase

It works really nice, and there is an .NET Data Provider available for it.

That would make your solution path a lot less complex.

--jeroen

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文