简体   繁体   English

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

[英]What is a good way of accessing dBase files using BDE and Delphi?

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... 首先,我必须说,关于Delphi,我是一个新手,尽管大约十四年前我在学校做了一些Turbo Pascal编程...

I have a commercial Delphi program which uses dBase database and BDE for accessing them. 我有一个商业的Delphi程序,它使用dBase数据库和BDE来访问它们。 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. 我基本上需要将另一个用C#编写的应用程序连接到该数据库,以便能够执行SQL操作,例如选择,插入,更新和删除。

Unfortunately using OLEDB against dBase results in broken indexes, only native BDE apps seem to be able to safely access the data. 不幸的是,对dBase使用OLEDB会导致索引损坏,只有本地BDE应用程序似乎才能安全地访问数据。

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

How would I go about doing this? 我将如何去做呢?

I have successfully gotten simple TTable-access to work, with the following code: 我已经使用以下代码成功完成了简单的TTable访问:

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? 除了执行直接SQL语句外,是否有其他方法可以达到相同目的?

You can do the same using TQuery component: 您可以使用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;

As Serg already wrote: You can use a tquery object to execute sql queries on dbase tables. 正如Serg所写的那样:您可以使用tquery对象在dbase表上执行sql查询。 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. 但是要当心:您建议这样做的方式-通过stdin将sql查询传递给程序,并使其在stdout上返回结果-在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#. 它可能更容易,并且会为您提供更好的性能,以用C#的方式在Delphi中编写COM服务器。

And one last point: The BDE has not been supported by Borland/Codegear/Embarcadero for several years. 最后一点:BDE多年来没有得到Borland / Codegear / Embarcadero的支持。 It still works but it gets harder and harder to keep it that way, especially with newer Windows versions than XP. 它仍然可以工作,但是保持这种方式变得越来越困难,尤其是在Windows版本比XP更新时。 One alternative might be tdbf (see sourceforge), but I have not enough experience with that to give you an informed opinion on it. 一种选择可能是tdbf(请参阅sourceforge),但是我对此的经验不足,无法为您提供有关它的见解。

Since the BDE has not been maintained since it was deprecated 10 years ago: 自从10年前弃用BDE以来,一直没有对其进行维护:

Did you consider Advantage Database Server ? 您是否考虑过Advantage Database Server It is a server that can access dBase, Clipper and other xBase 它是可以访问dBase,Clipper和其他xBase的服务器

It works really nice, and there is an .NET Data Provider available for it . 它工作得非常好,并且有.NET数据提供程序可用

That would make your solution path a lot less complex. 这将使您的解决方案路径变得不那么复杂。

--jeroen --jeroen

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

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