[Gas] (no subject)

Zachary C.Miller wolfgang at wolfgang.groogroo.com
Tue Feb 20 13:44:27 CST 2001


Subject:  DB porting
To:  gas at cu.groogroo.com
Date:  Tue, 20 Feb 2001 13:34:10 -0600 (CST)
Sender:  wolfgang at imsahp.cu.groogroo.com

Bob Cook will be porting DB::Base to work with either PostgreSQL or
Oracle or both. This should be a pretty quick and easy project but I
wanted to give out the details of how that would be done right now:

in the gas repository the file of interest is:
lib/Gas/DB/Base.pm

Basically the task of porting involves going through that file and
looking at all the functions and making sure they will work with your
DB server.

Within that file you can use this idiom to make special cases:

if($db->driver() eq 'mysql') {
	do_something_mysql_specific();
	$sql .= 'mysql_specific_keyword foo';
} elsif($db->driver() eq 'pg' {
	$sql .= 'postgesql_specific_keyword foo';
} else {
	do_something_generic();
}

Bob has suggested that we develop an object oriented approach to doing
these special cases but given the current structure of DB::Base I
think this would be difficult and I think the special cases will be
minimal so we can keep it all in one file for now. I would very much
like to go the object route eventually but I fear it would take a
major redesign of the DB stuff for this to work. 

Bob suggested that there is no auto_increment feature in some
non-MySQL databases. I think the appropriate way to deal with this is
to have DB::Base automatically (for the DB's that need/support it) do
an appropriate "create sequence" when create() is called for some
table having a key ='auto' field. And then the insert() and related
routines would add in the appropriate bits to make sure the key field
gets updated using the sequence. I don't know the specific SQL for
this because I only mainly use MySQL but I know the "active" software
on urbana.indymedia.org does something like this (using sequences for
auto numbered keys).

The DB::Base file is the interface Gas uses to generate all generic
SQL commands. If you do not already have an exising project with its
own DB modules then this Base.pm is the _only_ file that generates any
SQL strings at all.

Later on your project will probably also have DB modules of its own
which define table specific SQL commands. You have the option of
targetting those project specific files to the database your project
uses or of making them portable using the same methods outlined here. 

Someone (maybe me...probably me) should write a complete test suite
for DB stuff so that 1) a porter can identify which stuff in
DB/Base.pm needs to be ported 2) a given port can be rigorously tested
so there are no surprised during later development.

More forthcoming. 

-- 
Zachary C. Miller - @= - http://wolfgang.groogroo.com/
IMSA 1995 - UIUC 2000 - Just Another Leftist Muppet
 Social Justice, Community, Nonviolence, Decentralization, Feminism,
 Sustainability, Responsibility, Diversity, Democracy, Ecology
Ya Basta! - http://www.greens.org




More information about the Gas mailing list