[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [stellation-res] Database abstraction
|
On Tue, Aug 13, 2002 at 02:06:39PM +0000, Mark C. Chu-Carroll wrote:
>
> So... I'm looking at trying to create a database abstraction layer that
> will work accross Postgres, DB2, Oracle, MySQL/InnoDB, and
> Firebird.
>
> One option is to totally automate the SQL generation process. This
> allows us to smoothly handle things like the INNODB declarations
> that need to go onto the end of table creations, variations in typenames,
> etc.
Mark,
Please let down the Java hammer for a while. This can be trivially done
with a bit of templating in Perl. Nice and clean.
I don't have Oracle and DB/2 handy but if you give me three SQL scripts
that are correct for Postgres/Oracle/DB\/2 I will write the perl script
that generates them.
florin
>
> I've tried a first cut at doing this for table creation. I'm looking at a
> bit of test code, and I can't decide whether I like it (it's nicely abstract,
> and quite easy to write), or hate it (it's hard to see the SQL in it). Here's
> a sample: what do you folks think: is this a good direction, or am I being
> idiotically abstract?
>
> Here's the original SQL:
>
> CREATE TABLE Properties (INTEGER aid,
> INTEGER vid,
> INTEGER inheritable,
> VARCHAR(200) name,
> VARCHAR(1600) value,
> CONSTRAINT fk3 FOREIGN KEY (aid, vid) REFERENCES Versions(aid, vid)
> PRIMARY KEY(aid, vid, name))
>
>
> Here's the corresponding code:
> DatabaseCreateTableCommand cmd =
> _db.createTable("Properties")
> .addIntegerField("aid")
> .addIntegerField("vid")
> .addIntegerField("inheritable")
> .addShortStringField("name")
> .addLongStringField("value")
> .beginForeignKeyConstraint("fk3", "FOREIGN KEY")
> .addConstraintField("aid")
> .addConstraintField("vid")
> .beginForeignKeyReferences("Versions")
> .addConstraintField("aid")
> .addConstraintField("vid")
> .endForeignKeyConstraint()
> .beginPrimaryKeyConstraint()
> .addConstraintField("aid")
> .addConstraintField("vid")
> .addConstraintField("name")
> .endPrimaryKeyConstraint()
> .endCommand();
Brrrrrrrr....
--
"If it's not broken, let's fix it till it is."
41A9 2BDE 8E11 F1C5 87A6 03EE 34B3 E075 3B90 DFE4
Attachment:
pgpf7qPwkdvi8.pgp
Description: PGP signature