in reply to Module Design Review -- DB mini language

I personally can't quite see why this is any better than SQL.

Call me crazy, but I rather like SQL - it's pretty clear given enough whitespace.
Aliases make selecting from multiple tables and/or subselects tidy too.

Vanilla SQL* is going to be more portable than DAL - learn SQL and you can use it from Perl, PHP, $fave_language, whereas DAL is only being to be useful with your module to hand.

You're not providing anything clever (i.e. database independent SQL).

It'd be really cool if DAL spat out SQL that attempted to do The Right Thing, depending on the database it's talking too.

Interesting idea, but I can't see any practical use for it.

Cheers.

BazB

* OK, I know that Oracle, MySQL, PostGreSQL etc all have their own specific SQL extensions/mutations.

Update:
When I use SQL, I tend to go totally overkill on the whitespace.
Taking your example SQL, I have to admit the way you've formatted it is pretty nasty.

I'd lay it out as follows:

SELECT w.id, w.definition FROM words w, stock s, languages l, stockmatch m, types t WHERE s.word = ? AND l.name = ? AND s.languageID = l.id AND m.stockID = s.id AND w.id = m.wordID AND t.name = ? AND w.typeID = t.id;

I'd possibly group the where clauses together by table too, if it made it easier to figure out which tables/columns where being used without having to scan up and down the list.

You'd line everything up in Perl, why not do it in SQL?


If the information in this post is inaccurate, or just plain wrong, don't just downvote - please post explaining what's wrong.
That way everyone learns.

Replies are listed 'Best First'.
Re: Re: Module Design Review -- DB mini language
by tantarbobus (Hermit) on Feb 10, 2003 at 22:52 UTC
    I agree with you on the whitespace, but I think that, while it may increase typing, spelling out your joins is much cleaner and easier to read (if the db that you are using support it).
    SELECT words.id, words.definition FROM stock JOIN languages ON (stock.languageID = languages.id) JOIN stockmatch ON (stockmatch.stockID = stocks.id) JOIN words ON (stockmatch.wordID = words.word_id) JOIN types ON (words.typeID = types.id) WHERE stock.word = :stock_word AND language.name = :language_name AND type.name = :type_name
    And if you are joining two tables on a column that has the same name in both tables you can:
    SELECT * FROM table_one JOIN table_two USING (join_column)