Forum OpenACS Development: Response to Proposal for Tcl/SQL contract

Collapse
Posted by Ed Avis on

Personally I think that having mysterious SQL code in the .tcl files as well as in .xql files is a really bad idea. You'd end up with duplicate code in two places, and not know which one to change (or maybe you'd have to change both). Also you don't want code in your .tcl file which is never actually executed!

(Unless I have misunderstood Domingo Alvarez duarte's proposal.)

If you really really want to have a reminder of the SQL appearing in your .tcl file, make it into a comment! I'd advise against it, but if you like that sort of thing, using a comment gives the same effect as having a string of inline SQL code which is never used, but without the confusion.

The idea for a contract specifying what variables are used is a good idea. IMHO the best way to do it would be to 'call' SQL code like a procedure:

# Get the thingy with id 12345 and store its details into the 
# variables name and height.
# 
db_1row get_thingy {12345} {name height}

And in the .xql file, something like this (just pseudocode really, I'm not pretending that this is what you'd actually write):

get_thingy {
    # Input parameters
    id
} {
    # Output variable names
    nm ht
} {
    select thingy_name as nm,
           thingy_height as ht
    from thingies
    where thingy_id = :id
}

Then there wouldn't really be a possibility of getting out of sync because the variables must get matched up when the query is called. But this is something a bit further than what Dan Chak suggested.

With the original proposal of
db_1row query_name {first_names last_name something}

I'd be in favour _if_ these variable names are checked automatically somehow. If they are not checked and not actually used for anything, they shouldn't be in the code - better to put them as a comment explaining your intentions.