Using Zeos Lib for Database Connectivity

ZeosLib“aka Zeos, is a open source library that provide native access to many database systems, developed for Delphi, Kylix and Lazarus + Freepascal….”

So why we need it? I think every delphi developers would agree that it is quite annoying when application deployment involved database connectivity. First step we need to install suitable database drivers, configure the windows ODBC setting, then last step is to fine tune the database setting inside the BDE.

Not only requiring a lot of preparation work, but also creating a lot of trouble for latter on maintenance. The Zeos Lib aims for this weakness, it provides one step connectivity with the raw databases. All you need is to copy those required database dll to your application folder, that’s all. Wouldn’t it be nice with this simple step?

Here is just an example for using PostgreSQL (version 8.2), first copy the below files of dll from the bin folder of your PostgreSQL server installation to the application directory.

libpq.dll
comerr32.dll
iconv.dll
krb5_32.dll
libeay32.dll
libiconv-2.dll
libintl-2.dll
ssleay32.dll

Then inside the delphi application, put the following components to your applicaiton form:

TZConnection, two TZQuerys (one for simple SQL statement, one for displaying Chinese characters properly). Configure the following database connection as below:

TZConnection Setting

Some related components are added as well as shown below:

Application Form

We also need to execute the following code once the ZConnection is established, otherwise the Chinese characters will not be shown properly.  That why we need another TZQuery for achieving this purpose.

procedure TForm1.ZConnection1AfterConnect(Sender: TObject);
begin
qryTemp.Close;
qryTemp.SQL.Clear;
qryTemp.SQL.Add(‘Set Client_Encoding to “big5″‘);
qryTemp.ExecSQL;
end;

That’s all.

Application Result

Just so simple to use and easy for maintenance.  Happy Programming !!

References