Closed Thread Icon

Topic awaiting preservation: Coding to handle various databases (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=26317" title="Pages that link to Topic awaiting preservation: Coding to handle various databases (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Coding to handle various databases <span class="small">(Page 1 of 1)</span>\

 
H][RO
Bipolar (III) Inmate

From: Australia
Insane since: Oct 2002

posted posted 07-24-2005 03:13

I'm doing a project at the moment (actually in vb.net) and want to do some research in this area. The principles are the same for any coding, php etc.

Basically I have an interface which gets records from a database etc via the relevant queries. What i'm trying to figure out is what is the best way to do the code so that you could relatively *easily* change the type of database if you wanted. I will be using a postgre database and might want ot change it to mysql or even a nastier JET (access) database.

Im just wonder if there is a method that people use for this? Is there another layer that passes back arrays of values etc. I've been looking into xml especially since vb.net has built in stuff for this - im just finding it hard to see how I could get benefit from using it.

Anyhow any thoughts from you all would be great thanks.

DL-44
Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 07-24-2005 17:42

Commonly referred to as database abstraction -

http://www.gurusnetwork.com/tutorial/database_abstraction/

DmS
Maniac (V) Inmate

From: Sthlm, Sweden
Insane since: Oct 2000

posted posted 07-24-2005 19:01

Basic princple, separate the code that's specific for each db, connection and so on from the rest of the non-specific code.
Then you write a layer (procedural or OOP) that holds methods to insert, update, delete in the ways the application needs. This layer calls the specific code needed to connect to the db in question. The common layer you write should be the only thing the rest of the db sees.

What you should think about in the db-specific code is to make sure that the data is returned in the same format regardless of db.

/Dan

{cell 260} {Blog}
-{ ?There are two major products that come out of Berkeley: LSD and UNIX. We don't believe this to be a coincidence. - Jeremy S. Anderson" }-

H][RO
Bipolar (III) Inmate

From: Australia
Insane since: Oct 2002

posted posted 07-25-2005 01:41

I guess thats what I was thinking, the problem lies where some databases support some features where others dont. For examble using LIMIT in your queries which I do quite often these days for mysql. How would you normally handle that? Have something in the specific DB layer that removes it from the query string?

DL-44
Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 07-25-2005 03:16

I would think the other way around - the actual query string that gets fed to the DB should be created by that abstraction layer based on the criteria passed to it from the interface.

That way there is nothing to remove. The query is built however it needs to be built depending on the DB being used.

I've never done this myself....but that seems like the better approach overall.

H][RO
Bipolar (III) Inmate

From: Australia
Insane since: Oct 2002

posted posted 07-25-2005 07:13

Yeh I see what you mean, I guess the database functions in the abstraction could use LIMIT within them depending on the query... Mmm at this stage i will probably only use postgreSQL straight up but I like to leave it changable in the future. Will have to see what I can come up with.

Thanks for the help

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 07-25-2005 09:24

There's only one problem in Computer Science that can't be solved by another layer of indirection - I'll leave you to figure it out...

H][RO
Bipolar (III) Inmate

From: Australia
Insane since: Oct 2002

posted posted 07-25-2005 09:37

Ohhhh =/

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 07-25-2005 18:29

Yeah I've had to work with abstraction layers designed to remove the SQL from the equation.

It always sucks.



.:[ Never resist a perfect moment ]:.

H][RO
Bipolar (III) Inmate

From: Australia
Insane since: Oct 2002

posted posted 07-26-2005 01:23

I can imagine for normal stuff it would be pretty simple, but if you want to do joins and subqueries it could be a prick depending how different the databases are.

Now to figure out how to create reports in vb.net wihout bloody crystal reports

« BackwardsOnwards »

Show Forum Drop Down Menu