1
votes

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?

3
As someone said below, the BDE is seriously deprecated, and you shouldn't be using it in new code! :-) dBase, man?! 1989 called and it wants it database file format back. At least with tdbf (mentioned below) you can drop the horrid BDE-redistributable package. Good luck!Warren P

3 Answers

8
votes

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;
4
votes

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.

0
votes

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