[Info-vax] Better languages than BASIC
Lawrence D'Oliveiro
ldo at nz.invalid
Thu Jan 11 23:47:38 EST 2024
On Thu, 11 Jan 2024 22:38:55 -0500, bill wrote:
> And string handling is every bit as good as any other language.
Here, in Python, is the kind of dynamically-varying filter criteria I
did for a search function in one application. Note the inclusion of
field match checks only for fields where the user entered something:
conditions = \
(
list
( # free-text fields
"%(name)s like %(value)s"
%
{
"name" : field[0],
"value" :
sql_string("%" + escape_sql_wild(params.getvalue(field[1])) + "%"),
}
for field in
(
("make", "search_make"),
("model", "search_model"),
("details", "search_details"),
... etc ...
)
if params.getvalue(field[1]) != ""
)
+
list
( # date fields
"("
+
" or ".join
(
"%(name)s %(op)s %(value)s"
%
{
"name" : field[0],
"op" : op[0],
"value" : sql_string(params.getvalue(field[1])),
}
for op in
(
("<", "lt"),
("=", "eq"),
(">", "gt"),
)
if get_checkbox("%(name)s[%(op)s]" % {"name" : field[1], "op" : op[1]})
)
+
")"
for field in
(
("when_purchased", "search_when_purchased"),
("warranty_expiry", "search_warranty_expiry"),
)
if reduce
(
operator.__or__,
(
get_checkbox("%(name)s[%(op)s]" % {"name" : field[1], "op" : op})
for op in ("lt", "eq", "gt")
)
)
)
)
Expanding the list of conditions into the SQL query:
found_items = get_records \
(
table_name = "items",
fields =
(
"make", "model", "details", ... etc ...
),
condition = " and ".join(conditions),
extra = "order by make, model, inventory_nr"
)
Have you ever managed anything similar in COBOL?
More information about the Info-vax
mailing list