BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

"Database access" patterns - Opinion

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OO design
View previous topic :: View next topic  
Author Message
Mario
Guest





PostPosted: Sat Nov 15, 2003 2:21 pm    Post subject: "Database access" patterns - Opinion Reply with quote



Hi all!

I am trying to build an application which will access in future more than
one DB server.
I started now with Interbase and I have a question before going further.

I thought to use the Sigleton model for doing this and I don't know if this
is the best solution.
I have a connection class where some common methods are implemented and some
abstract methods are defined.
In the child class I have the abstract methods implemented.

I thought I should do this because of the fact that SQL statements differ
from server to server (sometimes)
and in the future I can build the next class(es) (Microsoft SQL Server e.g.)
without having to modify anything else in my app.
Is this a good aproach?!?!
I am using the Delphis DBExpress for doing this.
Is there any example available on the web how can this be or has been done?

Thanks for any opinion and help!
Mario

--------------------------------------------------------
{the main connection class}
TMDDBAbstractFactory = class
protected
MD_SHOW_EXCEPTIONS: Boolean;

MD_SQLConnection: TSQLConnection;
MD_SQLGeneralQuery: TSQLQuery;
public
constructor Create;
destructor Destroy; override;
{abstract widgets contructors}
//connects to a given database
//and returns True if the connection was successfull
function Connect2Database(DatabaseName: String) : Boolean; virtual;
abstract;
//creates a table in the database
//the TableFields is formated as FieldName||FieldType
//the FieldType will include also the constraints and all other
definitions
function CreateTable(TableName: String; TableFields: TStringList) :
Boolean; virtual; abstract;
//returns all records from the given table
//the result is true if the query can be executed
//and the dataset contains all the records in the table
function GetAllRecords(var ASimpleDataSet: TSimpleDataSet; TableName:
String;
SelectedFields: String = '*') : Boolean;
//returns the number of records in a given table as integer
function GetRecordCount(TableName: String) : Integer;
//inserts a record in the given table
function InsertRecordInTable(TableName: String; TableFields,
TableValues: Variant) : Boolean;
//deletes a record from the given table
function DeleteRecordFromTable(TableName: String; ConditionFields,
ConditionValues: Variant) : Boolean;
end;

--------------------------------------------------------
{Interbase connection class}
TMDDBInterbaseFactory = class(TMDDBAbstractFactory)
public
constructor Create;
{concrete widgets constructors}
function Connect2Database(DatabaseName: String) : Boolean; override;
function CreateTable(TableName: String;
TableFields: TStringList) : Boolean; override;
end;


Back to top
Joanna Carter (TeamB)
Guest





PostPosted: Sat Nov 15, 2003 2:32 pm    Post subject: Re: "Database access" patterns - Opinion Reply with quote



Mario wrote:

Quote:
I am trying to build an application which will access in future more
than one DB server.
I started now with Interbase and I have a question before going
further.

Looks like you have made an interesting first attempt, but have you looked
at my papers on Object Persistence Frameworks?? They are available from my
site:

www.carterconsulting.org.uk

Joanna

--
Joanna Carter (TeamB)

Consultant Software Engineer
TeamBUG support for UK-BUG
TeamMM support for ModelMaker



Back to top
Mario
Guest





PostPosted: Sat Nov 15, 2003 2:56 pm    Post subject: Re: "Database access" patterns - Opinion Reply with quote



Just started reading...
Thanks!

Mario

"Joanna Carter (TeamB)" <joannac (AT) btinternetXX (DOT) com> wrote

Quote:
Mario wrote:

| I am trying to build an application which will access in future more
| than one DB server.
| I started now with Interbase and I have a question before going
| further.

Looks like you have made an interesting first attempt, but have you looked
at my papers on Object Persistence Frameworks?? They are available from my
site:

www.carterconsulting.org.uk

Joanna

--
Joanna Carter (TeamB)

Consultant Software Engineer
TeamBUG support for UK-BUG
TeamMM support for ModelMaker





Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OO design All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.