首页 > 解决方案 > 验证输入参数的功能

问题描述

定义了验证输入参数的方法:

`validate_paramaters{[Date;Code;CodeType;Param]
 if[ not (14h=abs[type[Date]]);
      [
           .log.info["\tError - Exiting function - Date is not of the correct type"];
           : `$"Error - Date is not of the correct type"
         ]
       ];
if[ not (11h=abs[type[Code]]);
         [
           .log.info["\tError - Exiting function - Code is not of the correct type"];
           : `$"Error - Code is not of the correct type"
         ]
       ];
if[ not (-11h=type[CodeType]);
         [
           .log.info["\tError - Exiting function - CodeType is not of the correct type"];
           : $"Error - CodeType is not of the correct type"
         ]
       ];
:`validated

}`

但是现在 CodeType 的类型增加了更多:

 -11h=type[CodeType] `also can be` 99h=type[CodeType]

请给我一个指导,我现在如何验证 CodeType

标签: kdb

解决方案


替换你not (-11h=type[CodeType])not any -11 99h in type CodeType

关键字in允许您将 CodeType 的类型与数字类型列表进行比较。这将返回一个布尔列表。例如:

q)CodeType:`sample`dictionary!`a`b
q)-11 99h in type CodeType
01b

如果列表的任何成员为 True,则any前面的返回 a 。1b

q)any -11 99h in type CodeType
1b

最后,如果 CodeType 不是上述类型之一,您似乎会抛出错误,因此我们将在这一切前面加上not.


推荐阅读