project BLF > class Business Component > method ApiQueryFilterPrepare
Description
This method contains generic code for parsing the input filter criteria for API queries in table tFilter.
PreCondition
This method is made public so it can be called from the API query procedures, but it should not be called from anywhere else.
Parameters
icTables | input | character | tables in the query |
tFilter | input-output | temp-table | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
unused
program code (program1/business.p)
/* Convert any equality match on an alternate key into an equality match on the primary key. */
/* BLF-3750 */
/* Before introduction of data objects the ak_ programs were expecting string values to be enquoted. */
/* With data objects this is no longer the case, so the ak_ programs now must be run before enquoting string values. */
do viFcCount2 = num-entries(icTables,"|") to 1 by -1:
vcProcName = "ref_int/ak_" + lc(entry(1,entry(viFcCount2,icTables,"|"))).
if search(vcProcName + ".r") <> ?
or search(vcProcName + ".p") <> ?
then do:
run value (vcProcName + ".p")
(input viSessionID,
input entry(viFcCount2,icTables,"|"),
input-output dataset tFilter by-reference,
output viFcReturnSuper).
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.
end.
end.
/* Unkown value would make the entire for each statement unkown value. */
for each tFilter where tFilter.tcParameterValue = ? on error undo, throw:
tFilter.tcParameterValue = "".
end.
/* Look for matches without wildcards and make them more performant. */
for each tFilter where tFilter.tcDataType = "c":U on error undo, throw:
if tFilter.tcOperator = "matches":U
and index(tFilter.tcParameterValue,".":U) = 0
then do:
if index(tFilter.tcParameterValue,"*":U) = 0
then assign tFilter.tcOperator = "=":U.
else if index(tFilter.tcParameterValue,"*":U) = length(tFilter.tcParameterValue,"CHARACTER":U)
then assign tFilter.tcOperator = "begins":U
tFilter.tcParameterValue = substring(tFilter.tcParameterValue,1,length(tFilter.tcParameterValue,"CHARACTER":U) - 1,"CHARACTER":U).
end.
tFilter.tcParameterValue = <M-1 EnQuote (input tFilter.tcParameterValue (icToQuote)) in business>.
end.
/* Make sure parameter value is not empty. (This would cause syntax errors in the for each statement.) */
for each tFilter where tFilter.tcParameterValue = "" on error undo, throw:
tFilter.tcParameterValue = "?":U.
end.
/* Support can-do operator on other data types than string. */
for each tFilter where
tFilter.tcOperator = "can-do" and
tFilter.tcDataType <> "c" on error undo, throw:
do viFcCount2 = num-entries(tFilter.tcParameterValue) to 1 by -1:
create bFilter.
assign bFilter.tcBusinessFieldName = tFilter.tcBusinessFieldName
bFilter.tcDataType = tFilter.tcDataType
bFilter.tcOperator = "="
bFilter.tcParameterValue = entry(viFcCount2,tFilter.tcParameterValue).
end.
delete tFilter.
end.
/* Convert public string format for dates (YYYYMMDD) into progress syntax. */
for each tFilter where
tFilter.tcDataType = "t":U and
tFilter.tcParameterValue <> "today":U and
tFilter.tcParameterValue <> "?":U on error undo, throw:
tFilter.tcParameterValue = "date(":U + substring(tFilter.tcParameterValue,5,2,"CHARACTER":U) +
",":U + substring(tFilter.tcParameterValue,7,2,"CHARACTER":U) +
",":U + substring(tFilter.tcParameterValue,1,4,"CHARACTER":U) + ")":U.
end.