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

Arne Vajhøj arne at vajhoej.dk
Thu Aug 12 21:18:33 EDT 2021


On 8/12/2021 7:52 PM, Lawrence D’Oliveiro wrote:
> I said COBOL was (supposedly) designed specifically for “business”
> needs. But those “business” needs soon came to include
> database-intensive applications, for which COBOL was, and remains,
> completely unsuited.
COBOL is probably one of those languages with the highest percentage
using a database.

If we adjust the above to be relational databases, then COBOL is still
very much used.

It works.

> For an example of what I mean, how would you do the COBOL equivalent of what I can express in a single Python statement:
> 
>      filter_clause = " and ".join \
>        (
>          "%s = %s" % (field_name, format_sql_value(params[field_name]))
>          for field_name in field_names
>          if params[field_name] != ""
>        )
> 
> (That is, filter the query on fields where the user entered a value, not on those where the value was left blank.)


You are mixing two issues here:
1) handling a variable number of conditions in the SQL
2) handling the values

Re 2)

Escape function is not a good solution. Always parameters.
And Python DB API 2.0 supports parameters fine - execute
with placeholders in SQL and an array with parameters.

Re 1)

There are two well known solutions.

Single static SQL using the coalesce trick and sending over
NULL for not used parameters.

Building dynamic SQL with placeholders and just sending
over the parameters used.

(COBOL embedded SQL may lean heavily toward the first
solution)

Arne








More information about the Info-vax mailing list