International Developer Logo Last Updated 27.08.08 at 11.48
On Sale
This months front cover, click to see the table of contents.
Subscribe
 
TUTORIALS

Writing Portable SQL


Daniel winter   11.09.06

Designing a DAL

Building a database abstraction layer is no small undertaking. If there are no suitable DAL libraries available to you, or if you are dissatisfied with their features or performance, there are a few basic principles that may help to follow. Firstly, it is a good idea to separate the functionality of each database into a separate library. Unlike the simplified code examples given above, a base class or interface should be built which caters to the lowest common denominator - probably SQL-92. Each supported database would then be implemented in a separate class library that inherits the base class or implements the core interface. Where applicable, vendor specific features should be used to take advantage of the optimisations available. The base class must then be updated to provide a common workaround for the new DAL feature. Where equivalent features are not available in the other database types, the base class provides the equivalent functionality.

In addition to the object-oriented model described above, it is also a good idea to use a separate SQL statement store for each database type. This way, it is possible to avoid using SQL query strings within the business login of the application. Additionally, if a feature is available to a particular vendor – such as the CACHE keyword in MySQL SELECT statements – then it can be implemented in the statement storage file. Although a little beyond the scope of this tutorial, many portability issues that result from over-complexity can be avoided simply by using better database design principles. A familiarity with joins and indexes and their effect on performance can prove to be more valuable than a thoroughly implemented abstraction layer.

 

 

Online Resources

 

SQL-92/99/2003

http://savage.net.au/SQL

 

ADOdb for PHP

http://adodb.sourceforge.net

 

libdbi for C

http://libdbi.sourceforge.net/

 

Perl DBI

http://dbi.perl.org/

openrico.org/rico/home.page




   Previous Page  1 2 3 4 5 6 7 8 Next Page   

HAVE YOUR SAY
This article is rated  Rate this article