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

◇◆丶佛笑我妖孽 提交于 2019-12-24 11:28:47

问题


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?


回答1:


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;



回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/3221364/what-is-a-good-way-of-accessing-dbase-files-using-bde-and-delphi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!