CHMlib Logo Leading Translation Management System for Translation Agencies, Top Translation Management Software for Freelance Translators, Time Tracking Software, Word Count, Character Count and Line Count Software, Computer Assisted Translation Tool for Easy Word Count, Clipboard Character Count Software, User-Friendly Translation Memory Software, Terminology Management Software, Terminology Management Server, Microsoft Glossary Software, Dictionary of Acronyms, Social Network for Translators and Translation Agencies, Acronyms and Abbreviations Search Engine, Russian Translation Lab, Ukrainian Translation Lab.
You are reading help file online using chmlib.com
CrisisHelper - First Aid in Tough Times of World Economic Crisis


_bm0 Rave Reports Developer Guide

Example PAS .

Top  Previous  Next

The added fields and properties of the TDLSampleConnection class should be specific to the database system that the driver is being written for. Some database systems will require only one component (such as TADOConnection for the ADO driver) while others will require more than one component (such as TDatabase and TSession for the BDE driver). It is recommended to create read-only properties for each field so that the other classes, specifically the TDLSampleResultSet.OpenDataSet method, can access the require database system components.

 

RvDLSample.pas

 

unit RvDLSample;

 

interface

 

uses

Windows, SysUtils, Classes, Forms, RvDLCommon, RvDLBase, RvDLDataSet;

 

type

TDLSampleDriver = class(TDLDataSetDriver)

public

   function CreateConnection: TDLBaseConnection; override;

   function CreateResultSet(AConnection: TDLBaseConnection): TDLBaseResultSet; override;

   procedure Information(Params: PDLInformation); override;

end;

 

TDLSampleConnection = class(TDLDataSetConnection)

private

   FDatabase: TSampleDatabase; // Database component(s) specific to the Sample Database system

public

   procedure Connect(ADataSource, AUserName, APassword: string; AOptionList: TStringList); override;

   procedure Disconnect; override;

   procedure GetTableNames(List: TStrings); override;

   //

   property Database: TSampleDatabase read FDatabase;

end; { TDLSampleConnection }

 

TDLSampleResultSet = class(TDLDataSetResultSet)

public

   function OpenDataSet(QueryStr: string): TDataSet; override;

end; { TDLSampleResultSet }

 

implementation

 

{ TDLSampleDriver }

 

function TDLSampleDriver.CreateConnection: TDLBaseConnection;

begin

{ Create connection object }

Result := TDLSampleConnection.Create;

end;

 

function TDLSampleDriver.CreateResultSet(AConnection: TDLBaseConnection): TDLBaseResultSet;

begin

{ Create result set object }

Result := TDLSampleResultSet(AConnection).Create;

end;

 

procedure TDLSampleDriver.Information(Params: PDLInformation);

begin

{ Return installed state, version and driver names }

Params.Installed := true; // Should return whether database client exists on this system or not

Params.VerMajor := 1;

Params.VerMinor := 0;

StrPCopy(Params.InternalName,'Sample');

StrPCopy(Params.DisplayName,'Sample Database Engine');

end;

 

{ TDLSampleConnection }

 

procedure TDLSampleConnection.Connect(ADataSource, AUserName, APassword: string; AOptionList: TStringList);

begin

{ Create a connection to the database. Sample code below. }

FDatabase := TSampleDatabase.Create(nil);

Database.DataSource := ADataSource;

Database.UserName := AUserName;

Database.Password := APassword;

Database.Option1 := AOptionList.Values['Option1'];

Database.Option2 := AOptionList.Values['Option2'];

Database.Connected := true;

end;

 

procedure TDLSampleConnection.Disconnect;

begin

{ Disconnect from the database and free any allocations. Sample code below }

FreeAndNil(FDatabase);

end;

 

procedure TDLSampleConnection.GetTableNames(List: TStrings);

begin

{ Return a list of table names in this connection... }

Database.GetTableNames(List);

end;

 

{ TDLSampleResultSet }

 

function TDLSampleResultSet.OpenDataSet(QueryStr: string): TDataSet;

begin

{ Open a result set by creating query for QueryStr. Sample code below. }

Result := TSampleQuery.Create(Application);

try

   with TSampleQuery(Result) do begin

     Database := TDLSampleConnection(self.Connection).Database;

     SQL.Text := QueryStr;

     Open;

   end;

except

   Result.Free;

   raise; // re-raise the exception so that it can be handled by the DataLink system

end;

end;

 

initialization

RegisterDriverClass(TDLSampleDriver);

end.

 

The Connect method is used to initialize the database system object fields from the DataSource, UserName, Password and OptionList values. The Disconnect method should close and free any objects that were created in the Connect method. Lastly for the TDLSampleConnection class, the GetTableNames method should fill up the List parameter with the available table names for the current connection. The code for this method is usually quite different from one database system to another.

 

The TDLSampleResultSet.OpenDataSet method is used to create and open a TDataSet compatible component initialized for the current connection settings and QueryStr parameter (SQL text).

 

One other method that may need to be overridden is the TDLBaseConnection.GetFields method. The standard declaration of this method is:

 

procedure TDLBaseConnection.GetFields(TableName: string);

begin

with Driver.CreateResultSet(self) do try

// Create an empty result set to get field info only

Open('select * from ' + TableName + ' where 0=1');

GetFields(Driver.Fields); // Global Driver FieldList

Close;

finally

Free;

end; { with }

end;

 

If the database system is not compatible with the above SQL statement (select * from TableName where 0=1) and supports another method to retrieve the field information for a specific tablename this method can be overridden. If the alternate method does not require the creation of a resultset object, then the code for TDLDataSetResultSet.GetFields, specifically the calls to AFields.AllocFieldList and AFields.SetFieldItem, should be copied and modified in the overridden method.



You are reading help file online using chmlib.com

If you want your help file to be removed or added please send e-mail to chmlibcom@gmail.com