[Info-vax] Any stronger versions of the LMF planned ?, was: Re: LMF Licence Generator Code

Arne Vajhøj arne at vajhoej.dk
Wed Aug 18 14:49:19 EDT 2021


On 8/18/2021 4:27 AM, Lawrence D’Oliveiro wrote:
> On Sunday, August 15, 2021 at 12:46:16 PM UTC+12, Arne Vajhøj wrote:
>> In Python something like:
>> sqlstr = 'SELECT name1,name2 FROM pairs'
>> param = []
>> if any(activeconditions):
>> sqlstr = sqlstr + ' WHERE ' + ' AND '.join(map(lambda item:
>> item[0] + '=?', activeconditions))
>> param = list(map(lambda item: item[1], activeconditions))
>> c.execute(sqlstr, param)
>> Single static SQL using the coalesce trick and sending over NULL
>> for not used parameters means to use a fixed SQL string like:
>>
>> ... WHERE field1 = COLALESCE(?,field2) AND field2 = COLALESCE(?,field2) ...
>>
>> and send over values for all fields but NULL for those fields not to be
>> used.
>>
>> In Python something like:
>>
>> sqlstr = 'SELECT name1,name2 FROM pairs WHERE name1 =
>> COALESCE(?,name1) AND name2 = COALESCE(?,name2)'
>> allfields = ['name1', 'name2']
>> param = []
>> for f in allfields:
>> param.append(conditions[f])
>> c.execute(sqlstr, param)
>>
>> In VMS COBOL something like:
>>
>> 01 NAME1 PIC X(32).
>> 01 NAME2 PIC X(32).
>> 01 NAME1PRES PIC S9.
>> 01 FINDNAME1 PIC X(32).
>> 01 NAME2PRES PIC S9.
>> 01 FINDNAME2 PIC X(32).
>> EXEC SQL DECLARE curs CURSOR FOR SELECT name1,name2 FROM pairs WHERE
>> name1 = COALESCE(:findname1:name1pres,name1) AND name2 =
>> COALESCE(:findname2:name2pres,name2) END-EXEC.
>> ...
>> EXEC SQL OPEN curs END-EXEC
>> ...
>> EXEC SQL CLOSE curs END-EXEC.
> 
> At least you get points for trying. Notice your code is already about an order of magnitude larger than mine,

It is not.

The Python code is about the same (your code did not
show the SQL or execute, but that does not mean that
they are not needed).

The COBOL code is more lines. For one reason: everything need to be
declared with a type. You may not like that, but I think that the
COBOL programmers like that.

> Consider how you would add another search field: you have to add it in 3 places in the Python version, and is it actually 6 places in the COBOL one?!?

Not quite accurate.

The Python dynamic example does not use fieldnames in the code at all.

The Python static example will need an extra WHERE condition plus an
update of the list of field names - the list is not strictly necessary
but avoid the dependency on the order of fields, and when it is next to
the SQL then it should not be a problem.

The COBOL example will also need an extra WHERE condition and
will need both value and NULL indicator to be declared.

Arne




More information about the Info-vax mailing list